From 628f35bca4f14e8c6d9975116f155d564e6ebb1c Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:14:02 +0100 Subject: [PATCH] feat: add devnet tweaks --- Dockerfile.debian | 5 ++ stackslib/src/burnchains/bitcoin/indexer.rs | 7 +-- stackslib/src/burnchains/mod.rs | 16 ++++--- .../src/chainstate/stacks/boot/pox-4.clar | 16 +++---- .../chainstate/stacks/boot/pox-testnet.clar | 4 +- stackslib/src/core/mod.rs | 48 ++++++++++++------- .../burnchains/bitcoin_regtest_controller.rs | 4 +- testnet/stacks-node/src/config.rs | 17 ++++--- .../stacks-node/src/nakamoto_node/relayer.rs | 6 +-- 9 files changed, 75 insertions(+), 48 deletions(-) diff --git a/Dockerfile.debian b/Dockerfile.debian index 2fe262807e3..9e5ad891c9e 100644 --- a/Dockerfile.debian +++ b/Dockerfile.debian @@ -4,6 +4,11 @@ ARG STACKS_NODE_VERSION="No Version Info" ARG GIT_BRANCH='No Branch Info' ARG GIT_COMMIT='No Commit Info' +RUN apt update && apt-get install -y libclang-dev + +RUN rustup toolchain install stable +RUN rustup component add rustfmt --toolchain stable + WORKDIR /src COPY . . diff --git a/stackslib/src/burnchains/bitcoin/indexer.rs b/stackslib/src/burnchains/bitcoin/indexer.rs index 40cabd86d30..4dd10488249 100644 --- a/stackslib/src/burnchains/bitcoin/indexer.rs +++ b/stackslib/src/burnchains/bitcoin/indexer.rs @@ -1005,9 +1005,10 @@ impl BurnchainIndexer for BitcoinIndexer { false, )?; let first_block_height = self.get_first_block_height(); - let first_header = spv_client - .read_block_header(first_block_height)? - .expect("BUG: no first block header hash"); + let first_header = match spv_client.read_block_header(first_block_height) { + Ok(Some(res)) => res, + _ => return Err(burnchain_error::MissingHeaders), + }; let first_block_header_hash = BurnchainHeaderHash::from_bitcoin_hash(&first_header.header.bitcoin_hash()); diff --git a/stackslib/src/burnchains/mod.rs b/stackslib/src/burnchains/mod.rs index 26511e152cc..2b49feb21ad 100644 --- a/stackslib/src/burnchains/mod.rs +++ b/stackslib/src/burnchains/mod.rs @@ -468,17 +468,19 @@ impl PoxConstants { pub fn regtest_default() -> PoxConstants { PoxConstants::new( + 20, 5, 3, - 2, - 3333333333333333, - 1, + 25, + 5, BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT + POX_SUNSET_START, BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT + POX_SUNSET_END, - 1_000_000, - 2_000_000, - 4_000_000, - 3_000_000, + POX_V1_REGTEST_EARLY_UNLOCK_HEIGHT, + POX_V2_REGTEST_EARLY_UNLOCK_HEIGHT, + POX_V3_REGTEST_EARLY_UNLOCK_HEIGHT, + BITCOIN_REGTEST_STACKS_24_BURN_HEIGHT + .try_into() + .expect("Epoch transition height must be <= u32::MAX"), ) } diff --git a/stackslib/src/chainstate/stacks/boot/pox-4.clar b/stackslib/src/chainstate/stacks/boot/pox-4.clar index 5f0daf8b7bf..580234dabb6 100644 --- a/stackslib/src/chainstate/stacks/boot/pox-4.clar +++ b/stackslib/src/chainstate/stacks/boot/pox-4.clar @@ -69,10 +69,10 @@ (define-constant MAX_POX_REWARD_CYCLES u12) ;; Default length of the PoX registration window, in burnchain blocks. -(define-constant PREPARE_CYCLE_LENGTH (if is-in-mainnet u100 u50)) +(define-constant PREPARE_CYCLE_LENGTH (if is-in-mainnet u100 u5)) ;; Default length of the PoX reward cycle, in burnchain blocks. -(define-constant REWARD_CYCLE_LENGTH (if is-in-mainnet u2100 u1050)) +(define-constant REWARD_CYCLE_LENGTH (if is-in-mainnet u2100 u20)) ;; Stacking thresholds (define-constant STACKING_THRESHOLD_25 (if is-in-mainnet u20000 u8000)) @@ -563,7 +563,7 @@ ;; * The Stacker will receive rewards in the reward cycle following `start-burn-ht`. ;; Importantly, `start-burn-ht` may not be further into the future than the next reward cycle, ;; and in most cases should be set to the current burn block height. -;; +;; ;; To ensure that the Stacker is authorized to use the provided `signer-key`, the stacker ;; must provide either a signature have an authorization already saved. Refer to ;; `verify-signer-key-sig` for more information. @@ -711,7 +711,7 @@ ;; the lock period are inflexible, which means that the stacker must confirm their transaction ;; during the exact reward cycle and with the exact period that the signature or authorization was ;; generated for. -;; +;; ;; The `amount` field is checked to ensure it is not larger than `max-amount`, which is ;; a field in the authorization. `auth-id` is a random uint to prevent authorization ;; replays. @@ -723,7 +723,7 @@ ;; When `signer-sig` is present, the public key is recovered from the signature ;; and compared to `signer-key`. If `signer-sig` is `none`, the function verifies that an authorization was previously ;; added for this key. -;; +;; ;; This function checks to ensure that the authorization hasn't been used yet, but it ;; does _not_ store the authorization as used. The function `consume-signer-key-authorization` ;; handles that, and this read-only function is exposed for client-side verification. @@ -1063,10 +1063,10 @@ ;; *New in Stacks 2.1* ;; This method locks up an additional amount of STX from `tx-sender`'s, indicated ;; by `increase-by`. The `tx-sender` must already be Stacking & must not be -;; straddling more than one signer-key for the cycles effected. +;; straddling more than one signer-key for the cycles effected. ;; Refer to `verify-signer-key-sig` for more information on the authorization parameters ;; included here. -(define-public (stack-increase +(define-public (stack-increase (increase-by uint) (signer-sig (optional (buff 65))) (signer-key (buff 33)) @@ -1125,7 +1125,7 @@ ;; This method extends the `tx-sender`'s current lockup for an additional `extend-count` ;; and associates `pox-addr` with the rewards, The `signer-key` will be the key ;; used for signing. The `tx-sender` can thus decide to change the key when extending. -;; +;; ;; Because no additional STX are locked in this function, the `amount` field used ;; to verify the signer key authorization is zero. Refer to `verify-signer-key-sig` for more information. (define-public (stack-extend (extend-count uint) diff --git a/stackslib/src/chainstate/stacks/boot/pox-testnet.clar b/stackslib/src/chainstate/stacks/boot/pox-testnet.clar index a29b89ee789..f527be79a05 100644 --- a/stackslib/src/chainstate/stacks/boot/pox-testnet.clar +++ b/stackslib/src/chainstate/stacks/boot/pox-testnet.clar @@ -4,10 +4,10 @@ (define-constant MAX_POX_REWARD_CYCLES u12) ;; Default length of the PoX registration window, in burnchain blocks. -(define-constant PREPARE_CYCLE_LENGTH u50) +(define-constant PREPARE_CYCLE_LENGTH u5) ;; Default length of the PoX reward cycle, in burnchain blocks. -(define-constant REWARD_CYCLE_LENGTH u1050) +(define-constant REWARD_CYCLE_LENGTH u20) ;; Valid values for burnchain address versions. ;; These correspond to address hash modes in Stacks 2.0. diff --git a/stackslib/src/core/mod.rs b/stackslib/src/core/mod.rs index 629cb02c9a0..1535cdfc6cc 100644 --- a/stackslib/src/core/mod.rs +++ b/stackslib/src/core/mod.rs @@ -137,7 +137,17 @@ pub const BITCOIN_TESTNET_STACKS_24_BURN_HEIGHT: u64 = 2_432_545; pub const BITCOIN_TESTNET_STACKS_25_BURN_HEIGHT: u64 = 2_583_893; pub const BITCOIN_TESTNET_STACKS_30_BURN_HEIGHT: u64 = 30_000_000; -pub const BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT: u64 = 0; +// On regtest networks, we need to matured coinbases for mining Stacks blocks. +// We start at block #100 so we avoid indexing the first 100 non matured +// coinbases. +pub const BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT: u64 = 100; +pub const BITCOIN_REGTEST_STACKS_2_05_BURN_HEIGHT: u64 = 120; +pub const BITCOIN_REGTEST_STACKS_21_BURN_HEIGHT: u64 = 140; +pub const BITCOIN_REGTEST_STACKS_22_BURN_HEIGHT: u64 = 160; +pub const BITCOIN_REGTEST_STACKS_23_BURN_HEIGHT: u64 = 180; +pub const BITCOIN_REGTEST_STACKS_24_BURN_HEIGHT: u64 = 200; +pub const BITCOIN_REGTEST_STACKS_25_BURN_HEIGHT: u64 = 6000; +pub const BITCOIN_REGTEST_STACKS_30_BURN_HEIGHT: u64 = 7001; pub const BITCOIN_REGTEST_FIRST_BLOCK_TIMESTAMP: u32 = 0; pub const BITCOIN_REGTEST_FIRST_BLOCK_HASH: &str = "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"; @@ -179,16 +189,22 @@ pub const POX_V1_MAINNET_EARLY_UNLOCK_HEIGHT: u32 = (BITCOIN_MAINNET_STACKS_21_BURN_HEIGHT as u32) + 1; pub const POX_V1_TESTNET_EARLY_UNLOCK_HEIGHT: u32 = (BITCOIN_TESTNET_STACKS_21_BURN_HEIGHT as u32) + 1; +pub const POX_V1_REGTEST_EARLY_UNLOCK_HEIGHT: u32 = + (BITCOIN_REGTEST_STACKS_21_BURN_HEIGHT as u32) + 1; pub const POX_V2_MAINNET_EARLY_UNLOCK_HEIGHT: u32 = (BITCOIN_MAINNET_STACKS_22_BURN_HEIGHT as u32) + 1; pub const POX_V2_TESTNET_EARLY_UNLOCK_HEIGHT: u32 = (BITCOIN_TESTNET_STACKS_22_BURN_HEIGHT as u32) + 1; +pub const POX_V2_REGTEST_EARLY_UNLOCK_HEIGHT: u32 = + (BITCOIN_REGTEST_STACKS_22_BURN_HEIGHT as u32) + 1; pub const POX_V3_MAINNET_EARLY_UNLOCK_HEIGHT: u32 = (BITCOIN_MAINNET_STACKS_25_BURN_HEIGHT as u32) + 1; pub const POX_V3_TESTNET_EARLY_UNLOCK_HEIGHT: u32 = (BITCOIN_TESTNET_STACKS_25_BURN_HEIGHT as u32) + 1; +pub const POX_V3_REGTEST_EARLY_UNLOCK_HEIGHT: u32 = + (BITCOIN_REGTEST_STACKS_24_BURN_HEIGHT as u32) + 1; /// Burn block height at which the ASTRules::PrecheckSize becomes the default behavior on mainnet pub const AST_RULES_PRECHECK_SIZE: u64 = 752000; // on or about Aug 30 2022 @@ -400,56 +416,56 @@ lazy_static! { }, StacksEpoch { epoch_id: StacksEpochId::Epoch20, - start_height: 0, - end_height: 1000, + start_height: BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT, + end_height: BITCOIN_REGTEST_STACKS_2_05_BURN_HEIGHT, block_limit: HELIUM_BLOCK_LIMIT_20.clone(), network_epoch: PEER_VERSION_EPOCH_2_0 }, StacksEpoch { epoch_id: StacksEpochId::Epoch2_05, - start_height: 1000, - end_height: 2000, + start_height: BITCOIN_REGTEST_STACKS_2_05_BURN_HEIGHT, + end_height: BITCOIN_REGTEST_STACKS_21_BURN_HEIGHT, block_limit: HELIUM_BLOCK_LIMIT_20.clone(), network_epoch: PEER_VERSION_EPOCH_2_05 }, StacksEpoch { epoch_id: StacksEpochId::Epoch21, - start_height: 2000, - end_height: 3000, + start_height: BITCOIN_REGTEST_STACKS_21_BURN_HEIGHT, + end_height: BITCOIN_REGTEST_STACKS_22_BURN_HEIGHT, block_limit: HELIUM_BLOCK_LIMIT_20.clone(), network_epoch: PEER_VERSION_EPOCH_2_1 }, StacksEpoch { epoch_id: StacksEpochId::Epoch22, - start_height: 3000, - end_height: 4000, + start_height: BITCOIN_REGTEST_STACKS_22_BURN_HEIGHT, + end_height: BITCOIN_REGTEST_STACKS_23_BURN_HEIGHT, block_limit: HELIUM_BLOCK_LIMIT_20.clone(), network_epoch: PEER_VERSION_EPOCH_2_2 }, StacksEpoch { epoch_id: StacksEpochId::Epoch23, - start_height: 4000, - end_height: 5000, + start_height: BITCOIN_REGTEST_STACKS_23_BURN_HEIGHT, + end_height: BITCOIN_REGTEST_STACKS_24_BURN_HEIGHT, block_limit: HELIUM_BLOCK_LIMIT_20.clone(), network_epoch: PEER_VERSION_EPOCH_2_3 }, StacksEpoch { epoch_id: StacksEpochId::Epoch24, - start_height: 5000, - end_height: 6000, + start_height: BITCOIN_REGTEST_STACKS_24_BURN_HEIGHT, + end_height: BITCOIN_REGTEST_STACKS_25_BURN_HEIGHT, block_limit: HELIUM_BLOCK_LIMIT_20.clone(), network_epoch: PEER_VERSION_EPOCH_2_4 }, StacksEpoch { epoch_id: StacksEpochId::Epoch25, - start_height: 6000, - end_height: 7001, + start_height: BITCOIN_REGTEST_STACKS_25_BURN_HEIGHT, + end_height: BITCOIN_REGTEST_STACKS_30_BURN_HEIGHT, block_limit: BLOCK_LIMIT_MAINNET_21.clone(), network_epoch: PEER_VERSION_EPOCH_2_5 }, StacksEpoch { epoch_id: StacksEpochId::Epoch30, - start_height: 7001, + start_height: BITCOIN_REGTEST_STACKS_30_BURN_HEIGHT, end_height: STACKS_EPOCH_MAX, block_limit: BLOCK_LIMIT_MAINNET_21.clone(), network_epoch: PEER_VERSION_EPOCH_3_0 diff --git a/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs b/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs index f96c0c198b7..0bbae24f0bb 100644 --- a/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs +++ b/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs @@ -558,12 +558,12 @@ impl BitcoinRegtestController { burnchain_error::BurnchainPeerBroken => { // remote burnchain peer broke, and produced a shorter blockchain fork. // just keep trying - sleep_ms(5000); + sleep_ms(1000); continue; } _ => { // delay and try again - sleep_ms(5000); + sleep_ms(1000); continue; } } diff --git a/testnet/stacks-node/src/config.rs b/testnet/stacks-node/src/config.rs index 7901b6d8751..1bf0c0e3f79 100644 --- a/testnet/stacks-node/src/config.rs +++ b/testnet/stacks-node/src/config.rs @@ -3,6 +3,7 @@ use std::net::{Ipv4Addr, SocketAddr, ToSocketAddrs}; use std::path::PathBuf; use std::str::FromStr; use std::sync::{Arc, Mutex}; +use std::thread::sleep; use std::time::Duration; use std::{fs, thread}; @@ -1030,7 +1031,6 @@ impl Config { .collect(); let endpoint = format!("{}", observer.endpoint); - observers.insert(EventObserverConfig { endpoint, events_keys, @@ -1531,18 +1531,21 @@ impl BurnchainConfigFile { // Using std::net::LookupHost would be preferable, but it's // unfortunately unstable at this point. // https://doc.rust-lang.org/1.6.0/std/net/struct.LookupHost.html - let mut sock_addrs = format!("{}:1", &peer_host) - .to_socket_addrs() - .map_err(|e| format!("Invalid burnchain.peer_host: {}", &e))?; - let sock_addr = match sock_addrs.next() { - Some(addr) => addr, - None => { + let mut attempts = 0; + let mut addrs_iter = loop { + if let Ok(addrs_iter) = format!("{}:1", peer_host).to_socket_addrs() { + break addrs_iter; + } + attempts += 1; + if attempts == 15 { return Err(format!( "No IP address could be queried for '{}'", &peer_host )); } + sleep(std::time::Duration::from_secs(5)); }; + let sock_addr = addrs_iter.next().unwrap(); format!("{}", sock_addr.ip()) } None => default_burnchain_config.peer_host, diff --git a/testnet/stacks-node/src/nakamoto_node/relayer.rs b/testnet/stacks-node/src/nakamoto_node/relayer.rs index f638ae93241..20609db9af0 100644 --- a/testnet/stacks-node/src/nakamoto_node/relayer.rs +++ b/testnet/stacks-node/src/nakamoto_node/relayer.rs @@ -210,7 +210,7 @@ impl RelayerThread { miner_thread: None, is_miner, - next_initiative: Instant::now() + Duration::from_secs(10), + next_initiative: Instant::now() + Duration::from_secs(4), last_committed: None, } } @@ -804,10 +804,10 @@ impl RelayerThread { pub fn main(mut self, relay_rcv: Receiver) { debug!("relayer thread ID is {:?}", std::thread::current().id()); - self.next_initiative = Instant::now() + Duration::from_secs(10); + self.next_initiative = Instant::now() + Duration::from_secs(4); while self.globals.keep_running() { let directive = if Instant::now() >= self.next_initiative { - self.next_initiative = Instant::now() + Duration::from_secs(10); + self.next_initiative = Instant::now() + Duration::from_secs(4); self.initiative() } else { None