Skip to content

Commit 120348a

Browse files
committed
chore: avoid warning from duplicate block-commit
This change ended up being a lot larger than I'd hoped, but with a recent investigation into some networking failures when communicating with the bitcoin node, these warnings were annoying. I'm just trying to reduce false-positive warning logs. The problematic case shows up like this in the logs before this change: ``` INFO [1725975417.732025] [testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs:1634] [miner-block-http://127.0.0.1:35738] Abort attempt to re-submit identical LeaderBlockCommit WARN [1725975417.732029] [testnet/stacks-node/src/neon_node.rs:2759] [miner-block-http://127.0.0.1:35738] Relayer: Failed to submit Bitcoin transaction ```
1 parent 9cce325 commit 120348a

File tree

10 files changed

+135
-109
lines changed

10 files changed

+135
-109
lines changed

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

Lines changed: 76 additions & 67 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ impl BurnchainController for MocknetController {
168168
operation: BlockstackOperationType,
169169
_op_signer: &mut BurnchainOpSigner,
170170
_attempt: u64,
171-
) -> Option<Txid> {
171+
) -> Result<Txid, BurnchainControllerError> {
172172
let txid = operation.txid();
173173
self.queued_operations.push_back(operation);
174-
Some(txid)
174+
Ok(txid)
175175
}
176176

177177
fn sync(

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@ use super::operations::BurnchainOpSigner;
1919
pub enum Error {
2020
CoordinatorClosed,
2121
IndexerError(burnchains::Error),
22+
BurnchainError,
23+
MaxFeeRateExceeded,
24+
IdenticalOperation,
25+
NoUtxos,
26+
TransactionSubmissionFailed,
27+
SerializerError,
2228
}
2329

2430
impl fmt::Display for Error {
2531
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2632
match self {
2733
Error::CoordinatorClosed => write!(f, "ChainsCoordinator closed"),
2834
Error::IndexerError(ref e) => write!(f, "Indexer error: {:?}", e),
35+
Error::BurnchainError => write!(f, "Burnchain error"),
36+
Error::MaxFeeRateExceeded => write!(f, "Max fee rate exceeded"),
37+
Error::IdenticalOperation => write!(f, "Identical operation, not submitting"),
38+
Error::NoUtxos => write!(f, "No UTXOs available"),
39+
Error::TransactionSubmissionFailed => write!(f, "Transaction submission failed"),
40+
Error::SerializerError => write!(f, "Serializer error"),
2941
}
3042
}
3143
}
@@ -45,7 +57,7 @@ pub trait BurnchainController {
4557
operation: BlockstackOperationType,
4658
op_signer: &mut BurnchainOpSigner,
4759
attempt: u64,
48-
) -> Option<Txid>;
60+
) -> Result<Txid, Error>;
4961
fn sync(&mut self, target_block_height_opt: Option<u64>) -> Result<(BurnchainTip, u64), Error>;
5062
fn sortdb_ref(&self) -> &SortitionDB;
5163
fn sortdb_mut(&mut self) -> &mut SortitionDB;

