Skip to content

perf: deserialize DKG messages once#7401

Open
thepastaclaw wants to merge 1 commit into
dashpay:developfrom
thepastaclaw:perf/dkg-single-deserialize
Open

perf: deserialize DKG messages once#7401
thepastaclaw wants to merge 1 commit into
dashpay:developfrom
thepastaclaw:perf/dkg-single-deserialize

Conversation

@thepastaclaw

@thepastaclaw thepastaclaw commented Jul 2, 2026

Copy link
Copy Markdown

Issue being fixed or feature implemented

DKG network message intake currently deserializes each accepted payload twice: once on a copied payload in the p2p message handler for structural validation and again from the pending queue on the DKG worker thread. Because these messages contain BLS objects, the redundant intake pass repeats point decompression on a hot network path during DKG rounds.

Tracker: https://github.com/thepastaclaw/tracker/issues/1726

What was done?

  • Kept incoming contributions, complaints, justifications, and premature commitments as exact raw wire bytes in the existing per-message-type pending queues.
  • Replaced the temporary typed intake deserialize with a framing-only wire walk that validates canonical CompactSize counts and dynamic bitsets, quorum-parameter bounds, truncation, and trailing bytes without materializing BLS objects.
  • Kept the DKG worker as the sole typed, canonical, and active-scheme-aware deserialization point, immediately followed by the same parameter-derived structural checks and normal preverification.
  • Preserved the per-peer quota of twice the quorum size and added a queue-wide remote-message cap of four times the quorum size across reconnect-generated NodeIds for each message type, with one reserved slot for the local phase message. The parameter-derived per-message size caps, FIFO worker batches of up to eight, and duplicate tracking remain unchanged.
  • Check duplicate wire hashes before charging the sender's per-peer queue quota.
  • Preserve inventory hashes over the exact original wire bytes, own-message queueing, and malformed-message scoring behavior.
  • At the start of each new DKG round, discard the globally bounded leftover raw queues without typed or BLS deserialization. Messages that missed their matching phase cannot delay new-round initialization with unbounded stale BLS work.
  • Added focused functional coverage proving that trailing bytes are rejected at intake, that a framing-valid invalid BLS encoding is accepted into the raw queue but rejected and scored by the on-time worker, and that late framing-valid messages remain globally bounded across reconnect-generated NodeIds and are cleared without BLS decoding before the next round initializes.

Benchmark evidence

A temporary local benchmark compared representative old double-deserialize and new single-deserialize costs for QCONTRIB and QPCOMMITMENT payloads. The benchmark was removed from the codebase because it modeled the deleted legacy path and would be maintenance noise as a permanent bench_dash target. The benchmark notes are preserved at https://gist.github.com/thepastaclaw/b612f49db3d2870d45c6a6ace5c4b0ad.

Representative results:

DKG_QCONTRIB_DoubleDeserialize:      8,665,346.67 ns/op
DKG_QCONTRIB_SingleDeserialize:      4,296,081.31 ns/op
DKG_QPCOMMITMENT_DoubleDeserialize:    872,053.32 ns/op
DKG_QPCOMMITMENT_SingleDeserialize:    454,025.78 ns/op

This showed roughly a 2x reduction in the deserialization/decompression portion of the DKG message path for representative payloads.

How Has This Been Tested?

Validated on macOS arm64 with:

make -C src -j15 llmq/libbitcoin_node_a-net_dkg.o llmq/libbitcoin_node_a-dkgsessionhandler.o dashd
./src/test/test_dash --run_test=llmq_dkg_tests
test/functional/test_runner.py feature_llmq_dkg_intake.py
python3 -m py_compile test/functional/feature_llmq_dkg_intake.py
python3 test/lint/lint-includes.py
python3 test/lint/lint-circular-dependencies.py
test/lint/lint-whitespace.py --prev-commits=1
git diff --check upstream/develop...HEAD

Breaking Changes

None.

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 (for repository code-owners and collaborators only)

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

✅ No Merge Conflicts Detected

This PR currently has no conflicts with other open PRs.

@thepastaclaw

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@thepastaclaw

thepastaclaw commented Jul 2, 2026

Copy link
Copy Markdown
Author

🔍 Review in progress — actively reviewing now (commit 45821d0)

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR changes DKG pending-message deduplication and queue capacity handling, validates serialized payload structure before retention, defers typed deserialization until worker processing, and updates round processing. Unit and functional tests cover trailing bytes, malformed BLS keys, duplicate accounting, queue bounds, worker rejection, and late-message clearing.

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

Sequence Diagram(s)

