Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loggers for block number checks #1122

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/build-and-run-node-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 15 additions & 3 deletions crates/threshold-signature-server/src/helpers/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
pair: sr25519::Pair,
other_chains: &[LegacyRpcMethods<EntropyConfig>],
) {
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 =
Expand All @@ -381,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",
Expand All @@ -390,9 +393,14 @@ 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;

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
Expand All @@ -414,8 +422,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(), "");
}

pub async fn log_all_block_numbers(other_chains: &[LegacyRpcMethods<EntropyConfig>]) {
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);
}
}

Expand Down
14 changes: 10 additions & 4 deletions crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,12 +907,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;
Expand Down
2 changes: 2 additions & 0 deletions crates/threshold-signature-server/src/validator/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
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};
Expand All @@ -51,13 +53,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[0].ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context[0].ws_url).await.unwrap();

let api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.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();
Expand Down Expand Up @@ -114,7 +122,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(
Expand Down Expand Up @@ -142,7 +150,11 @@ async fn integration_test_register_sign_reshare_sign() {
);
}

async fn do_reshare(api: &OnlineClient<EntropyConfig>, rpc: &LegacyRpcMethods<EntropyConfig>) {
async fn do_reshare(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
rpcs: &[LegacyRpcMethods<EntropyConfig>],
) {
// 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();
Expand All @@ -161,13 +173,13 @@ async fn do_reshare(api: &OnlineClient<EntropyConfig>, rpc: &LegacyRpcMethods<En
new_signers: reshare_data.new_signers.into_iter().map(|s| s.to_vec()).collect(),
block_number: block_number - 1,
};

run_to_block(&rpc, block_number).await;
let ips = vec![3002, 3003, 3004];
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(
[3002, 3003, 3004]
.iter()
ips.iter()
.map(|port| {
client
.post(format!("http://127.0.0.1:{}/validator/reshare", port))
Expand All @@ -177,7 +189,8 @@ async fn do_reshare(api: &OnlineClient<EntropyConfig>, rpc: &LegacyRpcMethods<En
.collect::<Vec<_>>(),
)
.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(), "");
}

Expand Down Expand Up @@ -215,3 +228,12 @@ async fn do_reshare(api: &OnlineClient<EntropyConfig>, rpc: &LegacyRpcMethods<En
let new: HashSet<[u8; 32]> = new_signer_stash_accounts.iter().map(|s| s.0).collect();
assert_ne!(old, new);
}

pub async fn run_to_all_blocks(rpcs: &[LegacyRpcMethods<EntropyConfig>], 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;
}
}
}
14 changes: 10 additions & 4 deletions crates/threshold-signature-server/tests/sign_eth_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading