Skip to content

Commit bd1a3aa

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feat/local-signer-state-machine
2 parents c110f0d + f8f19d0 commit bd1a3aa

File tree

7 files changed

+246
-31
lines changed

7 files changed

+246
-31
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
77

88
## [Unreleased]
99

10-
### Added"
10+
### Added
11+
1112
- Add fee information to transaction log ending with "success" or "skipped", while building a new block
13+
- When a miner's config file is updated (ie with a new fee rate), a new block commit is issued using
14+
the new values ([#5924](https://github.com/stacks-network/stacks-core/pull/5924))
1215

1316
### Changed
1417

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ For an example of this process, see PRs
4848

4949
### Documentation Updates
5050

51-
- Any major changes should be added to the [CHANGELOG](CHANGELOG.md).
51+
- Any major changes should be added to the [CHANGELOG](CHANGELOG.md)[*].
5252
- Mention any required documentation changes in the description of your pull request.
5353
- If adding or updating an RPC endpoint, ensure the change is documented in the
5454
OpenAPI spec: [`./docs/rpc/openapi.yaml`](./docs/rpc/openapi.yaml).
5555
- If your code adds or modifies any major features (struct, trait,
5656
test, module, function, etc.), each should be documented according
5757
to our [coding guidelines](#Coding-Guidelines).
5858

59+
> [*] The Changelog focuses on product changes. A "major change" refers to updates that have a direct impact on the end user, such as introducing new features, modifying existing functionality, or optimizing runtime performance.
60+
On the other hand, changes that do not need to be reflected in the Changelog include code refactoring, writing tests, or automating processes, as these do not directly affect the user experience.
61+
5962
## Git Commit Messages
6063

6164
Aim to use descriptive git commit messages. We try to follow [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/).

stackslib/src/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ impl std::default::Default for Config {
11971197
}
11981198
}
11991199

1200-
#[derive(Clone, Debug, Default, Deserialize)]
1200+
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
12011201
pub struct BurnchainConfig {
12021202
pub chain: String,
12031203
pub mode: String,

testnet/stacks-node/src/globals.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use stacks::chainstate::coordinator::comm::CoordinatorChannels;
1010
use stacks::chainstate::stacks::db::unconfirmed::UnconfirmedTxMap;
1111
use stacks::chainstate::stacks::db::StacksChainState;
1212
use stacks::chainstate::stacks::miner::MinerStatus;
13-
use stacks::config::MinerConfig;
13+
use stacks::config::{BurnchainConfig, MinerConfig};
1414
use stacks::net::NetworkResult;
1515
use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, ConsensusHash};
1616

@@ -63,6 +63,8 @@ pub struct Globals<T> {
6363
pub leader_key_registration_state: Arc<Mutex<LeaderKeyRegistrationState>>,
6464
/// Last miner config loaded
6565
last_miner_config: Arc<Mutex<Option<MinerConfig>>>,
66+
/// Last burnchain config
67+
last_burnchain_config: Arc<Mutex<Option<BurnchainConfig>>>,
6668
/// Last miner spend amount
6769
last_miner_spend_amount: Arc<Mutex<Option<u64>>>,
6870
/// burnchain height at which we start mining
@@ -93,6 +95,7 @@ impl<T> Clone for Globals<T> {
9395
should_keep_running: self.should_keep_running.clone(),
9496
leader_key_registration_state: self.leader_key_registration_state.clone(),
9597
last_miner_config: self.last_miner_config.clone(),
98+
last_burnchain_config: self.last_burnchain_config.clone(),
9699
last_miner_spend_amount: self.last_miner_spend_amount.clone(),
97100
start_mining_height: self.start_mining_height.clone(),
98101
estimated_winning_probs: self.estimated_winning_probs.clone(),
@@ -125,6 +128,7 @@ impl<T> Globals<T> {
125128
should_keep_running,
126129
leader_key_registration_state: Arc::new(Mutex::new(leader_key_registration_state)),
127130
last_miner_config: Arc::new(Mutex::new(None)),
131+
last_burnchain_config: Arc::new(Mutex::new(None)),
128132
last_miner_spend_amount: Arc::new(Mutex::new(None)),
129133
start_mining_height: Arc::new(Mutex::new(start_mining_height)),
130134
estimated_winning_probs: Arc::new(Mutex::new(HashMap::new())),
@@ -355,6 +359,28 @@ impl<T> Globals<T> {
355359
}
356360
}
357361

362+
/// Get the last burnchain config
363+
pub fn get_last_burnchain_config(&self) -> Option<BurnchainConfig> {
364+
match self.last_burnchain_config.lock() {
365+
Ok(last_burnchain_config) => (*last_burnchain_config).clone(),
366+
Err(_e) => {
367+
error!("FATAL; failed to lock last burnchain config");
368+
panic!();
369+
}
370+
}
371+
}
372+
373+
/// Set the last burnchain config
374+
pub fn set_last_burnchain_config(&self, burnchain_config: BurnchainConfig) {
375+
match self.last_burnchain_config.lock() {
376+
Ok(ref mut last_burnchain_config) => **last_burnchain_config = Some(burnchain_config),
377+
Err(_e) => {
378+
error!("FATAL; failed to lock last burnchain config");
379+
panic!();
380+
}
381+
}
382+
}
383+
358384
/// Get the last miner spend amount
359385
pub fn get_last_miner_spend_amount(&self) -> Option<u64> {
360386
match self.last_miner_spend_amount.lock() {

testnet/stacks-node/src/nakamoto_node/relayer.rs

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use stacks::chainstate::stacks::miner::{
4242
set_mining_spend_amount, signal_mining_blocked, signal_mining_ready,
4343
};
4444
use stacks::chainstate::stacks::Error as ChainstateError;
45+
use stacks::config::BurnchainConfig;
4546
use stacks::core::mempool::MemPoolDB;
4647
use stacks::core::STACKS_EPOCH_3_1_MARKER;
4748
use stacks::monitoring::increment_stx_blocks_mined_counter;
@@ -1101,29 +1102,7 @@ impl RelayerThread {
11011102
return Err(NakamotoNodeError::SnapshotNotFoundForChainTip);
11021103
};
11031104

1104-
let burnchain_config = self.config.get_burnchain_config();
1105-
let last_miner_spend_opt = self.globals.get_last_miner_spend_amount();
1106-
let force_remine = if let Some(last_miner_spend_amount) = last_miner_spend_opt {
1107-
last_miner_spend_amount != burnchain_config.burn_fee_cap
1108-
} else {
1109-
false
1110-
};
1111-
if force_remine {
1112-
info!(
1113-
"Miner config changed; updating spend amount {}",
1114-
burnchain_config.burn_fee_cap
1115-
);
1116-
}
1117-
1118-
self.globals
1119-
.set_last_miner_spend_amount(burnchain_config.burn_fee_cap);
1120-
1121-
set_mining_spend_amount(
1122-
self.globals.get_miner_status(),
1123-
burnchain_config.burn_fee_cap,
1124-
);
1125-
// amount of burnchain tokens (e.g. sats) we'll spend across the PoX outputs
1126-
let burn_fee_cap = burnchain_config.burn_fee_cap;
1105+
let (_, burnchain_config) = self.check_burnchain_config_changed();
11271106

11281107
// let's commit, but target the current burnchain tip with our modulus so the commit is
11291108
// only valid if it lands in the targeted burnchain block height
@@ -1155,7 +1134,7 @@ impl RelayerThread {
11551134
highest_tenure_start_block_header.index_block_hash().0,
11561135
),
11571136
// the rest of this is the same as epoch2x commits, modulo the new epoch marker
1158-
burn_fee: burn_fee_cap,
1137+
burn_fee: burnchain_config.burn_fee_cap,
11591138
apparent_sender: sender,
11601139
key_block_ptr: u32::try_from(key.block_height)
11611140
.expect("FATAL: burn block height exceeded u32"),
@@ -1703,9 +1682,11 @@ impl RelayerThread {
17031682

17041683
// update local state
17051684
last_committed.set_txid(&txid);
1706-
self.globals
1707-
.counters
1708-
.bump_naka_submitted_commits(last_committed.burn_tip.block_height, tip_height);
1685+
self.globals.counters.bump_naka_submitted_commits(
1686+
last_committed.burn_tip.block_height,
1687+
tip_height,
1688+
last_committed.block_commit.burn_fee,
1689+
);
17091690
self.last_committed = Some(last_committed);
17101691

17111692
Ok(())
@@ -1768,6 +1749,21 @@ impl RelayerThread {
17681749
"burnchain view changed?" => %burnchain_changed,
17691750
"highest tenure changed?" => %highest_tenure_changed);
17701751

1752+
// If the miner spend or config has changed, we want to RBF with new config values.
1753+
let (burnchain_config_changed, _) = self.check_burnchain_config_changed();
1754+
let miner_config_changed = self.check_miner_config_changed();
1755+
1756+
if burnchain_config_changed || miner_config_changed {
1757+
info!("Miner spend or config changed; issuing block commit with new values";
1758+
"miner_spend_changed" => %burnchain_config_changed,
1759+
"miner_config_changed" => %miner_config_changed,
1760+
);
1761+
return Ok(Some(RelayerDirective::IssueBlockCommit(
1762+
stacks_tip_ch,
1763+
stacks_tip_bh,
1764+
)));
1765+
}
1766+
17711767
if !burnchain_changed && !highest_tenure_changed {
17721768
// nothing to do
17731769
return Ok(None);
@@ -2136,6 +2132,45 @@ impl RelayerThread {
21362132
debug!("Relayer: handled directive"; "continue_running" => continue_running);
21372133
continue_running
21382134
}
2135+
2136+
/// Reload config.burnchain to see if burn_fee_cap has changed.
2137+
/// If it has, update the miner spend amount and return true.
2138+
pub fn check_burnchain_config_changed(&self) -> (bool, BurnchainConfig) {
2139+
let burnchain_config = self.config.get_burnchain_config();
2140+
let last_burnchain_config_opt = self.globals.get_last_burnchain_config();
2141+
let burnchain_config_changed =
2142+
if let Some(last_burnchain_config) = last_burnchain_config_opt {
2143+
last_burnchain_config != burnchain_config
2144+
} else {
2145+
false
2146+
};
2147+
2148+
self.globals
2149+
.set_last_miner_spend_amount(burnchain_config.burn_fee_cap);
2150+
self.globals
2151+
.set_last_burnchain_config(burnchain_config.clone());
2152+
2153+
set_mining_spend_amount(
2154+
self.globals.get_miner_status(),
2155+
burnchain_config.burn_fee_cap,
2156+
);
2157+
2158+
(burnchain_config_changed, burnchain_config)
2159+
}
2160+
2161+
pub fn check_miner_config_changed(&self) -> bool {
2162+
let miner_config = self.config.get_miner_config();
2163+
let last_miner_config_opt = self.globals.get_last_miner_config();
2164+
let miner_config_changed = if let Some(last_miner_config) = last_miner_config_opt {
2165+
last_miner_config != miner_config
2166+
} else {
2167+
false
2168+
};
2169+
2170+
self.globals.set_last_miner_config(miner_config);
2171+
2172+
miner_config_changed
2173+
}
21392174
}
21402175

21412176
#[cfg(test)]

testnet/stacks-node/src/run_loop/neon.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub struct Counters {
117117
pub naka_signer_pushed_blocks: RunLoopCounter,
118118
pub naka_miner_directives: RunLoopCounter,
119119
pub naka_submitted_commit_last_stacks_tip: RunLoopCounter,
120+
pub naka_submitted_commit_last_commit_amount: RunLoopCounter,
120121

121122
pub naka_miner_current_rejections: RunLoopCounter,
122123
pub naka_miner_current_rejections_timeout_secs: RunLoopCounter,
@@ -178,6 +179,7 @@ impl Counters {
178179
&self,
179180
committed_burn_height: u64,
180181
committed_stacks_height: u64,
182+
committed_sats_amount: u64,
181183
) {
182184
Counters::inc(&self.naka_submitted_commits);
183185
Counters::set(
@@ -188,6 +190,10 @@ impl Counters {
188190
&self.naka_submitted_commit_last_stacks_tip,
189191
committed_stacks_height,
190192
);
193+
Counters::set(
194+
&self.naka_submitted_commit_last_commit_amount,
195+
committed_sats_amount,
196+
);
191197
}
192198

193199
pub fn bump_naka_mined_blocks(&self) {

0 commit comments

Comments
 (0)