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

Spend down the block budget limit by x% every block #5450

Merged
merged 30 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1443e8c
Spend down the block budget limit by 25% every block
jferrant Nov 11, 2024
74da2c8
Add tenure_cost_limit_per_block_percentage config option and only app…
jferrant Nov 11, 2024
33091d7
Convert cost_limit_percentage to a soft limit
jferrant Nov 12, 2024
ef332d2
Use the block limit BEFORE applying the hard check when running the s…
jferrant Nov 12, 2024
ef4426b
Do not apply the spend down per transaction rather do per block
jferrant Nov 12, 2024
068d18f
Fix build
jferrant Nov 12, 2024
7dbd45c
Fix tests to not spend down the tenure limit
jferrant Nov 12, 2024
c9c950d
Fix comment
jferrant Nov 12, 2024
fbf5564
WIP: incomplete test
jferrant Nov 13, 2024
c7f65f8
WIP: incomplete test
jferrant Nov 13, 2024
33ec9b8
WIP: incomplete test
jferrant Nov 13, 2024
728c5f0
Fix soft limit calculation
jferrant Nov 13, 2024
f15b426
Fix setting of soft limit
jferrant Nov 13, 2024
5f7d661
wip: use contract-call and change soft_limit_reached logic
hstove Nov 14, 2024
edb6429
Cleanup
jferrant Nov 14, 2024
2803411
fix: proper `soft_limit` set, and fix test mined_blocks assertion
hstove Nov 14, 2024
3452aa7
Cleanup
jferrant Nov 14, 2024
0c46dbe
WIP: incomplete test
jferrant Nov 14, 2024
d78bf72
Make test a bit stricter about soft limit check
jferrant Nov 14, 2024
9eb5a80
Fix failing tests
jferrant Nov 14, 2024
1e0fbba
CRC: use cost_after to determine if soft limit was exceeded
jferrant Nov 14, 2024
975251b
CRC: cleanup comment for soft_limit option
jferrant Nov 14, 2024
56087b0
CRC: fix miner config parsing
jferrant Nov 14, 2024
804b8b9
Remove old log
jferrant Nov 14, 2024
21ed874
Use ranges when checking percentage
jferrant Nov 14, 2024
95ca231
Default to 25% for tenure_cost_limit_per_block_percentage
jferrant Nov 15, 2024
f27e918
CRC: cleanup
jferrant Nov 15, 2024
99d9a80
Add an assert to account for a faulty test
jferrant Nov 15, 2024
b2d6fad
Cleanup
jferrant Nov 15, 2024
7a3946d
Fix assert
jferrant Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stackslib/src/chainstate/nakamoto/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub struct NakamotoBlockBuilder {
txs: Vec<StacksTransaction>,
/// header we're filling in
pub header: NakamotoBlockHeader,
/// The execution cost for the block
/// Optional soft limit for this block's budget usage
soft_limit: Option<ExecutionCost>,
}

Expand Down Expand Up @@ -536,7 +536,7 @@ impl NakamotoBlockBuilder {
.mempool_settings
.tenure_cost_limit_per_block_percentage
{
if percentage < 100 {
if (1..100).contains(&percentage) {
let mut remaining_limit = block_limit.clone();
let cost_so_far = tenure_tx.cost_so_far();
if remaining_limit.sub(&cost_so_far).is_ok() {
Expand Down
1 change: 0 additions & 1 deletion stackslib/src/chainstate/stacks/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2468,7 +2468,6 @@ impl StacksBlockBuilder {
}
}
Error::TransactionTooBigError(measured_cost) => {
debug!("TRANSACTION TOO BIG: {}", &txinfo.tx.txid());
if update_estimator {
if let Some(measured_cost) = measured_cost {
if let Err(e) = estimator.notify_event(
Expand Down
26 changes: 15 additions & 11 deletions testnet/stacks-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2572,16 +2572,20 @@ impl MinerConfigFile {
.map(|x| Secp256k1PrivateKey::from_hex(x))
.transpose()?;
let pre_nakamoto_mock_signing = mining_key.is_some();
let valid_tenure_cost_limit = self
.tenure_cost_limit_per_block_percentage
.map(|p| p < 100 && p > 0)
.unwrap_or(true);
if !valid_tenure_cost_limit {
return Err(
"miner.tenure_cost_limit_per_block_percentage must be between 1 and 100"
.to_string(),
);
};

let tenure_cost_limit_per_block_percentage =
if let Some(percentage) = self.tenure_cost_limit_per_block_percentage {
if (1..=100).contains(&percentage) {
Some(percentage)
} else {
return Err(
"miner.tenure_cost_limit_per_block_percentage must be between 1 and 100"
.to_string(),
);
}
} else {
miner_default_config.tenure_cost_limit_per_block_percentage
};
Ok(MinerConfig {
first_attempt_time_ms: self
.first_attempt_time_ms
Expand Down Expand Up @@ -2688,7 +2692,7 @@ impl MinerConfigFile {
first_rejection_pause_ms: self.first_rejection_pause_ms.unwrap_or(miner_default_config.first_rejection_pause_ms),
subsequent_rejection_pause_ms: self.subsequent_rejection_pause_ms.unwrap_or(miner_default_config.subsequent_rejection_pause_ms),
block_commit_delay: self.block_commit_delay_ms.map(Duration::from_millis).unwrap_or(miner_default_config.block_commit_delay),
tenure_cost_limit_per_block_percentage: self.tenure_cost_limit_per_block_percentage,
tenure_cost_limit_per_block_percentage,
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8707,6 +8707,7 @@ fn mock_mining() {
let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
naka_conf.node.pox_sync_sample_secs = 30;
naka_conf.miner.tenure_cost_limit_per_block_percentage = None;
let sender_sk = Secp256k1PrivateKey::new();
let sender_signer_sk = Secp256k1PrivateKey::new();
let sender_signer_addr = tests::to_addr(&sender_signer_sk);
Expand Down Expand Up @@ -9323,7 +9324,7 @@ fn skip_mining_long_tx() {
naka_conf.node.prometheus_bind = Some(prom_bind.clone());
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
naka_conf.miner.nakamoto_attempt_time_ms = 5_000;
naka_conf.miner.tenure_cost_limit_per_block_percentage = Some(100);
naka_conf.miner.tenure_cost_limit_per_block_percentage = None;
let sender_1_sk = Secp256k1PrivateKey::from_seed(&[30]);
let sender_2_sk = Secp256k1PrivateKey::from_seed(&[31]);
// setup sender + recipient for a test stx transfer
Expand Down
2 changes: 1 addition & 1 deletion testnet/stacks-node/src/tests/signer/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,7 @@ fn miner_forking() {
config.node.pox_sync_sample_secs = 30;
config.burnchain.pox_reward_length = Some(max_sortitions as u32);
config.miner.block_commit_delay = Duration::from_secs(0);
config.miner.tenure_cost_limit_per_block_percentage = Some(100);
config.miner.tenure_cost_limit_per_block_percentage = None;

config.events_observers.retain(|listener| {
let Ok(addr) = std::net::SocketAddr::from_str(&listener.endpoint) else {
Expand Down