Skip to content

Feat/sip 031 Mint-and-transfer per tenure infrastructure #6270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: release/3.2.0.0.0-rc1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clarity/src/vm/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ pub fn run_analysis(
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => {
| StacksEpochId::Epoch31
| StacksEpochId::Epoch32 => {
TypeChecker2_1::run_pass(&epoch, &mut contract_analysis, db, build_type_map)
}
StacksEpochId::Epoch10 => {
Expand Down
6 changes: 4 additions & 2 deletions clarity/src/vm/analysis/type_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ impl FunctionType {
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => self.check_args_2_1(accounting, args, clarity_version),
| StacksEpochId::Epoch31
| StacksEpochId::Epoch32 => self.check_args_2_1(accounting, args, clarity_version),
StacksEpochId::Epoch10 => {
Err(CheckErrors::Expects("Epoch10 is not supported".into()).into())
}
Expand All @@ -69,7 +70,8 @@ impl FunctionType {
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => {
| StacksEpochId::Epoch31
| StacksEpochId::Epoch32 => {
self.check_args_by_allowing_trait_cast_2_1(db, clarity_version, func_args)
}
StacksEpochId::Epoch10 => {
Expand Down
3 changes: 2 additions & 1 deletion clarity/src/vm/costs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ impl LimitedCostTracker {
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => COSTS_3_NAME.to_string(),
| StacksEpochId::Epoch31
| StacksEpochId::Epoch32 => COSTS_3_NAME.to_string(),
};
Ok(result)
}
Expand Down
2 changes: 2 additions & 0 deletions clarity/src/vm/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ macro_rules! switch_on_global_epoch {
StacksEpochId::Epoch30 => $Epoch205Version(args, env, context),
// Note: We reuse 2.05 for 3.1.
StacksEpochId::Epoch31 => $Epoch205Version(args, env, context),
// Note: We reuse 2.05 for 3.2.
StacksEpochId::Epoch32 => $Epoch205Version(args, env, context),
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion clarity/src/vm/test_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ pub fn generate_test_burn_state_db(epoch_id: StacksEpochId) -> UnitTestBurnState
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => UnitTestBurnStateDB {
| StacksEpochId::Epoch31
| StacksEpochId::Epoch32 => UnitTestBurnStateDB {
epoch_id,
ast_rules: ASTRules::PrecheckSize,
},
Expand Down
4 changes: 4 additions & 0 deletions clarity/src/vm/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ epochs_template! {
Epoch25,
Epoch30,
Epoch31,
Epoch32,
}

clarity_template! {
Expand All @@ -146,6 +147,9 @@ clarity_template! {
(Epoch31, Clarity1),
(Epoch31, Clarity2),
(Epoch31, Clarity3),
(Epoch32, Clarity1),
(Epoch32, Clarity2),
(Epoch32, Clarity3),
}

#[cfg(test)]
Expand Down
9 changes: 6 additions & 3 deletions clarity/src/vm/types/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@ impl TypeSignature {
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => self.admits_type_v2_1(other),
| StacksEpochId::Epoch31
| StacksEpochId::Epoch32 => self.admits_type_v2_1(other),
StacksEpochId::Epoch10 => Err(CheckErrors::Expects("epoch 1.0 not supported".into())),
}
}
Expand Down Expand Up @@ -793,7 +794,8 @@ impl TypeSignature {
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => self.canonicalize_v2_1(),
| StacksEpochId::Epoch31
| StacksEpochId::Epoch32 => self.canonicalize_v2_1(),
}
}

Expand Down Expand Up @@ -1152,7 +1154,8 @@ impl TypeSignature {
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => Self::least_supertype_v2_1(a, b),
| StacksEpochId::Epoch31
| StacksEpochId::Epoch32 => Self::least_supertype_v2_1(a, b),
StacksEpochId::Epoch10 => Err(CheckErrors::Expects("epoch 1.0 not supported".into())),
}
}
Expand Down
1 change: 1 addition & 0 deletions clarity/src/vm/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl ClarityVersion {
StacksEpochId::Epoch25 => ClarityVersion::Clarity2,
StacksEpochId::Epoch30 => ClarityVersion::Clarity3,
StacksEpochId::Epoch31 => ClarityVersion::Clarity3,
StacksEpochId::Epoch32 => ClarityVersion::Clarity3,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions sample/conf/testnet-signer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ start_height = 1900
[[burnchain.epochs]]
epoch_name = "3.1"
start_height = 2000

[[burnchain.epochs]]
epoch_name = "3.2"
start_height = 2100
1 change: 1 addition & 0 deletions stacks-common/src/libcommon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub mod consts {
pub const PEER_VERSION_EPOCH_2_5: u8 = 0x0a;
pub const PEER_VERSION_EPOCH_3_0: u8 = 0x0b;
pub const PEER_VERSION_EPOCH_3_1: u8 = 0x0c;
pub const PEER_VERSION_EPOCH_3_2: u8 = 0x0d;

/// this should be updated to the latest network epoch version supported by
/// this node. this will be checked by the `validate_epochs()` method.
Expand Down
44 changes: 35 additions & 9 deletions stacks-common/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub enum StacksEpochId {
Epoch25 = 0x0201a,
Epoch30 = 0x03000,
Epoch31 = 0x03001,
Epoch32 = 0x03002,
}

#[derive(Debug)]
Expand Down Expand Up @@ -269,7 +270,7 @@ impl StacksEpochId {
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25 => MempoolCollectionBehavior::ByStacksHeight,
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 => {
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 | StacksEpochId::Epoch32 => {
MempoolCollectionBehavior::ByReceiveTime
}
}
Expand All @@ -286,7 +287,10 @@ impl StacksEpochId {
| StacksEpochId::Epoch22
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24 => false,
StacksEpochId::Epoch25 | StacksEpochId::Epoch30 | StacksEpochId::Epoch31 => true,
StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31
| StacksEpochId::Epoch32 => true,
}
}

Expand All @@ -303,7 +307,8 @@ impl StacksEpochId {
StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => true,
| StacksEpochId::Epoch31
| StacksEpochId::Epoch32 => true,
}
}

Expand All @@ -319,7 +324,7 @@ impl StacksEpochId {
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25 => false,
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 => true,
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 | StacksEpochId::Epoch32 => true,
}
}

Expand All @@ -335,7 +340,7 @@ impl StacksEpochId {
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25 => false,
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 => true,
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 | StacksEpochId::Epoch32 => true,
}
}

Expand All @@ -350,7 +355,7 @@ impl StacksEpochId {
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25 => false,
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 => true,
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 | StacksEpochId::Epoch32 => true,
}
}

Expand Down Expand Up @@ -381,7 +386,9 @@ impl StacksEpochId {
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25 => 0,
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 => MINING_COMMITMENT_FREQUENCY_NAKAMOTO,
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 | StacksEpochId::Epoch32 => {
MINING_COMMITMENT_FREQUENCY_NAKAMOTO
}
}
}

Expand Down Expand Up @@ -417,7 +424,7 @@ impl StacksEpochId {
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25 => false,
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 => {
StacksEpochId::Epoch30 | StacksEpochId::Epoch31 | StacksEpochId::Epoch32 => {
cur_reward_cycle > first_epoch30_reward_cycle
}
}
Expand Down Expand Up @@ -535,13 +542,30 @@ impl StacksEpochId {
| StacksEpochId::Epoch30 => {
self.coinbase_reward_pre_sip029(first_burnchain_height, current_burnchain_height)
}
StacksEpochId::Epoch31 => self.coinbase_reward_sip029(
StacksEpochId::Epoch31 | StacksEpochId::Epoch32 => self.coinbase_reward_sip029(
mainnet,
first_burnchain_height,
current_burnchain_height,
),
}
}

/// Whether or not this epoch is part of the SIP-031 schedule
pub fn includes_sip_031(&self) -> bool {
match self {
StacksEpochId::Epoch10
| StacksEpochId::Epoch20
| StacksEpochId::Epoch2_05
| StacksEpochId::Epoch21
| StacksEpochId::Epoch22
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => false,
StacksEpochId::Epoch32 => true,
}
}
}

impl std::fmt::Display for StacksEpochId {
Expand All @@ -557,6 +581,7 @@ impl std::fmt::Display for StacksEpochId {
StacksEpochId::Epoch25 => write!(f, "2.5"),
StacksEpochId::Epoch30 => write!(f, "3.0"),
StacksEpochId::Epoch31 => write!(f, "3.1"),
StacksEpochId::Epoch32 => write!(f, "3.2"),
}
}
}
Expand All @@ -576,6 +601,7 @@ impl TryFrom<u32> for StacksEpochId {
x if x == StacksEpochId::Epoch25 as u32 => Ok(StacksEpochId::Epoch25),
x if x == StacksEpochId::Epoch30 as u32 => Ok(StacksEpochId::Epoch30),
x if x == StacksEpochId::Epoch31 as u32 => Ok(StacksEpochId::Epoch31),
x if x == StacksEpochId::Epoch32 as u32 => Ok(StacksEpochId::Epoch32),
_ => Err("Invalid epoch"),
}
}
Expand Down
73 changes: 17 additions & 56 deletions stacks-common/src/types/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,66 +184,26 @@ fn test_get_coinbase_at_effective_height() {
#[test]
fn test_epoch_coinbase_reward() {
// new coinbase schedule
assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 666050),
1_000_000_000
);
assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 666051),
1_000_000_000
);
for epoch in [StacksEpochId::Epoch31, StacksEpochId::Epoch32].iter() {
assert_eq!(epoch.coinbase_reward(true, 666050, 666050), 1_000_000_000);
assert_eq!(epoch.coinbase_reward(true, 666050, 666051), 1_000_000_000);

assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 944_999),
1_000_000_000
);
assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 945_000),
500_000_000
);
assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 945_001),
500_000_000
);
assert_eq!(epoch.coinbase_reward(true, 666050, 944_999), 1_000_000_000);
assert_eq!(epoch.coinbase_reward(true, 666050, 945_000), 500_000_000);
assert_eq!(epoch.coinbase_reward(true, 666050, 945_001), 500_000_000);

assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 1_049_999),
500_000_000
);
assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 1_050_000),
250_000_000
);
assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 1_050_001),
250_000_000
);
assert_eq!(epoch.coinbase_reward(true, 666050, 1_049_999), 500_000_000);
assert_eq!(epoch.coinbase_reward(true, 666050, 1_050_000), 250_000_000);
assert_eq!(epoch.coinbase_reward(true, 666050, 1_050_001), 250_000_000);

assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 1_259_999),
250_000_000
);
assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 1_260_000),
125_000_000
);
assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 1_260_001),
125_000_000
);
assert_eq!(epoch.coinbase_reward(true, 666050, 1_259_999), 250_000_000);
assert_eq!(epoch.coinbase_reward(true, 666050, 1_260_000), 125_000_000);
assert_eq!(epoch.coinbase_reward(true, 666050, 1_260_001), 125_000_000);

assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 1_469_999),
125_000_000
);
assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 1_470_000),
62_500_000
);
assert_eq!(
StacksEpochId::Epoch31.coinbase_reward(true, 666050, 1_470_001),
62_500_000
);
assert_eq!(epoch.coinbase_reward(true, 666050, 1_469_999), 125_000_000);
assert_eq!(epoch.coinbase_reward(true, 666050, 1_470_000), 62_500_000);
assert_eq!(epoch.coinbase_reward(true, 666050, 1_470_001), 62_500_000);
}

