From 682daf549c33c7581079a8244c5f1e010c28cecf Mon Sep 17 00:00:00 2001 From: Hugo C <911307+hugocaillard@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:31:14 -0500 Subject: [PATCH] feat: epoch 3.1 support (#1630) * feat: epoch 3.1 support * tests: fix sdk test --- Cargo.lock | 13 +++++++------ components/clarinet-cli/src/generate/project.rs | 11 ++++++----- components/clarinet-deployments/src/onchain/mod.rs | 1 + components/clarinet-deployments/src/requirements.rs | 10 ++++++++-- components/clarinet-deployments/src/types.rs | 4 ++++ components/clarinet-files/src/lib.rs | 11 ++++++----- components/clarinet-files/src/network_manifest.rs | 12 ++++++++++-- components/clarinet-files/src/project_manifest.rs | 1 + components/clarinet-sdk-wasm/src/core.rs | 1 + components/clarinet-sdk-wasm/src/ts_types.rs | 3 ++- .../clarinet-sdk/node/tests/simnet-usage.test.ts | 4 ++-- components/clarity-repl/src/repl/datastore.rs | 1 + components/clarity-repl/src/repl/mod.rs | 5 ++++- components/clarity-repl/src/repl/session.rs | 3 ++- components/stacks-network/src/orchestrator.rs | 5 +++++ 15 files changed, 60 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce3ec8d73..74afaf8a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -672,7 +672,7 @@ checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" [[package]] name = "clar2wasm" version = "0.1.0" -source = "git+https://github.com/stacks-network/clarity-wasm.git?branch=main#a3dc9cdde1bc510b674c2fc81f540124f87b4fc4" +source = "git+https://github.com/stacks-network/clarity-wasm.git?branch=main#41079f35fa5fcd606c304db9a258b9ac625a7b70" dependencies = [ "chrono", "clap", @@ -801,7 +801,7 @@ dependencies = [ [[package]] name = "clarity" version = "2.3.0" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat%2Fclarity-wasm-develop#28c1d9eecfd26443b6f78de754b51b9dcfac8402" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat%2Fclarity-wasm-develop#2ecb92e408e4ef3dc0589f49afd3bc18b582dca7" dependencies = [ "getrandom 0.2.8", "hashbrown 0.14.3", @@ -2817,7 +2817,7 @@ dependencies = [ [[package]] name = "libstackerdb" version = "0.0.1" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat%2Fclarity-wasm-develop#28c1d9eecfd26443b6f78de754b51b9dcfac8402" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat%2Fclarity-wasm-develop#2ecb92e408e4ef3dc0589f49afd3bc18b582dca7" dependencies = [ "clarity", "secp256k1 0.24.3", @@ -3493,7 +3493,7 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "pox-locking" version = "2.4.0" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat%2Fclarity-wasm-develop#28c1d9eecfd26443b6f78de754b51b9dcfac8402" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat%2Fclarity-wasm-develop#2ecb92e408e4ef3dc0589f49afd3bc18b582dca7" dependencies = [ "clarity", "slog", @@ -4770,7 +4770,7 @@ dependencies = [ [[package]] name = "stacks-common" version = "0.0.2" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat%2Fclarity-wasm-develop#28c1d9eecfd26443b6f78de754b51b9dcfac8402" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat%2Fclarity-wasm-develop#2ecb92e408e4ef3dc0589f49afd3bc18b582dca7" dependencies = [ "chrono", "curve25519-dalek 2.0.0", @@ -4869,7 +4869,7 @@ dependencies = [ [[package]] name = "stackslib" version = "0.0.1" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat%2Fclarity-wasm-develop#28c1d9eecfd26443b6f78de754b51b9dcfac8402" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat%2Fclarity-wasm-develop#2ecb92e408e4ef3dc0589f49afd3bc18b582dca7" dependencies = [ "chrono", "clar2wasm", @@ -4903,6 +4903,7 @@ dependencies = [ "stacks-common", "tikv-jemallocator", "time", + "toml 0.5.11", "url", "winapi 0.3.9", ] diff --git a/components/clarinet-cli/src/generate/project.rs b/components/clarinet-cli/src/generate/project.rs index a21c0867e..bf674ee3b 100644 --- a/components/clarinet-cli/src/generate/project.rs +++ b/components/clarinet-cli/src/generate/project.rs @@ -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}; @@ -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]] diff --git a/components/clarinet-deployments/src/onchain/mod.rs b/components/clarinet-deployments/src/onchain/mod.rs index 52d9ba1ac..5f09aad98 100644 --- a/components/clarinet-deployments/src/onchain/mod.rs +++ b/components/clarinet-deployments/src/onchain/mod.rs @@ -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; diff --git a/components/clarinet-deployments/src/requirements.rs b/components/clarinet-deployments/src/requirements.rs index 4059b7544..e784ed643 100644 --- a/components/clarinet-deployments/src/requirements.rs +++ b/components/clarinet-deployments/src/requirements.rs @@ -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; @@ -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 { @@ -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 } } @@ -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 } } diff --git a/components/clarinet-deployments/src/types.rs b/components/clarinet-deployments/src/types.rs index ec61c7ef2..e17343dcf 100644 --- a/components/clarinet-deployments/src/types.rs +++ b/components/clarinet-deployments/src/types.rs @@ -34,6 +34,8 @@ pub enum EpochSpec { Epoch2_5, #[serde(rename = "3.0")] Epoch3_0, + #[serde(rename = "3.1")] + Epoch3_1, } impl From for EpochSpec { @@ -47,6 +49,7 @@ impl From 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"), } } @@ -63,6 +66,7 @@ impl From for StacksEpochId { EpochSpec::Epoch2_4 => StacksEpochId::Epoch24, EpochSpec::Epoch2_5 => StacksEpochId::Epoch25, EpochSpec::Epoch3_0 => StacksEpochId::Epoch30, + EpochSpec::Epoch3_1 => StacksEpochId::Epoch31, } } } diff --git a/components/clarinet-files/src/lib.rs b/components/clarinet-files/src/lib.rs index 87125a63a..0ddb1f297 100644 --- a/components/clarinet-files/src/lib.rs +++ b/components/clarinet-files/src/lib.rs @@ -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, diff --git a/components/clarinet-files/src/network_manifest.rs b/components/clarinet-files/src/network_manifest.rs index e59cb178d..ddb262fd4 100644 --- a/components/clarinet-files/src/network_manifest.rs +++ b/components/clarinet-files/src/network_manifest.rs @@ -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"; @@ -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 @@ -189,6 +190,7 @@ pub struct DevnetConfigFile { pub epoch_2_4: Option, pub epoch_2_5: Option, pub epoch_3_0: Option, + pub epoch_3_1: Option, pub use_docker_gateway_routing: Option, pub docker_platform: Option, } @@ -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, } @@ -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); } @@ -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() diff --git a/components/clarinet-files/src/project_manifest.rs b/components/clarinet-files/src/project_manifest.rs index dddae707a..895c629f3 100644 --- a/components/clarinet-files/src/project_manifest.rs +++ b/components/clarinet-files/src/project_manifest.rs @@ -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()), }, }; diff --git a/components/clarinet-sdk-wasm/src/core.rs b/components/clarinet-sdk-wasm/src/core.rs index 59ce50293..07a48821c 100644 --- a/components/clarinet-sdk-wasm/src/core.rs +++ b/components/clarinet-sdk-wasm/src/core.rs @@ -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 diff --git a/components/clarinet-sdk-wasm/src/ts_types.rs b/components/clarinet-sdk-wasm/src/ts_types.rs index 8aab45167..0747c2126 100644 --- a/components/clarinet-sdk-wasm/src/ts_types.rs +++ b/components/clarinet-sdk-wasm/src/ts_types.rs @@ -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 = diff --git a/components/clarinet-sdk/node/tests/simnet-usage.test.ts b/components/clarinet-sdk/node/tests/simnet-usage.test.ts index 6de4a9dbc..258866fa3 100644 --- a/components/clarinet-sdk/node/tests/simnet-usage.test.ts +++ b/components/clarinet-sdk/node/tests/simnet-usage.test.ts @@ -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", () => { diff --git a/components/clarity-repl/src/repl/datastore.rs b/components/clarity-repl/src/repl/datastore.rs index d280edf34..8c56cf6a9 100644 --- a/components/clarity-repl/src/repl/datastore.rs +++ b/components/clarity-repl/src/repl/datastore.rs @@ -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, } } diff --git a/components/clarity-repl/src/repl/mod.rs b/components/clarity-repl/src/repl/mod.rs index 1b8852594..516881a08 100644 --- a/components/clarity-repl/src/repl/mod.rs +++ b/components/clarity-repl/src/repl/mod.rs @@ -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 { @@ -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() } diff --git a/components/clarity-repl/src/repl/session.rs b/components/clarity-repl/src/repl/session.rs index f00a0fced..dd672ccbe 100644 --- a/components/clarity-repl/src/repl/session.rs +++ b/components/clarity-repl/src/repl/session.rs @@ -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() } diff --git a/components/stacks-network/src/orchestrator.rs b/components/stacks-network/src/orchestrator.rs index bbb9fe027..0970ac9cc 100644 --- a/components/stacks-network/src/orchestrator.rs +++ b/components/stacks-network/src/orchestrator.rs @@ -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, @@ -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);