Skip to content

Commit

Permalink
feat: allow to customize the number of stacks signers and their key i…
Browse files Browse the repository at this point in the history
…n the devnet config
  • Loading branch information
hugocaillard committed Sep 6, 2024
1 parent a343642 commit f6e122e
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 203 deletions.
33 changes: 30 additions & 3 deletions components/clarinet-files/src/network_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ 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 libsecp256k1::{PublicKey, SecretKey};
use serde::Serialize;
use tiny_hderive::bip32::ExtendedPrivKey;
use toml::value::Value;

Expand Down Expand Up @@ -87,6 +88,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 Down Expand Up @@ -248,6 +251,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 Down Expand Up @@ -275,7 +280,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 @@ -892,7 +897,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 +966,28 @@ 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()
})
.unwrap_or(vec![
StacksPrivateKey::from_hex(
"7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801",
)
.unwrap(),
StacksPrivateKey::from_hex(
"530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101",
)
.unwrap(),
]),
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
25 changes: 9 additions & 16 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 @@ -688,17 +689,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 +719,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 +738,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

0 comments on commit f6e122e

Please sign in to comment.