Skip to content

Commit 0f18bf0

Browse files
committed
chore(test-suite): gateway-stress updates for v0.10
1 parent a0f04a0 commit 0f18bf0

File tree

11 files changed

+162
-95
lines changed

11 files changed

+162
-95
lines changed

test-suite/gateway-stress/Cargo.lock

Lines changed: 86 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-suite/gateway-stress/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "gateway-stress"
3-
version = "0.9.0"
3+
version = "0.10.0"
44
edition = "2024"
55

66
[dependencies]
7-
fhevm_gateway_bindings = { git = "https://github.com/zama-ai/fhevm.git", tag = "v0.9.11", default-features = false }
8-
gateway-sdk = { git = "https://github.com/zama-ai/fhevm.git", tag = "v0.9.11", default-features = false }
7+
fhevm_gateway_bindings = { git = "https://github.com/zama-ai/fhevm.git", tag = "v0.10.0-4", default-features = false }
8+
gateway-sdk = { git = "https://github.com/zama-ai/fhevm.git", tag = "v0.10.0-4", default-features = false }
99

10-
alloy = { version = "1.0", default-features = false, features = [
10+
alloy = { version = "1.0.38", default-features = false, features = [
1111
"essentials",
1212
"json-rpc",
1313
"reqwest-rustls-tls",
@@ -54,7 +54,7 @@ tokio = { version = "1.47.0", default-features = false, features = [
5454
] }
5555
tokio-util = "0.7.15"
5656
tracing = "0.1.41"
57-
tracing-subscriber = { version = "0.3.19", default-features = true, features = [
57+
tracing-subscriber = { version = "0.3.20", default-features = true, features = [
5858
"env-filter",
5959
] }
6060
rand = "0.9.2"

test-suite/gateway-stress/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ decrypts at the time of writing), at a given frequency and for a specified durat
1313
- [Stress testing](#stress-testing)
1414
- [Benchmarking](#benchmarking)
1515
- [Tracing](#tracing)
16+
- [Local e2e setup](#local-e2e-setup)
1617
- [Bonus: Generating handles via coprocessor stress-test-generator](#bonus-generating-handles-via-coprocessor-stress-test-generator)
1718

1819
## Build
@@ -119,6 +120,20 @@ RUST_LOG="gateway_stress=debug,alloy=debug" ./gateway-stress -c config/config.to
119120
RUST_LOG="debug" ./gateway-stress -c config/config.toml gw -t public
120121
```
121122

123+
## Local e2e setup
124+
125+
To play with the tool in a local e2e setup, follow these steps:
126+
- from the root of the `fehvm` repo: `cd test-suite/fhevm`
127+
- deploy the e2e setup using the `./fhevm-cli deploy` command
128+
- if using `fhevm` version > 0.10.0, fund the account the tool is using with ERC20 token (use the same private key as in [gateway-stress config](../gateway-stress/config/config.toml)):
129+
- `docker run --env-file env/staging/.env.gateway-mocked-payment.local -e TX_SENDER_PRIVATE_KEY="0x24af7cb5f6cd0f29df22c6f3e2f18ee5b3949f5a489a14b0674bef8fd89bfe91" -it --rm --network fhevm_default ghcr.io/zama-ai/fhevm/gateway-contracts:v0.10.0-4 "npx hardhat task:setTxSenderMockedPayment"`
130+
- generate ciphertext handles
131+
- `cd ../../coprocessor/fhevm-engine/stress-test-generator; rm -f data/handles_for*; EVGEN_SCENARIO=data/minitest_003_generate_handles_for_decryption.csv make run; cd -` (see [this section](#bonus-generating-handles-via-coprocessor-stress-test-generator) for more details)
132+
- update the `[[public_ct]]` and `[[user_ct]]` sections of the [gateway-stress config](../gateway-stress/config/config.toml) with one of the value of the `../../coprocessor/fhevm-engine/stress-test-generator/data/handles_for_pub_decryption` and `../../coprocessor/fhevm-engine/stress-test-generator/data/handles_for_usr_decryption` files
133+
- run the tool. Ex:
134+
- `cd ../gateway_stress`
135+
- `cargo run -- -c config/config.toml -p 1 -d "1s" gw -t user`
136+
122137
## Bonus: Generating handles via coprocessor stress-test-generator
123138

124139
To use this tool, you would need already existing handles to decrypt. You could use coprocessor's

test-suite/gateway-stress/config/config.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ parallel_requests = 1
1616
# # Defaults to false, if set to true, then `tests_interval` is ignored
1717
# sequential = false
1818

19-
# The ciphertexts to use for user decryptions
20-
[[user_ct]]
19+
# The ciphertexts to use for public decryptions
20+
[[public_ct]]
2121
# The handle used of the ciphertext
22-
handle = "0xc07ece86473ba540de4dbef63889f0233f5481dd7dff00000000000030390500"
23-
# The digest of the ciphertext
22+
handle = "0x1f9b79819b2581535a80f267862540c5eac12ee504ff00000000000030390500"
23+
# The digest of the ciphertext. Used only for DB tests, it can be a dummy value otherwise
2424
digest = "0x134b4f97e70be0e71a26e38304e096fd370188b5c11b89feb8a61176b73d1b5a"
2525

26-
# The ciphertexts to use for public decryptions
27-
[[public_ct]]
26+
# The ciphertexts to use for user decryptions
27+
[[user_ct]]
2828
# The handle used of the ciphertext
29-
handle = "0x57539e394a6ae1dc4b4f1b00248777ce265eb6d08bff00000000000030390500"
30-
# The digest of the ciphertext
29+
handle = "0x1d01f83fd1b14d84e9b8680790d993d6848aeb6462ff00000000000030390500"
30+
# The digest of the ciphertext. Used only for DB tests, it can be a dummy value otherwise
3131
digest = "0x134b4f97e70be0e71a26e38304e096fd370188b5c11b89feb8a61176b73d1b5a"
3232

3333
# Configuration section for stress test using the Gateway chain
@@ -42,7 +42,7 @@ host_chain_id = 12345
4242
gateway_chain_id = 54321
4343

4444
# Address of the Decryption contract (required)
45-
decryption_address = "0xF0bFB159C7381F7CB332586004d8247252C5b816"
45+
decryption_address = "0x35760912360E875DA50D40a74305575c23D55783"
4646

4747
# Wallet's private key as a hex string
4848
private_key = "24af7cb5f6cd0f29df22c6f3e2f18ee5b3949f5a489a14b0674bef8fd89bfe91"

test-suite/gateway-stress/src/blockchain/manager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,11 @@ impl GatewayTestManager {
210210
for result in results.iter() {
211211
w.serialize(result)?;
212212
}
213+
w.flush()?;
213214
}
214215
let bench_result = BenchAverageResult::new(bench_record, results);
215216
average_results_writer.serialize(bench_result)?;
217+
average_results_writer.flush()?;
216218
}
217219

218220
Ok(())

test-suite/gateway-stress/src/blockchain/nonce_manager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use async_trait::async_trait;
88
use futures::lock::{Mutex, MutexGuard};
99
use std::collections::{BTreeSet, HashMap, hash_map::Entry};
1010
use std::sync::Arc;
11-
use tracing::debug;
11+
use tracing::trace;
1212

1313
/// A robust, in-memory nonce manager for a scalable transaction engine.
1414
#[derive(Clone, Debug, Default)]
@@ -52,12 +52,12 @@ impl ZamaNonceManager {
5252
let nonce_to_use =
5353
if let Some(available_nonce) = account.available_nonces.iter().next().copied() {
5454
account.available_nonces.remove(&available_nonce);
55-
debug!(%address, nonce = available_nonce, "Reusing available nonce");
55+
trace!(%address, nonce = available_nonce, "Reusing available nonce");
5656
available_nonce
5757
} else {
5858
let next = account.next_nonce;
5959
account.next_nonce += 1;
60-
debug!(%address, nonce = next, "Using next sequential nonce");
60+
trace!(%address, nonce = next, "Using next sequential nonce");
6161
next
6262
};
6363

test-suite/gateway-stress/src/db/connector.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl DbConnector {
107107

108108
for reqs in requests.chunks(self.insertion_chunk_size) {
109109
let mut query_builder = QueryBuilder::new(
110-
"INSERT INTO public_decryption_requests(decryption_id, sns_ct_materials, extra_data) ",
110+
"INSERT INTO public_decryption_requests(decryption_id, sns_ct_materials, extra_data, otlp_context) ",
111111
);
112112
query_builder.push_values(reqs, |mut bind, req| {
113113
bind.push_bind(req.decryptionId.to_le_bytes_vec())
@@ -117,7 +117,8 @@ impl DbConnector {
117117
.map(SnsCiphertextMaterialDbItem::from)
118118
.collect::<Vec<_>>(),
119119
)
120-
.push_bind(req.extraData.to_vec());
120+
.push_bind(req.extraData.to_vec())
121+
.push_bind(alloy::hex::decode(EMPTY_OTLP_CONTEXT_SERIALIZED_HEX).unwrap());
121122
});
122123
query_builder.push(" RETURNING decryption_id, created_at");
123124

@@ -141,7 +142,7 @@ impl DbConnector {
141142

142143
for reqs in requests.chunks(self.insertion_chunk_size) {
143144
let mut query_builder = QueryBuilder::new("
144-
INSERT INTO user_decryption_requests(decryption_id, sns_ct_materials, user_address, public_key, extra_data)
145+
INSERT INTO user_decryption_requests(decryption_id, sns_ct_materials, user_address, public_key, extra_data, otlp_context)
145146
");
146147
query_builder.push_values(reqs, |mut bind, req| {
147148
bind.push_bind(req.decryptionId.to_le_bytes_vec())
@@ -153,7 +154,8 @@ impl DbConnector {
153154
)
154155
.push_bind(req.userAddress.to_vec())
155156
.push_bind(req.publicKey.to_vec())
156-
.push_bind(req.extraData.to_vec());
157+
.push_bind(req.extraData.to_vec())
158+
.push_bind(alloy::hex::decode(EMPTY_OTLP_CONTEXT_SERIALIZED_HEX).unwrap());
157159
});
158160
query_builder.push(" RETURNING decryption_id, created_at");
159161

@@ -175,3 +177,5 @@ impl Display for DbConnector {
175177
write!(f, "DbConnector {}", self.name)
176178
}
177179
}
180+
181+
const EMPTY_OTLP_CONTEXT_SERIALIZED_HEX: &str = "0000000000000000";

test-suite/gateway-stress/src/db/manager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,11 @@ impl DatabaseTestManager {
175175
for result in results.iter() {
176176
w.serialize(result)?;
177177
}
178+
w.flush()?;
178179
}
179180
let bench_result = BenchAverageResult::new(bench_record, results);
180181
average_results_writer.serialize(bench_result)?;
182+
average_results_writer.flush()?;
181183
}
182184

183185
if !args.skip_clear_db {

test-suite/gateway-stress/src/decryption/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod user;
55
pub use public::{init_public_decryption_response_listener, public_decryption_burst};
66
pub use user::{init_user_decryption_response_listener, user_decryption_burst};
77

8+
use crate::blockchain::manager::AppProvider;
89
use alloy::{
910
primitives::{B256, LogData, U256},
1011
providers::Provider,
@@ -15,8 +16,7 @@ use std::time::Duration;
1516
use tokio::sync::mpsc::UnboundedSender;
1617
use tracing::{debug, trace, warn};
1718

18-
use crate::blockchain::manager::AppProvider;
19-
19+
pub const BURST_WAIT_TIMEOUT: Duration = Duration::from_mins(5);
2020
pub const EVENT_LISTENER_POLLING: Duration = Duration::from_millis(500);
2121

2222
fn extract_id_from_receipt<F>(

test-suite/gateway-stress/src/decryption/public.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::{
22
blockchain::manager::AppProvider,
33
config::Config,
44
decryption::{
5-
BurstResult, EVENT_LISTENER_POLLING, extract_id_from_receipt, send_tx_with_retries,
5+
BURST_WAIT_TIMEOUT, BurstResult, EVENT_LISTENER_POLLING, extract_id_from_receipt,
6+
send_tx_with_retries,
67
},
78
};
89
use alloy::{
@@ -27,7 +28,7 @@ use tokio::{
2728
mpsc::{self, UnboundedReceiver, UnboundedSender},
2829
},
2930
task::JoinSet,
30-
time::Instant,
31+
time::{Instant, timeout},
3132
};
3233
use tracing::{Instrument, debug, error, trace};
3334

@@ -55,12 +56,15 @@ where
5556
debug!("Start of the burst...");
5657
let (id_sender, id_receiver) = mpsc::unbounded_channel();
5758
let wait_response_task = tokio::spawn(
58-
wait_for_burst_responses(
59-
burst_index,
60-
response_listener,
61-
id_receiver,
62-
config.clone(),
63-
responses_pb,
59+
timeout(
60+
BURST_WAIT_TIMEOUT,
61+
wait_for_burst_responses(
62+
burst_index,
63+
response_listener,
64+
id_receiver,
65+
config.clone(),
66+
responses_pb,
67+
),
6468
)
6569
.in_current_span(),
6670
);
@@ -88,8 +92,9 @@ where
8892
drop(id_sender); // Dropping last sender so `wait_for_responses` can exit properly
8993
let res = wait_response_task
9094
.await
91-
.inspect_err(|e| error!("{e}"))?
92-
.inspect_err(|e| error!("{e}"))?;
95+
.inspect_err(|e| error!("Burst wait task panic: {e}"))?
96+
.inspect_err(|_| error!("Bust wait timed out"))?
97+
.inspect_err(|e| error!("Burst wait error: {e}"))?;
9398
debug!("Successfully received all responses of the burst!");
9499
Ok(res)
95100
}

0 commit comments

Comments
 (0)