sequenceDiagram
  participant Peer
  participant NetDKG
  participant CDKGPendingMessages
  participant ProcessPendingMessageBatch
  participant PreVerifyMessage

  Peer->>NetDKG: ProcessMessage serialized payload
  NetDKG->>NetDKG: Validate size and wire structure
  NetDKG->>CDKGPendingMessages: Enqueue serialized payload
  ProcessPendingMessageBatch->>CDKGPendingMessages: Pop serialized payload
  ProcessPendingMessageBatch->>ProcessPendingMessageBatch: Deserialize and validate
  ProcessPendingMessageBatch->>PreVerifyMessage: Forward accepted message
Loading

Possibly related PRs

  • dashpay/dash#7314: Modifies the same DKG pending-message and network intake plumbing.
  • dashpay/dash#7397: Changes related DKG intake validation and processing paths.
  • dashpay/dash#7408: Modifies QCONTRIB structural validation in the same intake implementation.

Suggested reviewers: udjinm6, knst, kwvg

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.00% 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
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.
Title check ✅ Passed The title clearly matches the PR’s main change: reducing DKG message deserialization to once.
Description check ✅ Passed The description is directly about the same DKG intake/deserialization changes and related tests.
✨ 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

🧹 Nitpick comments (1)
src/bench/dkg_deserialize.cpp (1)

115-120: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Mirror the worker allocation in the double-deserialize benchmark.

The single-deserialize path includes std::make_shared, but the simulated old worker deserialize uses stack objects. If the removed worker path materialized shared typed messages, use make_shared here too so the comparison measures only the intended deserialize-count delta.

Proposed adjustment
-            llmq::CDKGContribution qc;
-            s >> qc;
-            ankerl::nanobench::doNotOptimizeAway(qc.contributions->blobs.size());
+            auto qc = std::make_shared<llmq::CDKGContribution>();
+            s >> *qc;
+            ankerl::nanobench::doNotOptimizeAway(qc->contributions->blobs.size());
-            llmq::CDKGPrematureCommitment qc;
-            s >> qc;
-            ankerl::nanobench::doNotOptimizeAway(qc.validMembers.size());
+            auto qc = std::make_shared<llmq::CDKGPrematureCommitment>();
+            s >> *qc;
+            ankerl::nanobench::doNotOptimizeAway(qc->validMembers.size());

Also applies to: 151-155

🤖 Prompt for 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.

