Skip to content

Commit

Permalink
feat: clarity-vm and epoch 2.4 support
Browse files Browse the repository at this point in the history
* feat: add support for epoch 2.2 in devnet

* chore: update stacks-rpc-client

* chore: update Cargo.lock

* fix: add default PoxInfo

* feat: add `pox_2_unlock_height` to burnchain config

* feat: add `stacksNodeVersion`

This function can be used to determine which version of the stacks-node
is supported by this library.

* fix: add missing `pox_2_unlock_height`

3da566b missed this field.

* feat: add 2.3 support

* feat: add support for epoch 2.4

Remove `pox_2_unlock_height` configuration. The node just uses 2.2
activation height + 1.

* feat: updates to fix `clarinet integrate`

This works with the `feat/2.4-clarity-wasm` branch of stacks-blockchain.

* feat: update height->block calculations

* feat: add epochs 2.2, 2.3, 2.4 to `::set_epoch`

* feat: add pox-3 to boot contracts

* fix: added missing pox-3.clar

* feat: pull in latest pox-3 contract

* feat: set exact 2.4 start height

* chore: use clarity-vm from crates.io

* chore: upgrade clarity-vm to 2.1.1

* refactor: remove comment

* refactor: remove comments

* chore: remove unused `PoxInfo` defaults

* fix: update default stacks-node image

* refactor: review

* chore: reapply clarity-vm 2.1 changes

---------

Co-authored-by: Brice Dobry <brice@hiro.so>
Co-authored-by: Hugo C <911307+hugocaillard@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 13, 2023
1 parent b08c86d commit 0c8de5b
Show file tree
Hide file tree
Showing 23 changed files with 2,565 additions and 397 deletions.
715 changes: 431 additions & 284 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ members = [
"components/stacks-rpc-client",
]
default-members = ["components/clarinet-cli"]

# [patch.crates-io]
# "clarity-vm" = { path = "../stacks-blockchain/clarity" }
1 change: 1 addition & 0 deletions components/clarinet-cli/src/runner/api_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ fn mine_block(state: &mut OpState, args: MineBlockArgs) -> Result<String, AnyErr
pox_cycle_position: 0,
pox_cycle_length: 0,
confirm_microblock_identifier: None,
stacks_block_hash: String::new(),
},
};
let result = handle_stacks_hook_action(
Expand Down
10 changes: 10 additions & 0 deletions components/clarinet-deployments/src/onchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use clarity_repl::codec::{
use clarity_repl::codec::{StacksTransaction, TransactionAnchorMode};
use clarity_repl::repl::session::{
BOOT_MAINNET_ADDRESS, BOOT_TESTNET_ADDRESS, V1_BOOT_CONTRACTS, V2_BOOT_CONTRACTS,
V3_BOOT_CONTRACTS,
};
use clarity_repl::repl::{Session, SessionSettings};
use reqwest::Url;
Expand Down Expand Up @@ -398,6 +399,12 @@ pub fn apply_on_chain_deployment(
format!("{}:{}", BOOT_TESTNET_ADDRESS, contract),
));
}
for contract in V3_BOOT_CONTRACTS {
contracts_ids_to_remap.insert((
format!("{}:{}", BOOT_MAINNET_ADDRESS, contract),
format!("{}:{}", BOOT_TESTNET_ADDRESS, contract),
));
}

