Skip to content

Commit b2217f0

Browse files
committed
refactor: remove attempt argument from build_leader_block_commit_tx
1 parent 1fec25e commit b2217f0

File tree

1 file changed

+59
-36
lines changed

1 file changed

+59
-36
lines changed

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

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,6 @@ impl BitcoinRegtestController {
15091509
epoch_id: StacksEpochId,
15101510
payload: LeaderBlockCommitOp,
15111511
signer: &mut BurnchainOpSigner,
1512-
_attempt: u64,
15131512
) -> Result<Transaction, BurnchainControllerError> {
15141513
// Are we currently tracking an operation?
15151514
if self.ongoing_block_commit.is_none() || !self.allow_rbf {
@@ -2069,7 +2068,7 @@ impl BitcoinRegtestController {
20692068
) -> Result<SerializedTx, BurnchainControllerError> {
20702069
let transaction = match operation {
20712070
BlockstackOperationType::LeaderBlockCommit(payload) => {
2072-
self.build_leader_block_commit_tx(epoch_id, payload, op_signer, attempt)
2071+
self.build_leader_block_commit_tx(epoch_id, payload, op_signer)
20732072
}
20742073
BlockstackOperationType::LeaderKeyRegister(payload) => {
20752074
self.build_leader_key_register_tx(epoch_id, payload, op_signer, attempt)
@@ -3517,12 +3516,7 @@ mod tests {
35173516
commit_op.burn_fee = 110_000;
35183517

35193518
let tx = btc_controller
3520-
.build_leader_block_commit_tx(
3521-
StacksEpochId::Epoch31,
3522-
commit_op.clone(),
3523-
&mut op_signer,
3524-
0,
3525-
)
3519+
.build_leader_block_commit_tx(StacksEpochId::Epoch31, commit_op.clone(), &mut op_signer)
35263520
.expect("Build leader block commit should work");
35273521

35283522
assert!(op_signer.is_disposed());
@@ -3575,20 +3569,14 @@ mod tests {
35753569
let commit_op = utils::create_templated_commit_op();
35763570

35773571
let _first_tx_ok = btc_controller
3578-
.build_leader_block_commit_tx(
3579-
StacksEpochId::Epoch31,
3580-
commit_op.clone(),
3581-
&mut op_signer,
3582-
0,
3583-
)
3572+
.build_leader_block_commit_tx(StacksEpochId::Epoch31, commit_op.clone(), &mut op_signer)
35843573
.expect("At first, building leader block commit should work");
35853574

35863575
// re-submitting same commit while previous it is not confirmed by the burnchain
35873576
let resubmit = btc_controller.build_leader_block_commit_tx(
35883577
StacksEpochId::Epoch31,
35893578
commit_op,
35903579
&mut op_signer,
3591-
0,
35923580
);
35933581

35943582
assert!(resubmit.is_err());
@@ -3626,12 +3614,7 @@ mod tests {
36263614
let commit_op = utils::create_templated_commit_op();
36273615

36283616
let first_tx_ok = btc_controller
3629-
.build_leader_block_commit_tx(
3630-
StacksEpochId::Epoch31,
3631-
commit_op.clone(),
3632-
&mut op_signer,
3633-
0,
3634-
)
3617+
.build_leader_block_commit_tx(StacksEpochId::Epoch31, commit_op.clone(), &mut op_signer)
36353618
.expect("At first, building leader block commit should work");
36363619

36373620
utils::mine_tx(&btc_controller, first_tx_ok); // Now tx is confirmed
@@ -3641,7 +3624,6 @@ mod tests {
36413624
StacksEpochId::Epoch31,
36423625
commit_op,
36433626
&mut op_signer,
3644-
0,
36453627
);
36463628

36473629
assert!(resubmit.is_err());
@@ -3681,12 +3663,7 @@ mod tests {
36813663
commit_op.burn_fee = 110_000;
36823664

36833665
let first_tx_ok = btc_controller
3684-
.build_leader_block_commit_tx(
3685-
StacksEpochId::Epoch31,
3686-
commit_op.clone(),
3687-
&mut op_signer,
3688-
0,
3689-
)
3666+
.build_leader_block_commit_tx(StacksEpochId::Epoch31, commit_op.clone(), &mut op_signer)
36903667
.expect("At first, building leader block commit should work");
36913668

36923669
let first_txid = first_tx_ok.txid();
@@ -3700,7 +3677,7 @@ mod tests {
37003677
commit_op.burn_fee += 10;
37013678

37023679
let rbf_tx = btc_controller
3703-
.build_leader_block_commit_tx(StacksEpochId::Epoch31, commit_op.clone(), &mut signer, 0)
3680+
.build_leader_block_commit_tx(StacksEpochId::Epoch31, commit_op.clone(), &mut signer)
37043681
.expect("Commit tx should be rbf-ed");
37053682

37063683
assert!(op_signer.is_disposed());
@@ -3761,12 +3738,7 @@ mod tests {
37613738
commit_op.burn_fee = 110_000;
37623739

37633740
let _first_tx_ok = btc_controller
3764-
.build_leader_block_commit_tx(
3765-
StacksEpochId::Epoch31,
3766-
commit_op.clone(),
3767-
&mut op_signer,
3768-
0,
3769-
)
3741+
.build_leader_block_commit_tx(StacksEpochId::Epoch31, commit_op.clone(), &mut op_signer)
37703742
.expect("At first, building leader block commit should work");
37713743

37723744
//re-gen signer othewise fails because it will be disposed during previous commit tx.
@@ -3775,7 +3747,7 @@ mod tests {
37753747
commit_op.burn_fee += 10;
37763748

37773749
let rbf_tx = btc_controller
3778-
.build_leader_block_commit_tx(StacksEpochId::Epoch31, commit_op.clone(), &mut signer, 0)
3750+
.build_leader_block_commit_tx(StacksEpochId::Epoch31, commit_op.clone(), &mut signer)
37793751
.expect("Commit tx should be rbf-ed");
37803752

37813753
assert!(op_signer.is_disposed());
@@ -3800,4 +3772,55 @@ mod tests {
38003772
assert_eq!(op_commit_2, rbf_tx.output[2]);
38013773
assert_eq!(op_change, rbf_tx.output[3]);
38023774
}
3775+
3776+
/// Tests related to `BitcoinRegtestController::make_operation_tx`
3777+
mod make_operation {
3778+
use super::*;
3779+
3780+
#[test]
3781+
#[ignore]
3782+
fn test_make_operation_leader_block_commit_tx_ok() {
3783+
if env::var("BITCOIND_TEST") != Ok("1".into()) {
3784+
return;
3785+
}
3786+
3787+
let keychain = utils::create_keychain();
3788+
let miner_pubkey = keychain.get_pub_key();
3789+
let mut op_signer = keychain.generate_op_signer();
3790+
3791+
let mut config = utils::create_config();
3792+
config.burnchain.local_mining_public_key = Some(miner_pubkey.to_hex());
3793+
3794+
let mut btcd_controller = BitcoinCoreController::new(config.clone());
3795+
btcd_controller
3796+
.start_bitcoind()
3797+
.expect("bitcoind should be started!");
3798+
3799+
let mut btc_controller = BitcoinRegtestController::new(config.clone(), None);
3800+
btc_controller
3801+
.connect_dbs()
3802+
.expect("Dbs initialization required!");
3803+
btc_controller.bootstrap_chain(101); // now, one utxo exists
3804+
3805+
let mut commit_op = utils::create_templated_commit_op();
3806+
commit_op.sunset_burn = 5_500;
3807+
commit_op.burn_fee = 110_000;
3808+
3809+
let tx = btc_controller
3810+
.make_operation_tx(
3811+
StacksEpochId::Epoch31,
3812+
BlockstackOperationType::LeaderBlockCommit(commit_op),
3813+
&mut op_signer,
3814+
0,
3815+
)
3816+
.expect("Build leader block commit should work");
3817+
3818+
assert!(op_signer.is_disposed());
3819+
3820+
assert_eq!(
3821+
"01000000014d9e9dc7d126446e90dd013f023937eba9cb2c88f4d12707400a3ede994a62c5000000008b483045022100e4f934cf20a42ae5709f96505b73ad4e7ab19f41931940257089bfe6935840780220503af1cafd02e42ed008ad473dd619ee591d6926333413275168cf2697ce91430141044227d7e5c0997524ce011c126f0464d43e7518872a9b1ad29436ac5142d73eab5fb48d764676900fc2fac56917412114bf7dfafe51f715cf466fe0c1a6c69d11fdffffff047c15000000000000536a4c5054335be88c3d30cb59a142f83de3b27f897a43bbb0f13316911bb98a3229973dae32afd5b9f21bc1f40f24e2c101ecd13c55b8619e5e03dad81de2c62a1cc1d8c1b375000008a300010000059800015ad8d60000000000001976a914000000000000000000000000000000000000000088acd8d60000000000001976a914000000000000000000000000000000000000000088acd4e3032a010000001976a9145e52c53cb96b55f0e3d719adbca21005bc54cb2e88ac00000000",
3822+
tx.to_hex()
3823+
);
3824+
}
3825+
}
38033826
}

0 commit comments

Comments
 (0)