In `@src/bench/dkg_deserialize.cpp` around lines 115 - 120, The old worker
deserialize benchmark path in the double-deserialize setup is not mirroring the
shared-allocation behavior used by the single-deserialize path. Update the
worker-side deserialize blocks in the benchmark function(s) that use CDataStream
and llmq::CDKGContribution so they materialize the typed message with
std::make_shared, matching the removed worker path’s allocation pattern. Keep
the deserialize-count comparison focused on the intended cost difference by
aligning the allocation behavior between the single and double-deserialize
cases.
🤖 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/llmq/dkgsessionhandler.h`:
- Around line 84-94: In CDKGPendingMessages, the duplicate-hash check currently
happens after incrementing messagesPerNode[from], so repeated duplicates can
consume the peer quota without adding work. Move the seenMessages.emplace(hash)
check ahead of the quota accounting in the same flow, then only increment
messagesPerNode[from] and continue enqueueing when the hash is new; keep the
existing logging and early returns in CDKGPendingMessages::AddMessage (or the
corresponding message-handling method).

---

Nitpick comments:
In `@src/bench/dkg_deserialize.cpp`:
- Around line 115-120: The old worker deserialize benchmark path in the
double-deserialize setup is not mirroring the shared-allocation behavior used by
the single-deserialize path. Update the worker-side deserialize blocks in the
benchmark function(s) that use CDataStream and llmq::CDKGContribution so they
materialize the typed message with std::make_shared, matching the removed worker
path’s allocation pattern. Keep the deserialize-count comparison focused on the
intended cost difference by aligning the allocation behavior between the single
and double-deserialize cases.
🪄 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

Run ID: 7c05047c-80ac-49ea-b4c5-0035e6ec8d3f

📥 Commits

Reviewing files that changed from the base of the PR and between 59d36a9 and c7e3cad.

📒 Files selected for processing (5)
  • src/Makefile.bench.include
  • src/bench/dkg_deserialize.cpp
  • src/llmq/dkgsessionhandler.cpp
  • src/llmq/dkgsessionhandler.h
  • src/llmq/net_dkg.cpp
💤 Files with no reviewable changes (1)
  • src/llmq/dkgsessionhandler.cpp

Comment thread src/llmq/dkgsessionhandler.h Outdated

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Code Review

Clean, well-scoped perf refactor eliminating a redundant DKG deserialize. All intake invariants (oversize ban, malformed ban, hash-over-wire-bytes, per-node/duplicate suppression, own-message enqueue form) are preserved and independently verified by multiple reviewers. Only remaining suggestion is a Dash-specific lint tracking update for the new benchmark file.

Source: reviewers: opus (general), claude-sonnet-5 (general), gpt-5.5[high] (general), opus (dash-core-commit-history), claude-sonnet-5 (dash-core-commit-history), gpt-5.5[high] (dash-core-commit-history); verifier: opus; specialists: dash-core-commit-history

🟡 1 suggestion

Findings not posted inline (1)

These findings could not be anchored to the current diff, but they are still part of this review.

  • [SUGGESTION] test/util/data/non-backported.txt:4: Add the new Dash-specific benchmark to non-backported tracking — This PR adds src/bench/dkg_deserialize.cpp, a Dash-specific benchmark that is not matched by the existing src/bench/bls*.cpp glob. test/lint/lint-cppcheck-dash.py (line 69-73) builds its Dash-specific file list exclusively from patterns in this file via git ls-files, so the new benchmark will be silently skipped by that extra lint coverage until it is added. Add a matching entry to keep Dash-specific bench files under cppcheck.
🤖 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 `test/util/data/non-backported.txt`:
- [SUGGESTION] test/util/data/non-backported.txt:4: Add the new Dash-specific benchmark to non-backported tracking
  This PR adds `src/bench/dkg_deserialize.cpp`, a Dash-specific benchmark that is not matched by the existing `src/bench/bls*.cpp` glob. `test/lint/lint-cppcheck-dash.py` (line 69-73) builds its Dash-specific file list exclusively from patterns in this file via `git ls-files`, so the new benchmark will be silently skipped by that extra lint coverage until it is added. Add a matching entry to keep Dash-specific bench files under cppcheck.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Code Review

Two suggestions remain against head 029fcc2. New finding in the latest delta: the dedupe-before-quota reorder correctly fixes duplicate resend quota charging, but a quota-exceeded drop now records the hash in seenMessages, so the same message can be poisoned for later legitimate delivery paths in the round. Carried-forward prior finding: src/bench/dkg_deserialize.cpp is still missing from test/util/data/non-backported.txt, so the extra cppcheck-dash lint pass will silently skip the new Dash-specific benchmark. No blocking issues; the benchmark allocation-shape fix is otherwise correct and well-scoped.

Source: reviewers: opus (general), claude-sonnet-5 (general), gpt-5.5[high] (general, failed), opus (dash-core-commit-history), claude-sonnet-5 (dash-core-commit-history), gpt-5.5[high] (dash-core-commit-history, failed); verifier: opus; specialists: dash-core-commit-history

🟡 2 suggestion(s)

Findings not posted inline (1)

These findings could not be anchored to the current diff, but they are still part of this review.

  • [SUGGESTION] test/util/data/non-backported.txt:4: Track new Dash-specific benchmark in non-backported.txt — This PR adds src/bench/dkg_deserialize.cpp, a Dash-specific benchmark that is not matched by the existing src/bench/bls*.cpp glob on line 4. test/lint/lint-cppcheck-dash.py builds its Dash-specific file list exclusively from the patterns in this file via git ls-files, so the new benchmark will be silently excluded from the extra cppcheck-dash coverage until it is listed here. Carried forward from the prior automated review at c7e3cad — still unresolved at head 029fcc2 (the tracked file was not touched by the latest push).
🤖 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.

New finding in the latest delta:
In `src/llmq/dkgsessionhandler.h`:
- [SUGGESTION] src/llmq/dkgsessionhandler.h:82-100: Quota-exceeded drop still poisons the message hash in seenMessages
  The reordered `PushPendingMessage` inserts `hash` into `seenMessages` at line 86 via `emplace(hash).second` before the quota check at line 92. If a sender is already at `maxMessagesPerNode` distinct-message quota, the function returns after having already committed the hash to `seenMessages`. Because `seenMessages` is keyed only by hash (not by sender), the same message subsequently delivered from any other peer — or via `AlreadyHave`/`HasSeen` paths — is now treated as "already seen" for the rest of the round and can never reach `pendingMessages`.
  
  This is a narrower variant of the bug fixed in e8d9b6d803: that commit correctly stopped duplicate resends from silently consuming a peer's quota, but the current ordering trades it for a case where a quota-exceeded drop poisons the hash for other, legitimate delivery paths. DKG already tolerates a single peer's messages being lost, so the operational impact is small, but the current shape unnecessarily couples the two intake failure modes. Splitting the seen-check (read-only) from the seen-insert (commit) so the hash is only recorded once the message is actually accepted preserves both invariants.

Carried-forward prior finding:
In `test/util/data/non-backported.txt`:
- [SUGGESTION] test/util/data/non-backported.txt:4: Track new Dash-specific benchmark in non-backported.txt
  This PR adds `src/bench/dkg_deserialize.cpp`, a Dash-specific benchmark that is not matched by the existing `src/bench/bls*.cpp` glob on line 4. `test/lint/lint-cppcheck-dash.py` builds its Dash-specific file list exclusively from the patterns in this file via `git ls-files`, so the new benchmark will be silently excluded from the extra cppcheck-dash coverage until it is listed here. Carried forward from the prior automated review at c7e3cad4 — still unresolved at head 029fcc228b (the tracked file was not touched by the latest push).

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Code Review

Both prior findings are cleanly resolved by the latest delta: PushPendingMessage now only marks a hash as seen after the per-node quota check passes (no more quota-drop poisoning), and src/bench/dkg_deserialize.cpp is now tracked in non-backported.txt. No new issues in the delta; the full PR stack (single-deserialize refactor, benchmark, dedupe/quota fix) preserves the documented intake invariants. Commit-history agents suggested squashing fixup commits, but Dash merges PRs without squashing and these are low-value stylistic notes that don't warrant blocking.

Source: reviewers: opus (general), claude-sonnet-5 (general), gpt-5.5[high] (general, failed), opus (dash-core-commit-history), claude-sonnet-5 (dash-core-commit-history), gpt-5.5[high] (dash-core-commit-history, failed); verifier: opus; specialists: dash-core-commit-history

@thepastaclaw

Copy link
Copy Markdown
Author

CI note: the current Build source failures are the same depends-cache infrastructure issue tracked in #7403, not a failure in this PR's DKG changes. The source jobs are exiting before compilation at actions/cache/restore with fail-on-cache-miss for freshly built depends cache keys, for example run 28630838726 / linux64-build job 84908995980. No branch change is appropriate for this PR; the workflow/cache fix belongs in #7403.

@thepastaclaw thepastaclaw force-pushed the perf/dkg-single-deserialize branch from 506a5e4 to 55e1d5e Compare July 4, 2026 14:26
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

@thepastaclaw thepastaclaw force-pushed the perf/dkg-single-deserialize branch from 55e1d5e to 98f20b1 Compare July 8, 2026 04:28
@thepastaclaw

Copy link
Copy Markdown
Author

Rebased this PR onto current upstream/develop and resolved the DKG conflict.

Preserved the single-deserialize typed queue path, kept the upstream contribution minSize lower-bound check, and retained the duplicate-before-quota / seen-after-quota behavior from the prior review fix.

Validation run locally on macOS arm64:

  • ./autogen.sh
  • ./configure --without-gui
  • make -C src llmq/libbitcoin_node_a-net_dkg.o bench/bench_dash -j4
  • git diff --check upstream/develop..HEAD
  • COMMIT_RANGE=upstream/develop..HEAD test/lint/lint-whitespace.py
  • COMMIT_RANGE=upstream/develop..HEAD test/lint/lint-cppcheck-dash.py
  • src/bench/bench_dash -filter='DKG_Q.*Deserialize'

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

@thepastaclaw Thanks for the update — rebasing onto upstream/develop and preserving the single-deserialize typed queue path, the contribution minSize check, and the duplicate-before-quota/seen-after-quota behavior all sound correct. The local validation steps (build, whitespace/cppcheck lint, and the DKG benchmark filter) look thorough. I'll kick off a fresh review of the rebased changes now.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@thepastaclaw thepastaclaw force-pushed the perf/dkg-single-deserialize branch from 98f20b1 to 51cf424 Compare July 8, 2026 16:32
@thepastaclaw

thepastaclaw commented Jul 8, 2026

Copy link
Copy Markdown
Author

Reworked this PR to remove the temporary old-vs-new benchmark from the codebase.

Current head 51cf424a2167d106c7677d4d7b8b444989396bfe is now a single production commit touching only:

  • src/llmq/dkgsessionhandler.cpp
  • src/llmq/dkgsessionhandler.h
  • src/llmq/net_dkg.cpp

The benchmark evidence is preserved in the PR description and in this gist:

https://gist.github.com/thepastaclaw/b612f49db3d2870d45c6a6ace5c4b0ad

Validation run locally on macOS arm64:

./autogen.sh
./configure --without-gui --disable-tests --disable-bench \
  --disable-wallet --without-miniupnpc --without-natpmp
make -C src llmq/libbitcoin_node_a-net_dkg.o -j4
make -C src llmq/libbitcoin_node_a-dkgsessionhandler.o -j4
python3 test/lint/lint-includes.py
python3 test/lint/lint-circular-dependencies.py
git diff --check upstream/develop
COMMIT_RANGE=upstream/develop..HEAD test/lint/lint-whitespace.py
npx markdownlint-cli2 /tmp/dash-7401-body-updated.md

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

@thepastaclaw Thanks for the update. Reducing the PR to a single production commit scoped to src/llmq/dkgsessionhandler.cpp, src/llmq/dkgsessionhandler.h, and src/llmq/net_dkg.cpp, while preserving the benchmark evidence in the PR description and gist, makes sense for keeping the diff focused. I'll trigger a fresh review of the current head now.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@PastaPastaPasta PastaPastaPasta marked this pull request as ready for review July 8, 2026 16:50
PastaPastaPasta
PastaPastaPasta previously approved these changes Jul 8, 2026

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

utACK 51cf424

@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: 51cf424a21

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/llmq/net_dkg.cpp Outdated
Comment thread src/llmq/dkgsessionhandler.h Outdated

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Code Review

I verified the current head 51cf424 against the active reviewer outputs and the older-SHA findings. The current PR diff is confined to the DKG typed pending-queue refactor; the quota poisoning issue is fixed, and the benchmark/non-backported findings are obsolete because src/bench/dkg_deserialize.cpp and test/util/data/non-backported.txt are no longer in the PR diff. No in-scope findings remain.

Source: reviewers: opus (claude general, failed), gpt-5.5 (codex general), opus (claude dash-core-commit-history, failed), gpt-5.5 (codex dash-core-commit-history); verifier: gpt-5.5 (codex; fallback: claude verifier unavailable); specialists: dash-core-commit-history

Prior finding reconciliation
  • Quota-exceeded drop still poisons the message hash in seenMessages — Fixed in the current code. src/llmq/dkgsessionhandler.h now performs a read-only duplicate check with seenMessages.count(hash) before the quota gate, returns on quota overflow without touching seenMessages, and only calls seenMessages.emplace(hash) after the quota check passes immediately before enqueue.
  • Track new Dash-specific benchmark in non-backported.txt — Obsolete at the assigned head. src/bench/dkg_deserialize.cpp is no longer present or tracked, and test/util/data/non-backported.txt is not part of the current PR diff.
  • Add the new Dash-specific benchmark to non-backported tracking — Obsolete at the assigned head for the same reason: the benchmark-only files from the older review are no longer in the PR diff.

Note: Claude/Opus lanes were unavailable due quota during this run; Codex reviewer and verifier lanes completed.

@thepastaclaw

Copy link
Copy Markdown
Author

Updated perf/dkg-single-deserialize with ce4180d18e8 to address the current review threads:

  • Pending DKG queues now retain bounded canonical CDataStream bytes rather than typed shared_ptr<Message> objects, preserving the previous compact retained-memory behavior.
  • DKG payload deserialization and structural checks now happen in the DKG phase worker immediately before PreVerifyMessage, so BLS-bearing objects are materialized under the active scheme at processing time while still deserializing only once.

Local validation:

  • ./autogen.sh
  • ./configure --without-gui --disable-tests --disable-bench --disable-wallet --without-miniupnpc --without-natpmp
  • make -C src llmq/libbitcoin_node_a-net_dkg.o -j4
  • make -C src llmq/libbitcoin_node_a-dkgsessionhandler.o -j4
  • git diff --check upstream/develop..HEAD
  • python3 test/lint/lint-includes.py
  • python3 test/lint/lint-circular-dependencies.py

@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: ce4180d18e

ℹ️ 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/llmq/net_dkg.cpp Outdated
@thepastaclaw thepastaclaw force-pushed the perf/dkg-single-deserialize branch from ce4180d to 48de1d0 Compare July 8, 2026 17:37
@thepastaclaw

Copy link
Copy Markdown
Author

Updated perf/dkg-single-deserialize with 48de1d0c4f2 to address the latest Codex review thread.

What changed:

  • DKG intake now validates a temporary copy of the canonical wire bytes before retaining anything in the pending queue.
  • Malformed or structurally invalid DKG payloads are banned immediately with malformed DKG message before PeerEraseObjectRequest / PushPendingMessage.
  • The pending queues still retain canonical CDataStream bytes, and the DKG worker still deserializes those bytes once at processing time.

Local validation:

  • ./configure --without-gui --disable-tests --disable-bench --without-miniupnpc --without-natpmp
  • make -C src llmq/libbitcoin_node_a-net_dkg.o -j4
  • make -C src llmq/libbitcoin_node_a-dkgsessionhandler.o -j4
  • make -C src dashd -j4
  • test/functional/feature_llmq_dkg_intake.py
  • git diff --check upstream/develop..HEAD
  • COMMIT_RANGE=upstream/develop..HEAD test/lint/lint-whitespace.py
  • python3 test/lint/lint-includes.py
  • python3 test/lint/lint-circular-dependencies.py
  • python3 -m py_compile test/functional/feature_llmq_dkg_intake.py

@thepastaclaw

Copy link
Copy Markdown
Author

Updated perf/dkg-single-deserialize with e2265ef810a03fe80ed0797df1fe35c53cc1a769 to address the current Codex review thread.

What changed:

  • DKG intake now performs a cheap wire-shape check before PeerEraseObjectRequest / PushPendingMessage.
  • Malformed/truncated pushed DKG payloads and under-min QCONTRIB blob counts are rejected immediately through the existing malformed DKG message misbehavior path.
  • Pending queues still retain canonical serialized CDataStream bytes, and typed deserialization remains in the DKG worker before PreVerifyMessage, preserving the CI-friendly serialized-queue design from the prior fix.

Local validation:

  • git diff --check HEAD~1..HEAD
  • make -C src llmq/libbitcoin_node_a-net_dkg.o dashd -j4
  • python3 test/lint/lint-includes.py
  • python3 test/lint/lint-circular-dependencies.py
  • test/functional/feature_llmq_dkg_intake.py --portseed=74011729
  • test/functional/feature_dip3_v19.py --configfile=/Users/claw/Projects/dash/worktrees/tracker-1729/test/config.ini --tmpdir=/private/tmp/dash_pr7401_feature_dip3_v19_wirecheck --randomseed=8319748680785945219 --timeout-factor=2 --portseed=74011730

Replied to and resolved the review thread: #7401 (comment)

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

@thepastaclaw Thanks for the update. Adding the cheap wire-shape check ahead of PeerEraseObjectRequest / PushPendingMessage to reject malformed/truncated payloads and under-min QCONTRIB blob counts immediately — while keeping canonical CDataStream bytes in the pending queues and typed deserialization in the worker before PreVerifyMessage — looks like the right approach and preserves the single-deserialize design. I'll trigger a fresh review of the current head (e2265ef810a03fe80ed0797df1fe35c53cc1a769) now.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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: e2265ef810

ℹ️ 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/llmq/net_dkg.cpp Outdated
@thepastaclaw thepastaclaw force-pushed the perf/dkg-single-deserialize branch from e2265ef to d291993 Compare July 8, 2026 21:05
@thepastaclaw

Copy link
Copy Markdown
Author

Updated the branch for the latest Codex review.

  • Commit: d291993
  • Change: the pre-queue DKG wire checker now deserializes and validates BLS public keys, signatures, and secret keys from the copied stream before queuing, so malformed non-zero BLS encodings hit the existing malformed DKG message misbehavior path immediately while queues still retain serialized bytes.
  • Tests: git diff --check HEAD~1..HEAD; make -C src llmq/libbitcoin_node_a-net_dkg.o dashd -j4; test/functional/feature_llmq_dkg_intake.py --portseed=74011729; seeded test/functional/feature_dip3_v19.py --randomseed=8319748680785945219 --timeout-factor=2 --portseed=74011731.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

@thepastaclaw Thanks for the update. Extending the pre-queue wire checker to deserialize and validate BLS public keys, signatures, and secret keys from the copied stream — so malformed non-zero BLS encodings are caught immediately via the existing malformed DKG message misbehavior path, while the pending queues still retain serialized bytes for the worker's single deserialization — looks like the right fix. I'll trigger a fresh review of the current head (d291993e8a379b3683c703a28351bb9a8929186f) now.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@thepastaclaw

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews resumed.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Author

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 exact head preserves bounded raw-byte queues, quota ordering, pre-queue malformed/trailing-byte rejection, and worker-side structural validation. It does not achieve the PR's stated performance goal: intake decompresses every BLS field and the worker decompresses the same fields again, while the new validity pass also creates a scheme-transition rejection path. The commit and PR descriptions still describe the superseded typed-queue implementation.

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)
  • Verifier: gpt-5.6-sol — verifier
  • Sonnet: not run (deferred by blocker gate)

🔴 1 blocking | 🟡 2 suggestion(s)

🤖 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/llmq/net_dkg.cpp`:
- [BLOCKING] src/llmq/net_dkg.cpp:152-154: BLS wire validation restores the dominant double-deserialization cost
  The intake checker calls `ReadAndCheckBLSObject` for every QCONTRIB verification-vector key, its ephemeral key, and its signature; QPCOMMITMENT similarly decodes its public key and both signatures. This invokes normal BLS deserialization and point decompression. Because the queue retains only `CDataStream`, `DeserializeAndCheckDKGMessage` later executes `ds >> *msg` and decompresses the same objects again. BLS decompression is the dominant cost identified by the PR and its benchmark, so the current implementation does not deliver the claimed single-deserialization or approximately 2x improvement. Validate malformed encodings without materializing all BLS objects at intake, or reuse the successfully decoded objects in the worker.