// old coinbase schedule
for epoch in [
Expand All @@ -254,6 +214,7 @@ fn test_epoch_coinbase_reward() {
StacksEpochId::Epoch23,
StacksEpochId::Epoch24,
StacksEpochId::Epoch25,
StacksEpochId::Epoch30,
]
.iter()
{
Expand Down
1 change: 1 addition & 0 deletions stackslib/src/chainstate/burn/db/sortdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3236,6 +3236,7 @@ impl SortitionDB {
StacksEpochId::Epoch25 => version_u32 >= 3,
StacksEpochId::Epoch30 => version_u32 >= 3,
StacksEpochId::Epoch31 => version_u32 >= 3,
StacksEpochId::Epoch32 => version_u32 >= 3,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::chainstate::stacks::address::PoxAddress;
use crate::core::{
StacksEpochId, STACKS_EPOCH_2_05_MARKER, STACKS_EPOCH_2_1_MARKER, STACKS_EPOCH_2_2_MARKER,
STACKS_EPOCH_2_3_MARKER, STACKS_EPOCH_2_4_MARKER, STACKS_EPOCH_2_5_MARKER,
STACKS_EPOCH_3_0_MARKER, STACKS_EPOCH_3_1_MARKER,
STACKS_EPOCH_3_0_MARKER, STACKS_EPOCH_3_1_MARKER, STACKS_EPOCH_3_2_MARKER,
};

// return type from parse_data below
Expand Down Expand Up @@ -877,6 +877,7 @@ impl LeaderBlockCommitOp {
StacksEpochId::Epoch25 => self.check_epoch_commit_marker(STACKS_EPOCH_2_5_MARKER),
StacksEpochId::Epoch30 => self.check_epoch_commit_marker(STACKS_EPOCH_3_0_MARKER),
StacksEpochId::Epoch31 => self.check_epoch_commit_marker(STACKS_EPOCH_3_1_MARKER),
StacksEpochId::Epoch32 => self.check_epoch_commit_marker(STACKS_EPOCH_3_2_MARKER),
}
}

Expand All @@ -897,7 +898,8 @@ impl LeaderBlockCommitOp {
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30
| StacksEpochId::Epoch31 => {
| StacksEpochId::Epoch31
| StacksEpochId::Epoch32 => {
// correct behavior -- uses *sortition height* to find the intended sortition ID
let sortition_height = self
.block_height
Expand Down
Loading