Skip to content

Commit 07a2e32

Browse files
committed
add BurnchainConfig documentation
1 parent 8f9c5ed commit 07a2e32

File tree

1 file changed

+280
-12
lines changed

1 file changed

+280
-12
lines changed

stackslib/src/config/mod.rs

Lines changed: 280 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,53 +1207,321 @@ impl std::default::Default for Config {
12071207

12081208
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
12091209
pub struct BurnchainConfig {
1210+
/// The underlying blockchain used for Proof-of-Transfer.
1211+
/// Currently, only `"bitcoin"` is supported.
1212+
///
1213+
/// Default: `"bitcoin"`
12101214
pub chain: String,
1215+
/// The operational mode or network profile for the Stacks node.
1216+
/// This setting determines network parameters (like chain ID, peer version),
1217+
/// default configurations, genesis block definitions, and overall node behavior.
1218+
///
1219+
/// Supported values: `"mainnet"`, `"mocknet"`, `"helium"`, `"neon"`, `"argon"`, `"krypton"`, `"xenon"`, `"nakamoto-neon"`.
1220+
///
1221+
/// Default: `"mocknet"`
12111222
pub mode: String,
1223+
/// The network-specific identifier used in P2P communication and database initialization .
1224+
/// Derived from `mode` during config load, unless explicitly overridden (for test purposes).
1225+
///
1226+
/// Default: Derived from [`BurnchainConfig::mode`] ([`CHAIN_ID_MAINNET`] for `mainnet`, [`CHAIN_ID_TESTNET`] otherwise).
12121227
pub chain_id: u32,
1228+
/// The peer protocol version number used in P2P communication.
1229+
/// This parameter cannot be set via the configuration file.
1230+
///
1231+
/// Default: Derived from [`BurnchainConfig::mode`] ([`PEER_VERSION_MAINNET`] for `mainnet`, [`PEER_VERSION_TESTNET`] otherwise).
12131232
pub peer_version: u32,
1233+
/// Specifies a mandatory wait period (in milliseconds) after receiving a burnchain tip
1234+
/// before the node attempts to build the anchored block for the new tenure.
1235+
/// This duration effectively schedules the start of the block-building
1236+
/// process relative to the tip's arrival time.
1237+
/// Only when [`BurnchainConfig::mode`] is `"helium"` or `"mocknet"`.
1238+
///
1239+
/// Default: `5000` milliseconds.
1240+
/// `10000` milliseconds when launched with the `helium` or `mocknet` subcommands.
12141241
pub commit_anchor_block_within: u64,
1242+
/// The Maximum amount (in sats) of "burn commitment" to broadcast for the next block's leader election.
1243+
/// Acts as a safety cap to limit the maximum amount spent on mining.
1244+
///
1245+
/// It serves as both the target fee and a fallback if dynamic fee calculations fail or cannot be performed
1246+
///
1247+
/// This setting can be hot-reloaded from a miner's config file, allowing adjustment without restarting.
1248+
/// Primarily relevant for miners.
1249+
///
1250+
/// Default: `20000` satoshis
12151251
pub burn_fee_cap: u64,
1252+
/// The hostname or IP address of the bitcoin node peer.
1253+
///
1254+
/// This field is required for all node configurations as it specifies where to find the underlying
1255+
/// bitcoin node to interact with for PoX operations, block validation, and mining.
1256+
///
1257+
/// Default: `"0.0.0.0"`
12161258
pub peer_host: String,
1259+
/// The P2P network port of the bitcoin node specified by [`BurnchainConfig::peer_host`].
1260+
///
1261+
/// Default: `8333`
12171262
pub peer_port: u16,
1263+
/// The RPC port of the bitcoin node specified by [`BurnchainConfig::peer_host`].
1264+
///
1265+
/// Default: `8332`
12181266
pub rpc_port: u16,
1267+
/// Flag indicating whether to use SSL/TLS when connecting to the bitcoin node's RPC interface.
1268+
///
1269+
/// Default: `false`
12191270
pub rpc_ssl: bool,
1271+
/// The username for authenticating with the bitcoin node's RPC interface.
1272+
/// Required if the bitcoin node requires RPC authentication.
1273+
///
1274+
/// Default: `None`
12201275
pub username: Option<String>,
1276+
/// The password for authenticating with the bitcoin node's RPC interface.
1277+
/// Required if the bitcoin node requires RPC authentication.
1278+
///
1279+
/// Default: `None`
12211280
pub password: Option<String>,
1222-
/// Timeout, in seconds, for communication with bitcoind
1281+
/// Timeout duration, in seconds, for RPC calls made to the bitcoin node.
1282+
/// Configures the timeout on the underlying HTTP client.
1283+
///
1284+
/// Default: `60` seconds
12231285
pub timeout: u32,
1286+
/// The network "magic bytes" used to identify packets for the specific bitcoin network instance
1287+
/// (e.g., mainnet, testnet, regtest). Must match the magic bytes of the connected bitcoin node.
1288+
///
1289+
/// These two-byte identifiers help ensure that nodes only connect to peers on the same network type.
1290+
/// Common values include:
1291+
/// - "X2" for mainnet
1292+
/// - "T2" for Xenon testnet
1293+
/// - Other values for specific test networks
1294+
///
1295+
/// Configured as a 2-character ASCII string (e.g., "X2" for mainnet).
1296+
///
1297+
/// Default: [`BLOCKSTACK_MAGIC_MAINNET`] (corresponds to "X2") unless overridden by [`BurnchainConfig::mode`] (e.g., "T2" for Xenon testnet).
12241298
pub magic_bytes: MagicBytes,
1299+
/// The public key associated with the local mining address.
1300+
/// Provided as a hex string representing a public key.
1301+
/// This is intended strictly for testing purposes. Only used for [`BurnchainConfig::mode`] "helium".
1302+
///
1303+
/// Used to derive the mining address for generating and receiving coinbase rewards.
1304+
///
1305+
/// Default: `None`
12251306
pub local_mining_public_key: Option<String>,
1307+
/// Optional bitcoin block height at which the Stacks node process should gracefully exit.
1308+
/// When bitcoin reaches this height, the node logs a message and initiates a graceful shutdown.
1309+
///
1310+
/// This is intended strictly for testing purposes.
1311+
///
1312+
/// Default: `None`
12261313
pub process_exit_at_block_height: Option<u64>,
1314+
/// The interval, in seconds, at which the node polls the bitcoin node for new blocks and state updates.
1315+
///
1316+
/// The default value of 10 seconds is mainly intended for testing purposes.
1317+
/// It's suggested to set this to a higher value for mainnet e.g. 300 seconds (5 minutes).
1318+
///
1319+
/// Default: `10` seconds
12271320
pub poll_time_secs: u64,
1321+
/// The default fee rate in satoshis per virtual byte (sats/vB) to use when estimating fees for miners
1322+
/// to submit bitcoin transactions (like block commits or leader key registrations).
1323+
/// Primarily relevant for miners.
1324+
///
1325+
/// Default: [`DEFAULT_SATS_PER_VB`] (currently 50 satoshis per virtual byte)
12281326
pub satoshis_per_byte: u64,
1229-
/// Maximum percentage of `satoshis_per_byte` that a Bitcoin fee rate may
1230-
/// be increased to when RBFing a transaction
1327+
/// Maximum fee rate multiplier allowed when using Replace-By-Fee (RBF) for bitcoin transactions.
1328+
/// Expressed as a percentage of the original [`BurnchainConfig::satoshis_per_byte`] rate (e.g.,
1329+
/// 150 means the fee rate can be increased up to 1.5x). Used in mining logic for RBF decisions
1330+
/// to cap the replacement fee rate.
1331+
/// Primarily relevant for miners.
1332+
///
1333+
/// Default: [`DEFAULT_MAX_RBF_RATE`] (currently 150, i.e., 1.5x)
12311334
pub max_rbf: u64,
1335+
/// Estimated size (in virtual bytes) of a leader key registration transaction on bitcoin.
1336+
/// Used for fee calculation in mining logic by multiplying with the fee rate [`BurnchainConfig::satoshis_per_byte`].
1337+
/// Primarily relevant for miners.
1338+
///
1339+
/// Default: [`OP_TX_LEADER_KEY_ESTIM_SIZE`] (currently 290)
12321340
pub leader_key_tx_estimated_size: u64,
1341+
/// Estimated size (in virtual bytes) of a block commit transaction on bitcoin.
1342+
/// Used for fee calculation in mining logic by multiplying with the fee rate [`BurnchainConfig::satoshis_per_byte`].
1343+
/// Primarily relevant for miners.
1344+
///
1345+
/// Default: [`OP_TX_BLOCK_COMMIT_ESTIM_SIZE`] (currently 380)
12331346
pub block_commit_tx_estimated_size: u64,
1234-
/// Amount to increment the fee by, in Sats/vByte, when RBFing a Bitcoin
1235-
/// transaction
1347+
/// The incremental amount (in Sats/vByte) to add to the previous transaction's
1348+
/// fee rate for RBF bitcoin transactions.
1349+
/// Primarily relevant for miners.
1350+
///
1351+
/// Default: [`DEFAULT_RBF_FEE_RATE_INCREMENT`] (currently 5 satoshis per virtual byte)
12361352
pub rbf_fee_increment: u64,
1353+
/// Overrides the default starting bitcoin block height for the node.
1354+
/// Allows starting synchronization from a specific historical point in test environments.
1355+
/// Should be used together with [`BurnchainConfig::first_burn_block_timestamp`] and [`BurnchainConfig::first_burn_block_hash`] for proper operation.
1356+
///
1357+
/// Applied only if [`BurnchainConfig::mode`] is not "mainnet".
1358+
/// This is intended strictly for testing purposes.
1359+
///
1360+
/// Default: `None` (uses the burnchain's default starting height for the mode).
12371361
pub first_burn_block_height: Option<u64>,
1362+
/// Overrides the default starting block timestamp of the burnchain.
1363+
/// Should be used together with [`BurnchainConfig::first_burn_block_height`] and [`BurnchainConfig::first_burn_block_hash`] for proper operation.
1364+
///
1365+
/// Applied only if [`BurnchainConfig::mode`] is not "mainnet".
1366+
/// This is intended strictly for testing purposes.
1367+
///
1368+
/// Default: `None` (uses the burnchain's default starting timestamp).
12381369
pub first_burn_block_timestamp: Option<u32>,
1370+
/// Overrides the default starting block hash of the burnchain.
1371+
/// Should be used together with [`BurnchainConfig::first_burn_block_timestamp`] and [`BurnchainConfig::first_burn_block_height`] for proper operation.
1372+
///
1373+
/// Applied only if [`BurnchainConfig::mode`] is not "mainnet".
1374+
/// This is intended strictly for testing purposes.
1375+
///
1376+
/// Default: `None` (uses the burnchain's default starting block hash).
12391377
pub first_burn_block_hash: Option<String>,
1240-
/// Custom override for the definitions of the epochs. This will only be applied for testnet and
1241-
/// regtest nodes.
1378+
/// Custom override for the definitions of Stacks epochs (start/end burnchain heights, consensus rules).
1379+
/// This setting allows testing specific epoch transitions or custom consensus rules by defining exactly
1380+
/// when each epoch starts on bitcoin.
1381+
///
1382+
/// **Configuration:**
1383+
/// Configured as a list `[[burnchain.epochs]]` in TOML, each with:
1384+
/// - `epoch_name`: A string identifying the epoch (e.g., `"1.0"`, `"2.05"`, `"3.1"`).
1385+
/// - `start_height`: The Bitcoin block height at which this epoch becomes active.
1386+
///
1387+
/// Example TOML entry:
1388+
/// ```toml
1389+
/// [[burnchain.epochs]]
1390+
/// epoch_name = "2.1"
1391+
/// start_height = 150
1392+
/// ```
1393+
///
1394+
/// **Details:**
1395+
/// Epochs define distinct protocol rule sets (consensus rules, execution costs, capabilities).
1396+
/// When configured, the list must include all epochs sequentially from "1.0" up to the
1397+
/// highest desired epoch, without skipping any intermediate ones.
1398+
/// Valid `epoch_name` values currently include:
1399+
/// `"1.0"`, `"2.0"`, `"2.05"`, `"2.1"`, `"2.2"`, `"2.3"`, `"2.4"`, `"2.5"`, `"3.0"`, `"3.1"`.
1400+
///
1401+
/// **Validation Rules:**
1402+
/// - Epochs must be provided in strict chronological order (`1.0`, `2.0`, `2.05`...).
1403+
/// - `start_height` values must be non-decreasing across the list.
1404+
/// - Epoch `"1.0"` must have `start_height = 0`.
1405+
/// - The number of defined epochs cannot exceed the maximum supported by the node software.
1406+
///
1407+
/// Applied only if [`BurnchainConfig::mode`] is not "mainnet".
1408+
/// This is intended strictly for testing purposes.
1409+
///
1410+
/// Default: `None` (uses the standard epoch definitions for the selected `mode`).
12421411
pub epochs: Option<EpochList<ExecutionCost>>,
1412+
/// Sets a custom burnchain height for PoX-2 activation (for testing).
1413+
///
1414+
/// This affects two key transitions:
1415+
/// 1. The block height at which PoX v1 lockups are automatically unlocked.
1416+
/// 2. The block height from which PoX reward set calculations switch to PoX v2 rules.
1417+
///
1418+
/// **Behavior:**
1419+
/// - This value directly sets the auto unlock height for PoX v1 lockups before transition to PoX v2. This
1420+
/// also defines the burn height at which PoX reward sets are calculated using PoX v2 rather than v1.
1421+
/// - If custom [`BurnchainConfig::epochs`] are provided:
1422+
/// - This value is used to validate that Epoch 2.1's start height is ≤ this value.
1423+
/// - However, the height specified in `epochs` for Epoch 2.1 takes precedence.
1424+
///
1425+
/// Applied only if [`BurnchainConfig::mode`] is not "mainnet".
1426+
///
1427+
/// Default: `None`.
12431428
pub pox_2_activation: Option<u32>,
1429+
/// Overrides the length (in bitcoin blocks) of the PoX reward cycle.
1430+
///
1431+
/// Applied only if [`BurnchainConfig::mode`] is not "mainnet".
1432+
///
1433+
/// Default: `None` (uses the standard reward cycle length for the mode).
12441434
pub pox_reward_length: Option<u32>,
1435+
/// Overrides the length (in bitcoin blocks) of the PoX prepare phase.
1436+
///
1437+
/// Applied only if [`BurnchainConfig::mode`] is not "mainnet".
1438+
///
1439+
/// Default: `None` (uses the standard prepare phase length for the mode).
12451440
pub pox_prepare_length: Option<u32>,
1441+
/// Overrides the bitcoin height at which the PoX sunset period begins in epochs before 2.1.
1442+
/// The sunset period represents a planned phase-out of the PoX mechanism. During this period,
1443+
/// stacking rewards gradually decrease, eventually ceasing entirely. This parameter allows
1444+
/// testing the PoX sunset transition by explicitly setting its start height.
1445+
///
1446+
/// Applied only if [`BurnchainConfig::mode`] is not "mainnet".
1447+
///
1448+
/// Default: `None` (uses the standard sunset start height for the mode).
1449+
/// Deprecated: The sunset phase was removed in Epoch 2.1. This parameter can still be used for testing purposes for epochs before 2.1.
12461450
pub sunset_start: Option<u32>,
1451+
///
1452+
/// Overrides the bitcoin height, non-inclusive, at which the PoX sunset period ends in epochs before 2.1.
1453+
/// After this height, Stacking rewards are disabled completely. This parameter works together
1454+
/// with `sunset_start` to define the full sunset transition period for PoX.
1455+
///
1456+
/// Applied only if [`BurnchainConfig::mode`] is not "mainnet".
1457+
///
1458+
/// Default: `None` (uses the standard sunset end height for the mode).
1459+
/// Deprecated: The sunset phase was removed in Epoch 2.1. This parameter can still be used for testing purposes for epochs before 2.1.
12471460
pub sunset_end: Option<u32>,
1461+
/// Specifies the name of the Bitcoin wallet to use within the connected bitcoin node.
1462+
/// Used to interact with a specific named wallet if the bitcoin node manages multiple wallets.
1463+
///
1464+
/// If the specified wallet doesn't exist, the node will attempt to create it via the createwallet RPC call.
1465+
/// This is particularly useful for miners who need to manage separate wallets for testing or organizational purposes.
1466+
///
1467+
/// Primarily relevant for miners interacting with multi-wallet Bitcoin nodes.
1468+
///
1469+
/// Default: `""` (empty string, implying the default wallet or no specific wallet needed).
12481470
pub wallet_name: String,
1471+
/// Override for the burnchain height activating stricter AST size checks pre-epoch 3.0 for testing purposes.
1472+
///
1473+
/// Used pre-epoch 3.0 to control activation before it became standard (at burn height `752000`).
1474+
/// Ignored in standard production builds as the underlying mechanism is disabled unless the `testing` feature is active.
1475+
///
1476+
/// Default: `None`.
1477+
/// Deprecated: This setting is ignored in Epoch 3.0+.
12491478
pub ast_precheck_size_height: Option<u64>,
1479+
/// Overrides for the burnchain block affirmation map for specific reward cycles.
1480+
/// Allows manually setting the miner affirmation ('p'resent/'n'ot-present/'a'bsent) map for a
1481+
/// given cycle, bypassing the map normally derived from sortition results.
1482+
///
1483+
/// **Configuration:**
1484+
/// Configured as a list `[[burnchain.affirmation_overrides]]` in TOML, each with:
1485+
/// - `reward_cycle`: The cycle number to override.
1486+
/// - `affirmation`: The 'p'/'n'/'a' sequence representing the map. Must have length `reward_cycle - 1`.
1487+
///
1488+
/// Example TOML:
1489+
/// ```toml
1490+
/// [[burnchain.affirmation_overrides]]
1491+
/// reward_cycle = 413
1492+
/// affirmation = "pna..." # Must be 412 chars long
1493+
/// ```
1494+
///
1495+
/// **Details:**
1496+
/// Special defaults are added when [`BurnchainConfig::mode`] is "xenon" or the node
1497+
/// is launched with the `testnet` subcommand, but config entries take precedence.
1498+
/// At startup, these overrides are written to the `BurnchainDB` (`overrides` table).
1499+
/// Primarily used for testing or recovering from network issues.
1500+
///
1501+
/// Default: Empty `HashMap`.
1502+
/// Deprecated: This setting is ignored in Epoch 3.0+. Only used in the neon-node.
12501503
pub affirmation_overrides: HashMap<u64, AffirmationMap>,
1251-
/// fault injection to simulate a slow burnchain peer.
1252-
/// Delay burnchain block downloads by the given number of millseconds
1504+
/// Fault injection setting for testing. Introduces an artificial delay (in milliseconds)
1505+
/// before processing each burnchain block download. Simulates a slow burnchain connection.
1506+
/// Only intended for testing environments.
1507+
///
1508+
/// Default: `0` (no delay).
12531509
pub fault_injection_burnchain_block_delay: u64,
1254-
/// The maximum number of unspent UTXOs to request from the bitcoin node.
1255-
/// This value is passed as the `maximumCount` query option to the
1256-
/// `listunspent` RPC call.
1510+
/// The maximum number of unspent transaction outputs (UTXOs) to request from the bitcoin node.
1511+
///
1512+
/// This value is passed as the `maximumCount` parameter to the bitcoin node. It helps manage
1513+
/// response size and processing load, particularly relevant for miners querying for available
1514+
/// UTXOs to fund operations like block commits or leader key registrations.
1515+
///
1516+
/// Setting this limit too high might lead to performance issues or timeouts when querying
1517+
/// nodes with a very large number of UTXOs. Conversely, setting it too low might prevent
1518+
/// the miner from finding enough UTXOs in a single query to meet the required funding amount
1519+
/// for a transaction, even if sufficient funds exist across more UTXOs not returned by the limited query.
1520+
///
1521+
/// This value must be `<= 1024`.
1522+
/// Primarily relevant for miners.
1523+
///
1524+
/// Default: `Some(1024)`
12571525
pub max_unspent_utxos: Option<u64>,
12581526
}
12591527

0 commit comments

Comments
 (0)