- [SUGGESTION] src/llmq/net_dkg.cpp:102-108: Intake BLS validation can reject a valid opposite-scheme encoding
  `ds >> obj` selects the mutable process-wide `bls::bls_legacy_scheme`. `CBLSWrapper::Unserialize` deliberately resets an object when its bytes are canonical only under the opposite scheme, so `obj.IsValid()` fails and the verified sender receives a score of 100. `ProcessMessage` does not hold `cs_main` across this pass, while activation, reorganization, and failed or dry-run block validation can change and subsequently restore the global scheme. A message valid under the stable scheme can therefore be classified as malformed during a transient scheme change; the previous structural intake pass did not require temporary BLS objects to remain valid, allowing the worker to deserialize the queued bytes after the scheme stabilized. Select the scheme from stable quorum/chain context or validate the encoding independently of the mutable global flag.

In `<commit:d291993>`:
- [SUGGESTION] <commit:d291993>:1: Reword the commit to match the raw-queue implementation
  Commit d291993e says intake enqueues an already-typed `std::shared_ptr<Message>`, makes `CDKGPendingMessages` a typed template, and removes worker deserialization. The exact head instead stores `std::shared_ptr<CDataStream>`, performs BLS-object deserialization during `CheckDKGMessageWireStructure`, and fully deserializes the message again in the worker. Update the subject, body, and PR description after settling the implementation so permanent history describes the code that will actually merge.

Note: the verifier’s canonical action is REQUEST_CHANGES, but GitHub does not allow an author to request changes on their own PR. This exact-SHA preliminary review is posted as COMMENT while preserving the validated blocker gate.

@thepastaclaw thepastaclaw force-pushed the perf/dkg-single-deserialize branch from d291993 to 9561ac9 Compare July 15, 2026 04:30

@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: 9561ac9683

ℹ️ 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/llmq/net_dkg.cpp
@thepastaclaw thepastaclaw force-pushed the perf/dkg-single-deserialize branch from 9561ac9 to d5b4334 Compare July 15, 2026 06:26
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews resumed.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Preliminary review — Codex only

Exact-head review confirms that seven prior issues are fixed, the benchmark-tracking concern is outdated, and intake-side BLS decoding remains deliberately deferred. The latest delta introduces one blocking issue: stale queues are decoded synchronously and without a global or authenticated-identity bound before the next DKG round initializes. An authenticated masternode can renew the per-NodeId quota through reconnects and accumulate enough BLS-heavy messages to delay or prevent round participation.

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 (failed), gpt-5.6-sol — dash-core-commit-history (failed), gpt-5.6-sol — general (failed), gpt-5.6-sol — dash-core-commit-history (failed), gpt-5.6-sol — general (failed), gpt-5.6-sol — dash-core-commit-history (failed), gpt-5.6-sol — general (failed), gpt-5.6-sol — dash-core-commit-history (failed), gpt-5.6-sol — general (completed), gpt-5.6-sol — dash-core-commit-history (completed)
  • Verifier: gpt-5.6-sol — verifier
  • Sonnet: not run (deferred by blocker gate)

