Skip to content

Commit

Permalink
Merge branch 'gdemay/fix-nonce-workload' into 'rc--2023-11-15_23-00'
Browse files Browse the repository at this point in the history
fix: ensure nonce used for update request is at most 32 bytes

Follow-up on [MR-16066](https://gitlab.com/dfinity-lab/public/ic/-/merge_requests/16066) to ensure that update requests used in `workload_generator` use a nonce of at most 32 bytes. The previously used nonce was some bytes derived from pretty-printing a timestamp and a counter. The new nonce is the SHA2-256 of the previous bytes so that the result is guaranteed to be 32 bytes. 

See merge request dfinity-lab/public/ic!16167
  • Loading branch information
gregorydemay committed Nov 17, 2023
2 parents 27ff924 + 72d5d5a commit d73659a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rs/workload_generator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DEPENDENCIES = [
"//rs/canister_client",
"//rs/canister_client/sender",
"//rs/config",
"//rs/crypto/sha2",
"//rs/monitoring/metrics",
"//rs/http_endpoints/metrics",
"//rs/test_utilities/identity",
Expand Down
1 change: 1 addition & 0 deletions rs/workload_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ backoff = "0.3.0"
ic-canister-client = { path = "../canister_client" }
ic-canister-client-sender = { path = "../canister_client/sender" }
ic-config = { path = "../config" }
ic-crypto-sha2 = { path = "../crypto/sha2" }
ic-ic00-types = { path = "../types/ic00_types" }
ic-metrics = { path = "../monitoring/metrics" }
ic-http-endpoints-metrics = { path = "../http_endpoints/metrics" }
Expand Down
5 changes: 3 additions & 2 deletions rs/workload_generator/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,15 @@ impl Engine {
arg: Vec<u8>,
n: usize,
) -> bool {
let nonce = plan.nonce.clone();
let nonce =
ic_crypto_sha2::Sha256::hash(&format!("inc {} {}", plan.nonce.clone(), n).into_bytes());
let deadline = Instant::now() + agent.ingress_timeout;
let (content, request_id) = prepare_update(
&agent.sender,
&plan.canister_id,
method,
arg,
format!("inc {} {}", nonce, n).into_bytes(),
nonce.to_vec(),
expiry_time_from_now(),
agent.sender_field.clone(),
)
Expand Down

0 comments on commit d73659a

Please sign in to comment.