Skip to content

Commit 2b5dcdc

Browse files
committed
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into fix/signers-verify-reward-cycle
2 parents b83c3c5 + 464b796 commit 2b5dcdc

File tree

6 files changed

+89
-16
lines changed

6 files changed

+89
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1616
- When a transaction is dropped due to replace-by-fee, the `/drop_mempool_tx` event observer payload now includes `new_txid`, which is the transaction that replaced this dropped transaction. When a transaction is dropped for other reasons, `new_txid` is `null`. [#5381](https://github.com/stacks-network/stacks-core/pull/5381)
1717
- Nodes will assume that all PoX anchor blocks exist by default, and stall initial block download indefinitely to await their arrival (#5502)
1818

19-
## [3.1.0.0.1]
20-
21-
### Added
22-
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-
25-
### Changed
26-
27-
## [3.1.0.0.0]
19+
## [3.1.0.0.2]
2820

2921
### Added
3022

@@ -33,6 +25,8 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
3325
- `/v2/clarity/marf/:marf_key_hash`
3426
- `/v2/clarity/metadata/:principal/:contract_name/:clarity_metadata_key`
3527
- 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))
28+
- 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))
29+
- Set the epoch to 3.1 in the Clarity DB upon activation.
3630

3731
### Changed
3832

stacks-signer/CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,26 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1515
- Improvements to the stale signer cleanup logic: deletes the prior signer if it has no remaining unprocessed blocks in its database
1616
- Signers now listen to new block events from the stacks node to determine whether a block has been successfully appended to the chain tip
1717

18-
## [3.1.0.0.1.0]
18+
# [3.1.0.0.2.1]
1919

20-
### Added
20+
## Added
21+
22+
## Changed
23+
24+
- Prevent old reward cycle signers from processing block validation response messages that do not apply to blocks from their cycle.
25+
26+
## [3.1.0.0.2.0]
27+
28+
## Added
29+
30+
- **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)
2131

2232
### Changed
2333

2434
- Added tenure extend timestamp to signer block responses
2535
- Added tenure_idle_timeout_secs configuration option for determining when a time-based tenure extend will be accepted
2636

37+
2738
## [3.1.0.0.0.0]
2839

2940
### Added

stackslib/src/chainstate/nakamoto/mod.rs

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

39533953
// is this stacks block the first of a new epoch?
39543954
let (applied_epoch_transition, mut tx_receipts) =
3955-
StacksChainState::process_epoch_transition(&mut clarity_tx, burn_header_height)?;
3955+
StacksChainState::process_epoch_transition(
3956+
&mut clarity_tx,
3957+
sortition_dbconn.as_burn_state_db(),
3958+
burn_header_height,
3959+
)?;
39563960

39573961
debug!(
39583962
"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
@@ -4046,6 +4046,7 @@ impl StacksChainState {
40464046
/// Return (applied?, receipts)
40474047
pub fn process_epoch_transition(
40484048
clarity_tx: &mut ClarityTx,
4049+
burn_dbconn: &dyn BurnStateDB,
40494050
chain_tip_burn_header_height: u32,
40504051
) -> Result<(bool, Vec<StacksTransactionReceipt>), Error> {
40514052
// is this stacks block the first of a new epoch?
@@ -4106,14 +4107,29 @@ impl StacksChainState {
41064107
current_epoch = StacksEpochId::Epoch30;
41074108
}
41084109
StacksEpochId::Epoch30 => {
4109-
// no special initialization is needed, since only the coinbase emission
4110-
// schedule is changing.
4110+
receipts.append(&mut clarity_tx.block.initialize_epoch_3_1()?);
41114111
current_epoch = StacksEpochId::Epoch31;
41124112
}
41134113
StacksEpochId::Epoch31 => {
41144114
panic!("No defined transition from Epoch31 forward")
41154115
}
41164116
}
4117+
4118+
if current_epoch > StacksEpochId::Epoch2_05 {
4119+
// clarity tx should now have the current epoch
4120+
assert_eq!(
4121+
clarity_tx.block.get_epoch(),
4122+
current_epoch,
4123+
"FATAL: clarity_tx does not have the current epoch"
4124+
);
4125+
4126+
// clarity DB should now have the current epoch
4127+
assert_eq!(
4128+
clarity_tx.block.get_clarity_db_epoch_version(burn_dbconn)?,
4129+
current_epoch,
4130+
"FATAL: clarity DB does not report the current epoch"
4131+
);
4132+
}
41174133
}
41184134
}
41194135

@@ -5200,7 +5216,11 @@ impl StacksChainState {
52005216

52015217
// is this stacks block the first of a new epoch?
52025218
let (applied_epoch_transition, mut tx_receipts) =
5203-
StacksChainState::process_epoch_transition(&mut clarity_tx, burn_tip_height)?;
5219+
StacksChainState::process_epoch_transition(
5220+
&mut clarity_tx,
5221+
burn_dbconn,
5222+
burn_tip_height,
5223+
)?;
52045224

52055225
debug!(
52065226
"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 ClarityBlockConnection<'_, '_> {
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> ClarityBlockConnection<'a, '_> {
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)