Skip to content

backport: partial bitcoin#25717, #25963 - anti-dos header sync - #7514

Open
knst wants to merge 2 commits into
dashpay:developfrom
knst:bp-25717-extremely-partial
Open

backport: partial bitcoin#25717, #25963 - anti-dos header sync#7514
knst wants to merge 2 commits into
dashpay:developfrom
knst:bp-25717-extremely-partial

Conversation

@knst

@knst knst commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

This PR replaces #7318

What was done?

This PR doesn't actually have enabled anything relevant to anti-DoS header sync.

Pre-sync is deleted, not disabled - no HeadersSyncState, no commitment buffer, no PRESYNC/REDOWNLOAD state.
Header acceptance hasn't changed path: CheckBlockHeader → ContextualCheckBlockHeader → ChainLock conflict check → checkpoints, and headers are downloaded once.

This PR includes multiple useful refactorings and code changes to reduce conflicts for further backports and reduce divergency between Dash Core codebase and Bitcoin Core.

Survived changes:

  • refactoring of GetLocator and its usages
  • changed setNumBlocks interface in qt code
  • changed interface of notification uiInterface.NotifyHeaderTip

How Has This Been Tested?

Run unit & functional tests.

Breaking Changes

N/A

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone

@thepastaclaw

thepastaclaw commented Aug 2, 2026

Copy link
Copy Markdown

✅ Final review complete — no blockers (commit fabb2ce)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05d490d3f8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/chain.h
/** Return a CBlockLocator that refers to a block in this chain (by default the tip). */
CBlockLocator GetLocator(const CBlockIndex* pindex = nullptr) const;
/** Return a CBlockLocator that refers to the tip in of this chain. */
CBlockLocator GetLocator() const;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore the indexed locator call sites

Removing the CChain::GetLocator(const CBlockIndex*) overload here leaves src/node/interfaces.cpp:1087 still calling active.GetLocator(index), so any build of ChainImpl::findBlock(...FoundBlock().locator(...)) fails with no matching member function instead of using the new free GetLocator(index). The backport guidance specifically warns to resolve these API conflicts rather than only matching upstream shape.

AGENTS.md reference: AGENTS.md:L153-L155

Useful? React with 👍 / 👎.