testnet/stacks-node/src/nakamoto_node/relayer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@ impl RelayerThread {
530530
let op = Self::make_key_register_op(vrf_pk, burnchain_tip_consensus_hash, &miner_pkh);
531531

532532
let mut op_signer = self.keychain.generate_op_signer();
533-
if let Some(txid) =
534-
self.bitcoin_controller
535-
.submit_operation(cur_epoch, op, &mut op_signer, 1)
533+
if let Ok(txid) = self
534+
.bitcoin_controller
535+
.submit_operation(cur_epoch, op, &mut op_signer, 1)
536536
{
537537
// advance key registration state
538538
self.last_vrf_key_burn_height = Some(burn_block.block_height);
@@ -1048,8 +1048,8 @@ impl RelayerThread {
10481048
&mut op_signer,
10491049
1,
10501050
)
1051-
.ok_or_else(|| {
1052-
warn!("Failed to submit block-commit bitcoin transaction");
1051+
.map_err(|e| {
1052+
warn!("Failed to submit block-commit bitcoin transaction: {}", e);
10531053
NakamotoNodeError::BurnchainSubmissionFailed
10541054
})?;
10551055

testnet/stacks-node/src/neon_node.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ use super::{BurnchainController, Config, EventDispatcher, Keychain};
213213
use crate::burnchains::bitcoin_regtest_controller::{
214214
addr2str, burnchain_params_from_config, BitcoinRegtestController, OngoingBlockCommit,
215215
};
216-
use crate::burnchains::make_bitcoin_indexer;
216+
use crate::burnchains::{make_bitcoin_indexer, Error as BurnchainControllerError};
217217
use crate::chain_data::MinerStats;
218218
use crate::config::NodeConfig;
219219
use crate::globals::{NeonGlobals as Globals, RelayerDirective};
@@ -2753,16 +2753,21 @@ impl BlockMinerThread {
27532753
} = self.config.get_node_config(false);
27542754

27552755
let res = bitcoin_controller.submit_operation(target_epoch_id, op, &mut op_signer, attempt);
2756-
if res.is_none() {
2757-
self.failed_to_submit_last_attempt = true;
2758-
if !mock_mining {
2759-
warn!("Relayer: Failed to submit Bitcoin transaction");
2760-
return None;
2756+
self.failed_to_submit_last_attempt = match res {
2757+
Ok(_) => false,
2758+
Err(BurnchainControllerError::IdenticalOperation) => {
2759+
info!("Relayer: Block-commit already submitted");
2760+
true
27612761
}
2762-
debug!("Relayer: Mock-mining enabled; not sending Bitcoin transaction");
2763-
} else {
2764-
self.failed_to_submit_last_attempt = false;
2765-
}
2762+
Err(_) if mock_mining => {
2763+
debug!("Relayer: Mock-mining enabled; not sending Bitcoin transaction");
2764+
true
2765+
}
2766+
Err(e) => {
2767+
warn!("Relayer: Failed to submit Bitcoin transaction: {:?}", e);
2768+
true
2769+
}
2770+
};
27662771

27672772
let assembled_block = AssembledAnchorBlock {
27682773
parent_consensus_hash: parent_block_info.parent_consensus_hash,
@@ -3620,7 +3625,7 @@ impl RelayerThread {
36203625
);
36213626

36223627
let mut one_off_signer = self.keychain.generate_op_signer();
3623-
if let Some(txid) =
3628+
if let Ok(txid) =
36243629
self.bitcoin_controller
36253630
.submit_operation(cur_epoch, op, &mut one_off_signer, 1)
36263631
{

testnet/stacks-node/src/run_loop/neon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl RunLoop {
497497
return burnchain_error::ShutdownInitiated;
498498
}
499499
}
500-
Error::IndexerError(_) => {}
500+
_ => {}
501501
}
502502
error!("Burnchain controller stopped: {}", e);
503503
panic!();

testnet/stacks-node/src/tests/epoch_205.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ fn transition_empty_blocks() {
629629
&mut op_signer,
630630
1,
631631
);
632-
assert!(res.is_some(), "Failed to submit block-commit");
632+
assert!(res.is_ok(), "Failed to submit block-commit");
633633
}
634634

635635
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);

testnet/stacks-node/src/tests/epoch_21.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ fn transition_fixes_bitcoin_rigidity() {
678678
&mut miner_signer,
679679
1
680680
)
681-
.is_some(),
681+
.is_ok(),
682682
"Pre-stx operation should submit successfully"
683683
);
684684

@@ -713,7 +713,7 @@ fn transition_fixes_bitcoin_rigidity() {
713713
&mut spender_signer,
714714
1
715715
)
716-
.is_some(),
716+
.is_ok(),
717717
"Transfer operation should submit successfully"
718718
);
719719

@@ -835,7 +835,7 @@ fn transition_fixes_bitcoin_rigidity() {
835835
&mut miner_signer,
836836
1
837837
)
838-
.is_some(),
838+
.is_ok(),
839839
"Pre-stx operation should submit successfully"
840840
);
841841

@@ -866,7 +866,7 @@ fn transition_fixes_bitcoin_rigidity() {
866866
&mut spender_signer,
867867
1
868868
)
869-
.is_some(),
869+
.is_ok(),
870870
"Transfer operation should submit successfully"
871871
);
872872

@@ -1946,7 +1946,7 @@ fn transition_empty_blocks() {
19461946
let mut op_signer = keychain.generate_op_signer();
19471947
let res =
19481948
bitcoin_controller.submit_operation(StacksEpochId::Epoch21, op, &mut op_signer, 1);
1949-
assert!(res.is_some(), "Failed to submit block-commit");
1949+
assert!(res.is_ok(), "Failed to submit block-commit");
19501950
}
19511951

19521952
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,7 @@ fn vote_for_aggregate_key_burn_op() {
28762876
&mut miner_signer,
28772877
1
28782878
)
2879-
.is_some(),
2879+
.is_ok(),
28802880
"Pre-stx operation should submit successfully"
28812881
);
28822882

@@ -2952,7 +2952,7 @@ fn vote_for_aggregate_key_burn_op() {
29522952
&mut signer_burnop_signer,
29532953
1
29542954
)
2955-
.is_some(),
2955+
.is_ok(),
29562956
"Vote for aggregate key operation should submit successfully"
29572957
);
29582958