🔴 1 blocking

🤖 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/llmq/net_dkg.cpp`:
- [BLOCKING] src/llmq/net_dkg.cpp:520-527: Round-start drain performs an unbounded synchronous BLS workload
  The normal phase path limits each batch to eight messages, but this new round-start path drains and deserializes every stale message before `InitNewQuorum`. Queue capacity is enforced per `NodeId`, while `CConnman` assigns every connection a fresh ID and MNAuth supplies no persistent per-ProTx quota; an authenticated masternode can therefore reconnect after the matching phase and add another `2 * params.size` messages. For a size-400 quorum, each connection can retain 800 distinct QCONTRIBs. Each payload can contain the required valid verification-vector public keys followed by an invalid final signature, forcing all preceding BLS point decoding before failure, while varying an unchecked field produces distinct inventory hashes. Messages from disconnected NodeIds are not penalized because `PeerMisbehaving` cannot find their peer state, and the loop continues decoding even when a peer is still connected. Bound stale work globally or by authenticated ProTx identity, or process it under a strict budget that cannot delay new-round initialization.

Note: the verifier’s canonical action is REQUEST_CHANGES, but GitHub does not allow an author to request changes on their own PR. This exact-SHA preliminary review is posted as COMMENT while preserving the validated blocker gate.

Comment thread src/llmq/net_dkg.cpp Outdated
@thepastaclaw thepastaclaw force-pushed the perf/dkg-single-deserialize branch from d5b4334 to 5d42157 Compare July 15, 2026 07:47
@thepastaclaw

Copy link
Copy Markdown
Author

Addressed the round-start stale-BLS workload in amended commit 5d42157: each raw message-type queue is now capped globally across remote NodeIds, reserves one local-message slot, avoids rejected-ID metadata growth, and clears bounded stale raw bytes without typed/BLS deserialization. Added queue-level churn/cap/reset coverage and an end-to-end reconnect-overflow test. Targeted build, llmq_dkg_tests, feature_llmq_dkg_intake.py, Python/include/circular/whitespace lints, clang-format diff, and diff checks pass. Fresh exact-head CI and automated review follow-through are running.

@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: 5d42157166

ℹ️ 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/llmq/dkgsessionhandler.cpp Outdated

@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/llmq/dkgsessionhandler.cpp`:
- Around line 46-50: Update the pending-queue capacity logic in the DKG session
handler to count remote entries independently of the local entry, so remote
messages can always use the full maxMessagesPerNode allowance regardless of
enqueue order while still enforcing the total maxPendingMessages limit. Preserve
the existing local enqueue behavior and Dash-specific DKG handling, and add a
focused unit test covering local-first enqueue followed by the maximum remote
messages.
🪄 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

