From d13419323f6794e4cd7add2011837aafee115a7b Mon Sep 17 00:00:00 2001 From: Brice Dobry Date: Fri, 28 Jun 2024 14:01:46 -0400 Subject: [PATCH] feat: make miner retry when signature collection times out --- .../stacks-node/src/nakamoto_node/miner.rs | 8 +- testnet/stacks-node/src/tests/signer/mod.rs | 1 + testnet/stacks-node/src/tests/signer/v0.rs | 90 ++++++++++++++++++- 3 files changed, 92 insertions(+), 7 deletions(-) diff --git a/testnet/stacks-node/src/nakamoto_node/miner.rs b/testnet/stacks-node/src/nakamoto_node/miner.rs index 421702bcfb..edd26243d2 100644 --- a/testnet/stacks-node/src/nakamoto_node/miner.rs +++ b/testnet/stacks-node/src/nakamoto_node/miner.rs @@ -248,12 +248,8 @@ impl BlockMinerThread { ) { Ok(x) => x, Err(e) => { - error!( - "Unrecoverable error while gathering signatures: {e:?}. Ending tenure." - ); - return Err(NakamotoNodeError::MiningFailure( - ChainstateError::MinerAborted, - )); + error!("Error while gathering signatures: {e:?}. Will try mining again."); + continue; } }; diff --git a/testnet/stacks-node/src/tests/signer/mod.rs b/testnet/stacks-node/src/tests/signer/mod.rs index 794c00f05a..0ac82f4365 100644 --- a/testnet/stacks-node/src/tests/signer/mod.rs +++ b/testnet/stacks-node/src/tests/signer/mod.rs @@ -118,6 +118,7 @@ impl + Send + 'static, T: SignerEventTrait + 'static> SignerTest = SignerTest::new( + num_signers, + vec![(sender_addr.clone(), send_amt + send_fee)], + ); + let http_origin = format!("http://{}", &signer_test.running_nodes.conf.node.rpc_bind); + + signer_test.boot_to_epoch_3(); + + signer_test.mine_nakamoto_block(Duration::from_secs(30)); + + // Stall block validation so the signers will not be able to sign. + TEST_VALIDATE_STALL.lock().unwrap().replace(true); + + let proposals_before = signer_test + .running_nodes + .nakamoto_blocks_proposed + .load(Ordering::SeqCst); + let blocks_before = signer_test + .running_nodes + .nakamoto_blocks_mined + .load(Ordering::SeqCst); + + // submit a tx so that the miner will mine a block + let sender_nonce = 0; + let transfer_tx = + make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + submit_tx(&http_origin, &transfer_tx); + + info!("Submitted transfer tx and waiting for block proposal"); + loop { + let blocks_proposed = signer_test + .running_nodes + .nakamoto_blocks_proposed + .load(Ordering::SeqCst); + if blocks_proposed > proposals_before { + break; + } + std::thread::sleep(Duration::from_millis(100)); + } + + info!("Block proposed, verifying that it is not processed"); + + // Wait 20 seconds to be sure that the timeout has occurred + std::thread::sleep(Duration::from_secs(20)); + assert_eq!( + signer_test + .running_nodes + .nakamoto_blocks_mined + .load(Ordering::SeqCst), + blocks_before + ); + + // Disable the stall and wait for the block to be processed on retry + info!("Disable the stall and wait for the block to be processed"); + TEST_VALIDATE_STALL.lock().unwrap().replace(false); + loop { + let blocks_mined = signer_test + .running_nodes + .nakamoto_blocks_mined + .load(Ordering::SeqCst); + if blocks_mined > blocks_before { + break; + } + std::thread::sleep(Duration::from_millis(100)); + } + + signer_test.shutdown(); +}