From 760d10f523b2fce63e53d9c9e54029cad0592301 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Mon, 21 Oct 2024 13:25:25 -0400 Subject: [PATCH 1/9] add loggers for block number checks --- .../src/helpers/tests.rs | 16 +++++++++++++--- .../threshold-signature-server/src/user/tests.rs | 14 ++++++++++---- .../tests/register_sign_reshare_sign.rs | 14 ++++++++++---- .../tests/sign_eth_tx.rs | 14 ++++++++++---- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/crates/threshold-signature-server/src/helpers/tests.rs b/crates/threshold-signature-server/src/helpers/tests.rs index ef3b37c7e..2ac8c0e4b 100644 --- a/crates/threshold-signature-server/src/helpers/tests.rs +++ b/crates/threshold-signature-server/src/helpers/tests.rs @@ -358,18 +358,20 @@ pub async fn store_program_and_register( (verifying_key, program_hash) } - /// Do a network jumpstart DKG pub async fn do_jump_start( api: &OnlineClient, rpc: &LegacyRpcMethods, pair: sr25519::Pair, + other_chains: &Vec>, ) { run_to_block(rpc, 2).await; + log_all_block_numbers(other_chains).await; let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1; put_jumpstart_request_on_chain(api, rpc, pair).await; run_to_block(rpc, block_number + 1).await; + log_all_block_numbers(other_chains).await; let selected_validators_query = entropy::storage().registry().jumpstart_dkg(block_number); let validators_info = @@ -393,6 +395,10 @@ pub async fn do_jump_start( let response_results = join_all(results).await; + for response_result in response_results { + assert_eq!(response_result.unwrap().text().await.unwrap(), ""); + } + let jump_start_status_query = entropy::storage().staking_extension().jump_start_progress(); let mut jump_start_status = query_chain(api, rpc, jump_start_status_query.clone(), None) .await @@ -414,8 +420,12 @@ pub async fn do_jump_start( } assert_eq!(format!("{:?}", jump_start_status), format!("{:?}", JumpStartStatus::Done)); - for response_result in response_results { - assert_eq!(response_result.unwrap().text().await.unwrap(), ""); +} + +async fn log_all_block_numbers(other_chains: &Vec>) { + for (i, other_chain) in other_chains.into_iter().enumerate() { + let block_number = other_chain.chain_get_header(None).await.unwrap().unwrap().number; + tracing::info!("Block number for rpc `{}`: `{}`", i, block_number); } } diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index 111efb54f..e96b1ca4b 100644 --- a/crates/threshold-signature-server/src/user/tests.rs +++ b/crates/threshold-signature-server/src/user/tests.rs @@ -906,12 +906,18 @@ async fn test_jumpstart_network() { spawn_testing_validators(ChainSpecType::Integration).await; let force_authoring = true; - let substrate_context = &test_node_process_testing_state(force_authoring).await[0]; + let substrate_context = &test_node_process_testing_state(force_authoring).await; - let api = get_api(&substrate_context.ws_url).await.unwrap(); - let rpc = get_rpc(&substrate_context.ws_url).await.unwrap(); + let api = get_api(&substrate_context[0].ws_url).await.unwrap(); + let rpc = get_rpc(&substrate_context[0].ws_url).await.unwrap(); + + let mut other_rpcs = vec![]; + for context in substrate_context { + let next_rpc = get_rpc(&context.ws_url).await.unwrap(); + other_rpcs.push(next_rpc) + } - do_jump_start(&api, &rpc, AccountKeyring::Alice.pair()).await; + do_jump_start(&api, &rpc, AccountKeyring::Alice.pair(), &other_rpcs).await; let client = reqwest::Client::new(); let response_key = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3001).await; diff --git a/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs b/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs index 3f6660aa6..261c102d6 100644 --- a/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs +++ b/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs @@ -51,13 +51,19 @@ async fn integration_test_register_sign_reshare_sign() { spawn_testing_validators(ChainSpecType::Integration).await; let force_authoring = true; - let substrate_context = &test_node_process_testing_state(force_authoring).await[0]; + let substrate_context = &test_node_process_testing_state(force_authoring).await; - let api = get_api(&substrate_context.ws_url).await.unwrap(); - let rpc = get_rpc(&substrate_context.ws_url).await.unwrap(); + let api = get_api(&substrate_context[0].ws_url).await.unwrap(); + let rpc = get_rpc(&substrate_context[0].ws_url).await.unwrap(); + + let mut other_rpcs = vec![]; + for context in substrate_context { + let next_rpc = get_rpc(&context.ws_url).await.unwrap(); + other_rpcs.push(next_rpc) + } // First jumpstart the network - do_jump_start(&api, &rpc, AccountKeyring::Alice.pair()).await; + do_jump_start(&api, &rpc, AccountKeyring::Alice.pair(), &other_rpcs).await; // Now register an account let account_owner = AccountKeyring::Ferdie.pair(); diff --git a/crates/threshold-signature-server/tests/sign_eth_tx.rs b/crates/threshold-signature-server/tests/sign_eth_tx.rs index e8564065f..c9ae1238d 100644 --- a/crates/threshold-signature-server/tests/sign_eth_tx.rs +++ b/crates/threshold-signature-server/tests/sign_eth_tx.rs @@ -53,13 +53,19 @@ async fn integration_test_sign_eth_tx() { spawn_testing_validators(ChainSpecType::Integration).await; let force_authoring = true; - let substrate_context = &test_node_process_testing_state(force_authoring).await[0]; + let substrate_context = &test_node_process_testing_state(force_authoring).await; - let api = get_api(&substrate_context.ws_url).await.unwrap(); - let rpc = get_rpc(&substrate_context.ws_url).await.unwrap(); + let api = get_api(&substrate_context[0].ws_url).await.unwrap(); + let rpc = get_rpc(&substrate_context[0].ws_url).await.unwrap(); + + let mut other_rpcs = vec![]; + for context in substrate_context { + let next_rpc = get_rpc(&context.ws_url).await.unwrap(); + other_rpcs.push(next_rpc) + } // First jumpstart the network - do_jump_start(&api, &rpc, AccountKeyring::Alice.pair()).await; + do_jump_start(&api, &rpc, AccountKeyring::Alice.pair(), &other_rpcs).await; let account_owner = AccountKeyring::Ferdie.pair(); let signature_request_author = AccountKeyring::One; From c631d27cc2eac68cabc15c9c2d0886161ed1bb13 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Mon, 21 Oct 2024 13:54:25 -0400 Subject: [PATCH 2/9] fmt --- crates/threshold-signature-server/src/helpers/tests.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/threshold-signature-server/src/helpers/tests.rs b/crates/threshold-signature-server/src/helpers/tests.rs index 2ac8c0e4b..1c156be3c 100644 --- a/crates/threshold-signature-server/src/helpers/tests.rs +++ b/crates/threshold-signature-server/src/helpers/tests.rs @@ -363,7 +363,7 @@ pub async fn do_jump_start( api: &OnlineClient, rpc: &LegacyRpcMethods, pair: sr25519::Pair, - other_chains: &Vec>, + other_chains: &[LegacyRpcMethods], ) { run_to_block(rpc, 2).await; log_all_block_numbers(other_chains).await; @@ -383,6 +383,7 @@ pub async fn do_jump_start( let client = reqwest::Client::new(); let mut results = vec![]; + log_all_block_numbers(other_chains).await; for validator_info in validators_info { let url = format!( "http://{}/generate_network_key", @@ -392,6 +393,7 @@ pub async fn do_jump_start( results.push(client.post(url).body(onchain_user_request.clone().encode()).send()) } } + log_all_block_numbers(other_chains).await; let response_results = join_all(results).await; @@ -422,8 +424,8 @@ pub async fn do_jump_start( assert_eq!(format!("{:?}", jump_start_status), format!("{:?}", JumpStartStatus::Done)); } -async fn log_all_block_numbers(other_chains: &Vec>) { - for (i, other_chain) in other_chains.into_iter().enumerate() { +async fn log_all_block_numbers(other_chains: &[LegacyRpcMethods]) { + for (i, other_chain) in other_chains.iter().enumerate() { let block_number = other_chain.chain_get_header(None).await.unwrap().unwrap().number; tracing::info!("Block number for rpc `{}`: `{}`", i, block_number); } From 91b3d0c83adc0f853375522728e48c29aa9e2b84 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Mon, 28 Oct 2024 10:07:16 -0400 Subject: [PATCH 3/9] add run to all blocks --- .../tests/register_sign_reshare_sign.rs | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs b/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs index cad941af9..59ef99e24 100644 --- a/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs +++ b/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs @@ -120,7 +120,7 @@ async fn integration_test_register_sign_reshare_sign() { ); // Do a reshare - do_reshare(&api, &rpc).await; + do_reshare(&api, &rpc, &other_rpcs).await; // Sign a message again let recoverable_signature = test_client::sign( @@ -148,7 +148,11 @@ async fn integration_test_register_sign_reshare_sign() { ); } -async fn do_reshare(api: &OnlineClient, rpc: &LegacyRpcMethods) { +async fn do_reshare( + api: &OnlineClient, + rpc: &LegacyRpcMethods, + rpcs: &[LegacyRpcMethods], +) { // Get current signers let signer_query = entropy::storage().staking_extension().signers(); let signer_stash_accounts = query_chain(&api, &rpc, signer_query, None).await.unwrap().unwrap(); @@ -167,13 +171,12 @@ async fn do_reshare(api: &OnlineClient, rpc: &LegacyRpcMethods, rpc: &LegacyRpcMethods>(), ) .await; - for response_result in response_results { + for (i, response_result) in response_results.into_iter().enumerate() { + dbg!(ips[i]); assert_eq!(response_result.unwrap().text().await.unwrap(), ""); } @@ -221,3 +225,12 @@ async fn do_reshare(api: &OnlineClient, rpc: &LegacyRpcMethods = new_signer_stash_accounts.iter().map(|s| s.0).collect(); assert_ne!(old, new); } + +pub async fn run_to_all_blocks(rpcs: &[LegacyRpcMethods], block_run: u32) { + let mut current_block = 0; + for rpc in rpcs { + while current_block < block_run { + current_block = rpc.chain_get_header(None).await.unwrap().unwrap().number; + } + } +} From 79333f8642ddf2a3f93d23aa3b31fe1668144096 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 21 Nov 2024 20:43:06 -0500 Subject: [PATCH 4/9] more logging --- crates/threshold-signature-server/src/helpers/tests.rs | 2 +- crates/threshold-signature-server/src/validator/api.rs | 2 ++ .../tests/register_sign_reshare_sign.rs | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/threshold-signature-server/src/helpers/tests.rs b/crates/threshold-signature-server/src/helpers/tests.rs index 1c156be3c..079fe1924 100644 --- a/crates/threshold-signature-server/src/helpers/tests.rs +++ b/crates/threshold-signature-server/src/helpers/tests.rs @@ -424,7 +424,7 @@ pub async fn do_jump_start( assert_eq!(format!("{:?}", jump_start_status), format!("{:?}", JumpStartStatus::Done)); } -async fn log_all_block_numbers(other_chains: &[LegacyRpcMethods]) { +pub async fn log_all_block_numbers(other_chains: &[LegacyRpcMethods]) { for (i, other_chain) in other_chains.iter().enumerate() { let block_number = other_chain.chain_get_header(None).await.unwrap().unwrap().number; tracing::info!("Block number for rpc `{}`: `{}`", i, block_number); diff --git a/crates/threshold-signature-server/src/validator/api.rs b/crates/threshold-signature-server/src/validator/api.rs index aff360cb5..2abc1a351 100644 --- a/crates/threshold-signature-server/src/validator/api.rs +++ b/crates/threshold-signature-server/src/validator/api.rs @@ -266,6 +266,8 @@ pub async fn validate_new_reshare( // we subtract 1 as the message info is coming from the previous block if latest_block_number.saturating_sub(1) != chain_data.block_number { + tracing::info!("latest_block_number: {}", latest_block_number.saturating_sub(1)); + tracing::info!("chain_data.block_number: {}", chain_data.block_number); return Err(ValidatorErr::StaleData); } diff --git a/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs b/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs index 59ef99e24..12cc52726 100644 --- a/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs +++ b/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs @@ -33,7 +33,7 @@ use entropy_testing_utils::{ }, spawn_testing_validators, test_node_process_testing_state, ChainSpecType, }; -use entropy_tss::helpers::tests::{do_jump_start, initialize_test_logger, run_to_block}; +use entropy_tss::helpers::tests::{do_jump_start, initialize_test_logger, run_to_block, log_all_block_numbers}; use futures::future::join_all; use serial_test::serial; use sp_core::{Encode, Pair}; @@ -175,6 +175,7 @@ async fn do_reshare( run_to_all_blocks(rpcs, block_number).await; // Send the OCW message to all TS servers who don't have a chain node let client = reqwest::Client::new(); + log_all_block_numbers(rpcs).await; let response_results = join_all( ips.iter() .map(|port| { From 8a4a730b420c28154e853eac1367801c6092df32 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 21 Nov 2024 20:44:07 -0500 Subject: [PATCH 5/9] yaml --- .github/workflows/build-and-run-node-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-run-node-test.yaml b/.github/workflows/build-and-run-node-test.yaml index 0c28340f6..020d2e41e 100644 --- a/.github/workflows/build-and-run-node-test.yaml +++ b/.github/workflows/build-and-run-node-test.yaml @@ -34,6 +34,6 @@ jobs: run: | pushd node cargo build --all-targets --release -j $(nproc) - cargo test --all-targets --release + cargo test --all-targets --release -- --test integration_test_register_sign_reshare_sign --nocapture yarn --cwd ../crates/protocol/nodejs-test test cargo test -p entropy-tss --release --features=test_helpers -F wasm_test test_wasm From 00a8e7ad4c8ded27635fcb5d7635feed1f4712a3 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 21 Nov 2024 20:55:26 -0500 Subject: [PATCH 6/9] yaml --- .github/workflows/build-and-run-node-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-run-node-test.yaml b/.github/workflows/build-and-run-node-test.yaml index 020d2e41e..7deeb6bb7 100644 --- a/.github/workflows/build-and-run-node-test.yaml +++ b/.github/workflows/build-and-run-node-test.yaml @@ -34,6 +34,6 @@ jobs: run: | pushd node cargo build --all-targets --release -j $(nproc) - cargo test --all-targets --release -- --test integration_test_register_sign_reshare_sign --nocapture + cargo test -p entropy-tss --all-targets --release -- --test integration_test_register_sign_reshare_sign --nocapture yarn --cwd ../crates/protocol/nodejs-test test cargo test -p entropy-tss --release --features=test_helpers -F wasm_test test_wasm From a142fb685347fcc67b50f6d9ca48b99c2a8e3c7c Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 21 Nov 2024 20:56:51 -0500 Subject: [PATCH 7/9] yaml --- .github/workflows/build-and-run-node-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-run-node-test.yaml b/.github/workflows/build-and-run-node-test.yaml index 7deeb6bb7..0c28340f6 100644 --- a/.github/workflows/build-and-run-node-test.yaml +++ b/.github/workflows/build-and-run-node-test.yaml @@ -34,6 +34,6 @@ jobs: run: | pushd node cargo build --all-targets --release -j $(nproc) - cargo test -p entropy-tss --all-targets --release -- --test integration_test_register_sign_reshare_sign --nocapture + cargo test --all-targets --release yarn --cwd ../crates/protocol/nodejs-test test cargo test -p entropy-tss --release --features=test_helpers -F wasm_test test_wasm From 9f123b63cf535db46ad7ac080230d6627bd6cb99 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 21 Nov 2024 21:14:03 -0500 Subject: [PATCH 8/9] yaml --- .github/workflows/build-and-run-node-test.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-and-run-node-test.yaml b/.github/workflows/build-and-run-node-test.yaml index 0c28340f6..abc505b38 100644 --- a/.github/workflows/build-and-run-node-test.yaml +++ b/.github/workflows/build-and-run-node-test.yaml @@ -33,7 +33,5 @@ jobs: - name: Run `cargo build && cargo test` run: | pushd node - cargo build --all-targets --release -j $(nproc) - cargo test --all-targets --release - yarn --cwd ../crates/protocol/nodejs-test test - cargo test -p entropy-tss --release --features=test_helpers -F wasm_test test_wasm + cd crates/threshold-signature-server + cargo test --release -- --test integration_test_register_sign_reshare_sign --nocapture \ No newline at end of file From 72e904c98fbd555fe9042f562f34c91a830fb972 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Fri, 22 Nov 2024 19:19:59 -0500 Subject: [PATCH 9/9] lint --- .../tests/register_sign_reshare_sign.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs b/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs index 12cc52726..c59d374ab 100644 --- a/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs +++ b/crates/threshold-signature-server/tests/register_sign_reshare_sign.rs @@ -33,7 +33,9 @@ use entropy_testing_utils::{ }, spawn_testing_validators, test_node_process_testing_state, ChainSpecType, }; -use entropy_tss::helpers::tests::{do_jump_start, initialize_test_logger, run_to_block, log_all_block_numbers}; +use entropy_tss::helpers::tests::{ + do_jump_start, initialize_test_logger, log_all_block_numbers, run_to_block, +}; use futures::future::join_all; use serial_test::serial; use sp_core::{Encode, Pair};