@@ -3433,7 +3433,7 @@ fn stack_stx_burn_op_integration_test() {
34333433
&mut miner_signer_1,
34343434
1
34353435
)
3436-
.is_some(),
3436+
.is_ok(),
34373437
"Pre-stx operation should submit successfully"
34383438
);
34393439

@@ -3463,7 +3463,7 @@ fn stack_stx_burn_op_integration_test() {
34633463
&mut miner_signer_2,
34643464
1
34653465
)
3466-
.is_some(),
3466+
.is_ok(),
34673467
"Pre-stx operation should submit successfully"
34683468
);
34693469
info!("Submitted 2 pre-stx ops at block {block_height}, mining a few blocks...");
@@ -3604,7 +3604,7 @@ fn stack_stx_burn_op_integration_test() {
36043604
&mut signer_burnop_signer_1,
36053605
1
36063606
)
3607-
.is_some(),
3607+
.is_ok(),
36083608
"Stack STX operation should submit successfully"
36093609
);
36103610

@@ -3631,7 +3631,7 @@ fn stack_stx_burn_op_integration_test() {
36313631
&mut signer_burnop_signer_2,
36323632
1
36333633
)
3634-
.is_some(),
3634+
.is_ok(),
36353635
"Stack STX operation should submit successfully"
36363636
);
36373637

testnet/stacks-node/src/tests/neon_integrations.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ fn stx_transfer_btc_integration_test() {
19341934
&mut miner_signer,
19351935
1
19361936
)
1937-
.is_some(),
1937+
.is_ok(),
19381938
"Pre-stx operation should submit successfully"
19391939
);
19401940

@@ -1964,7 +1964,7 @@ fn stx_transfer_btc_integration_test() {
19641964
&mut spender_signer,
19651965
1
19661966
)
1967-
.is_some(),
1967+
.is_ok(),
19681968
"Transfer operation should submit successfully"
19691969
);
19701970
// should be elected in the same block as the transfer, so balances should be unchanged.
@@ -2215,7 +2215,7 @@ fn stx_delegate_btc_integration_test() {
22152215
&mut miner_signer,
22162216
1
22172217
)
2218-
.is_some(),
2218+
.is_ok(),
22192219
"Pre-stx operation should submit successfully"
22202220
);
22212221

@@ -2244,7 +2244,7 @@ fn stx_delegate_btc_integration_test() {
22442244
&mut spender_signer,
22452245
1
22462246
)
2247-
.is_some(),
2247+
.is_ok(),
22482248
"Delegate operation should submit successfully"
22492249
);
22502250

@@ -2507,7 +2507,7 @@ fn stack_stx_burn_op_test() {
25072507
&mut miner_signer_1,
25082508
1
25092509
)
2510-
.is_some(),
2510+
.is_ok(),
25112511
"Pre-stx operation should submit successfully"
25122512
);
25132513

@@ -2528,7 +2528,7 @@ fn stack_stx_burn_op_test() {
25282528
&mut miner_signer_2,
25292529
1
25302530
)
2531-
.is_some(),
2531+
.is_ok(),
25322532
"Pre-stx operation should submit successfully"
25332533
);
25342534
info!("Submitted 2 pre-stx ops at block {block_height}, mining a few blocks...");
@@ -2614,7 +2614,7 @@ fn stack_stx_burn_op_test() {
26142614
&mut spender_signer_1,
26152615
1
26162616
)
2617-
.is_some(),
2617+
.is_ok(),
26182618
"Stack STX operation with some signer key should submit successfully"
26192619
);
26202620

@@ -2642,7 +2642,7 @@ fn stack_stx_burn_op_test() {
26422642
&mut spender_signer_2,
26432643
1
26442644
)
2645-
.is_some(),
2645+
.is_ok(),
26462646
"Stack STX operation with no signer key should submit successfully"
26472647
);
26482648

@@ -2949,7 +2949,7 @@ fn vote_for_aggregate_key_burn_op_test() {
29492949
&mut miner_signer,
29502950
1
29512951
)
2952-
.is_some(),
2952+
.is_ok(),
29532953
"Pre-stx operation should submit successfully"
29542954
);
29552955

@@ -3006,7 +3006,7 @@ fn vote_for_aggregate_key_burn_op_test() {
30063006
&mut spender_signer,
30073007
1
30083008
)
3009-
.is_some(),
3009+
.is_ok(),
30103010
"Vote for aggregate key operation should submit successfully"
30113011
);
30123012

0 commit comments

Comments
 (0)