consensus/bor: prevent empty blocks when remaining build time is insufficient#2093
Merged
consensus/bor: prevent empty blocks when remaining build time is insufficient#2093
Conversation
…fficient The late-block check in Prepare only extended the block deadline when the current time was already past the target (now.After(header.GetActualTime())). This missed the case where remaining time was positive but too small to actually include any transactions — the interrupt timer in the worker would fire almost immediately, and after the 500ms state root reservation, zero time remained for transaction execution. Example with blockTime=2s, parent ActualTime at T: - Target block time: T + 2s - Prepare runs at T + 1.991s, remaining = 9ms - Old code: 9ms > 0, so now.After(target) is false — no extension - Worker starts interrupt timer with 9ms delay, which fires immediately - Result: empty block with 0 transactions - New code: 9ms < minBlockBuildTime (1s), so the check triggers - Prepare extends header time to now + 2s, giving a full build window - Worker gets ~2s for transaction execution - Result: block includes transactions as expected The fix introduces a minBlockBuildTime constant (1s) and changes the condition from "is past target" to "has less than minBlockBuildTime remaining", ensuring the miner always has enough time to fill the block.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2093 +/- ##
===========================================
+ Coverage 50.59% 50.61% +0.01%
===========================================
Files 875 875
Lines 151820 151820
===========================================
+ Hits 76815 76845 +30
+ Misses 69929 69896 -33
- Partials 5076 5079 +3
... and 22 files with indirect coverage changes
🚀 New features to boost your workflow:
|
kamuikatsurgi
approved these changes
Feb 28, 2026
pratikspatil024
approved these changes
Mar 2, 2026
marcello33
approved these changes
Mar 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
The late-block check in Prepare only extended the block deadline when the current time was already past the target (now.After(header.GetActualTime())). This missed the case where remaining time was positive but too small to actually include any transactions — the interrupt timer in the worker would fire almost immediately, and after the 500ms state root reservation, zero time remained for transaction execution.
Example with blockTime=2s, parent ActualTime at T.
Before
After
The fix introduces a minBlockBuildTime constant (1s) and changes the condition from "is past target" to "has less than minBlockBuildTime remaining", ensuring the miner always has enough time to fill the block.
Changes
Breaking changes
Please complete this section if any breaking changes have been made, otherwise delete it
Nodes audience
In case this PR includes changes that must be applied only to a subset of nodes, please specify how you handled it (e.g. by adding a flag with a default value...)
Checklist
Cross repository changes
Testing
Manual tests
Please complete this section with the steps you performed if you ran manual tests for this functionality, otherwise delete it
Additional comments
Please post additional comments in this section if you have them, otherwise delete it