Skip to content

consensus/bor: prevent empty blocks when remaining build time is insufficient#2093

Merged
cffls merged 1 commit intodevelopfrom
fix_empty_block
Mar 2, 2026
Merged

consensus/bor: prevent empty blocks when remaining build time is insufficient#2093
cffls merged 1 commit intodevelopfrom
fix_empty_block

Conversation

@cffls
Copy link
Copy Markdown
Contributor

@cffls cffls commented Feb 27, 2026

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

  • 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

After

  • 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.

Changes

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)
  • Changes only for a subset of nodes

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

  • I have added at least 2 reviewer or the whole pos-v1 team
  • I have added sufficient documentation in code
  • I will be resolving comments - if any - by pushing each fix in a separate commit and linking the commit hash in the comment reply
  • Created a task in Jira and informed the team for implementation in Erigon client (if applicable)
  • Includes RPC methods changes, and the Notion documentation has been updated

Cross repository changes

  • This PR requires changes to heimdall
    • In case link the PR here:
  • This PR requires changes to matic-cli
    • In case link the PR here:

Testing

  • I have added unit tests
  • I have added tests to CI
  • I have tested this code manually on local environment
  • I have tested this code manually on remote devnet using express-cli
  • I have tested this code manually on amoy
  • I have created new e2e tests into express-cli

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

…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.
@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.61%. Comparing base (fdbc857) to head (98bafae).
⚠️ Report is 6 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             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     
Files with missing lines Coverage Δ
consensus/bor/bor.go 83.18% <100.00%> (ø)

... and 22 files with indirect coverage changes

Files with missing lines Coverage Δ
consensus/bor/bor.go 83.18% <100.00%> (ø)

... and 22 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cffls cffls merged commit 82b9c74 into develop Mar 2, 2026
24 of 25 checks passed
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