Skip to content

Commit 04fbd00

Browse files
committed
fix: set epoch to 3.1 in Clarity DB
1 parent 70d24ea commit 04fbd00

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

stackslib/src/chainstate/stacks/db/blocks.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4104,8 +4104,7 @@ impl StacksChainState {
41044104
current_epoch = StacksEpochId::Epoch30;
41054105
}
41064106
StacksEpochId::Epoch30 => {
4107-
// no special initialization is needed, since only the coinbase emission
4108-
// schedule is changing.
4107+
receipts.append(&mut clarity_tx.block.initialize_epoch_3_1()?);
41094108
current_epoch = StacksEpochId::Epoch31;
41104109
}
41114110
StacksEpochId::Epoch31 => {

stackslib/src/clarity_vm/clarity.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,32 @@ impl<'a, 'b> ClarityBlockConnection<'a, 'b> {
15241524
})
15251525
}
15261526

1527+
pub fn initialize_epoch_3_1(&mut self) -> Result<Vec<StacksTransactionReceipt>, Error> {
1528+
// use the `using!` statement to ensure that the old cost_tracker is placed
1529+
// back in all branches after initialization
1530+
using!(self.cost_track, "cost tracker", |old_cost_tracker| {
1531+
// epoch initialization is *free*.
1532+
// NOTE: this also means that cost functions won't be evaluated.
1533+
self.cost_track.replace(LimitedCostTracker::new_free());
1534+
self.epoch = StacksEpochId::Epoch31;
1535+
self.as_transaction(|tx_conn| {
1536+
// bump the epoch in the Clarity DB
1537+
tx_conn
1538+
.with_clarity_db(|db| {
1539+
db.set_clarity_epoch_version(StacksEpochId::Epoch31)?;
1540+
Ok(())
1541+
})
1542+
.unwrap();
1543+
1544+
// require 3.1 rules henceforth in this connection as well
1545+
tx_conn.epoch = StacksEpochId::Epoch31;
1546+
});
1547+
1548+
debug!("Epoch 3.1 initialized");
1549+
(old_cost_tracker, Ok(vec![]))
1550+
})
1551+
}
1552+
15271553
pub fn start_transaction_processing<'c>(&'c mut self) -> ClarityTransactionConnection<'c, 'a> {
15281554
let store = &mut self.datastore;
15291555
let cost_track = &mut self.cost_track;

0 commit comments

Comments
 (0)