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.

replay_transactions: self.replay_transactions.unwrap_or_default(),
stackerdb_timeout: self.stackerdb_timeout_secs.map(Duration::from_secs).unwrap_or(miner_default_config.stackerdb_timeout),
max_tenure_bytes: self.max_tenure_bytes.unwrap_or(miner_default_config.max_tenure_bytes),
log_skipped_transactions: false
Copy link
Contributor

Choose a reason for hiding this comment

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

These skipped events might be nice for the explorer to show why a transaction is not being picked up. We might want to consider passing this option through the config file. If we don't do that, and only allow it to be set in tests, then why don't we remove this field from MinerConfigFile? My preference would be to support setting it in the config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I already have it in another patch. But actually it is pretty tiny, so i can definitely include it in this one.

/// One block will contains 3 of the deployed contracts (the block size will be reached at it)
/// The following one will contains 2 of the deployed contract (tenure size limit will be reached)
/// Start a new tenure to process the remaining transactions.
fn smaller_tenure_size_for_miner_on_two_tenures() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test to verify that the size can grow after a time-based tenure extend?

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

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.

3 participants