Run ID: b3d3c15b-d49b-4699-a70b-0dc569245709

📥 Commits

Reviewing files that changed from the base of the PR and between d5b4334 and 5d42157.

📒 Files selected for processing (5)
  • src/llmq/dkgsessionhandler.cpp
  • src/llmq/dkgsessionhandler.h
  • src/llmq/net_dkg.cpp
  • src/test/llmq_dkg_tests.cpp
  • test/functional/feature_llmq_dkg_intake.py

Comment thread src/llmq/dkgsessionhandler.cpp Outdated
Keep incoming DKG messages as exact raw wire bytes after cheap framing validation. The DKG worker remains the sole normal typed and BLS deserialization point, avoiding repeated point decoding on the message-handler thread.

Preserve authenticated-only intake, parameter-derived size and framing checks, exact-wire inventory hashes, duplicate-before-quota ordering, worker preverification, malformed-message scoring in the matching phase, and own-message processing.

Bound each raw message-type queue across all remote NodeIds to four times the quorum size, allowing two peers to use their full per-node quotas, with one reserved slot for the local phase message. New-round cleanup discards bounded stale raw bytes without deserializing them, so reconnect churn cannot create an unbounded synchronous BLS workload before quorum initialization.

Add unit coverage for per-node and queue-wide caps, duplicate ordering, local-message capacity, and round clearing. Update the focused functional test to cover worker-deferred BLS rejection plus bounded late-message retention across reconnect-generated NodeIds and prompt next-round initialization.

