Skip to content

Commit

Permalink
feat: epoch 3.1 support (#1630)
Browse files Browse the repository at this point in the history
* feat: epoch 3.1 support

* tests: fix sdk test
  • Loading branch information
hugocaillard authored Dec 17, 2024
1 parent 4d658d3 commit 682daf5
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 25 deletions.
13 changes: 7 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions components/clarinet-cli/src/generate/project.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use clarinet_files::{
DEFAULT_BITCOIN_EXPLORER_IMAGE, DEFAULT_BITCOIN_NODE_IMAGE, DEFAULT_DERIVATION_PATH,
DEFAULT_EPOCH_2_0, DEFAULT_EPOCH_2_05, DEFAULT_EPOCH_2_1, DEFAULT_EPOCH_2_2, DEFAULT_EPOCH_2_3,
DEFAULT_EPOCH_2_4, DEFAULT_EPOCH_2_5, DEFAULT_EPOCH_3_0, DEFAULT_FAUCET_MNEMONIC,
DEFAULT_POSTGRES_IMAGE, DEFAULT_STACKER_MNEMONIC, DEFAULT_STACKS_API_IMAGE,
DEFAULT_STACKS_EXPLORER_IMAGE, DEFAULT_STACKS_MINER_MNEMONIC, DEFAULT_STACKS_NODE_IMAGE,
DEFAULT_STACKS_SIGNER_IMAGE, DEFAULT_SUBNET_API_IMAGE, DEFAULT_SUBNET_CONTRACT_ID,
DEFAULT_SUBNET_MNEMONIC, DEFAULT_SUBNET_NODE_IMAGE,
DEFAULT_EPOCH_2_4, DEFAULT_EPOCH_2_5, DEFAULT_EPOCH_3_0, DEFAULT_EPOCH_3_1,
DEFAULT_FAUCET_MNEMONIC, DEFAULT_POSTGRES_IMAGE, DEFAULT_STACKER_MNEMONIC,
DEFAULT_STACKS_API_IMAGE, DEFAULT_STACKS_EXPLORER_IMAGE, DEFAULT_STACKS_MINER_MNEMONIC,
DEFAULT_STACKS_NODE_IMAGE, DEFAULT_STACKS_SIGNER_IMAGE, DEFAULT_SUBNET_API_IMAGE,
DEFAULT_SUBNET_CONTRACT_ID, DEFAULT_SUBNET_MNEMONIC, DEFAULT_SUBNET_NODE_IMAGE,
};

use super::changes::{Changes, DirectoryCreation, FileCreation};
Expand Down Expand Up @@ -353,6 +353,7 @@ disable_stacks_api = false
# epoch_2_4 = {DEFAULT_EPOCH_2_4}
# epoch_2_5 = {DEFAULT_EPOCH_2_5}
# epoch_3_0 = {DEFAULT_EPOCH_3_0}
# epoch_3_1 = {DEFAULT_EPOCH_3_1}
# Send some stacking orders
[[devnet.pox_stacking_orders]]
Expand Down
1 change: 1 addition & 0 deletions components/clarinet-deployments/src/onchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ pub fn apply_on_chain_deployment(
EpochSpec::Epoch2_4 => network_manifest.devnet.as_ref().unwrap().epoch_2_4,
EpochSpec::Epoch2_5 => network_manifest.devnet.as_ref().unwrap().epoch_2_5,
EpochSpec::Epoch3_0 => network_manifest.devnet.as_ref().unwrap().epoch_3_0,
EpochSpec::Epoch3_1 => network_manifest.devnet.as_ref().unwrap().epoch_3_1,
};
let mut epoch_transition_successful =
current_bitcoin_block_height > after_bitcoin_block;
Expand Down
10 changes: 8 additions & 2 deletions components/clarinet-deployments/src/requirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub const MAINNET_23_START_HEIGHT: u32 = 104_359;
pub const MAINNET_24_START_HEIGHT: u32 = 107_055;
pub const MAINNET_25_START_HEIGHT: u32 = 147_290;
pub const MAINNET_30_START_HEIGHT: u32 = 171_833;
pub const MAINNET_31_START_HEIGHT: u32 = 340_555;

pub const TESTNET_20_START_HEIGHT: u32 = 0;
pub const TESTNET_2_05_START_HEIGHT: u32 = 1;
Expand All @@ -138,6 +139,7 @@ pub const TESTNET_23_START_HEIGHT: u32 = 4;
pub const TESTNET_24_START_HEIGHT: u32 = 5;
pub const TESTNET_25_START_HEIGHT: u32 = 6;
pub const TESTNET_30_START_HEIGHT: u32 = 45_560;
pub const TESTNET_31_START_HEIGHT: u32 = 199_005;

fn epoch_for_height(is_mainnet: bool, height: u32) -> StacksEpochId {
if is_mainnet {
Expand All @@ -162,8 +164,10 @@ fn epoch_for_mainnet_height(height: u32) -> StacksEpochId {
StacksEpochId::Epoch24
} else if height < MAINNET_30_START_HEIGHT {
StacksEpochId::Epoch25
} else {
} else if height < MAINNET_31_START_HEIGHT {
StacksEpochId::Epoch30
} else {
StacksEpochId::Epoch31
}
}

Expand All @@ -182,8 +186,10 @@ fn epoch_for_testnet_height(height: u32) -> StacksEpochId {
StacksEpochId::Epoch24
} else if height < TESTNET_30_START_HEIGHT {
StacksEpochId::Epoch25
} else {
} else if height < TESTNET_31_START_HEIGHT {
StacksEpochId::Epoch30
} else {
StacksEpochId::Epoch31
}
}

Expand Down
4 changes: 4 additions & 0 deletions components/clarinet-deployments/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum EpochSpec {
Epoch2_5,
#[serde(rename = "3.0")]
Epoch3_0,
#[serde(rename = "3.1")]
Epoch3_1,
}

impl From<StacksEpochId> for EpochSpec {
Expand All @@ -47,6 +49,7 @@ impl From<StacksEpochId> for EpochSpec {
StacksEpochId::Epoch24 => EpochSpec::Epoch2_4,
StacksEpochId::Epoch25 => EpochSpec::Epoch2_5,
StacksEpochId::Epoch30 => EpochSpec::Epoch3_0,
StacksEpochId::Epoch31 => EpochSpec::Epoch3_1,
StacksEpochId::Epoch10 => unreachable!("epoch 1.0 is not supported"),
}
}
Expand All @@ -63,6 +66,7 @@ impl From<EpochSpec> for StacksEpochId {
EpochSpec::Epoch2_4 => StacksEpochId::Epoch24,
EpochSpec::Epoch2_5 => StacksEpochId::Epoch25,
EpochSpec::Epoch3_0 => StacksEpochId::Epoch30,
EpochSpec::Epoch3_1 => StacksEpochId::Epoch31,
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions components/clarinet-files/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ pub use network_manifest::{
NetworkManifestFile, PoxStackingOrder, DEFAULT_BITCOIN_EXPLORER_IMAGE,
DEFAULT_BITCOIN_NODE_IMAGE, DEFAULT_DERIVATION_PATH, DEFAULT_DOCKER_PLATFORM,
DEFAULT_EPOCH_2_0, DEFAULT_EPOCH_2_05, DEFAULT_EPOCH_2_1, DEFAULT_EPOCH_2_2, DEFAULT_EPOCH_2_3,
DEFAULT_EPOCH_2_4, DEFAULT_EPOCH_2_5, DEFAULT_EPOCH_3_0, DEFAULT_FAUCET_MNEMONIC,
DEFAULT_FIRST_BURN_HEADER_HEIGHT, DEFAULT_POSTGRES_IMAGE, DEFAULT_STACKER_MNEMONIC,
DEFAULT_STACKS_API_IMAGE, DEFAULT_STACKS_EXPLORER_IMAGE, DEFAULT_STACKS_MINER_MNEMONIC,
DEFAULT_STACKS_NODE_IMAGE, DEFAULT_STACKS_SIGNER_IMAGE, DEFAULT_SUBNET_API_IMAGE,
DEFAULT_SUBNET_CONTRACT_ID, DEFAULT_SUBNET_MNEMONIC, DEFAULT_SUBNET_NODE_IMAGE,
DEFAULT_EPOCH_2_4, DEFAULT_EPOCH_2_5, DEFAULT_EPOCH_3_0, DEFAULT_EPOCH_3_1,
DEFAULT_FAUCET_MNEMONIC, DEFAULT_FIRST_BURN_HEADER_HEIGHT, DEFAULT_POSTGRES_IMAGE,
DEFAULT_STACKER_MNEMONIC, DEFAULT_STACKS_API_IMAGE, DEFAULT_STACKS_EXPLORER_IMAGE,
DEFAULT_STACKS_MINER_MNEMONIC, DEFAULT_STACKS_NODE_IMAGE, DEFAULT_STACKS_SIGNER_IMAGE,
DEFAULT_SUBNET_API_IMAGE, DEFAULT_SUBNET_CONTRACT_ID, DEFAULT_SUBNET_MNEMONIC,
DEFAULT_SUBNET_NODE_IMAGE,
};
pub use project_manifest::{
ProjectManifest, ProjectManifestFile, RequirementConfig, INVALID_CLARITY_VERSION,
Expand Down
12 changes: 10 additions & 2 deletions components/clarinet-files/src/network_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use toml::value::Value;

pub const DEFAULT_DERIVATION_PATH: &str = "m/44'/5757'/0'/0/0";

pub const DEFAULT_STACKS_NODE_IMAGE: &str = "quay.io/hirosystems/stacks-node:devnet-3.0";
pub const DEFAULT_STACKS_SIGNER_IMAGE: &str = "quay.io/hirosystems/stacks-signer:devnet-3.0";
pub const DEFAULT_STACKS_NODE_IMAGE: &str = "quay.io/hirosystems/stacks-node:devnet-3.1";
pub const DEFAULT_STACKS_SIGNER_IMAGE: &str = "quay.io/hirosystems/stacks-signer:devnet-3.1";
pub const DEFAULT_STACKS_API_IMAGE: &str = "hirosystems/stacks-blockchain-api:master";

pub const DEFAULT_BITCOIN_NODE_IMAGE: &str = "quay.io/hirosystems/bitcoind:26.0";
Expand Down Expand Up @@ -47,6 +47,7 @@ pub const DEFAULT_EPOCH_2_3: u64 = 103;
pub const DEFAULT_EPOCH_2_4: u64 = 104;
pub const DEFAULT_EPOCH_2_5: u64 = 108;
pub const DEFAULT_EPOCH_3_0: u64 = 142;
pub const DEFAULT_EPOCH_3_1: u64 = 144;

// Currently, the pox-4 contract has these values hardcoded:
// https://github.com/stacks-network/stacks-core/blob/e09ab931e2f15ff70f3bb5c2f4d7afb[…]42bd7bec6/stackslib/src/chainstate/stacks/boot/pox-testnet.clar
Expand Down Expand Up @@ -189,6 +190,7 @@ pub struct DevnetConfigFile {
pub epoch_2_4: Option<u64>,
pub epoch_2_5: Option<u64>,
pub epoch_3_0: Option<u64>,
pub epoch_3_1: Option<u64>,
pub use_docker_gateway_routing: Option<bool>,
pub docker_platform: Option<String>,
}
Expand Down Expand Up @@ -360,6 +362,7 @@ pub struct DevnetConfig {
pub epoch_2_4: u64,
pub epoch_2_5: u64,
pub epoch_3_0: u64,
pub epoch_3_1: u64,
pub use_docker_gateway_routing: bool,
pub docker_platform: String,
}
Expand Down Expand Up @@ -743,6 +746,10 @@ impl NetworkManifest {
devnet_config.epoch_3_0 = Some(*val);
}

if let Some(ref val) = devnet_override.epoch_3_1 {
devnet_config.epoch_3_1 = Some(*val);
}

if let Some(val) = devnet_override.network_id {
devnet_config.network_id = Some(val);
}
Expand Down Expand Up @@ -1062,6 +1069,7 @@ impl NetworkManifest {
epoch_2_4: devnet_config.epoch_2_4.unwrap_or(DEFAULT_EPOCH_2_4),
epoch_2_5: devnet_config.epoch_2_5.unwrap_or(DEFAULT_EPOCH_2_5),
epoch_3_0: devnet_config.epoch_3_0.unwrap_or(DEFAULT_EPOCH_3_0),
epoch_3_1: devnet_config.epoch_3_1.unwrap_or(DEFAULT_EPOCH_3_1),
stacks_node_env_vars: devnet_config
.stacks_node_env_vars
.take()
Expand Down
1 change: 1 addition & 0 deletions components/clarinet-files/src/project_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ fn get_epoch_and_clarity_version(
"2.4" => StacksEpochId::Epoch24,
"2.5" => StacksEpochId::Epoch25,
"3" | "3.0" => StacksEpochId::Epoch30,
"3.1" => StacksEpochId::Epoch31,
_ => return Err(INVALID_EPOCH.into()),
},
};
Expand Down
1 change: 1 addition & 0 deletions components/clarinet-sdk-wasm/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ impl SDK {
"2.4" => StacksEpochId::Epoch24,
"2.5" => StacksEpochId::Epoch25,
"3.0" => StacksEpochId::Epoch30,
"3.1" => StacksEpochId::Epoch31,
_ => {
log!("Invalid epoch {epoch}. Using default epoch");
DEFAULT_EPOCH
Expand Down
3 changes: 2 additions & 1 deletion components/clarinet-sdk-wasm/src/ts_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ const STACKS_EPOCH_ID_STRING: &'static str = r#"export type StacksEpochId =
| "Epoch23"
| "Epoch24"
| "Epoch25"
| "Epoch30";"#;
| "Epoch30"
| "Epoch31";"#;

#[wasm_bindgen(typescript_custom_section)]
const CLARITY_VERSION_STRING: &'static str =
Expand Down
4 changes: 2 additions & 2 deletions components/clarinet-sdk/node/tests/simnet-usage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ describe("basic simnet interactions", () => {

// @ts-ignore
// "0" is an invalid epoch
// it logs that 0 is invalid and defaults to 3.0
// it logs that 0 is invalid and defaults to 3.1
simnet.setEpoch("0");
expect(simnet.currentEpoch).toBe("3.0");
expect(simnet.currentEpoch).toBe("3.1");
});

it("can get default clarity version for current epoch", () => {
Expand Down
1 change: 1 addition & 0 deletions components/clarity-repl/src/repl/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn epoch_to_peer_version(epoch: StacksEpochId) -> u8 {
StacksEpochId::Epoch24 => PEER_VERSION_EPOCH_2_4,
StacksEpochId::Epoch25 => PEER_VERSION_EPOCH_2_5,
StacksEpochId::Epoch30 => PEER_VERSION_EPOCH_3_0,
StacksEpochId::Epoch31 => PEER_VERSION_EPOCH_3_1,
}
}

Expand Down
5 changes: 4 additions & 1 deletion components/clarity-repl/src/repl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use clarity::types::StacksEpochId;
use clarity::vm::ClarityVersion;

pub const DEFAULT_CLARITY_VERSION: ClarityVersion = ClarityVersion::Clarity3;
pub const DEFAULT_EPOCH: StacksEpochId = StacksEpochId::Epoch30;
pub const DEFAULT_EPOCH: StacksEpochId = StacksEpochId::Epoch31;

#[derive(Deserialize, Debug, Clone)]
pub struct ClarityContract {
Expand Down Expand Up @@ -94,6 +94,9 @@ impl Serialize for ClarityContract {
StacksEpochId::Epoch30 => {
map.serialize_entry("epoch", &3.0)?;
}
StacksEpochId::Epoch31 => {
map.serialize_entry("epoch", &3.1)?;
}
}
map.end()
}
Expand Down
3 changes: 2 additions & 1 deletion components/clarity-repl/src/repl/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,9 @@ impl Session {
Some("2.4") => StacksEpochId::Epoch24,
Some("2.5") => StacksEpochId::Epoch25,
Some("3.0") => StacksEpochId::Epoch30,
Some("3.1") => StacksEpochId::Epoch31,
_ => {
return "Usage: ::set_epoch 2.0 | 2.05 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | 3.0"
return "Usage: ::set_epoch 2.0 | 2.05 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | 3.0 | 3.1"
.red()
.to_string()
}
Expand Down
5 changes: 5 additions & 0 deletions components/stacks-network/src/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,10 @@ start_height = {epoch_2_5}
[[burnchain.epochs]]
epoch_name = "3.0"
start_height = {epoch_3_0}
[[burnchain.epochs]]
epoch_name = "3.1"
start_height = {epoch_3_1}
"#,
epoch_2_0 = devnet_config.epoch_2_0,
epoch_2_05 = devnet_config.epoch_2_05,
Expand All @@ -1221,6 +1225,7 @@ start_height = {epoch_3_0}
epoch_2_4 = devnet_config.epoch_2_4,
epoch_2_5 = devnet_config.epoch_2_5,
epoch_3_0 = devnet_config.epoch_3_0,
epoch_3_1 = devnet_config.epoch_3_1,
));

let mut stacks_conf_path = PathBuf::from(&devnet_config.working_dir);
Expand Down

0 comments on commit 682daf5

Please sign in to comment.