Skip to content

Conversation

rdeioris
Copy link
Contributor

@rdeioris rdeioris commented Sep 12, 2025

Description

This patch introduces monitoring and limiting for the size of a whole tenure. Note that tenure extend resets the counter.

For allowing more targeted tests, it introduces a config option for the miner (not exposed to the file based configuration) for enabling logging of skipped transactions (that are not logged or sent to the event system).

Applicable issues

Additional info (benefits, drawbacks, caveats)

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo
  • New integration test(s) added to bitcoin-tests.yml

@rdeioris rdeioris marked this pull request as ready for review September 16, 2025 13:11
@rdeioris rdeioris requested review from a team as code owners September 16, 2025 13:11
Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

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

Added some comments for improvements.

One thing I think it missing is an update to the code where the miner decides whether or not it should attempt to tenure extend, see stacks-node/src/nakamoto_node/miner.rs:1676

                // Do not extend if we have spent < 50% of the budget, since it is
                // not necessary.
                let usage = self
                    .tenure_budget
                    .proportion_largest_dimension(&self.tenure_cost);
                if usage < self.config.miner.tenure_extend_cost_threshold {
                    return Ok(NakamotoTenureInfo {
                        coinbase_tx: None,
                        tenure_change_tx: None,
                    });
                }

I think it should also attempt to extend if the size is >50% of the budget.

Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

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

I'm not seeing the code where the miner checks max_tenure_size to stop mining blocks?

@rdeioris
Copy link
Contributor Author

I'm not seeing the code where the miner checks max_tenure_size to stop mining blocks?

I did it for allowing smaller transactions to be included (given that the check is done at transaction inclusion). The only case I see for completely disabling block mining is if the current tenure size is so near to the limit that it is impossibile for any transaction to be included

@rdeioris
Copy link
Contributor Author

Added some comments for improvements.

One thing I think it missing is an update to the code where the miner decides whether or not it should attempt to tenure extend, see stacks-node/src/nakamoto_node/miner.rs:1676

                // Do not extend if we have spent < 50% of the budget, since it is
                // not necessary.
                let usage = self
                    .tenure_budget
                    .proportion_largest_dimension(&self.tenure_cost);
                if usage < self.config.miner.tenure_extend_cost_threshold {
                    return Ok(NakamotoTenureInfo {
                        coinbase_tx: None,
                        tenure_change_tx: None,
                    });
                }

I think it should also attempt to extend if the size is >50% of the budget.

Love it, working on it

@jcnelson
Copy link
Member

Looks like CI is still failing

@rdeioris rdeioris requested review from obycode and jcnelson October 1, 2025 06:42
@rdeioris rdeioris enabled auto-merge October 6, 2025 13:18
Copy link

@aaronb-stacks aaronb-stacks left a comment

Choose a reason for hiding this comment

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

LGTM!

marf_values.push(nakamoto_keys::make_tenure_id_value(&tenure_id));
} else {
// if we are here (no new tenure or tenure_extend) we need to accumulate the parent total tenure size
if let Some(current_total_tenure_size) =
Copy link
Member

Choose a reason for hiding this comment

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

When would this ever be None? The default value for the tenure size is 0 from the migration, and this is always set, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, do you want me to explicitely manage it?

/// size so far exceeds this percentage. If the cost usage is below
/// this threshold, a time-based extension will not be attempted, even if the
/// [`MinerConfig::tenure_timeout`] duration has elapsed. This prevents miners
/// from extending tenures very early if they have produced only small blocks.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is desired behavior. Consider the following:

  1. Transactions T1, T2, and T3 enter the mempool. T1 is 20% of the size budget, T2 is 29% of the size budget, and T3 is 52% of the size budget.
  2. The miner wakes up and mines T1 and T2, meaning that 49% of the size budget has been used.
  3. The miner cannot mine T3 yet, because it the size of T1, T2, and T3 exceed 100%. But with this change, the miner will never receive a time-based tenure-extend either, since only 49% of the size budget has been used.

Copy link
Member

Choose a reason for hiding this comment

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

Also, I'm not seeing where this logic is applied in the signer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@obycode any thought ? i think the current behaviour you suggested was the main reason for not requiring a signer code update. Am I right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants