Skip to content

Commit

Permalink
fix: wait for new block proposal to be found
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Oct 21, 2024
1 parent 3fd883d commit e8a5673
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
4 changes: 0 additions & 4 deletions stacks-signer/src/v0/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ pub static TEST_PAUSE_BLOCK_BROADCAST: std::sync::Mutex<Option<bool>> = std::syn
/// Skip broadcasting the block to the network
pub static TEST_SKIP_BLOCK_BROADCAST: std::sync::Mutex<Option<bool>> = std::sync::Mutex::new(None);

#[cfg(any(test, feature = "testing"))]
/// Skip checking a block proposal's sortition
pub static TEST_SKIP_SORTITION_CHECK: std::sync::Mutex<Option<bool>> = std::sync::Mutex::new(None);

/// The stacks signer registered for the reward cycle
#[derive(Debug)]
pub struct Signer {
Expand Down
59 changes: 32 additions & 27 deletions testnet/stacks-node/src/tests/signer/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ fn miner_wait_for_proposal() {
vec![(sender_addr.clone(), (send_amt + send_fee) * 5)],
|_signer_conf| {},
|neon_conf| {
neon_conf.miner.wait_for_proposals_secs = 20;
neon_conf.miner.wait_for_proposals_secs = 30;
},
None,
None,
Expand All @@ -641,8 +641,6 @@ fn miner_wait_for_proposal() {
.map(StacksPublicKey::from_private)
.collect();

let short_timeout = Duration::from_secs(30);

// Make all but 1 signers ignore. We need 1 signer to view it so that they save
// it in their SignerDB. If a signer has never seen a block, they won't
// handle other signer's block responses, which is what causes the signer to
Expand Down Expand Up @@ -685,31 +683,39 @@ fn miner_wait_for_proposal() {
})
.expect("Timed out waiting for block proposal");

let block_proposal = test_observer::get_stackerdb_chunks()
.into_iter()
.flat_map(|chunk| chunk.modified_slots)
.filter_map(|chunk| SignerMessage::consensus_deserialize(&mut chunk.data.as_slice()).ok())
.filter_map(|message| {
let SignerMessage::BlockProposal(proposal) = message else {
return None;
};
let has_transfer = proposal.block.txs.iter().any(|tx| {
let TransactionPayload::TokenTransfer(recipient_principal, ..) = tx.clone().payload
else {
return false;
let mut block_proposal: Option<BlockProposal> = None;

wait_for(30, || {
block_proposal = test_observer::get_stackerdb_chunks()
.into_iter()
.flat_map(|chunk| chunk.modified_slots)
.filter_map(|chunk| {
SignerMessage::consensus_deserialize(&mut chunk.data.as_slice()).ok()
})
.filter_map(|message| {
let SignerMessage::BlockProposal(proposal) = message else {
return None;
};
recipient_principal == recipient_addr.into()
});
if has_transfer {
Some(proposal)
} else {
None
}
})
.last()
.expect("Expected a block proposal to be found");
let has_transfer = proposal.block.txs.iter().any(|tx| {
let TransactionPayload::TokenTransfer(recipient_principal, ..) =
tx.clone().payload
else {
return false;
};
recipient_principal == recipient_addr.into()
});
if has_transfer {
Some(proposal)
} else {
None
}
})
.last();
Ok(block_proposal.is_some())
})
.expect("Timed out waiting for block proposal");

let block = block_proposal.block;
let block = block_proposal.unwrap().block;

// First propose a block to the signers that does not have the correct consensus hash or BitVec. This should be rejected BEFORE
// the block is submitted to the node for validation.
Expand All @@ -719,7 +725,6 @@ fn miner_wait_for_proposal() {
"signer_sig_hash" => %block_signer_signature_hash_1,
);

signer_test.propose_block(block.clone(), short_timeout);
info!("------ Mining BTC Block ------");
next_block_and_wait(
&mut signer_test.running_nodes.btc_regtest_controller,
Expand Down

0 comments on commit e8a5673

Please sign in to comment.