Skip to content

Commit bbea1c7

Browse files
committed
wip: update tx replay tests to work with failsafe
1 parent 772798b commit bbea1c7

File tree

3 files changed

+467
-795
lines changed

3 files changed

+467
-795
lines changed

testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,6 +2833,17 @@ impl BitcoinRPCRequest {
28332833
BitcoinRPCRequest::send(config, payload)
28342834
}
28352835

2836+
pub fn get_chain_tips(config: &Config) -> RPCResult<serde_json::Value> {
2837+
let payload = BitcoinRPCRequest {
2838+
method: "getchaintips".to_string(),
2839+
params: vec![],
2840+
id: "stacks".to_string(),
2841+
jsonrpc: "2.0".to_string(),
2842+
};
2843+
2844+
BitcoinRPCRequest::send(config, payload)
2845+
}
2846+
28362847
pub fn send(config: &Config, payload: BitcoinRPCRequest) -> RPCResult<serde_json::Value> {
28372848
let request = BitcoinRPCRequest::build_rpc_request(config, &payload);
28382849
let timeout = Duration::from_secs(u64::from(config.burnchain.timeout));

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use libsigner::v0::messages::{
3232
use libsigner::v0::signer_state::MinerState;
3333
use libsigner::{BlockProposal, SignerEntries, SignerEventTrait};
3434
use serde::{Deserialize, Serialize};
35+
use stacks::burnchains::Txid;
3536
use stacks::chainstate::coordinator::comm::CoordinatorChannels;
3637
use stacks::chainstate::nakamoto::signer_set::NakamotoSigners;
3738
use stacks::chainstate::nakamoto::NakamotoBlock;
@@ -192,6 +193,9 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
192193
let (mut naka_conf, _miner_account) =
193194
naka_neon_integration_conf(snapshot_name.map(|n| n.as_bytes()));
194195

196+
naka_conf.miner.activated_vrf_key_path =
197+
Some(format!("{}/vrf_key", naka_conf.node.working_dir));
198+
195199
node_config_modifier(&mut naka_conf);
196200

197201
// Add initial balances to the config
@@ -1023,6 +1027,20 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
10231027
})
10241028
}
10251029

1030+
pub fn wait_for_replay_set_eq(&self, timeout: u64, expected_txids: Vec<String>) {
1031+
self.wait_for_signer_state_check(timeout, |state| {
1032+
let Some(replay_set) = state.get_tx_replay_set() else {
1033+
return Ok(false);
1034+
};
1035+
let txids = replay_set
1036+
.iter()
1037+
.map(|tx| tx.txid().to_hex())
1038+
.collect::<Vec<_>>();
1039+
Ok(txids == expected_txids)
1040+
})
1041+
.expect("Timed out waiting for replay set to be equal to expected txids");
1042+
}
1043+
10261044
/// Replace the test's configured signer st
10271045
pub fn replace_signers(
10281046
&mut self,
@@ -1509,6 +1527,31 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
15091527
.send_message_with_retry::<SignerMessage>(accepted.into())
15101528
.expect("Failed to send accept signature");
15111529
}
1530+
1531+
/// Get the txid of the parent block commit transaction for the given miner
1532+
pub fn get_parent_block_commit_txid(&self, miner_pk: &StacksPublicKey) -> Option<Txid> {
1533+
let Some(confirmed_utxo) = self
1534+
.running_nodes
1535+
.btc_regtest_controller
1536+
.get_all_utxos(&miner_pk)
1537+
.into_iter()
1538+
.find(|utxo| utxo.confirmations == 0)
1539+
else {
1540+
return None;
1541+
};
1542+
let unconfirmed_txid = Txid::from_bitcoin_tx_hash(&confirmed_utxo.txid);
1543+
let unconfirmed_tx = self
1544+
.running_nodes
1545+
.btc_regtest_controller
1546+
.get_raw_transaction(&unconfirmed_txid);
1547+
let parent_txid = unconfirmed_tx
1548+
.input
1549+
.get(0)
1550+
.expect("First input should exist")
1551+
.previous_output
1552+
.txid;
1553+
Some(Txid::from_bitcoin_tx_hash(&parent_txid))
1554+
}
15121555
}
15131556

15141557
fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(

0 commit comments

Comments
 (0)