Skip to content
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

Feat/customize number of signers in devnet #1555

Merged
merged 8 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
180 changes: 118 additions & 62 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions components/clarinet-files/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ toml = { version = "0.5.6", features = ["preserve_order"] }
url = { version = "2.2.2", features = ["serde"] }
tiny-hderive = "0.3.0"
bitcoin = { version = "0.29.2", optional = true }
lazy_static = { workspace = true}

clarity = { workspace = true }

Expand Down
47 changes: 42 additions & 5 deletions components/clarinet-files/src/network_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use bip39::{Language, Mnemonic};
use chainhook_types::{BitcoinNetwork, StacksNetwork};
use clarinet_utils::get_bip39_seed_from_mnemonic;
use clarity::address::AddressHashMode;
use clarity::types::chainstate::StacksAddress;
use clarity::types::chainstate::{StacksAddress, StacksPrivateKey};
use clarity::util::{hash::bytes_to_hex, secp256k1::Secp256k1PublicKey};
use clarity::vm::types::QualifiedContractIdentifier;
use lazy_static::lazy_static;
use libsecp256k1::{PublicKey, SecretKey};
use serde::Serialize;
use tiny_hderive::bip32::ExtendedPrivKey;
use toml::value::Value;

Expand Down Expand Up @@ -44,8 +46,8 @@ pub const DEFAULT_EPOCH_2_2: u64 = 102;
pub const DEFAULT_EPOCH_2_3: u64 = 103;
pub const DEFAULT_EPOCH_2_4: u64 = 104;
pub const DEFAULT_EPOCH_2_5: u64 = 108;
// Epoch 3.0 isn't stable for now, let's focus on running 2.5
pub const DEFAULT_EPOCH_3_0: u64 = 100001;
// Mainnet run on Epoch 2.5, which shoud remain the default for devnet
pub const DEFAULT_EPOCH_3_0: u64 = 1000001;

// 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 All @@ -54,6 +56,19 @@ pub const DEFAULT_POX_PREPARE_LENGTH: u64 = 4;
pub const DEFAULT_POX_REWARD_LENGTH: u64 = 10;
pub const DEFAULT_FIRST_BURN_HEADER_HEIGHT: u64 = 100;

lazy_static! {
pub static ref DEFAULT_PRIVATE_KEYS: [StacksPrivateKey; 2] = [
StacksPrivateKey::from_hex(
"7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801",
)
.unwrap(),
StacksPrivateKey::from_hex(
"530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101",
)
.unwrap(),
];
}

