Skip to content

Commit

Permalink
feat: add devnet tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocaillard committed Mar 26, 2024
1 parent aaab6bc commit 628f35b
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 48 deletions.
5 changes: 5 additions & 0 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -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 . .
Expand Down
7 changes: 4 additions & 3 deletions stackslib/src/burnchains/bitcoin/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
16 changes: 9 additions & 7 deletions stackslib/src/burnchains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
}

Expand Down
16 changes: 8 additions & 8 deletions stackslib/src/chainstate/stacks/boot/pox-4.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions stackslib/src/chainstate/stacks/boot/pox-testnet.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
48 changes: 32 additions & 16 deletions stackslib/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
17 changes: 10 additions & 7 deletions testnet/stacks-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -1030,7 +1031,6 @@ impl Config {
.collect();

let endpoint = format!("{}", observer.endpoint);

observers.insert(EventObserverConfig {
endpoint,
events_keys,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions testnet/stacks-node/src/nakamoto_node/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -804,10 +804,10 @@ impl RelayerThread {
pub fn main(mut self, relay_rcv: Receiver<RelayerDirective>) {
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
Expand Down

0 comments on commit 628f35b

Please sign in to comment.