Skip to content

Commit 328d946

Browse files
authored
Merge branch 'develop' into fix/signerdb-pubkey
2 parents d008360 + 3fa16aa commit 328d946

File tree

1 file changed

+52
-49
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+52
-49
lines changed

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ impl MultipleMinerTest {
713713
sortdb: &SortitionDB,
714714
cause: TenureChangeCause,
715715
timeout_secs: u64,
716-
) -> Result<(), String> {
716+
) -> Result<serde_json::Value, String> {
717717
let start = Instant::now();
718718
let stacks_height_before = self.get_peer_stacks_tip_height();
719719
self.mine_bitcoin_blocks_and_confirm(sortdb, 1, timeout_secs)?;
@@ -941,7 +941,8 @@ fn wait_for_tenure_change_tx(
941941
timeout_secs: u64,
942942
cause: TenureChangeCause,
943943
expected_height: u64,
944-
) -> Result<(), String> {
944+
) -> Result<serde_json::Value, String> {
945+
let mut result = None;
945946
wait_for(timeout_secs, || {
946947
let blocks = test_observer::get_blocks();
947948
for block in blocks {
@@ -956,14 +957,16 @@ fn wait_for_tenure_change_tx(
956957
if let TransactionPayload::TenureChange(payload) = &parsed.payload {
957958
if payload.cause == cause {
958959
info!("Found tenure change transaction: {parsed:?}");
960+
result = Some(block);
959961
return Ok(true);
960962
}
961963
}
962964
}
963965
}
964966
}
965967
Ok(false)
966-
})
968+
})?;
969+
Ok(result.unwrap())
967970
}
968971

969972
/// Waits for a block proposal to be observed in the test_observer stackerdb chunks at the expected height
@@ -3166,16 +3169,19 @@ fn tenure_extend_with_other_transactions() {
31663169
let idle_timeout = Duration::from_secs(30);
31673170
let mut signer_test: SignerTest<SpawnedSigner> = SignerTest::new_with_config_modifications(
31683171
num_signers,
3169-
vec![(sender_addr, send_amt + send_fee)],
3172+
vec![(sender_addr, (send_amt + send_fee) * 2)],
31703173
|config| {
31713174
config.tenure_idle_timeout = idle_timeout;
3175+
config.tenure_idle_timeout_buffer = Duration::from_secs(1);
31723176
},
31733177
|config| {
31743178
config.miner.tenure_extend_cost_threshold = 0;
31753179
},
31763180
None,
31773181
None,
31783182
);
3183+
let miner_sk = signer_test.running_nodes.conf.miner.mining_key.unwrap();
3184+
let miner_pk = StacksPublicKey::from_private(&miner_sk);
31793185
let http_origin = format!("http://{}", &signer_test.running_nodes.conf.node.rpc_bind);
31803186

31813187
signer_test.boot_to_epoch_3();
@@ -3186,65 +3192,62 @@ fn tenure_extend_with_other_transactions() {
31863192
info!("Pause miner so it doesn't propose a block before the tenure extend");
31873193
TEST_MINE_STALL.set(true);
31883194

3189-
// Submit a transaction to be included with the tenure extend
3195+
info!("---- Trigger a block proposal but pause its broadcast ----");
3196+
let stacks_tip_height = get_chain_info(&signer_test.running_nodes.conf).stacks_tip_height;
3197+
// Submit a transaction to force a response from signers that indicate that the tenure extend timeout is exceeded
3198+
let mut sender_nonce = 0;
31903199
let transfer_tx = make_stacks_transfer(
31913200
&sender_sk,
3192-
0,
3201+
sender_nonce,
31933202
send_fee,
31943203
signer_test.running_nodes.conf.burnchain.chain_id,
31953204
&recipient,
31963205
send_amt,
31973206
);
3198-
let _tx = submit_tx(&http_origin, &transfer_tx);
3207+
let _ = submit_tx(&http_origin, &transfer_tx);
3208+
sender_nonce += 1;
3209+
3210+
TEST_BROADCAST_PROPOSAL_STALL.set(vec![miner_pk]);
3211+
TEST_MINE_STALL.set(false);
31993212

32003213
info!("---- Wait for tenure extend timeout ----");
3214+
sleep_ms(idle_timeout.as_millis() as u64 + 5);
32013215

3202-
sleep_ms(idle_timeout.as_millis() as u64 + 1000);
3216+
TEST_MINE_STALL.set(true);
3217+
TEST_BROADCAST_PROPOSAL_STALL.set(vec![]);
3218+
// Submit a transaction to be included with the tenure extend
3219+
let transfer_tx = make_stacks_transfer(
3220+
&sender_sk,
3221+
sender_nonce,
3222+
send_fee,
3223+
signer_test.running_nodes.conf.burnchain.chain_id,
3224+
&recipient,
3225+
send_amt,
3226+
);
3227+
let to_find = submit_tx(&http_origin, &transfer_tx);
32033228

3204-
info!("---- Resume miner to propose a block with the tenure extend ----");
3229+
info!("---- Resume miner to propose a block with the tenure extend and transfer tx ----");
32053230
TEST_MINE_STALL.set(false);
3206-
32073231
// Now, wait for a block with a tenure extend
3208-
wait_for(idle_timeout.as_secs() + 10, || {
3209-
let blocks = test_observer::get_blocks();
3210-
let last_block = &blocks.last().unwrap();
3211-
let transactions = last_block["transactions"].as_array().unwrap();
3212-
let (first_tx, other_txs) = transactions.split_first().unwrap();
3213-
let raw_tx = first_tx["raw_tx"].as_str().unwrap();
3214-
let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap();
3215-
let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap();
3216-
let found_tenure_extend = match &parsed.payload {
3217-
TransactionPayload::TenureChange(payload)
3218-
if payload.cause == TenureChangeCause::Extended =>
3219-
{
3220-
info!("Found tenure extend transaction: {parsed:?}");
3221-
true
3222-
}
3223-
_ => false,
3224-
};
3225-
if found_tenure_extend {
3226-
let found_transfer = other_txs.iter().any(|tx| {
3227-
let raw_tx = tx["raw_tx"].as_str().unwrap();
3228-
let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap();
3229-
let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap();
3230-
match &parsed.payload {
3231-
TransactionPayload::TokenTransfer(..) => true,
3232-
_ => false,
3233-
}
3234-
});
3235-
if found_transfer {
3236-
info!("Found transfer transaction");
3237-
Ok(true)
3238-
} else {
3239-
Err("No transfer transaction found together with the tenure extend".to_string())
3240-
}
3241-
} else {
3242-
info!("No tenure change transaction found");
3243-
Ok(false)
3244-
}
3245-
})
3232+
let block = wait_for_tenure_change_tx(
3233+
idle_timeout.as_secs() + 10,
3234+
TenureChangeCause::Extended,
3235+
stacks_tip_height + 2,
3236+
)
32463237
.expect("Timed out waiting for a block with a tenure extend");
3247-
3238+
let transactions = block["transactions"].as_array().unwrap();
3239+
assert!(
3240+
transactions.len() > 1,
3241+
"Expected at least 2 transactions in the block"
3242+
);
3243+
assert!(
3244+
transactions.iter().any(|tx| {
3245+
let tx = tx.as_object().unwrap();
3246+
let txid = tx["txid"].as_str().unwrap();
3247+
txid[2..] == to_find
3248+
}),
3249+
"Failed to find the transfer tx in the block"
3250+
);
32483251
signer_test.shutdown();
32493252
}
32503253

0 commit comments

Comments
 (0)