Comment thread src/net_processing.cpp
std::string msg_type = UsesCompressedHeaders(peer) ? NetMsgType::GETHEADERS2 : NetMsgType::GETHEADERS;
MaybeSendGetHeaders(pto,
msg_type, m_chainman.ActiveChain().GetLocator(state.m_chain_sync.m_work_header->pprev),
msg_type, GetLocator(state.m_chain_sync.m_work_header->pprev),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep the genesis locator in eviction probes

When m_work_header is the genesis block, m_work_header->pprev is null; the old member call treated a null argument as the active tip and sent a genesis locator, but the new free GetLocator(nullptr) serializes an empty locator. Peers in this code handle an empty getheaders locator by looking up only hashStop, and because MaybeSendGetHeaders passes a zero stop hash they return no headers, so an initial-sync eviction probe from a genesis-only node can never elicit the headers needed to prove the peer has caught up.

Useful? React with 👍 / 👎.

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1171d684-a6f2-4ccf-af77-4fae40ba8fc2

📥 Commits

Reviewing files that changed from the base of the PR and between 05d490d and fabb2ce.

📒 Files selected for processing (22)
  • src/chain.cpp
  • src/chain.h
  • src/index/base.cpp
  • src/interfaces/node.h
  • src/net_processing.cpp
  • src/node/interface_ui.cpp
  • src/node/interface_ui.h
  • src/node/interfaces.cpp
  • src/primitives/block.h
  • src/qt/bitcoin.cpp
  • src/qt/bitcoingui.cpp
  • src/qt/bitcoingui.h
  • src/qt/clientmodel.cpp
  • src/qt/clientmodel.h
  • src/qt/informationwidget.cpp
  • src/qt/informationwidget.h
  • src/qt/rpcconsole.cpp
  • src/qt/rpcconsole.h
  • src/qt/sendcoinsdialog.cpp
  • src/qt/sendcoinsdialog.h
  • src/test/skiplist_tests.cpp
  • src/validation.cpp
🚧 Files skipped from review as they are similar to previous changes (22)
  • src/validation.cpp
  • src/qt/bitcoin.cpp
  • src/interfaces/node.h
  • src/qt/bitcoingui.cpp
  • src/index/base.cpp
  • src/test/skiplist_tests.cpp
  • src/qt/sendcoinsdialog.cpp
  • src/node/interface_ui.cpp
  • src/primitives/block.h
  • src/node/interface_ui.h
  • src/qt/bitcoingui.h
  • src/node/interfaces.cpp
  • src/qt/sendcoinsdialog.h
  • src/qt/informationwidget.cpp
  • src/qt/clientmodel.cpp
  • src/chain.cpp
  • src/chain.h
  • src/net_processing.cpp
  • src/qt/rpcconsole.h
  • src/qt/rpcconsole.cpp
  • src/qt/informationwidget.h
  • src/qt/clientmodel.h

Walkthrough

The PR extracts block locator construction into free functions and updates locator callers. Header-tip notifications now pass height and timestamp instead of block-index pointers. Qt synchronization updates now use the typed SyncType enum across models, signals, GUI components, and widgets.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: pastapastapasta

Sequence Diagram(s)

sequenceDiagram
  participant Validation
  participant ClientUI
  participant ClientModel
  participant BitcoinGUI
  participant InformationWidget
  Validation->>ClientUI: send header height and timestamp
  ClientUI->>ClientModel: deliver BlockTip and synchronization state
  ClientModel->>BitcoinGUI: emit tip data and SyncType
  BitcoinGUI->>InformationWidget: update block information
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the partial backport of Bitcoin Core PRs #25717 and #25963 and its header-sync scope.
Description check ✅ Passed The description accurately explains the omitted anti-DoS mechanism and the included locator, Qt, and UI interface refactorings.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/chain.h`:
- Around line 481-482: Update the remaining caller in FillBlock to use the
standalone ::GetLocator(index) function instead of active.GetLocator(index),
matching the argument-free CChain::GetLocator declaration and restoring
compilation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2aebc17c-9a2c-4058-97ad-766fe93eb103

📥 Commits

Reviewing files that changed from the base of the PR and between 310b4f3 and 05d490d.

📒 Files selected for processing (22)
  • src/chain.cpp
  • src/chain.h
  • src/index/base.cpp
  • src/interfaces/node.h
  • src/net_processing.cpp
  • src/node/interface_ui.cpp
  • src/node/interface_ui.h
  • src/node/interfaces.cpp
  • src/primitives/block.h
  • src/qt/bitcoin.cpp
  • src/qt/bitcoingui.cpp
  • src/qt/bitcoingui.h
  • src/qt/clientmodel.cpp
  • src/qt/clientmodel.h
  • src/qt/informationwidget.cpp
  • src/qt/informationwidget.h
  • src/qt/rpcconsole.cpp
  • src/qt/rpcconsole.h
  • src/qt/sendcoinsdialog.cpp
  • src/qt/sendcoinsdialog.h
  • src/test/skiplist_tests.cpp
  • src/validation.cpp

Comment thread src/chain.h
@knst
knst requested review from PastaPastaPasta and UdjinM6 August 2, 2026 16:38

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Preliminary review — Codex only

The locator and header-tip refactors are generally adapted consistently, but the indexed locator API migration is incomplete. FillBlock still calls the removed CChain::GetLocator(const CBlockIndex*) overload, causing src/node/interfaces.cpp to fail compilation until it uses the new free function.

Validated blockers were found in the Codex precheck. Sonnet is deferred until a fresh Codex revalidation clears the blocker gate.

Review provenance

  • Codex reviewers: gpt-5.6-sol — general (completed), gpt-5.6-sol — dash-core-commit-history (completed), gpt-5.6-sol — backport-reviewer (completed)
  • Verifier: gpt-5.6-sol — verifier
  • Sonnet: not run (deferred by blocker gate)

🔴 1 blocking

1 additional finding(s) omitted (not in diff).

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/node/interfaces.cpp`:
- [BLOCKING] src/node/interfaces.cpp:1087: bitcoin#25717 locator refactor misses the bitcoin#25494 FillBlock caller
  This backport removes the indexed `CChain::GetLocator(const CBlockIndex*)` overload and introduces the free `GetLocator(const CBlockIndex*)` replacement, but `FillBlock` still calls `active.GetLocator(index)`. No matching member function now exists, so this translation unit cannot compile. Upstream commit `ed470940cdd` updated this exact caller as part of the same API refactor; apply that omitted transformation here.

@knst
knst marked this pull request as draft August 2, 2026 18:28
knst and others added 2 commits August 3, 2026 01:31
BACKPORT NOTE:
This PR doesn't actually have enabled anything relevant to anti-DoS header sync.

Pre-sync is deleted, not disabled - no HeadersSyncState, no commitment buffer,
no PRESYNC/REDOWNLOAD state.
Header acceptance hasn't changed path: CheckBlockHeader → ContextualCheckBlockHeader → ChainLock conflict check → checkpoints,
and headers are downloaded once.

This PR includes multiple useful refactorings and code changes to reduce conflicts for further backports and reduce divergency between
Dash Core codebase and Bitcoin Core.

Survived changes:
 - refactoring of GetLocator and its usages
 - changed setNumBlocks interface in qt code
 - changed interface of notification uiInterface.NotifyHeaderTip

---------------
3add234 ui: show header pre-synchronization progress (Pieter Wuille)
738421c Emit NotifyHeaderTip signals for pre-synchronization progress (Pieter Wuille)
376086f Make validation interface capable of signalling header presync (Pieter Wuille)
93eae27 Test large reorgs with headerssync logic (Suhas Daftuar)
3555473 Track headers presync progress and log it (Pieter Wuille)
03712dd Expose HeadersSyncState::m_current_height in getpeerinfo() (Suhas Daftuar)
150a548 Test headers sync using minchainwork threshold (Suhas Daftuar)
0b6aa82 Add unit test for HeadersSyncState (Suhas Daftuar)
83c6a0c Reduce spurious messages during headers sync (Suhas Daftuar)
ed6cddd Require callers of AcceptBlockHeader() to perform anti-dos checks (Suhas Daftuar)
551a8d9 Utilize anti-DoS headers download strategy (Suhas Daftuar)
ed47094 Add functions to construct locators without CChain (Pieter Wuille)
84852bb Add bitdeque, an std::deque<bool> analogue that does bit packing. (Pieter Wuille)
1d4cfa4 Add function to validate difficulty changes (Suhas Daftuar)

Pull request description:

  New nodes starting up for the first time lack protection against DoS from low-difficulty headers. While checkpoints serve as our protection against headers that fork from the main chain below the known checkpointed values, this protection only applies to nodes that have been able to download the honest chain to the checkpointed heights.

  We can protect all nodes from DoS from low-difficulty headers by adopting a different strategy: before we commit to storing a header in permanent storage, first verify that the header is part of a chain that has sufficiently high work (either `nMinimumChainWork`, or something comparable to our tip). This means that we will download headers from a given peer twice: once to verify the work on the chain, and a second time when permanently storing the headers.

  The p2p protocol doesn't provide an easy way for us to ensure that we receive the same headers during the second download of peer's headers chain. To ensure that a peer doesn't (say) give us the main chain in phase 1 to trick us into permanently storing an alternate, low-work chain in phase 2, we store commitments to the headers during our first download, which we validate in the second download.

  Some parameters must be chosen for commitment size/frequency in phase 1, and validation of commitments in phase 2. In this PR, those parameters are chosen to both (a) minimize the per-peer memory usage that an attacker could utilize, and (b) bound the expected amount of permanent memory that an attacker could get us to use to be well-below the memory growth that we'd get from the honest chain (where we expect 1 new block header every 10 minutes).

  After this PR, we should be able to remove checkpoints from our code, which is a nice philosophical change for us to make as well, as there has been confusion over the years about the role checkpoints play in Bitcoin's consensus algorithm.

  Thanks to Pieter Wuille for collaborating on this design.

ACKs for top commit:
  Sjors:
    re-tACK 3add234
  mzumsande:
    re-ACK 3add234
  sipa:
    re-ACK 3add234
  glozow:
    ACK 3add234

Tree-SHA512: e7789d65f62f72141b8899eb4a2fb3d0621278394d2d7adaa004675250118f89a4e4cb42777fe56649d744ec445ad95141e10f6def65f0a58b7b35b2e654a875

Co-authored-by: fanquake <fanquake@gmail.com>
…tidy fixup

6b24dfe CBlockLocator: performance-move-const-arg Clang tidy fixups (Jon Atack)

Pull request description:

  Fix Clang-tidy CI errors on master.  See https://cirrus-ci.com/task/4806752200818688?logs=ci#L4696 for an example.

ACKs for top commit:
  MarcoFalke:
    review ACK 6b24dfe
  vasild:
    ACK 6b24dfe

Tree-SHA512: 7a67acf7b42da07b63fbb392236e9a7be8cf35c36e37ca980c4467fe8295c2eda8aef10f41a1e3036cd9ebece47fa957fc3256033f853bd6a97ce2ca42799a0a

Co-authored-by: MacroFake <falke.marco@gmail.com>
@knst
knst force-pushed the bp-25717-extremely-partial branch from 05d490d to fabb2ce Compare August 2, 2026 18:32
@knst
knst marked this pull request as ready for review August 2, 2026 19:44

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Final validation — Codex + Sonnet

Carried-forward prior finding: FIXED. At exact head fabb2ce, FillBlock now uses the free GetLocator(index) API, and genuinely new findings in the latest delta: none. Full-current-PR Codex and Sonnet reviewer evidence identified no remaining in-scope correctness or backport-adaptation issues.

Source: reviewers codex/general=gpt-5.6-sol(completed); codex/dash-core-commit-history=gpt-5.6-sol(completed); codex/backport-reviewer=gpt-5.6-sol(completed); claude/general=claude-sonnet-5(completed); claude/dash-core-commit-history=claude-sonnet-5(failed); claude/backport-reviewer=claude-sonnet-5(failed); claude/dash-core-commit-history=claude-sonnet-5(failed); claude/backport-reviewer=claude-sonnet-5(completed); claude/dash-core-commit-history=claude-sonnet-5(failed); claude/dash-core-commit-history=claude-sonnet-5(completed); verifier=codex/final-verifier=gpt-5.6-sol(completed) fallback_for_sonnet_verifier=true; coordinator=openclaw-agent/cliproxy/gpt-5.6-sol(orchestration-only).

Review provenance

  • Codex reviewers: gpt-5.6-sol — general (completed), gpt-5.6-sol — dash-core-commit-history (completed), gpt-5.6-sol — backport-reviewer (completed)
  • Verifier: gpt-5.6-sol — final-verifier (fallback)
  • Sonnet reviewers: claude-sonnet-5 — general (completed), claude-sonnet-5 — dash-core-commit-history (failed), claude-sonnet-5 — backport-reviewer (failed), claude-sonnet-5 — dash-core-commit-history (failed), claude-sonnet-5 — backport-reviewer (completed), claude-sonnet-5 — dash-core-commit-history (failed), claude-sonnet-5 — dash-core-commit-history (completed)

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.

2 participants