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

Stacks 2.05: Allow epochs to be specified in Toml for Testnet #2910

Merged
merged 12 commits into from
Nov 15, 2021
11 changes: 10 additions & 1 deletion src/burnchains/bitcoin/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,18 @@ impl BurnchainIndexer for BitcoinIndexer {

/// Get a vector of the stacks epochs. This notion of epochs is dependent on the burn block height.
/// Valid epochs include stacks 1.0, stacks 2.0, stacks 2.05, and so on.
///
/// Choose according to:
/// 1) Use the custom epochs defined on the underlying `BitcoinIndexerConfig`, if they exist.
/// 2) Use hard-coded static values, otherwise.
///
/// It is an error (panic) to set custom epochs if running on `Mainnet`.
fn get_stacks_epochs(&self) -> Vec<StacksEpoch> {
match self.config.epochs {
Some(ref epochs) => epochs.clone(),
Some(ref epochs) => {
assert!(self.runtime.network_id != BitcoinNetworkType::Mainnet);
epochs.clone()
}
Comment on lines +717 to +720
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the wrong place to panic -- the panic should occur earlier, when the configuration is first applied (as in somewhere in testnet/stacks-node/src/config or the neon run loop). I think leave this assertion in place, but just add another one that occurs earlier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seconded. Never put off until runtime that which can be handled at boot time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put a check in BitcoinRegtestController::with_burnchain.

None => get_bitcoin_stacks_epochs(self.runtime.network_id),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/chainstate/burn/db/sortdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,7 @@ impl SortitionDB {
first_burn_header_timestamp: u64,
epochs_ref: &[StacksEpoch],
) -> Result<(), db_error> {
debug!("Instantiate SortDB");
debug!("Instantiating SortDB with epochs {:?}", &epochs_ref);

sql_pragma(self.conn(), "PRAGMA journal_mode = WAL;")?;

Expand Down
4 changes: 2 additions & 2 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub fn check_fault_injection(fault_name: &str) -> bool {
}

#[repr(u32)]
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Hash, Copy)]
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Hash, Copy, Serialize, Deserialize)]
pub enum StacksEpochId {
Epoch10 = 0x01000,
Epoch20 = 0x02000,
Expand Down Expand Up @@ -213,7 +213,7 @@ impl TryFrom<u32> for StacksEpochId {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct StacksEpoch {
pub epoch_id: StacksEpochId,
pub start_height: u64,
Expand Down
35 changes: 21 additions & 14 deletions testnet/stacks-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use stacks::burnchains::{MagicBytes, BLOCKSTACK_MAGIC_MAINNET};
use stacks::chainstate::stacks::miner::BlockBuilderSettings;
use stacks::chainstate::stacks::MAX_BLOCK_LEN;
use stacks::core::mempool::MemPoolWalkSettings;
use stacks::core::StacksEpoch;
use stacks::core::{
CHAIN_ID_MAINNET, CHAIN_ID_TESTNET, PEER_VERSION_MAINNET, PEER_VERSION_TESTNET,
};
Expand All @@ -28,14 +27,16 @@ use stacks::util::secp256k1::Secp256k1PrivateKey;
use stacks::util::secp256k1::Secp256k1PublicKey;
use stacks::vm::types::{AssetIdentifier, PrincipalData, QualifiedContractIdentifier};

use stacks::core::StacksEpoch;

const DEFAULT_SATS_PER_VB: u64 = 50;
const DEFAULT_MAX_RBF_RATE: u64 = 150; // 1.5x
const DEFAULT_RBF_FEE_RATE_INCREMENT: u64 = 5;
const LEADER_KEY_TX_ESTIM_SIZE: u64 = 290;
const BLOCK_COMMIT_TX_ESTIM_SIZE: u64 = 350;
const INV_REWARD_CYCLES_TESTNET: u64 = 6;

#[derive(Clone, Deserialize, Default)]
#[derive(Clone, Deserialize, Default, Debug)]
pub struct ConfigFile {
pub burnchain: Option<BurnchainConfigFile>,
pub node: Option<NodeConfigFile>,
Expand Down Expand Up @@ -280,7 +281,7 @@ impl ConfigFile {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Config {
pub burnchain: BurnchainConfig,
pub node: NodeConfig,
Expand Down Expand Up @@ -486,7 +487,10 @@ impl Config {
rbf_fee_increment: burnchain
.rbf_fee_increment
.unwrap_or(default_burnchain_config.rbf_fee_increment),
epochs: default_burnchain_config.epochs,
epochs: match burnchain.epochs {
Some(epochs) => Some(epochs),
None => default_burnchain_config.epochs,
},
}
}
None => default_burnchain_config,
Expand Down Expand Up @@ -895,7 +899,7 @@ impl std::default::Default for Config {
}
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
gregorycoppola marked this conversation as resolved.
Show resolved Hide resolved
pub struct BurnchainConfig {
pub chain: String,
pub mode: String,
Expand All @@ -919,6 +923,8 @@ pub struct BurnchainConfig {
pub leader_key_tx_estimated_size: u64,
pub block_commit_tx_estimated_size: u64,
pub rbf_fee_increment: u64,
// Custom override for the definitions of the epochs. This will only be applies for testnet and
// regtest nodes.
gregorycoppola marked this conversation as resolved.
Show resolved Hide resolved
pub epochs: Option<Vec<StacksEpoch>>,
}

Expand Down Expand Up @@ -979,7 +985,7 @@ impl BurnchainConfig {
}
}

#[derive(Clone, Deserialize, Default)]
#[derive(Clone, Serialize, Deserialize, Default, Debug)]
gregorycoppola marked this conversation as resolved.
Show resolved Hide resolved
pub struct BurnchainConfigFile {
pub chain: Option<String>,
pub burn_fee_cap: Option<u64>,
Expand All @@ -1001,6 +1007,7 @@ pub struct BurnchainConfigFile {
pub block_commit_tx_estimated_size: Option<u64>,
pub rbf_fee_increment: Option<u64>,
pub max_rbf: Option<u64>,
pub epochs: Option<Vec<StacksEpoch>>,
}

#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -1348,7 +1355,7 @@ impl MinerConfig {
}
}

#[derive(Clone, Default, Deserialize)]
#[derive(Clone, Default, Deserialize, Debug)]
gregorycoppola marked this conversation as resolved.
Show resolved Hide resolved
pub struct ConnectionOptionsFile {
pub inbox_maxlen: Option<usize>,
pub outbox_maxlen: Option<usize>,
Expand Down Expand Up @@ -1391,7 +1398,7 @@ pub struct ConnectionOptionsFile {
pub antientropy_public: Option<bool>,
}

#[derive(Clone, Deserialize, Default)]
#[derive(Clone, Deserialize, Default, Debug)]
pub struct NodeConfigFile {
pub name: Option<String>,
pub seed: Option<String>,
Expand All @@ -1414,7 +1421,7 @@ pub struct NodeConfigFile {
pub use_test_genesis_chainstate: Option<bool>,
}

#[derive(Clone, Deserialize)]
#[derive(Clone, Deserialize, Debug)]
pub struct FeeEstimationConfigFile {
pub cost_estimator: Option<String>,
pub fee_estimator: Option<String>,
Expand All @@ -1435,27 +1442,27 @@ impl Default for FeeEstimationConfigFile {
}
}

#[derive(Clone, Deserialize, Default)]
#[derive(Clone, Deserialize, Default, Debug)]
pub struct MinerConfigFile {
pub min_tx_fee: Option<u64>,
pub first_attempt_time_ms: Option<u64>,
pub subsequent_attempt_time_ms: Option<u64>,
pub probability_pick_no_estimate_tx: Option<u8>,
}

#[derive(Clone, Deserialize, Default)]
#[derive(Clone, Deserialize, Default, Debug)]
pub struct EventObserverConfigFile {
pub endpoint: String,
pub events_keys: Vec<String>,
}

#[derive(Clone, Default)]
#[derive(Clone, Default, Debug)]
pub struct EventObserverConfig {
pub endpoint: String,
pub events_keys: Vec<EventKeyType>,
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum EventKeyType {
SmartContractEvent((QualifiedContractIdentifier, String)),
AssetEvent(AssetIdentifier),
Expand Down Expand Up @@ -1531,7 +1538,7 @@ pub struct InitialBalance {
pub amount: u64,
}

#[derive(Clone, Deserialize, Default)]
#[derive(Clone, Deserialize, Default, Debug)]
pub struct InitialBalanceFile {
pub address: String,
pub amount: u64,
Expand Down