Skip to content

Commit da50e51

Browse files
committed
refactor: cleaned compute_forked_txs_set_in_same_cycle, #5971
1 parent 9f000bf commit da50e51

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

stacks-signer/src/v0/signer_state.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,18 +1026,18 @@ impl LocalStateMachine {
10261026

10271027
/// Retrieves the set of transactions that were part of a Bitcoin fork within the same reward cycle.
10281028
///
1029-
/// This method identifies the range of Tenures affected by a fork, from the `tip` down to the `fork_origin`
1029+
/// This method identifies the range of Tenures affected by a fork, from the `fork_tip` down to the `fork_origin`
10301030
///
1031-
/// It then verifies whether the fork occurred entirely within the current reward cycle. If so,
1032-
/// collect the relevant transactions (skipping TenureChange, Coinbase, and Microblocks).
1031+
/// It then verifies whether the fork occurred entirely within the reward cycle related to the `fork_tip`. If so,
1032+
/// collect the relevant transactions (skipping TenureChange, Coinbase, and PoisonMicroblock).
10331033
/// Otherwise, if fork involve a different reward cycle cancel the search.
10341034
///
10351035
/// # Arguments
10361036
///
10371037
/// * `db` - A reference to the SignerDb, used to fetch burn block information.
10381038
/// * `client` - A reference to a `StacksClient`, used to query chain state and fork information.
10391039
/// * `fork_origin` - The burn block that originated the fork.
1040-
/// * `tip` - The burn block tip in the fork sequence.
1040+
/// * `fork_tip` - The burn block tip in the fork sequence.
10411041
///
10421042
/// # Returns
10431043
///
@@ -1050,33 +1050,29 @@ impl LocalStateMachine {
10501050
db: &SignerDb,
10511051
client: &StacksClient,
10521052
fork_origin: &NewBurnBlock,
1053-
tip: &NewBurnBlock,
1053+
fork_tip: &NewBurnBlock,
10541054
) -> Result<Option<Vec<StacksTransaction>>, SignerChainstateError> {
10551055
// Determine the tenures that were forked
1056-
let mut parent_burn_block_info = db.get_burn_block_by_ch(&tip.consensus_hash)?;
1057-
let last_forked_tenure = tip.consensus_hash;
1058-
let mut first_forked_tenure = tip.consensus_hash;
1059-
let mut forked_tenures = vec![(tip.consensus_hash, tip.burn_block_height)];
1056+
let mut parent_burn_block_info = db.get_burn_block_by_ch(&fork_tip.consensus_hash)?;
1057+
let last_forked_tenure = fork_tip.consensus_hash;
1058+
let mut first_forked_tenure = fork_tip.consensus_hash;
10601059
while parent_burn_block_info.block_height > fork_origin.burn_block_height {
10611060
parent_burn_block_info =
10621061
db.get_burn_block_by_hash(&parent_burn_block_info.parent_burn_block_hash)?;
10631062
first_forked_tenure = parent_burn_block_info.consensus_hash;
1064-
forked_tenures.push((
1065-
parent_burn_block_info.consensus_hash,
1066-
parent_burn_block_info.block_height,
1067-
));
10681063
}
10691064
let fork_info =
10701065
client.get_tenure_forking_info(&first_forked_tenure, &last_forked_tenure)?;
10711066

10721067
// Check if fork occurred within current reward cycle. Reject tx replay otherwise.
10731068
let reward_cycle_info = client.get_current_reward_cycle_info()?;
10741069

1075-
let current_reward_cycle = reward_cycle_info.reward_cycle;
1070+
//let target_reward_cycle = reward_cycle_info.reward_cycle;
1071+
let target_reward_cycle = reward_cycle_info.get_reward_cycle(fork_tip.burn_block_height);
10761072
let is_fork_in_current_reward_cycle = fork_info.iter().all(|fork_info| {
10771073
let block_height = fork_info.burn_block_height;
10781074
let block_rc = reward_cycle_info.get_reward_cycle(block_height);
1079-
block_rc == current_reward_cycle
1075+
block_rc == target_reward_cycle
10801076
});
10811077

10821078
if !is_fork_in_current_reward_cycle {

0 commit comments

Comments
 (0)