Skip to content

Commit 5a661fd

Browse files
committed
fix: rc_consensus_hash in the burn view is the stacks tip consensus hash, not the reward cycle consensus hash
1 parent c659fca commit 5a661fd

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

stackslib/src/chainstate/burn/db/sortdb.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3883,34 +3883,21 @@ impl SortitionDB {
38833883
.unwrap_or(&burnchain.first_block_hash)
38843884
.clone();
38853885

3886-
let rc = burnchain
3887-
.block_height_to_reward_cycle(chain_tip.block_height)
3888-
.expect("FATAL: block height does not have a reward cycle");
3889-
3890-
let rc_height = burnchain.reward_cycle_to_block_height(rc);
3891-
let rc_consensus_hash = SortitionDB::get_ancestor_snapshot(
3892-
conn,
3893-
cmp::min(chain_tip.block_height, rc_height),
3894-
&chain_tip.sortition_id,
3895-
)?
3896-
.map(|sn| sn.consensus_hash)
3897-
.ok_or(db_error::NotFoundError)?;
3898-
38993886
test_debug!(
39003887
"Chain view: {},{}-{},{},{}",
39013888
chain_tip.block_height,
39023889
chain_tip.burn_header_hash,
39033890
stable_block_height,
39043891
&burn_stable_block_hash,
3905-
&rc_consensus_hash,
3892+
&chain_tip.canonical_stacks_tip_consensus_hash,
39063893
);
39073894
Ok(BurnchainView {
39083895
burn_block_height: chain_tip.block_height,
39093896
burn_block_hash: chain_tip.burn_header_hash,
39103897
burn_stable_block_height: stable_block_height,
39113898
burn_stable_block_hash: burn_stable_block_hash,
39123899
last_burn_block_hashes: last_burn_block_hashes,
3913-
rc_consensus_hash,
3900+
rc_consensus_hash: chain_tip.canonical_stacks_tip_consensus_hash,
39143901
})
39153902
}
39163903
}
@@ -4099,6 +4086,21 @@ impl SortitionDB {
40994086
Ok((consensus_hash, stacks_block_hash))
41004087
}
41014088

4089+
#[cfg(test)]
4090+
pub fn set_canonical_stacks_chain_tip(
4091+
conn: &Connection,
4092+
ch: &ConsensusHash,
4093+
bhh: &BlockHeaderHash,
4094+
height: u64,
4095+
) -> Result<(), db_error> {
4096+
let tip = SortitionDB::get_canonical_burn_chain_tip(conn)?;
4097+
let args: &[&dyn ToSql] = &[ch, bhh, &u64_to_sql(height)?, &tip.sortition_id];
4098+
conn.execute("UPDATE snapshots SET canonical_stacks_tip_consensus_hash = ?1, canonical_stacks_tip_hash = ?2, canonical_stacks_tip_height = ?3
4099+
WHERE sortition_id = ?4", args)
4100+
.map_err(db_error::SqliteError)?;
4101+
Ok(())
4102+
}
4103+
41024104
/// Get the maximum arrival index for any known snapshot.
41034105
fn get_max_arrival_index(conn: &Connection) -> Result<u64, db_error> {
41044106
match conn

0 commit comments

Comments
 (0)