Skip to content

Commit

Permalink
reload from config for up to date satoshis_per_byte
Browse files Browse the repository at this point in the history
  • Loading branch information
tippenein committed Nov 15, 2023
1 parent 049db7e commit 17e9864
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 7 additions & 3 deletions testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,12 @@ impl BitcoinRegtestController {
) -> Option<Transaction> {
let public_key = signer.get_public_key();

let btc_miner_fee = self.config.burnchain.leader_key_tx_estimated_size
* self.config.burnchain.satoshis_per_byte;
// reload the config to find satoshis_per_byte changes
let satoshis_per_byte = match self.config.get_burnchain_config() {
Ok(s) => s.satoshis_per_byte,
Err(_) => self.config.burnchain.satoshis_per_byte,
};
let btc_miner_fee = self.config.burnchain.leader_key_tx_estimated_size * satoshis_per_byte;
let budget_for_outputs = DUST_UTXO_LIMIT;
let total_required = btc_miner_fee + budget_for_outputs;

Expand Down Expand Up @@ -831,7 +835,7 @@ impl BitcoinRegtestController {

tx.output = vec![consensus_output];

let fee_rate = self.config.burnchain.satoshis_per_byte;
let fee_rate = satoshis_per_byte;

self.finalize_tx(
epoch_id,
Expand Down
19 changes: 17 additions & 2 deletions testnet/stacks-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const INV_REWARD_CYCLES_TESTNET: u64 = 6;

#[derive(Clone, Deserialize, Default, Debug)]
pub struct ConfigFile {
pub path: Option<String>,
pub burnchain: Option<BurnchainConfigFile>,
pub node: Option<NodeConfigFile>,
pub ustx_balance: Option<Vec<InitialBalanceFile>>,
Expand Down Expand Up @@ -178,7 +179,9 @@ mod tests {
impl ConfigFile {
pub fn from_path(path: &str) -> Result<ConfigFile, String> {
let content = fs::read_to_string(path).map_err(|e| format!("Invalid path: {}", &e))?;
Self::from_str(&content)
let mut f = Self::from_str(&content)?;
f.path = Some(path.to_string());
Ok(f)
}

pub fn from_str(content: &str) -> Result<ConfigFile, String> {
Expand Down Expand Up @@ -353,6 +356,7 @@ impl ConfigFile {

#[derive(Clone, Debug)]
pub struct Config {
pub config_path: Option<String>,
pub burnchain: BurnchainConfig,
pub node: NodeConfig,
pub initial_balances: Vec<InitialBalance>,
Expand Down Expand Up @@ -394,6 +398,16 @@ lazy_static! {
}

impl Config {
/// get the up-to-date burnchain from the config
pub fn get_burnchain_config(&self) -> Result<BurnchainConfig, String> {
if let Some(path) = &self.config_path {
let config_file = ConfigFile::from_path(path.as_str())?;
let config = Config::from_config_file(config_file)?;
Ok(config.burnchain)
} else {
Ok(self.burnchain.clone())
}
}
/// Apply any test settings to this burnchain config struct
fn apply_test_settings(&self, burnchain: &mut Burnchain) {
if self.burnchain.get_bitcoin_network().1 == BitcoinNetworkType::Mainnet {
Expand Down Expand Up @@ -1148,6 +1162,7 @@ impl Config {
};

Ok(Config {
config_path: config_file.path,
node,
burnchain,
initial_balances,
Expand Down Expand Up @@ -1308,6 +1323,7 @@ impl std::default::Default for Config {
let estimation = FeeEstimationConfig::default();

Config {
config_path: None,
burnchain,
node,
initial_balances: vec![],
Expand Down Expand Up @@ -1386,7 +1402,6 @@ impl BurnchainConfig {
ast_precheck_size_height: None,
}
}

pub fn get_rpc_url(&self, wallet: Option<String>) -> String {
let scheme = match self.rpc_ssl {
true => "https://",
Expand Down

0 comments on commit 17e9864

Please sign in to comment.