for batch_spec in deployment.plan.batches.iter() {
let epoch = match batch_spec.epoch {
Expand Down Expand Up @@ -771,6 +778,9 @@ pub fn apply_on_chain_deployment(
EpochSpec::Epoch2_0 => network_manifest.devnet.as_ref().unwrap().epoch_2_0,
EpochSpec::Epoch2_05 => network_manifest.devnet.as_ref().unwrap().epoch_2_05,
EpochSpec::Epoch2_1 => network_manifest.devnet.as_ref().unwrap().epoch_2_1,
EpochSpec::Epoch2_2 => network_manifest.devnet.as_ref().unwrap().epoch_2_2,
EpochSpec::Epoch2_3 => network_manifest.devnet.as_ref().unwrap().epoch_2_3,
EpochSpec::Epoch2_4 => network_manifest.devnet.as_ref().unwrap().epoch_2_4,
};
let mut epoch_transition_successful =
current_bitcoin_block_height > after_bitcoin_block;
Expand Down
27 changes: 22 additions & 5 deletions components/clarinet-deployments/src/requirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,17 @@ pub async fn retrieve_contract(

pub const MAINNET_20_START_HEIGHT: u32 = 1;
pub const MAINNET_2_05_START_HEIGHT: u32 = 40_607;
// TODO: This is estimated. Replace with exact height once 2.1 is activated.
pub const MAINNET_21_START_HEIGHT: u32 = 99_564;
pub const TESTNET_20_START_HEIGHT: u32 = 1;
pub const MAINNET_21_START_HEIGHT: u32 = 99_113;
pub const MAINNET_22_START_HEIGHT: u32 = 103_900;
pub const MAINNET_23_START_HEIGHT: u32 = 104_359;
pub const MAINNET_24_START_HEIGHT: u32 = 107_055;

pub const TESTNET_20_START_HEIGHT: u32 = 1;
pub const TESTNET_2_05_START_HEIGHT: u32 = 20_216;
pub const TESTNET_21_START_HEIGHT: u32 = 99_113;
pub const TESTNET_22_START_HEIGHT: u32 = 105_923;
pub const TESTNET_23_START_HEIGHT: u32 = 106_196;
pub const TESTNET_24_START_HEIGHT: u32 = 106_979;

fn epoch_for_height(is_mainnet: bool, height: u32) -> StacksEpochId {
if is_mainnet {
Expand All @@ -142,8 +147,14 @@ fn epoch_for_mainnet_height(height: u32) -> StacksEpochId {
StacksEpochId::Epoch20
} else if height < MAINNET_21_START_HEIGHT {
StacksEpochId::Epoch2_05
} else {
} else if height < MAINNET_22_START_HEIGHT {
StacksEpochId::Epoch21
} else if height < MAINNET_23_START_HEIGHT {
StacksEpochId::Epoch22
} else if height < MAINNET_24_START_HEIGHT {
StacksEpochId::Epoch23
} else {
StacksEpochId::Epoch24
}
}

Expand All @@ -152,8 +163,14 @@ fn epoch_for_testnet_height(height: u32) -> StacksEpochId {
StacksEpochId::Epoch20
} else if height < TESTNET_21_START_HEIGHT {
StacksEpochId::Epoch2_05
} else {
} else if height < TESTNET_22_START_HEIGHT {
StacksEpochId::Epoch21
} else if height < TESTNET_23_START_HEIGHT {
StacksEpochId::Epoch22
} else if height < TESTNET_24_START_HEIGHT {
StacksEpochId::Epoch23
} else {
StacksEpochId::Epoch24
}
}

Expand Down
12 changes: 12 additions & 0 deletions components/clarinet-deployments/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ pub enum EpochSpec {
Epoch2_05,
#[serde(rename = "2.1")]
Epoch2_1,
#[serde(rename = "2.2")]
Epoch2_2,
#[serde(rename = "2.3")]
Epoch2_3,
#[serde(rename = "2.4")]
Epoch2_4,
}

impl From<StacksEpochId> for EpochSpec {
Expand All @@ -35,6 +41,9 @@ impl From<StacksEpochId> for EpochSpec {
StacksEpochId::Epoch20 => EpochSpec::Epoch2_0,
StacksEpochId::Epoch2_05 => EpochSpec::Epoch2_05,
StacksEpochId::Epoch21 => EpochSpec::Epoch2_1,
StacksEpochId::Epoch22 => EpochSpec::Epoch2_2,
StacksEpochId::Epoch23 => EpochSpec::Epoch2_3,
StacksEpochId::Epoch24 => EpochSpec::Epoch2_4,
StacksEpochId::Epoch10 => unreachable!("epoch 1.0 is not supported"),
}
}
Expand All @@ -46,6 +55,9 @@ impl Into<StacksEpochId> for EpochSpec {
EpochSpec::Epoch2_0 => StacksEpochId::Epoch20,
EpochSpec::Epoch2_05 => StacksEpochId::Epoch2_05,
EpochSpec::Epoch2_1 => StacksEpochId::Epoch21,
EpochSpec::Epoch2_2 => StacksEpochId::Epoch22,
EpochSpec::Epoch2_3 => StacksEpochId::Epoch23,
EpochSpec::Epoch2_4 => StacksEpochId::Epoch24,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/clarinet-files/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ edition = "2021"
[dependencies]
serde = "1"
serde_derive = "1"
chainhook-types = "=1.0.3"
# chainhook-types = { version = "=1.0.3", path = "../../../chainhook/components/chainhook-types-rs" }
chainhook-types = "=1.0.5"
# chainhook-types = { version = "=1.0.5", path = "../../../chainhook/components/chainhook-types-rs" }
clarinet-utils = { version = "1", path = "../clarinet-utils" }
clarity-repl = { version = "1", path = "../clarity-repl", default-features = false, optional = true }
bip39 = { version = "1.0.1", default-features = false }
Expand Down
26 changes: 25 additions & 1 deletion components/clarinet-files/src/network_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use toml::value::Value;

pub const DEFAULT_DERIVATION_PATH: &str = "m/44'/5757'/0'/0/0";
pub const DEFAULT_BITCOIN_NODE_IMAGE: &str = "quay.io/hirosystems/bitcoind:devnet-v3";
pub const DEFAULT_STACKS_NODE_IMAGE: &str = "quay.io/hirosystems/stacks-node:devnet-v3";
pub const DEFAULT_STACKS_NODE_IMAGE: &str = "quay.io/hirosystems/stacks-node:devnet-2.4.0.0.0";
pub const DEFAULT_BITCOIN_EXPLORER_IMAGE: &str = "quay.io/hirosystems/bitcoin-explorer:devnet";
pub const DEFAULT_STACKS_API_IMAGE: &str = "hirosystems/stacks-blockchain-api:latest";
pub const DEFAULT_STACKS_EXPLORER_IMAGE: &str = "hirosystems/explorer:latest";
Expand All @@ -39,6 +39,9 @@ pub const DEFAULT_EPOCH_2_0: u64 = 100;
pub const DEFAULT_EPOCH_2_05: u64 = 102;
pub const DEFAULT_EPOCH_2_1: u64 = 106;
pub const DEFAULT_POX2_ACTIVATION: u64 = 109;
pub const DEFAULT_EPOCH_2_2: u64 = 122;
pub const DEFAULT_EPOCH_2_3: u64 = 128;
pub const DEFAULT_EPOCH_2_4: u64 = 134;

#[derive(Serialize, Deserialize, Debug)]
pub struct NetworkManifestFile {
Expand Down Expand Up @@ -123,6 +126,9 @@ pub struct DevnetConfigFile {
pub epoch_2_0: Option<u64>,
pub epoch_2_05: Option<u64>,
pub epoch_2_1: Option<u64>,
pub epoch_2_2: Option<u64>,
pub epoch_2_3: Option<u64>,
pub epoch_2_4: Option<u64>,
pub pox_2_activation: Option<u64>,
pub use_docker_gateway_routing: Option<bool>,
pub docker_platform: Option<String>,
Expand Down Expand Up @@ -244,6 +250,9 @@ pub struct DevnetConfig {
pub epoch_2_0: u64,
pub epoch_2_05: u64,
pub epoch_2_1: u64,
pub epoch_2_2: u64,
pub epoch_2_3: u64,
pub epoch_2_4: u64,
pub pox_2_activation: u64,
pub use_docker_gateway_routing: bool,
pub docker_platform: String,
Expand Down Expand Up @@ -609,6 +618,18 @@ impl NetworkManifest {
devnet_config.epoch_2_1 = Some(val.clone());
}

if let Some(ref val) = devnet_override.epoch_2_2 {
devnet_config.epoch_2_2 = Some(val.clone());
}

if let Some(ref val) = devnet_override.epoch_2_3 {
devnet_config.epoch_2_3 = Some(val.clone());
}

if let Some(ref val) = devnet_override.epoch_2_4 {
devnet_config.epoch_2_4 = Some(val.clone());
}

if let Some(ref val) = devnet_override.pox_2_activation {
devnet_config.pox_2_activation = Some(val.clone());
}
Expand Down Expand Up @@ -837,6 +858,9 @@ impl NetworkManifest {
epoch_2_0: devnet_config.epoch_2_0.unwrap_or(DEFAULT_EPOCH_2_0),
epoch_2_05: devnet_config.epoch_2_05.unwrap_or(DEFAULT_EPOCH_2_05),
epoch_2_1: devnet_config.epoch_2_1.unwrap_or(DEFAULT_EPOCH_2_1),
epoch_2_2: devnet_config.epoch_2_2.unwrap_or(DEFAULT_EPOCH_2_2),
epoch_2_3: devnet_config.epoch_2_3.unwrap_or(DEFAULT_EPOCH_2_3),
epoch_2_4: devnet_config.epoch_2_4.unwrap_or(DEFAULT_EPOCH_2_4),
pox_2_activation: devnet_config
.pox_2_activation
.unwrap_or(DEFAULT_POX2_ACTIVATION),
Expand Down
15 changes: 14 additions & 1 deletion components/clarinet-files/src/project_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::str::FromStr;
use toml::value::Value;

const INVALID_CLARITY_VERSION: &str = "clarity_version field invalid (value supported: 1, 2)";
const INVALID_EPOCH: &str = "epoch field invalid (value supported: 2.0, 2.05, 2.1)";
const INVALID_EPOCH: &str = "epoch field invalid (value supported: 2.0, 2.05, 2.1, 2.2, 2.3, 2.4)";

#[derive(Deserialize, Debug, Clone)]
pub struct ClarityContractMetadata {
Expand Down Expand Up @@ -169,6 +169,7 @@ impl ProjectManifest {
"costs".to_string(),
"pox".to_string(),
"pox-2".to_string(),
"pox-3".to_string(),
"lockup".to_string(),
"costs-2".to_string(),
"costs-3".to_string(),
Expand Down Expand Up @@ -287,6 +288,12 @@ fn get_epoch_and_clarity_version(
StacksEpochId::Epoch2_05
} else if epoch.eq("2.1") {
StacksEpochId::Epoch21
} else if epoch.eq("2.2") {
StacksEpochId::Epoch22
} else if epoch.eq("2.3") {
StacksEpochId::Epoch23
} else if epoch.eq("2.4") {
StacksEpochId::Epoch24
} else {
return Err(INVALID_EPOCH.into());
}
Expand All @@ -298,6 +305,12 @@ fn get_epoch_and_clarity_version(
StacksEpochId::Epoch2_05
} else if epoch.eq(&2.1) {
StacksEpochId::Epoch21
} else if epoch.eq(&2.2) {
StacksEpochId::Epoch22
} else if epoch.eq(&2.3) {
StacksEpochId::Epoch23
} else if epoch.eq(&2.4) {
StacksEpochId::Epoch24
} else {
return Err(INVALID_EPOCH.into());
}
Expand Down
5 changes: 2 additions & 3 deletions components/clarity-repl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clarity-repl"
version = "1.6.2"
version = "1.6.4"
description = "Clarity REPL"
authors = [
"Ludo Galabru <ludo@hiro.so>",
Expand Down Expand Up @@ -34,8 +34,7 @@ integer-sqrt = "0.1.3"
rand = "=0.7.3"
getrandom = { version = "0.2.3", features = ["js"] }
atty = "0.2.14"
clarity-vm = { version = "=2.0.2", default-features = false, optional = true }
# clarity-vm = { path = "../../../stacks-blockchain/clarity", default-features = false, optional = true }
clarity-vm = { version = "2", default-features = false, optional = true }

# DAP Debugger
tokio = { version = "1.24", features = ["full"], optional = true }
Expand Down
12 changes: 10 additions & 2 deletions components/clarity-repl/src/repl/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ const BOOT_CODE_BNS: &'static str = std::include_str!("bns.clar");
const BOOT_CODE_GENESIS: &'static str = std::include_str!("genesis.clar");
pub const POX_1_NAME: &'static str = "pox";
pub const POX_2_NAME: &'static str = "pox-2";
pub const POX_3_NAME: &'static str = "pox-3";

const POX_2_TESTNET_CONSTS: &'static str = std::include_str!("pox-testnet.clar");
const POX_2_MAINNET_CONSTS: &'static str = std::include_str!("pox-mainnet.clar");
const POX_2_BODY: &'static str = std::include_str!("pox-2.clar");
const POX_3_BODY: &'static str = std::include_str!("pox-3.clar");

pub const COSTS_1_NAME: &'static str = "costs";
pub const COSTS_2_NAME: &'static str = "costs-2";
Expand All @@ -47,8 +49,12 @@ lazy_static! {
format!("{}\n{}", BOOT_CODE_POX_MAINNET_CONSTS, POX_2_BODY);
pub static ref POX_2_TESTNET_CODE: String =
format!("{}\n{}", BOOT_CODE_POX_TESTNET_CONSTS, POX_2_BODY);
pub static ref POX_3_MAINNET_CODE: String =
format!("{}\n{}", BOOT_CODE_POX_MAINNET_CONSTS, POX_3_BODY);
pub static ref POX_3_TESTNET_CODE: String =
format!("{}\n{}", BOOT_CODE_POX_TESTNET_CONSTS, POX_3_BODY);
pub static ref BOOT_CODE_COST_VOTING_TESTNET: String = make_testnet_cost_voting();
pub static ref STACKS_BOOT_CODE_MAINNET: [(&'static str, &'static str); 10] = [
pub static ref STACKS_BOOT_CODE_MAINNET: [(&'static str, &'static str); 11] = [
("pox", &BOOT_CODE_POX_MAINNET),
("lockup", BOOT_CODE_LOCKUP),
("costs", BOOT_CODE_COSTS),
Expand All @@ -59,8 +65,9 @@ lazy_static! {
("costs-v2", &BOOT_CODE_COSTS_2), // for backwards compatibility with old Clarinet.toml files
("pox-2", &POX_2_MAINNET_CODE),
("costs-3", &BOOT_CODE_COSTS_3),
("pox-3", &POX_3_MAINNET_CODE),
];
pub static ref STACKS_BOOT_CODE_TESTNET: [(&'static str, &'static str); 10] = [
pub static ref STACKS_BOOT_CODE_TESTNET: [(&'static str, &'static str); 11] = [
("pox", &BOOT_CODE_POX_TESTNET),
("lockup", BOOT_CODE_LOCKUP),
("costs", BOOT_CODE_COSTS),
Expand All @@ -71,6 +78,7 @@ lazy_static! {
("costs-v2", &BOOT_CODE_COSTS_2_TESTNET), // for backwards compatibility with old Clarinet.toml files
("pox-2", &POX_2_TESTNET_CODE),
("costs-3", &BOOT_CODE_COSTS_3_TESTNET),
("pox-3", &POX_3_TESTNET_CODE),
];
}

Expand Down
Loading

0 comments on commit 0c8de5b

Please sign in to comment.