#[derive(Serialize, Deserialize, Debug)]
pub struct NetworkManifestFile {
network: NetworkConfigFile,
Expand Down Expand Up @@ -87,6 +102,8 @@ pub struct DevnetConfigFile {
pub stacks_node_subsequent_attempt_time_ms: Option<u32>,
pub stacks_node_env_vars: Option<Vec<String>>,
pub stacks_node_next_initiative_delay: Option<u16>,
pub stacks_signers_keys: Option<Vec<String>>,
pub stacks_signers_env_vars: Option<Vec<String>>,
pub stacks_api_env_vars: Option<Vec<String>>,
pub stacks_explorer_env_vars: Option<Vec<String>>,
pub subnet_node_env_vars: Option<Vec<String>>,
Expand All @@ -104,6 +121,7 @@ pub struct DevnetConfigFile {
pub faucet_derivation_path: Option<String>,
pub bitcoin_controller_block_time: Option<u32>,
pub bitcoin_controller_automining_disabled: Option<bool>,
pub pre_nakamoto_mock_signing: Option<bool>,
pub working_dir: Option<String>,
pub postgres_port: Option<u16>,
pub postgres_username: Option<String>,
Expand Down Expand Up @@ -248,6 +266,8 @@ pub struct DevnetConfig {
pub stacks_api_port: u16,
pub stacks_api_events_port: u16,
pub stacks_api_env_vars: Vec<String>,
pub stacks_signers_keys: Vec<StacksPrivateKey>,
pub stacks_signers_env_vars: Vec<String>,
pub stacks_explorer_port: u16,
pub stacks_explorer_env_vars: Vec<String>,
pub bitcoin_explorer_port: u16,
Expand All @@ -265,6 +285,7 @@ pub struct DevnetConfig {
pub faucet_btc_address: String,
pub faucet_mnemonic: String,
pub faucet_derivation_path: String,
pub pre_nakamoto_mock_signing: bool,
pub working_dir: String,
pub postgres_port: u16,
pub postgres_username: String,
Expand All @@ -275,7 +296,7 @@ pub struct DevnetConfig {
pub execute_script: Vec<ExecuteScript>,
pub bitcoin_node_image_url: String,
pub stacks_node_image_url: String,
pub stacks_signer_image_url: String,
pub stacks_signers_image_url: String,
pub stacks_api_image_url: String,
pub stacks_explorer_image_url: String,
pub postgres_image_url: String,
Expand Down Expand Up @@ -857,6 +878,9 @@ impl NetworkManifest {
.miner_coinbase_recipient
.unwrap_or(miner_stx_address),
miner_wallet_name: devnet_config.miner_wallet_name.unwrap_or("".to_string()),
pre_nakamoto_mock_signing: devnet_config
.pre_nakamoto_mock_signing
.unwrap_or_default(),
faucet_btc_address,
faucet_stx_address,
faucet_mnemonic,
Expand Down Expand Up @@ -892,7 +916,7 @@ impl NetworkManifest {
.stacks_node_image_url
.take()
.unwrap_or(DEFAULT_STACKS_NODE_IMAGE.to_string()),
stacks_signer_image_url: devnet_config
stacks_signers_image_url: devnet_config
.stacks_signer_image_url
.take()
.unwrap_or(DEFAULT_STACKS_SIGNER_IMAGE.to_string()),
Expand Down Expand Up @@ -961,6 +985,19 @@ impl NetworkManifest {
.stacks_node_env_vars
.take()
.unwrap_or_default(),
stacks_signers_keys: devnet_config
.stacks_signers_keys
.take()
.map(|keys| {
keys.into_iter()
.map(|key| StacksPrivateKey::from_hex(&key).unwrap())
.collect::<Vec<clarity::util::secp256k1::Secp256k1PrivateKey>>()
})
.unwrap_or(DEFAULT_PRIVATE_KEYS.to_vec()),
stacks_signers_env_vars: devnet_config
.stacks_signers_env_vars
.take()
.unwrap_or_default(),
stacks_api_env_vars: devnet_config.stacks_api_env_vars.take().unwrap_or_default(),
stacks_explorer_env_vars: devnet_config
.stacks_explorer_env_vars
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-sdk/node/tests/pox-locking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe("test pox-3", () => {
describe("test pox-4", () => {
const poxContract = `${poxDeployer}.pox-4`;

// wallet_1, wallet_2, wallet_3 private keys
// wallet_1 and wallet_2 private keys
const stackingKeys = [
"7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801",
"530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101",
Expand Down
2 changes: 1 addition & 1 deletion components/stacks-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
atty = "0.2.14"
ansi_term = "0.12.1"
bollard = "0.16.0"
bollard = "0.17"
bitcoin = "0.29.2"
bitcoincore-rpc = "0.16.0"
serde = { version = "1", features = ["derive"] }
Expand Down
28 changes: 10 additions & 18 deletions components/stacks-network/src/chains_coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,8 @@ pub async fn start_chains_coordinator(
let chains_coordinator_commands_oper = sel.recv(&chains_coordinator_commands_rx);
let observer_event_oper = sel.recv(&observer_event_rx);

let DevnetConfig {
enable_subnet_node, ..
} = config.devnet_config;
let enable_subnet_node = config.devnet_config.enable_subnet_node;
let stacks_signers_keys = config.devnet_config.stacks_signers_keys.clone();

loop {
let oper = sel.select();
Expand Down Expand Up @@ -314,7 +313,9 @@ pub async fn start_chains_coordinator(
format!("mining blocks (chain_tip = #{})", bitcoin_block_height);

// Stacking orders can't be published until devnet is ready
if bitcoin_block_height >= DEFAULT_FIRST_BURN_HEADER_HEIGHT + 10 {
if !stacks_signers_keys.is_empty()
&& bitcoin_block_height >= DEFAULT_FIRST_BURN_HEADER_HEIGHT + 10
{
let res = publish_stacking_orders(
&config.devnet_config,
&devnet_event_tx,
Expand Down Expand Up @@ -654,10 +655,9 @@ pub async fn publish_stacking_orders(
Ok(pox_info) => Some(pox_info),
Err(e) => {
let _ = devnet_event_tx.send(DevnetEvent::warning(format!(
"Unable to parse pox info: {}",
"unable to parse pox info: {}",
e
)));

None
}
},
Expand Down Expand Up @@ -688,17 +688,6 @@ pub async fn publish_stacking_orders(
.and_then(|version| version.parse().ok())
.unwrap_or(1); // pox 1 contract is `pox.clar`

let default_signing_keys = [
StacksPrivateKey::from_hex(
"7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801",
)
.unwrap(),
StacksPrivateKey::from_hex(
"530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101",
)
.unwrap(),
];

let mut transactions = 0;
for (i, pox_stacking_order) in devnet_config.pox_stacking_orders.iter().enumerate() {
if !should_publish_stacking_orders(&current_cycle, pox_stacking_order) {
Expand Down Expand Up @@ -729,6 +718,9 @@ pub async fn publish_stacking_orders(
let btc_address_moved = pox_stacking_order.btc_address.clone();
let duration = pox_stacking_order.duration;

let signer_key =
devnet_config.stacks_signers_keys[i % devnet_config.stacks_signers_keys.len()];

let stacking_result =
hiro_system_kit::thread_named("Stacking orders handler").spawn(move || {
let default_fee = fee_rate * 1000;
Expand All @@ -745,7 +737,7 @@ pub async fn publish_stacking_orders(
pox_version,
bitcoin_block_height,
current_cycle.into(),
&default_signing_keys[i % 2],
&signer_key,
extend_stacking,
&btc_address_moved,
stx_amount,
Expand Down
15 changes: 6 additions & 9 deletions components/stacks-network/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,17 @@ pub fn send_status_update(
status: Status,
comment: &str,
) {
// leaving it a variable in case we want to make it dynamic in the future
let signers_services = 2;
let subnet_services = if with_subnets { 2 } else { 0 };

let order = match name {
"bitcoin-node" => 0,
"stacks-node" => 1,
"stacks-signer-1" => 2,
"stacks-signer-2" => 3,
"stacks-api" => signers_services + 2,
"subnet-node" => signers_services + 3,
"subnet-api" => signers_services + 4,
"stacks-explorer" => signers_services + subnet_services + 3,
"bitcoin-explorer" => signers_services + subnet_services + 4,
"stacks-signers" => 2,
"stacks-api" => 3,
"subnet-node" => 4,
"subnet-api" => 5,
"stacks-explorer" => subnet_services + 4,
"bitcoin-explorer" => subnet_services + 5,
_ => return,
};

Expand Down
Loading
Loading