Skip to content

Conversation

@Sjors
Copy link
Member

@Sjors Sjors commented Dec 31, 2025

At startup isInitialBlockDownload() stops returning true once there’s less than a day of blocks left to sync. Connected mining clients will receive a flood of new templates as these last blocks are connected.

Fix this by briefly pausing block template creation while the best header chain is ahead of the tip. If no tip update happens for one second, we stop waiting.

It's not safe to keep waiting, because a malicious miner could announce a header and delay revealing the block, causing all other miners using this software to stall.

The cooldown only applies to createNewBlock(), which is typically called once per connected client; waitNext() remains unchanged.

Fixes #33994

@DrahtBot DrahtBot changed the title mining: add cooldown to createNewBlock() immediately after IBD mining: add cooldown to createNewBlock() immediately after IBD Dec 31, 2025
@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 31, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34184.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK bensig

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #33966 (refactor: disentangle miner startup defaults from runtime options by Sjors)
  • #33965 (mining: fix -blockreservedweight shadows IPC option by Sjors)
  • #33922 (mining: add getMemoryLoad() and track template non-mempool memory footprint by Sjors)
  • #33819 (mining: getCoinbase() returns struct instead of raw tx by Sjors)
  • #33795 (test: Ignore error message give from python because of PYTHON_GIL by kevkevinpal)
  • #32420 (miner: drop dummy extraNonce in coinbase scriptSig for templates requested via IPC by Sjors)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

At startup isInitialBlockDownload() stops returning true once there’s
less than a day of blocks left to sync. Connected mining clients will
receive a flood of new templates as these last blocks are connected.

Fix this by briefly pausing block template creation while the best
header chain is ahead of the tip. If no tip update happens for one
second, we stop waiting.

It’s not safe to keep waiting, because a malicious miner could announce
a header and delay revealing the block, causing all other miners using
this software to stall.

The cooldown only applies to createNewBlock(), which is typically called
once per connected client. Subsequent templates are provided by
waitNext().

Fixes bitcoin#33994
@Sjors Sjors force-pushed the 2025/12/cool-down branch from 62524ac to e8b01c4 Compare December 31, 2025 07:19
@Sjors
Copy link
Member Author

Sjors commented Dec 31, 2025

Switched to avoid mock time for the cooldown mechanism (it's possible, but would require additional refactoring).

Added a constraint to ignore alternative header branches. This probably doesn't matter in real life, but it does in tests. E.g. the assume_utxo test "Check importing a snapshot where current chain-tip is not an ancestor of the snapshot block but has less work" creates an alternative chain of blocks despite having better headers (but not their blocks). In real life this implies a giant block witholding attack.

@bensig
Copy link
Contributor

bensig commented Jan 3, 2026

ACK e8b01c4

Tested on macOS - interface_ipc.py passes.

Code review:

  • Using SteadyClock for the cooldown (independent of mocktime) is the right call
  • BestHeaderAheadOfActiveTip() correctly uses ancestor check to ignore competing branches
  • 1s timeout prevents DoS from header-only attacks while still allowing catch-up during final IBD

Nice fix for #33994

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mining IPC createNewBlock should not return before IBD is over

3 participants