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

Fix: update microblock mining behavior #2981

Merged
merged 11 commits into from
Feb 8, 2022

Conversation

pavitthrap
Copy link
Contributor

@pavitthrap pavitthrap commented Dec 22, 2021

While working on #2975, I noticed some unexpected logic in the miner.

Here is a summary of changes in this PR:

  • Updated mine_next_microblock to keep track of block_limit_hit. This variable toggles between NO_LIMIT_HIT, CONTRACT_LIMIT_HIT, and LIMIT_REACHED. Keeping track of this signals the microblock builder to stop processing transactions once the block limit is hit.
  • Updated mine_next_transaction (which is used by mine_next_microblock) to take block_limit_hit as an input. This allows the function to skip over appropriate transactions (for example when block_limit_hit=CONTRACT_LIMIT_HIT, contract call and smart contract payloads will be automatically skipped).
  • Moved logic that updates mined_origin_nonces in build_anchored_block so that it only gets executed if the transaction being considered was successfully mined. As it was before, these values were sometimes being updated even when the transaction processing failed.
  • Changed location of where transactions were being added to the considered set for the microblock mining flow. It was originally in mine_next_transaction, but I moved the logic out to the calling function because I thought it was (a) more readable, and (b) it now mirrors the logic for the anchored block mining flow.

I need feedback on the following change:

  • Currently, the block_limit_hit variable moves onto its next state if a transaction errors with either BlockTooBigError or TransactionTooBigError. I removed this transition for the latter case, since I felt that it didn't make sense to change the block's limit behavior for an invalid tx that consumes >80% of the block budget that we are anyway dropping from the mempool.

Tests:
Ran existing tests.
Added 4 tests:

  • block limit behavior
  • microblock limit behavior
  • transaction too large in anchored block mining
  • transaction too large in microblock mining

@codecov
Copy link

codecov bot commented Dec 22, 2021

Codecov Report

Merging #2981 (1b9441a) into develop (c1b05d0) will increase coverage by 0.00%.
The diff coverage is 73.72%.

Impacted file tree graph

@@            Coverage Diff            @@
##           develop    #2981    +/-   ##
=========================================
  Coverage    82.65%   82.66%            
=========================================
  Files          242      242            
  Lines       195781   196143   +362     
=========================================
+ Hits        161829   162136   +307     
- Misses       33952    34007    +55     
Impacted Files Coverage Δ
src/chainstate/stacks/miner.rs 92.98% <60.63%> (-0.91%) ⬇️
testnet/stacks-node/src/tests/neon_integrations.rs 88.35% <75.94%> (+0.40%) ⬆️
src/vm/ast/traits_resolver/mod.rs 94.44% <0.00%> (-3.97%) ⬇️
src/chainstate/stacks/address.rs 91.84% <0.00%> (-2.49%) ⬇️
src/vm/analysis/errors.rs 69.84% <0.00%> (-0.51%) ⬇️
src/core/mempool.rs 83.65% <0.00%> (-0.49%) ⬇️
src/vm/database/key_value_wrapper.rs 96.48% <0.00%> (-0.32%) ⬇️
src/util/pipe.rs 86.26% <0.00%> (-0.28%) ⬇️
src/net/atlas/download.rs 83.94% <0.00%> (-0.24%) ⬇️
... and 30 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1b05d0...1b9441a. Read the comment docs.

@pavitthrap pavitthrap marked this pull request as draft January 3, 2022 15:30
@pavitthrap pavitthrap marked this pull request as ready for review January 11, 2022 16:09
Error::BlockTooBigError => {
// done mining -- our execution budget is exceeded.
// Make the block from the transactions we did manage to get
test_debug!("Block budget exceeded on tx {}", &tx.txid());
Copy link
Member

@jcnelson jcnelson Jan 31, 2022

Choose a reason for hiding this comment

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

Can this test_debug! statement be merged with the ones in either if branch, so that there's just one debug line emitted here? Makes it easier to grep for this event in test output. Same below.

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.

LGTM! Let's just make sure all the tests pass first. Looks like you might have some uncommitted code or something, because the unit tests are failing with a compile error.

@pavitthrap pavitthrap changed the base branch from feat/miner-structured-logging to develop February 1, 2022 16:36
Copy link
Member

@kantai kantai left a comment

Choose a reason for hiding this comment

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

LGTM -- just had some comments on log entries.

@pavitthrap pavitthrap merged commit e5b306e into develop Feb 8, 2022
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