Skip to content

Commit ed839e4

Browse files
authored
Merge pull request #5572 from stacks-network/release/3.1.0.0.2
merge Release/3.1.0.0.2 to master
2 parents 70d24ea + 59f06b3 commit ed839e4

File tree

6 files changed

+81
-16
lines changed

6 files changed

+81
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1111

1212
### Changed
1313

14-
## [3.1.0.0.1]
15-
16-
### Added
17-
18-
- A miner will now generate a tenure-extend when at least 70% of the signers have confirmed that they are willing to allow one, via the new timestamp included in block responses. This allows the miner to refresh its budget in between Bitcoin blocks. ([#5476](https://github.com/stacks-network/stacks-core/discussions/5476))
19-
20-
### Changed
21-
22-
## [3.1.0.0.0]
14+
## [3.1.0.0.2]
2315

2416
### Added
2517

@@ -28,6 +20,8 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
2820
- `/v2/clarity/marf/:marf_key_hash`
2921
- `/v2/clarity/metadata/:principal/:contract_name/:clarity_metadata_key`
3022
- When a proposed block is validated by a node, the block can be validated even when the block version is different than the node's default ([#5539](https://github.com/stacks-network/stacks-core/pull/5539))
23+
- A miner will now generate a tenure-extend when at least 70% of the signers have confirmed that they are willing to allow one, via the new timestamp included in block responses. This allows the miner to refresh its budget in between Bitcoin blocks. ([#5476](https://github.com/stacks-network/stacks-core/discussions/5476))
24+
- Set the epoch to 3.1 in the Clarity DB upon activation.
3125

3226
### Changed
3327

stacks-signer/CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1111

1212
## Changed
1313

14-
## [3.1.0.0.1.0]
14+
## [3.1.0.0.2.0]
1515

16-
### Added
16+
## Added
17+
18+
- **SIP-029 consensus rules, activating in epoch 3.1 at block 875,000** (see [SIP-029](https://github.com/will-corcoran/sips/blob/feat/sip-029-halving-alignment/sips/sip-029/sip-029-halving-alignment.md) for details)
1719

1820
### Changed
1921

2022
- Added tenure extend timestamp to signer block responses
2123
- Added tenure_idle_timeout_secs configuration option for determining when a time-based tenure extend will be accepted
2224

25+
2326
## [3.1.0.0.0.0]
2427

2528
### Added

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3937,7 +3937,11 @@ impl NakamotoChainState {
39373937

39383938
// is this stacks block the first of a new epoch?
39393939
let (applied_epoch_transition, mut tx_receipts) =
3940-
StacksChainState::process_epoch_transition(&mut clarity_tx, burn_header_height)?;
3940+
StacksChainState::process_epoch_transition(
3941+
&mut clarity_tx,
3942+
sortition_dbconn.as_burn_state_db(),
3943+
burn_header_height,
3944+
)?;
39413945

39423946
debug!(
39433947
"Setup block: Processed epoch transition";

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4044,6 +4044,7 @@ impl StacksChainState {
40444044
/// Return (applied?, receipts)
40454045
pub fn process_epoch_transition(
40464046
clarity_tx: &mut ClarityTx,
4047+
burn_dbconn: &dyn BurnStateDB,
40474048
chain_tip_burn_header_height: u32,
40484049
) -> Result<(bool, Vec<StacksTransactionReceipt>), Error> {
40494050
// is this stacks block the first of a new epoch?
@@ -4104,14 +4105,29 @@ impl StacksChainState {
41044105
current_epoch = StacksEpochId::Epoch30;
41054106
}
41064107
StacksEpochId::Epoch30 => {
4107-
// no special initialization is needed, since only the coinbase emission
4108-
// schedule is changing.
4108+
receipts.append(&mut clarity_tx.block.initialize_epoch_3_1()?);
41094109
current_epoch = StacksEpochId::Epoch31;
41104110
}
41114111
StacksEpochId::Epoch31 => {
41124112
panic!("No defined transition from Epoch31 forward")
41134113
}
41144114
}
4115+
4116+
if current_epoch > StacksEpochId::Epoch2_05 {
4117+
// clarity tx should now have the current epoch
4118+
assert_eq!(
4119+
clarity_tx.block.get_epoch(),
4120+
current_epoch,
4121+
"FATAL: clarity_tx does not have the current epoch"
4122+
);
4123+
4124+
// clarity DB should now have the current epoch
4125+
assert_eq!(
4126+
clarity_tx.block.get_clarity_db_epoch_version(burn_dbconn)?,
4127+
current_epoch,
4128+
"FATAL: clarity DB does not report the current epoch"
4129+
);
4130+
}
41154131
}
41164132
}
41174133

@@ -5198,7 +5214,11 @@ impl StacksChainState {
51985214

51995215
// is this stacks block the first of a new epoch?
52005216
let (applied_epoch_transition, mut tx_receipts) =
5201-
StacksChainState::process_epoch_transition(&mut clarity_tx, burn_tip_height)?;
5217+
StacksChainState::process_epoch_transition(
5218+
&mut clarity_tx,
5219+
burn_dbconn,
5220+
burn_tip_height,
5221+
)?;
52025222

52035223
debug!(
52045224
"Setup block: Processed epoch transition at {}/{}",

stackslib/src/clarity_vm/clarity.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,21 @@ impl<'a, 'b> ClarityBlockConnection<'a, 'b> {
226226
None => None,
227227
}
228228
}
229+
230+
/// Load the epoch ID from the clarity DB.
231+
/// Used to sanity-check epoch transitions.
232+
pub fn get_clarity_db_epoch_version(
233+
&mut self,
234+
burn_state_db: &dyn BurnStateDB,
235+
) -> Result<StacksEpochId, Error> {
236+
let mut db = self.datastore.as_clarity_db(self.header_db, burn_state_db);
237+
// NOTE: the begin/roll_back shouldn't be necessary with how this gets used in practice,
238+
// but is put here defensively.
239+
db.begin();
240+
let result = db.get_clarity_epoch_version();
241+
db.roll_back()?;
242+
Ok(result?)
243+
}
229244
}
230245

231246
impl ClarityInstance {
@@ -1524,6 +1539,32 @@ impl<'a, 'b> ClarityBlockConnection<'a, 'b> {
15241539
})
15251540
}
15261541

1542+
pub fn initialize_epoch_3_1(&mut self) -> Result<Vec<StacksTransactionReceipt>, Error> {
1543+
// use the `using!` statement to ensure that the old cost_tracker is placed
1544+
// back in all branches after initialization
1545+
using!(self.cost_track, "cost tracker", |old_cost_tracker| {
1546+
// epoch initialization is *free*.
1547+
// NOTE: this also means that cost functions won't be evaluated.
1548+
self.cost_track.replace(LimitedCostTracker::new_free());
1549+
self.epoch = StacksEpochId::Epoch31;
1550+
self.as_transaction(|tx_conn| {
1551+
// bump the epoch in the Clarity DB
1552+
tx_conn
1553+
.with_clarity_db(|db| {
1554+
db.set_clarity_epoch_version(StacksEpochId::Epoch31)?;
1555+
Ok(())
1556+
})
1557+
.unwrap();
1558+
1559+
// require 3.1 rules henceforth in this connection as well
1560+
tx_conn.epoch = StacksEpochId::Epoch31;
1561+
});
1562+
1563+
debug!("Epoch 3.1 initialized");
1564+
(old_cost_tracker, Ok(vec![]))
1565+
})
1566+
}
1567+
15271568
pub fn start_transaction_processing<'c>(&'c mut self) -> ClarityTransactionConnection<'c, 'a> {
15281569
let store = &mut self.datastore;
15291570
let cost_track = &mut self.cost_track;

stackslib/src/core/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,10 @@ pub static STACKS_EPOCH_3_0_MARKER: u8 = 0x0b;
496496

497497
/// Stacks 3.1 epoch marker. All block-commits in 3.1 must have a memo bitfield with this value
498498
/// *or greater*.
499-
pub static STACKS_EPOCH_3_1_MARKER: u8 = 0x0c;
499+
/// NOTE: it has to be 0x0d because a prior release of 3.1 with 0x0c before activation had a
500+
/// consensus bug. This forces miners with this buggy release off the network if they are still
501+
/// running it prior to 3.1 activation.
502+
pub static STACKS_EPOCH_3_1_MARKER: u8 = 0x0d;
500503

501504
#[test]
502505
fn test_ord_for_stacks_epoch() {

0 commit comments

Comments
 (0)