Co-Authored-By: Claude <noreply@anthropic.com>
@thepastaclaw thepastaclaw force-pushed the perf/dkg-single-deserialize branch from 5d42157 to 45821d0 Compare July 15, 2026 08:28
@thepastaclaw

Copy link
Copy Markdown
Author

Addressed both queue-cap review findings in the amended single commit 45821d0:

  • remote capacity now permits two peers to consume their full per-peer quotas while remaining globally bounded at 4x quorum size;
  • remote occupancy is independent of the reserved local slot, so local-first enqueueing does not reduce remote capacity;
  • added focused queue tests for local-first ordering, two-peer fairness, overflow rejection, pop recovery, and clear/reset behavior;
  • updated the functional reconnect-bound test to the new cap.

Validation: focused unit tests passed, feature_llmq_dkg_intake.py passed, diff/py_compile checks passed, and the clean code-review gate returned ship with zero findings.

@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: 45821d078a

ℹ️ 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/llmq/net_dkg.cpp
@thepastaclaw

Copy link
Copy Markdown
Author

Exact-head CI is complete for 45821d078a9. The amended single commit still contains all review fixes, and the branch needs no further change.

Two functional-test failures are unrelated to this DKG-only diff:

  • TSAN: p2p_node_network_limited.py --v2transport hit the known connect_nodes(0, 2) peer-disconnect race tracked in test: p2p_node_network_limited.py --v2transport intermittently disconnects during connect_nodes #7288, with the same NODE_NETWORK_LIMITED stack on all three attempts.
  • Multiprocess: feature_governance.py --legacy-wallet timed out waiting for one trigger vote. The same exact-head legacy and descriptor tests passed in both the normal Linux and UBSAN jobs, and the descriptor variant passed in the multiprocess job itself. This PR changes only DKG intake/queue code and focused DKG tests, not governance or multiprocess code.

All build, lint, format, unit-test, and remaining functional-test jobs passed or were intentionally skipped. No rerun or branch mutation was performed.

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