Skip to content

Commit

Permalink
fix: set epoch to 3.1 in Clarity DB
Browse files Browse the repository at this point in the history
  • Loading branch information
obycode committed Dec 11, 2024
1 parent b0d9179 commit 014a84b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 1 addition & 2 deletions stackslib/src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4104,8 +4104,7 @@ impl StacksChainState {
current_epoch = StacksEpochId::Epoch30;
}
StacksEpochId::Epoch30 => {
// no special initialization is needed, since only the coinbase emission
// schedule is changing.
receipts.append(&mut clarity_tx.block.initialize_epoch_3_1()?);
current_epoch = StacksEpochId::Epoch31;
}
StacksEpochId::Epoch31 => {
Expand Down
26 changes: 26 additions & 0 deletions stackslib/src/clarity_vm/clarity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,32 @@ impl<'a, 'b> ClarityBlockConnection<'a, 'b> {
})
}

pub fn initialize_epoch_3_1(&mut self) -> Result<Vec<StacksTransactionReceipt>, Error> {
// use the `using!` statement to ensure that the old cost_tracker is placed
// back in all branches after initialization
using!(self.cost_track, "cost tracker", |old_cost_tracker| {
// epoch initialization is *free*.
// NOTE: this also means that cost functions won't be evaluated.
self.cost_track.replace(LimitedCostTracker::new_free());
self.epoch = StacksEpochId::Epoch31;
self.as_transaction(|tx_conn| {
// bump the epoch in the Clarity DB
tx_conn
.with_clarity_db(|db| {
db.set_clarity_epoch_version(StacksEpochId::Epoch31)?;
Ok(())
})
.unwrap();

// require 3.1 rules henceforth in this connection as well
tx_conn.epoch = StacksEpochId::Epoch31;
});

debug!("Epoch 3.1 initialized");
(old_cost_tracker, Ok(vec![]))
})
}

pub fn start_transaction_processing<'c>(&'c mut self) -> ClarityTransactionConnection<'c, 'a> {
let store = &mut self.datastore;
let cost_track = &mut self.cost_track;
Expand Down

0 comments on commit 014a84b

Please sign in to comment.