Skip to content

Commit 5c6780c

Browse files
committed
refactor: introduce TxReplayScope struct, #6184
1 parent efe0f60 commit 5c6780c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

stacks-signer/src/v0/signer_state.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,17 @@ pub struct NewBurnBlock {
8888
pub consensus_hash: ConsensusHash,
8989
}
9090

91-
/// Scope of Tx Replay in terms of Burn block boundaries
92-
/// - tuple.0 is the fork originating the tx replay,
93-
/// - tuple.1 is the canonical burnchain tip when Tx Replay begun
94-
pub type TxReplayScopeOpt = Option<(NewBurnBlock, NewBurnBlock)>;
91+
/// Represents the scope of Tx Replay in terms of burn block boundaries.
92+
#[derive(Debug)]
93+
pub struct TxReplayScope {
94+
/// The burn block where the fork that originated the transaction replay began.
95+
pub fork_origin: NewBurnBlock,
96+
/// The canonical burn chain tip at the time the transaction replay started.
97+
pub past_tip: NewBurnBlock,
98+
}
99+
100+
/// Optional `TxReplayScope`, representing the potential absence of a replay scope.
101+
pub type TxReplayScopeOpt = Option<TxReplayScope>;
95102

96103
impl LocalStateMachine {
97104
/// Initialize a local state machine by querying the local stacks-node
@@ -936,7 +943,7 @@ impl LocalStateMachine {
936943
"prior_state_machine.burn_block" => %prior_state_machine.burn_block,
937944
);
938945

939-
let (fork_origin, past_tip) = match tx_replay_scope {
946+
let scope = match tx_replay_scope {
940947
Some(scope) => scope,
941948
None => {
942949
warn!("Tx Replay: BUG! Scope cannot be None while in replay mode!");
@@ -945,7 +952,7 @@ impl LocalStateMachine {
945952
};
946953

947954
let is_deepest_fork =
948-
expected_burn_block.burn_block_height < fork_origin.burn_block_height;
955+
expected_burn_block.burn_block_height < scope.fork_origin.burn_block_height;
949956
if !is_deepest_fork {
950957
//if it is within the scope or after - this is not a new fork, but the continue of a reorg
951958
info!("Tx Replay: nothing todo. Reorg in progress!");
@@ -958,9 +965,12 @@ impl LocalStateMachine {
958965
db,
959966
client,
960967
expected_burn_block,
961-
past_tip,
968+
&scope.past_tip,
962969
)? {
963-
let scope = (expected_burn_block.clone(), past_tip.clone());
970+
let scope = TxReplayScope {
971+
fork_origin: expected_burn_block.clone(),
972+
past_tip: scope.past_tip.clone(),
973+
};
964974

965975
info!("Tx Replay: replay set updated with {} tx(s)", replay_set.len();
966976
"tx_replay_set" => ?replay_set,
@@ -1010,7 +1020,10 @@ impl LocalStateMachine {
10101020
}
10111021
Some(replay_set) => {
10121022
let scope_opt = if !replay_set.is_empty() {
1013-
let scope = (expected_burn_block.clone(), potential_replay_tip);
1023+
let scope = TxReplayScope {
1024+
fork_origin: expected_burn_block.clone(),
1025+
past_tip: potential_replay_tip,
1026+
};
10141027
info!("Tx Replay: replay set updated with {} tx(s)", replay_set.len();
10151028
"tx_replay_set" => ?replay_set,
10161029
"tx_replay_scope" => ?scope);

0 commit comments

Comments
 (0)