Skip to content

Conversation

@PastaPastaPasta
Copy link
Member

@PastaPastaPasta PastaPastaPasta commented Nov 11, 2025

Issue being fixed or feature implemented

Return by value with std::optional over using return by reference

What was done?

How Has This Been Tested?

builds

Breaking Changes

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

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

@PastaPastaPasta PastaPastaPasta added this to the 23.1 milestone Nov 11, 2025
@github-actions
Copy link

github-actions bot commented Nov 11, 2025

⚠️ Potential Merge Conflicts Detected

This PR has potential conflicts with the following open PRs:

Please coordinate with the authors of these PRs to avoid merge conflicts.

@coderabbitai
Copy link

coderabbitai bot commented Nov 11, 2025

Walkthrough

This PR converts many bool + out-parameter getters to std::optional return values across multiple subsystems (chainlock, instantsend, LLMQ signing & recovered sigs DB, DKG session/handler/manager, signing shares, blockprocessor, net_processing, RPC quorums, masternode). It extracts four DKG types into a new public header llmq/dkgtypes.h and adds that header to src/Makefile.am. CActiveMasternodeManager::GetLocalAddress now returns std::optional<CService> and adds additional address-finding fallbacks. Locking annotations are preserved where present.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant OldGet as GetXxx (old)
    participant NewGet as GetXxx (new)

    rect rgb(245,245,255)
    Note over Caller,OldGet: Old pattern — bool + out-parameter
    Caller->>OldGet: GetXxx(hash, outParam)
    alt Found
        OldGet-->>Caller: true (outParam filled)
        Note over Caller: check bool, use outParam
    else Not found
        OldGet-->>Caller: false
        Note over Caller: treat missing
    end
    end

    rect rgb(245,255,245)
    Note over Caller,NewGet: New pattern — std::optional<T>
    Caller->>NewGet: GetXxx(hash)
    alt Found
        NewGet-->>Caller: optional<T> (has value)
        Note over Caller: dereference and use value
    else Not found
        NewGet-->>Caller: std::nullopt
        Note over Caller: handle absence
    end
    end
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

  • Heterogeneous, cross-cutting API and public-header changes affecting many files and call sites.
  • Areas requiring extra attention:
    • src/llmq/dkgtypes.h and its exposure via src/Makefile.am (public API, header guards, serialization/sign-hash correctness).
    • All header signature changes that added #include <optional> and updated function signatures; verify ABI, inline/static issues, and lock annotations (EXCLUSIVE_LOCKS_REQUIRED).
    • src/llmq/signing.{h,cpp} and CRecoveredSigsDb — DB read/deserialize and callers now use std::optional.
    • src/llmq/dkgsession{,handler,mgr}.{h,cpp} — movement of DKG types into dkgtypes.h and removal from dkgsession.h; ensure serialization/usage consistency.
    • src/net_processing.cpp — many GETDATA branches now dereference optionals for message creation; verify safe presence checks and message lifetimes.
    • src/masternode/node.{cpp,h} — GetLocalAddress behavior changes and new fallback logic; verify InitInternal error paths and m_info.service assignment.
    • Search for remaining legacy bool+out-parameter usages and update call sites to avoid unsafe dereferences.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.11% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor: avoid return by reference and prefer return by value' accurately summarizes the main refactoring objective shown across the changeset, which systematically converts function signatures from out-parameter patterns to std::optional returns.
Description check ✅ Passed The description is related to the changeset, stating the primary goal of returning by value with std::optional over using return by reference, though it lacks detail about what specifically was changed.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7c51e and d9393a8.

📒 Files selected for processing (1)
  • src/llmq/dkgsession.h (1 hunks)
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: kwvg
Repo: dashpay/dash PR: 6543
File: src/wallet/receive.cpp:240-251
Timestamp: 2025-02-06T14:34:30.466Z
Learning: Pull request #6543 is focused on move-only changes and refactoring, specifically backporting from Bitcoin. Behavior changes should be proposed in separate PRs.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/wallet/wallet.cpp:0-0
Timestamp: 2025-07-29T14:33:01.040Z
Learning: In refactoring PRs like #6761, kwvg acknowledges code safety improvements (like null pointer checks and unused parameter warnings) but prefers to defer them to follow-up PRs to maintain focus on the primary refactoring objectives, avoiding scope creep.
Learnt from: kwvg
Repo: dashpay/dash PR: 6718
File: test/functional/test_framework/test_framework.py:2102-2102
Timestamp: 2025-06-09T16:43:20.996Z
Learning: In the test framework consolidation PR (#6718), user kwvg prefers to limit functional changes to those directly related to MasternodeInfo, avoiding scope creep even for minor improvements like error handling consistency.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.cpp:247-250
Timestamp: 2025-07-29T14:32:48.369Z
Learning: In PR #6761, kwvg acknowledged a null pointer check issue in ChainLockSigner::Cleanup() method but deferred it to follow-up, consistent with the pattern of avoiding scope creep in refactoring PRs.
📚 Learning: 2025-07-29T14:33:01.040Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/wallet/wallet.cpp:0-0
Timestamp: 2025-07-29T14:33:01.040Z
Learning: In refactoring PRs like #6761, kwvg acknowledges code safety improvements (like null pointer checks and unused parameter warnings) but prefers to defer them to follow-up PRs to maintain focus on the primary refactoring objectives, avoiding scope creep.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-06-09T16:43:20.996Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6718
File: test/functional/test_framework/test_framework.py:2102-2102
Timestamp: 2025-06-09T16:43:20.996Z
Learning: In the test framework consolidation PR (#6718), user kwvg prefers to limit functional changes to those directly related to MasternodeInfo, avoiding scope creep even for minor improvements like error handling consistency.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-11-04T18:24:27.241Z
Learnt from: UdjinM6
Repo: dashpay/dash PR: 6933
File: src/llmq/utils.cpp:284-298
Timestamp: 2025-11-04T18:24:27.241Z
Learning: In consensus-critical code (such as quorum formation, block validation, or deployment activation logic), do not suggest changes to the logic itself even if the implementation appears theoretically incorrect or off-by-one. Consensus rules, once deployed on the Dash network, must be preserved exactly to avoid network forks. Refactoring PRs should maintain perfect behavioral equivalence. Only suggest logic changes if explicitly accompanied by a DIP (Dash Improvement Proposal) or if the maintainer indicates the consensus rule needs to be changed with appropriate activation logic.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-10-05T20:38:28.457Z
Learnt from: knst
Repo: dashpay/dash PR: 6871
File: contrib/guix/libexec/build.sh:358-360
Timestamp: 2025-10-05T20:38:28.457Z
Learning: In the Dash repository, when backporting code from Bitcoin Core, typos and minor issues in comments should be kept as-is to reduce merge conflicts in future backports, even if they remain unfixed in Bitcoin Core's master branch.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-10-13T12:37:12.357Z
Learnt from: knst
Repo: dashpay/dash PR: 6883
File: src/rpc/rawtransaction.cpp:1088-1125
Timestamp: 2025-10-13T12:37:12.357Z
Learning: In backport pull requests (especially from Bitcoin Core), treat "moved" or refactored code as out-of-scope for content-level review. Focus validation on verifying that code is moved correctly: no fields added, no fields removed, no fields reordered, and no unexpected changes beyond whitespace adjustments. Pre-existing issues in the upstream code should be preserved to maintain fidelity to the original implementation.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-07-29T14:32:48.369Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.cpp:247-250
Timestamp: 2025-07-29T14:32:48.369Z
Learning: In PR #6761, kwvg acknowledged a null pointer check issue in ChainLockSigner::Cleanup() method but deferred it to follow-up, consistent with the pattern of avoiding scope creep in refactoring PRs.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-07-23T09:28:32.783Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.cpp:15-250
Timestamp: 2025-07-23T09:28:32.783Z
Learning: In refactoring PRs like #6761, kwvg prefers to defer code formatting fixes to separate follow-up PRs when formatting is not the primary objective, to maintain focus on the structural changes and avoid scope creep.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-08-11T17:16:36.654Z
Learnt from: PastaPastaPasta
Repo: dashpay/dash PR: 6804
File: src/qt/proposalwizard.cpp:40-42
Timestamp: 2025-08-11T17:16:36.654Z
Learning: In the Dash repository, when a PR adds new files that are not from Bitcoin backports, these files must be added to the list in test/util/data/non-backported.txt. This applies to newly created files like qt/proposalwizard.{h,cpp} and forms/proposalwizard.ui. Limited exemptions may exist for subtrees and similar cases.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-10-25T07:08:51.918Z
Learnt from: knst
Repo: dashpay/dash PR: 6916
File: src/univalue/include/univalue.h:81-88
Timestamp: 2025-10-25T07:08:51.918Z
Learning: For backport PRs from bitcoin/bitcoin, bitcoin-core/gui, etc., backported changes should match the original upstream PRs even if they appear strange, modify vendored code, or seem to violate coding guidelines. Still flag genuine issues like bugs, undefined behavior, crashes, compilation errors, or linter failures.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-07-17T15:48:29.418Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6752
File: src/wallet/load.cpp:164-164
Timestamp: 2025-07-17T15:48:29.418Z
Learning: In Dash Core, kwvg prefers using assert() statements to document expected behavior in code paths, especially when the called function also has internal asserts. This is used as a defensive programming pattern rather than requiring conditional error handling.

Applied to files:

  • src/llmq/dkgsession.h
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: linux64_tsan-build / Build source
  • GitHub Check: mac-build / Build source
  • GitHub Check: linux64_fuzz-build / Build source
  • GitHub Check: linux64-build / Build source
  • GitHub Check: linux64_sqlite-build / Build source
  • GitHub Check: linux64_ubsan-build / Build source
  • GitHub Check: arm-linux-build / Build source
  • GitHub Check: win64-build / Build source
  • GitHub Check: linux64_nowallet-build / Build source
  • GitHub Check: Lint / Run linters
🔇 Additional comments (1)
src/llmq/dkgsession.h (1)

9-9: LGTM! Good refactoring to extract DKG types.

The addition of llmq/dkgtypes.h is correct. Moving the four DKG types (CDKGContribution, CDKGComplaint, CDKGJustification, CDKGPrematureCommitment) to a dedicated header improves modularity and reusability.

Regarding the past review comment about removing bls/bls_ies.h and util/underlying.h: these headers have been removed as suggested, which is correct since:

  • bls/bls_ies.h is now included transitively through dkgtypes.h (needed for line 142's CBLSIESMultiRecipientObjects)
  • util/underlying.h is not directly used in this header

The refactoring aligns well with the PR's objective of improving code structure.


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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/masternode/node.cpp (1)

239-260: Preserve the failure reason when GetLocalAddress() returns nullopt

With connected peers but no IPv4 candidate, we now return std::nullopt without touching m_error. InitInternal() then switches to SOME_ERROR, yet GetStatus() shows “Error. ” with an empty reason—this is a regression from the previous bool/out-param version, which populated the message before returning false. Please set m_error (and log once) right before the final return std::nullopt; so operators keep the actionable guidance.

-        if (empty) {
-            m_error = "Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only.";
-            LogPrintf("CActiveMasternodeManager::GetLocalAddress -- ERROR: %s\n", m_error);
-            return std::nullopt;
-        }
+        if (empty) {
+            m_error = "Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only.";
+            LogPrintf("CActiveMasternodeManager::GetLocalAddress -- ERROR: %s\n", m_error);
+        }
     }
     if (!fFoundLocal) {
+        if (m_error.empty()) {
+            m_error = "Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only.";
+            LogPrintf("CActiveMasternodeManager::GetLocalAddress -- ERROR: %s\n", m_error);
+        }
         return std::nullopt;
     }
🧹 Nitpick comments (2)
src/net_processing.cpp (1)

2825-2827: Optional-return usage is consistent; consider moving payloads to avoid copies.

Dereferencing the optionals passes lvalues, which may copy sizable structs. Moving the contained value can hint rvalue usage during serialization. Optional change, keep scope focused.

Apply move on the contained value (repeat for similar lines):

-                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QFCOMMITMENT, *opt_commitment));
+                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QFCOMMITMENT, std::move(*opt_commitment)));

-                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QCONTRIB, *opt_contrib));
+                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QCONTRIB, std::move(*opt_contrib)));

-                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QCOMPLAINT, *opt_complaint));
+                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QCOMPLAINT, std::move(*opt_complaint)));

-                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QJUSTIFICATION, *opt_justification));
+                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QJUSTIFICATION, std::move(*opt_justification)));

-                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QPCOMMITMENT, *opt_premature));
+                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QPCOMMITMENT, std::move(*opt_premature)));

-                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QSIGREC, *opt_rec_sig));
+                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QSIGREC, std::move(*opt_rec_sig)));

-                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::CLSIG, *opt_clsig));
+                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::CLSIG, std::move(*opt_clsig)));

-                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::ISDLOCK, *opt_islock));
+                m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::ISDLOCK, std::move(*opt_islock)));

Optional follow-up: a tiny helper to DRY this pattern can be introduced later. Based on learnings.

Also applies to: 2832-2834, 2839-2841, 2846-2848, 2853-2855, 2860-2862, 2867-2869, 2874-2876

src/chainlock/chainlock.h (1)

94-94: Add [[nodiscard]] to GetChainLockByHash; remove noexcept suggestion.

The [[nodiscard]] attribute is a good polish to prevent ignored optional results. However, noexcept is incorrect here—the function acquires a lock via LOCK(cs) (src/sync.h:347), which uses DebugLock and can throw on lock contention or failure. Additionally, ChainLockSig copy construction is not marked noexcept, so the function's return operation may also throw.

Apply only the [[nodiscard]] part:

-    std::optional<chainlock::ChainLockSig> GetChainLockByHash(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
+    [[nodiscard]] std::optional<chainlock::ChainLockSig> GetChainLockByHash(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);

Verification confirmed no legacy two-argument call sites exist; only one compatible call site found in src/net_processing.cpp:2867.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 368eebb and c824b62.

📒 Files selected for processing (21)
  • src/Makefile.am (1 hunks)
  • src/chainlock/chainlock.cpp (1 hunks)
  • src/chainlock/chainlock.h (2 hunks)
  • src/instantsend/instantsend.cpp (2 hunks)
  • src/instantsend/instantsend.h (2 hunks)
  • src/instantsend/signing.cpp (1 hunks)
  • src/llmq/blockprocessor.cpp (1 hunks)
  • src/llmq/blockprocessor.h (1 hunks)
  • src/llmq/dkgsession.h (1 hunks)
  • src/llmq/dkgsessionhandler.cpp (1 hunks)
  • src/llmq/dkgsessionhandler.h (2 hunks)
  • src/llmq/dkgsessionmgr.cpp (1 hunks)
  • src/llmq/dkgsessionmgr.h (2 hunks)
  • src/llmq/signing.cpp (8 hunks)
  • src/llmq/signing.h (4 hunks)
  • src/llmq/signing_shares.cpp (4 hunks)
  • src/llmq/signing_shares.h (2 hunks)
  • src/masternode/node.cpp (3 hunks)
  • src/masternode/node.h (2 hunks)
  • src/net_processing.cpp (1 hunks)
  • src/rpc/quorums.cpp (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.{cpp,h,cc,cxx,hpp}

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.{cpp,h,cc,cxx,hpp}: Dash Core C++ codebase must be written in C++20 and require at least Clang 16 or GCC 11.1
Dash uses unordered_lru_cache for efficient caching with LRU eviction

Files:

  • src/llmq/blockprocessor.h
  • src/chainlock/chainlock.h
  • src/llmq/dkgsession.h
  • src/llmq/signing_shares.h
  • src/masternode/node.h
  • src/net_processing.cpp
  • src/llmq/dkgsessionhandler.cpp
  • src/instantsend/instantsend.h
  • src/chainlock/chainlock.cpp
  • src/llmq/dkgsessionhandler.h
  • src/instantsend/signing.cpp
  • src/rpc/quorums.cpp
  • src/llmq/dkgsessionmgr.cpp
  • src/llmq/blockprocessor.cpp
  • src/llmq/signing.cpp
  • src/masternode/node.cpp
  • src/llmq/dkgsessionmgr.h
  • src/llmq/signing.h
  • src/instantsend/instantsend.cpp
  • src/llmq/signing_shares.cpp
src/{masternode,evo}/**/*.{cpp,h,cc,cxx,hpp}

📄 CodeRabbit inference engine (CLAUDE.md)

Masternode lists must use immutable data structures (Immer library) for thread safety

Files:

  • src/masternode/node.h
  • src/masternode/node.cpp
🧠 Learnings (7)
📓 Common learnings
Learnt from: kwvg
Repo: dashpay/dash PR: 6543
File: src/wallet/receive.cpp:240-251
Timestamp: 2025-02-06T14:34:30.466Z
Learning: Pull request #6543 is focused on move-only changes and refactoring, specifically backporting from Bitcoin. Behavior changes should be proposed in separate PRs.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/wallet/wallet.cpp:0-0
Timestamp: 2025-07-29T14:33:01.040Z
Learning: In refactoring PRs like #6761, kwvg acknowledges code safety improvements (like null pointer checks and unused parameter warnings) but prefers to defer them to follow-up PRs to maintain focus on the primary refactoring objectives, avoiding scope creep.
Learnt from: kwvg
Repo: dashpay/dash PR: 6718
File: test/functional/test_framework/test_framework.py:2102-2102
Timestamp: 2025-06-09T16:43:20.996Z
Learning: In the test framework consolidation PR (#6718), user kwvg prefers to limit functional changes to those directly related to MasternodeInfo, avoiding scope creep even for minor improvements like error handling consistency.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.cpp:247-250
Timestamp: 2025-07-29T14:32:48.369Z
Learning: In PR #6761, kwvg acknowledged a null pointer check issue in ChainLockSigner::Cleanup() method but deferred it to follow-up, consistent with the pattern of avoiding scope creep in refactoring PRs.
📚 Learning: 2025-07-23T09:30:34.631Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.h:5-6
Timestamp: 2025-07-23T09:30:34.631Z
Learning: Dash Core uses BITCOIN_ prefix for header guards as the standard convention, inherited from Bitcoin Core. Only a few BLS-specific files in src/bls/ use DASH_ prefix. The vast majority of files (385+) use BITCOIN_ prefix.

Applied to files:

  • src/Makefile.am
📚 Learning: 2025-07-20T18:42:49.794Z
Learnt from: CR
Repo: dashpay/dash PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-07-20T18:42:49.794Z
Learning: Applies to src/**/*.{cpp,h,cc,cxx,hpp} : Dash uses unordered_lru_cache for efficient caching with LRU eviction

Applied to files:

  • src/instantsend/instantsend.h
📚 Learning: 2025-10-21T11:09:34.688Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6849
File: src/governance/governance.cpp:1339-1343
Timestamp: 2025-10-21T11:09:34.688Z
Learning: In the Dash Core codebase, `CacheMap` (defined in src/cachemap.h) is internally thread-safe and uses its own `mutable CCriticalSection cs` to protect access to its members. Methods like `GetSize()`, `Insert()`, `Get()`, `HasKey()`, etc., can be called without holding external locks.

Applied to files:

  • src/instantsend/instantsend.h
📚 Learning: 2025-07-29T14:32:48.369Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.cpp:247-250
Timestamp: 2025-07-29T14:32:48.369Z
Learning: In PR #6761, kwvg acknowledged a null pointer check issue in ChainLockSigner::Cleanup() method but deferred it to follow-up, consistent with the pattern of avoiding scope creep in refactoring PRs.

Applied to files:

  • src/chainlock/chainlock.cpp
📚 Learning: 2025-10-02T18:29:54.756Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6840
File: src/net_processing.cpp:2882-2886
Timestamp: 2025-10-02T18:29:54.756Z
Learning: Across net_processing.cpp, once LLMQContext (m_llmq_ctx) is asserted non-null, its subcomponents (e.g., isman, qdkgsman, quorum_block_processor) are treated as initialized and used without extra null checks.

Applied to files:

  • src/llmq/dkgsessionhandler.h
📚 Learning: 2025-05-10T00:54:15.597Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6629
File: src/evo/deterministicmns.cpp:473-485
Timestamp: 2025-05-10T00:54:15.597Z
Learning: In the current implementation of `NetInfoEntry`, only `CService` is a valid type and `std::monostate` represents an invalid state. Entries that don't provide a valid `CService` through `GetAddrPort()` should be rejected with an exception, not silently skipped.

Applied to files:

  • src/masternode/node.cpp
🧬 Code graph analysis (13)
src/llmq/blockprocessor.h (1)
src/llmq/blockprocessor.cpp (2)
  • GetMineableCommitmentByHash (723-731)
  • GetMineableCommitmentByHash (723-723)
src/chainlock/chainlock.h (2)
src/chainlock/clsig.h (1)
  • chainlock (15-38)
src/chainlock/chainlock.cpp (2)
  • GetChainLockByHash (98-108)
  • GetChainLockByHash (98-98)
src/llmq/signing_shares.h (1)
src/llmq/signing_shares.cpp (4)
  • GetSessionInfoByRecvId (155-169)
  • GetSessionInfoByRecvId (155-155)
  • GetSessionInfoByRecvId (1362-1366)
  • GetSessionInfoByRecvId (1362-1362)
src/masternode/node.h (1)
src/masternode/node.cpp (2)
  • GetLocalAddress (218-260)
  • GetLocalAddress (218-218)
src/net_processing.cpp (3)
src/instantsend/instantsend.cpp (1)
  • inv (422-422)
src/coinjoin/server.cpp (1)
  • inv (375-375)
src/llmq/dkgsession.cpp (4)
  • inv (301-301)
  • inv (609-609)
  • inv (820-820)
  • inv (1175-1175)
src/llmq/dkgsessionhandler.cpp (1)
src/llmq/dkgsessionmgr.cpp (8)
  • GetContribution (206-221)
  • GetContribution (206-206)
  • GetComplaint (223-238)
  • GetComplaint (223-223)
  • GetJustification (240-255)
  • GetJustification (240-240)
  • GetPrematureCommitment (257-272)
  • GetPrematureCommitment (257-257)
src/instantsend/instantsend.h (2)
src/instantsend/lock.h (1)
  • instantsend (18-41)
src/instantsend/instantsend.cpp (2)
  • GetInstantSendLockByHash (840-862)
  • GetInstantSendLockByHash (840-840)
src/chainlock/chainlock.cpp (1)
src/chainlock/chainlock.h (2)
  • cs (64-135)
  • cs (65-132)
src/llmq/dkgsessionhandler.h (2)
src/llmq/dkgsessionmgr.cpp (8)
  • GetContribution (206-221)
  • GetContribution (206-206)
  • GetComplaint (223-238)
  • GetComplaint (223-223)
  • GetJustification (240-255)
  • GetJustification (240-240)
  • GetPrematureCommitment (257-272)
  • GetPrematureCommitment (257-257)
src/llmq/dkgsessionhandler.cpp (8)
  • GetContribution (630-638)
  • GetContribution (630-630)
  • GetComplaint (640-648)
  • GetComplaint (640-640)
  • GetJustification (650-658)
  • GetJustification (650-650)
  • GetPrematureCommitment (660-668)
  • GetPrematureCommitment (660-660)
src/llmq/dkgsessionmgr.cpp (1)
src/llmq/dkgsessionhandler.cpp (8)
  • GetContribution (630-638)
  • GetContribution (630-630)
  • GetComplaint (640-648)
  • GetComplaint (640-640)
  • GetJustification (650-658)
  • GetJustification (650-650)
  • GetPrematureCommitment (660-668)
  • GetPrematureCommitment (660-660)
src/masternode/node.cpp (2)
src/net.cpp (2)
  • GetLocalAddress (231-234)
  • GetLocalAddress (231-231)
src/masternode/node.h (1)
  • cs (48-87)
src/llmq/dkgsessionmgr.h (2)
src/llmq/dkgsessionmgr.cpp (8)
  • GetContribution (206-221)
  • GetContribution (206-206)
  • GetComplaint (223-238)
  • GetComplaint (223-223)
  • GetJustification (240-255)
  • GetJustification (240-240)
  • GetPrematureCommitment (257-272)
  • GetPrematureCommitment (257-257)
src/llmq/dkgsessionhandler.cpp (8)
  • GetContribution (630-638)
  • GetContribution (630-630)
  • GetComplaint (640-648)
  • GetComplaint (640-640)
  • GetJustification (650-658)
  • GetJustification (650-650)
  • GetPrematureCommitment (660-668)
  • GetPrematureCommitment (660-660)
src/llmq/signing.h (1)
src/llmq/signing.cpp (18)
  • GetRecoveredSigByHash (118-127)
  • GetRecoveredSigByHash (118-118)
  • GetRecoveredSigById (129-132)
  • GetRecoveredSigById (129-129)
  • TruncateRecoveredSig (213-218)
  • TruncateRecoveredSig (213-213)
  • TruncateRecoveredSig (643-646)
  • TruncateRecoveredSig (643-643)
  • GetVoteForId (277-285)
  • GetVoteForId (277-277)
  • GetVoteForId (712-715)
  • GetVoteForId (712-712)
  • ReadRecoveredSig (100-116)
  • ReadRecoveredSig (100-100)
  • GetRecoveredSigForGetData (367-379)
  • GetRecoveredSigForGetData (367-367)
  • GetRecoveredSigForId (691-694)
  • GetRecoveredSigForId (691-691)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: arm-linux-build / Build source
  • GitHub Check: linux64_tsan-build / Build source
  • GitHub Check: mac-build / Build source
  • GitHub Check: linux64_ubsan-build / Build source
  • GitHub Check: linux64_sqlite-build / Build source
  • GitHub Check: linux64_fuzz-build / Build source
  • GitHub Check: linux64-build / Build source
  • GitHub Check: linux64_nowallet-build / Build source
  • GitHub Check: win64-build / Build source
  • GitHub Check: Lint / Run linters
🔇 Additional comments (15)
src/llmq/signing_shares.h (2)

347-347: LGTM - Clean refactoring to std::optional.

The method signature change from bool+out-parameter to std::optional<SessionInfo> return is correct and aligns with the PR objectives.


475-475: LGTM - Consistent refactoring across the class.

The manager-level method signature mirrors the node state method's refactoring pattern correctly.

src/llmq/signing_shares.cpp (6)

155-169: LGTM - Correct implementation of optional-return pattern.

The function properly returns std::nullopt when the session is not found and returns a populated SessionInfo by value otherwise. The move semantics will handle this efficiently.


355-388: LGTM - Proper handling of optional return value.

The code correctly uses the if-initializer pattern to check the optional and safely dereferences sessionInfo with the -> operator throughout. The separation between getting SessionInfo for validation and retrieving the actual Session* to modify it is appropriate since SessionInfo is a lightweight copy.


392-416: LGTM - Consistent with other callsites.

The optional handling follows the same correct pattern as ProcessMessageSigSharesInv.


420-469: LGTM - Correct handling with both reference and pointer access.

The code properly dereferences the optional with *sessionInfo on line 421 to pass by const reference, and uses the -> operator for member access throughout. All usage is safe within the if-block scope.


906-925: LGTM - Proper optional value checks and dereferencing.

The code consistently checks has_value() before dereferencing prevMsgHashOpt with either * or -> operators. The ternary expressions on lines 921 and 924 safely handle both the present and absent cases.


1362-1366: LGTM - Clean delegation with appropriate locking.

The manager method correctly delegates to the node state method while holding the appropriate lock, and returns the optional directly.

src/instantsend/signing.cpp (1)

302-305: Optional-based conflict check looks correct. The migration cleanly guards the dereference before logging, matching the new std::optional API from CSigningManager::GetVoteForId.

src/Makefile.am (1)

270-274: Header export update acknowledged. Including llmq/dkgtypes.h in the public set keeps the build in sync with the type relocation done in this refactor.

src/masternode/node.h (1)

14-87: Return-type refactor looks good. Switching GetLocalAddress to std::optional keeps the locking contract intact and aligns with the new call sites.

src/rpc/quorums.cpp (1)

735-741: Recovered-sig lookup handled safely. The std::optional flow preserves the previous error handling without risking invalid access.

src/llmq/blockprocessor.cpp (1)

723-731: Optional return enables clearer callers. Returning std::optional here keeps locking semantics the same while avoiding mutable out parameters.

src/llmq/dkgsession.h (1)

9-10: Include adjustment is appropriate. Pulling in llmq/dkgtypes.h pairs with the new location of the DKG message types referenced later in this header.

src/chainlock/chainlock.h (1)

25-25: Include for std::optional looks good.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c824b62 and 91c0950.

📒 Files selected for processing (1)
  • src/llmq/signing_shares.cpp (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.{cpp,h,cc,cxx,hpp}

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.{cpp,h,cc,cxx,hpp}: Dash Core C++ codebase must be written in C++20 and require at least Clang 16 or GCC 11.1
Dash uses unordered_lru_cache for efficient caching with LRU eviction

Files:

  • src/llmq/signing_shares.cpp
🧠 Learnings (1)
📓 Common learnings
Learnt from: kwvg
Repo: dashpay/dash PR: 6543
File: src/wallet/receive.cpp:240-251
Timestamp: 2025-02-06T14:34:30.466Z
Learning: Pull request #6543 is focused on move-only changes and refactoring, specifically backporting from Bitcoin. Behavior changes should be proposed in separate PRs.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/wallet/wallet.cpp:0-0
Timestamp: 2025-07-29T14:33:01.040Z
Learning: In refactoring PRs like #6761, kwvg acknowledges code safety improvements (like null pointer checks and unused parameter warnings) but prefers to defer them to follow-up PRs to maintain focus on the primary refactoring objectives, avoiding scope creep.
Learnt from: kwvg
Repo: dashpay/dash PR: 6718
File: test/functional/test_framework/test_framework.py:2102-2102
Timestamp: 2025-06-09T16:43:20.996Z
Learning: In the test framework consolidation PR (#6718), user kwvg prefers to limit functional changes to those directly related to MasternodeInfo, avoiding scope creep even for minor improvements like error handling consistency.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.cpp:247-250
Timestamp: 2025-07-29T14:32:48.369Z
Learning: In PR #6761, kwvg acknowledged a null pointer check issue in ChainLockSigner::Cleanup() method but deferred it to follow-up, consistent with the pattern of avoiding scope creep in refactoring PRs.
🪛 GitHub Actions: Clang Diff Format Check
src/llmq/signing_shares.cpp

[error] 368-368: Clang-format differences detected in formatting of the log message. Run clang-format (or the project's clang-format-diff workflow) to apply formatting changes. Command: git diff -U0 origin/develop -- $(git ls-files -- $(cat test/util/data/non-backported.txt)) | ./contrib/devtools/clang-format-diff.py -p1 > diff_output.txt


[error] 450-451: Clang-format differences detected in the log message formatting. Run clang-format (or the project's clang-format-diff workflow) to apply formatting changes. Command: git diff -U0 origin/develop -- $(git ls-files -- $(cat test/util/data/non-backported.txt)) | ./contrib/devtools/clang-format-diff.py -p1 > diff_output.txt

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: mac-build / Build source
  • GitHub Check: linux64_tsan-build / Build source
  • GitHub Check: win64-build / Build source
  • GitHub Check: linux64_ubsan-build / Build source
  • GitHub Check: linux64_fuzz-build / Build source
  • GitHub Check: linux64_sqlite-build / Build source
  • GitHub Check: linux64-build / Build source
  • GitHub Check: arm-linux-build / Build source
  • GitHub Check: linux64_nowallet-build / Build source
  • GitHub Check: Lint / Run linters
🔇 Additional comments (5)
src/llmq/signing_shares.cpp (5)

155-169: LGTM! Clean refactoring to std::optional return type.

The function correctly returns std::nullopt when the session is not found and properly constructs a SessionInfo value when found. This eliminates the bool + out-parameter pattern and aligns with modern C++20 practices.


355-387: LGTM! Safe optional consumption pattern.

The code correctly uses the if-with-initializer pattern to check and consume the optional. All dereferencing operations (sessionInfo->) are safely within the scope where the optional is guaranteed to have a value. The distinction between SessionInfo (value snapshot) and Session* (mutable reference) is properly maintained.


391-415: LGTM! Consistent optional handling.

The function follows the same safe pattern as ProcessMessageSigSharesInv, correctly checking and consuming the optional return value. All accesses are guarded by the optional check.


906-927: LGTM! Safe optional handling with proper guard checks.

The code correctly handles the optional returned by db.GetVoteForId():

  • Line 907 uses short-circuit evaluation to safely check and dereference
  • Lines 911 and 916 dereference within the if block where the value is guaranteed
  • Lines 921 and 924 use explicit has_value() checks in ternary expressions

All optional accesses are properly guarded.


1362-1366: LGTM! Clean forwarding function.

The function correctly forwards the optional return value from the node state's GetSessionInfoByRecvId method.

Comment on lines 368 to 374
if (!sessionInfo->quorum->HasVerificationVector()) {
// TODO we should allow to ask other nodes for the quorum vvec if we missed it in the DKG
LogPrint(BCLog::LLMQ_SIGS, /* Continued */
"CSigSharesManager::%s -- we don't have the quorum vvec for %s, not requesting sig shares. node=%d\n",
__func__, sessionInfo->quorumHash.ToString(), pfrom.GetId());
return true;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix clang-format differences in log message.

The pipeline reports clang-format differences on line 370 (the LogPrint call). Please run clang-format to resolve these formatting issues.

Run the following to fix formatting:

#!/bin/bash
# Run clang-format on the file
git diff -U0 origin/develop -- src/llmq/signing_shares.cpp | ./contrib/devtools/clang-format-diff.py -p1
🧰 Tools
🪛 GitHub Actions: Clang Diff Format Check

[error] 368-368: Clang-format differences detected in formatting of the log message. Run clang-format (or the project's clang-format-diff workflow) to apply formatting changes. Command: git diff -U0 origin/develop -- $(git ls-files -- $(cat test/util/data/non-backported.txt)) | ./contrib/devtools/clang-format-diff.py -p1 > diff_output.txt

🤖 Prompt for AI Agents
In src/llmq/signing_shares.cpp around lines 368 to 374, the LogPrint call on
line 370 has clang-format style differences; fix by reformatting that LogPrint
invocation to match project style (wrap arguments/line breaks as clang-format
expects) and then run the provided clang-format-diff script to apply the
formatting changes: git diff -U0 origin/develop -- src/llmq/signing_shares.cpp |
./contrib/devtools/clang-format-diff.py -p1. Ensure no functional changes are
made, only whitespace/line-break adjustments so the file passes the CI
clang-format check.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91c0950 and 41b9579.

📒 Files selected for processing (1)
  • src/llmq/dkgtypes.h (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.{cpp,h,cc,cxx,hpp}

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.{cpp,h,cc,cxx,hpp}: Dash Core C++ codebase must be written in C++20 and require at least Clang 16 or GCC 11.1
Dash uses unordered_lru_cache for efficient caching with LRU eviction

Files:

  • src/llmq/dkgtypes.h
🧠 Learnings (1)
📓 Common learnings
Learnt from: kwvg
Repo: dashpay/dash PR: 6543
File: src/wallet/receive.cpp:240-251
Timestamp: 2025-02-06T14:34:30.466Z
Learning: Pull request #6543 is focused on move-only changes and refactoring, specifically backporting from Bitcoin. Behavior changes should be proposed in separate PRs.
Learnt from: kwvg
Repo: dashpay/dash PR: 6718
File: test/functional/test_framework/test_framework.py:2102-2102
Timestamp: 2025-06-09T16:43:20.996Z
Learning: In the test framework consolidation PR (#6718), user kwvg prefers to limit functional changes to those directly related to MasternodeInfo, avoiding scope creep even for minor improvements like error handling consistency.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/wallet/wallet.cpp:0-0
Timestamp: 2025-07-29T14:33:01.040Z
Learning: In refactoring PRs like #6761, kwvg acknowledges code safety improvements (like null pointer checks and unused parameter warnings) but prefers to defer them to follow-up PRs to maintain focus on the primary refactoring objectives, avoiding scope creep.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.cpp:247-250
Timestamp: 2025-07-29T14:32:48.369Z
Learning: In PR #6761, kwvg acknowledged a null pointer check issue in ChainLockSigner::Cleanup() method but deferred it to follow-up, consistent with the pattern of avoiding scope creep in refactoring PRs.
🧬 Code graph analysis (1)
src/llmq/dkgtypes.h (2)
src/bls/bls.h (2)
  • CBLSSecretKey (273-277)
  • CBLSSignature (346-349)
src/llmq/signing_shares.h (1)
  • GetSignHash (75-85)
🪛 GitHub Actions: Clang Diff Format Check
src/llmq/dkgtypes.h

[error] 1-1: Clang format differences found in this file. Run clang-format-diff.py to fix formatting.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: linux64_multiprocess-build / Build source
  • GitHub Check: mac-build / Build source
  • GitHub Check: arm-linux-build / Build source
  • GitHub Check: linux64_nowallet-build / Build source
  • GitHub Check: win64-build / Build source
  • GitHub Check: linux64_tsan-build / Build source
  • GitHub Check: linux64-build / Build source
  • GitHub Check: linux64_fuzz-build / Build source
  • GitHub Check: linux64_ubsan-build / Build source
  • GitHub Check: linux64_sqlite-build / Build source
🔇 Additional comments (1)
src/llmq/dkgtypes.h (1)

1-193: Resolve the clang-format check failure.

CI is currently failing with clang-format-diff complaints on this file. Please run the project’s formatting script (e.g. contrib/devtools/clang-format-diff.py) over the touched ranges before re-pushing.

if (!VerifySigSharesInv(sessionInfo.llmqType, inv)) {
return false;
}
if (auto sessionInfo = GetSessionInfoByRecvId(pfrom.GetId(), inv.sessionId)) {
Copy link

Choose a reason for hiding this comment

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

I don't like increasing nested level here tbh. Consider changing this to

auto sessionInfo = GetSessionInfoByRecvId(pfrom.GetId(), inv.sessionId);
if (!sessionInfo) return true;

Same ProcessMessageGetSigShares and ProcessMessageBatchedSigShares.

Copy link
Member Author

Choose a reason for hiding this comment

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

}
session->announced.Merge(inv);
session->knows.Merge(inv);
return true;
Copy link

Choose a reason for hiding this comment

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

this line can be dropped, same for other functions

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand what you mean

@github-actions
Copy link

This pull request has conflicts, please rebase.

#define BITCOIN_LLMQ_DKGSESSION_H

#include <llmq/commitment.h>
#include <llmq/dkgtypes.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can probably drop

#include <bls/bls_ies.h>

and something else once dkgtypes.h is split

@coderabbitai, validate list of included headers for this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

@coderabbitai please review this comment

Copy link

Choose a reason for hiding this comment

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# Check what symbols are used from each include in dkgsession.h
echo "=== Analyzing includes in src/llmq/dkgsession.h ==="
echo

# Check for bls_ies.h usage
echo "1. Checking bls/bls_ies.h usage:"
rg -n "CBLS.*IES|IES.*Recipient" src/llmq/dkgsession.h

echo
echo "2. Checking util/underlying.h usage (ToUnderlying):"
rg -n "ToUnderlying|underlying" src/llmq/dkgsession.h

echo
echo "3. Checking batchedlogger.h usage:"
rg -n "CBatchedLogger" src/llmq/dkgsession.h

echo
echo "4. Checking saltedhasher.h usage:"
rg -n "Salted|Uint256HashSet" src/llmq/dkgsession.h

echo
echo "5. Checking what dkgtypes.h defines:"
cat src/llmq/dkgtypes.h | head -50

echo
echo "6. Checking if any types from dkgtypes.h are forward-declarable:"
rg -n "CDKG(Contribution|Complaint|Justification|PrematureCommitment)" src/llmq/dkgsession.h

echo
echo "7. Check includes in dkgtypes.h:"
rg "^#include" src/llmq/dkgtypes.h

Length of output: 3176


@PastaPastaPasta, @knst is correct! After analyzing the includes in src/llmq/dkgsession.h, I can confirm that the following includes are now redundant and can be removed:

  1. #include <bls/bls_ies.h> - This can be dropped because:

    • It's used for CBLSIESMultiRecipientObjects<CBLSSecretKey> (line 144)
    • However, dkgtypes.h already includes bls/bls_ies.h
    • The type will be available transitively through dkgtypes.h
  2. #include <util/underlying.h> - This can be dropped because:

    • It's not directly used anywhere in dkgsession.h
    • dkgtypes.h already includes it
    • If needed in the future, it's available transitively

Current necessary includes:

  • llmq/commitment.h - used for CFinalCommitment
  • llmq/dkgtypes.h - provides CDKGContribution, CDKGComplaint, CDKGJustification, CDKGPrematureCommitment (stored as full objects in std::map members, can't be forward-declared)
  • batchedlogger.h - base class for CDKGLogger
  • bls/bls.h - BLS types (CBLSId, CBLSSecretKey, BLSVerificationVectorPtr, etc.)
  • bls/bls_worker.h - CBLSWorker& member
  • evo/types.h - CDeterministicMN types
  • saltedhasher.h - Uint256HashSet type
  • sync.h - Mutex, GUARDED_BY
  • optional - std::optional usage
  • unordered_set - std::unordered_set

Would you like me to create an issue to track the removal of these redundant includes?


🧬 Code Graph Analysis Results
  • File: src/llmq/dkgsessionmgr.h

    • Snippet (32-61)
    • Content: Contributions cache key/entry types and their usage:
      • ContributionsCacheKey (llmqType, quorumHash, proTxHash) with operator<
      • ContributionsCacheEntry (entryTime, vvec, skContribution)
      • Contributes a thread-safe cache for verified contributions and SK contributions, guarded by contributionsCacheCs
    • Rationale: Helps understand how CDKGSessionManager caches verified contributions and SK shares for DKG sessions.
  • File: src/llmq/dkgsessionhandler.h

    • Snippet (65-208)
    • Content: CDKGPendingMessages class
      • Manages per-node pending messages (contributions, complaints, justifications, premature commitments)
      • Synchronization via cs_messages
      • Methods to PushPendingMessage, PopPendingMessages, HasSeen, Misbehaving, Clear
      • Template helper to PushPendingMessage and to PopAndDeserializeMessages
    • Rationale: Explains how a quorum session queues and processes batched DKG messages before full verification.
  • File: src/llmq/dkgsession.h

    • Snippet (not a separate file; reference for context)
    • Content: CDKGLogger forward usage
    • Rationale: Provides context for how logging is associated with a CDKGSession instance.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::CDKGSession constructor) - Line ~70-88
    • Content: CDKGSession constructor initializes DKG session with parameters, blsWorker, managers, and session state
    • Rationale: Shows how a DKG session is instantiated, which informs how the rest of the session lifecycle is expected to operate.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::Contribute) - Line ~157-178
    • Content: Generating contributions via blsWorker and preparing to send
    • Rationale: Core step of Phase 1; helps understand how local contributions are created.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::SendContributions) - Line ~180-230
    • Content: Building, encrypting, signing and sending own contributions
    • Rationale: Critical for understanding how a member’s contribution is prepared and distributed.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::PreVerifyMessage for CDKGContribution) - Line ~233-277
    • Content: Validation logic for incoming contributions (quorum hash, member validation, vector lengths, verification)
    • Rationale: Key for understanding pre-verification checks before deeper processing.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::ReceiveMessage for CDKGContribution) - Line ~280-360
    • Content: Handling of received contributions, decryption path, verification queuing, and relay logic
    • Rationale: Details on how contributions are accepted, decrypted, and propagated.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::PreVerifyMessage for CDKGComplaint) - Line ~550-590
    • Content: Validation logic for complaints (quorum hash, member validity, bad/complaint counts)
    • Rationale: Clarifies pre-verification rules for complaints.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::ReceiveMessage for CDKGComplaint) - Line ~592-651
    • Content: Handling of received complaints, relay, and member state updates
    • Rationale: Explains how complaints are recorded and relayed.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::PreVerifyMessage for CDKGJustification) - Line ~744-800
    • Content: Validation logic for justifications (quorum hash, member, contributions, and counts)
    • Rationale: Details pre-verification for justifications.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::ReceiveMessage for CDKGJustification) - Line ~802-892
    • Content: Handling of justified shares, verification of contributions, and updating state
    • Rationale: Explains how justifications are processed and how SK contributions are integrated.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::ReceiveMessage for CDKGPrematureCommitment) - Line ~1113-1188
    • Content: Premature commitment handling, vector verification, and relay logic
    • Rationale: Clarifies how premature commitments are validated and relayed.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::ReceiveMessage for CDKGPrematureCommitment) - Line ~1113-1113
    • Content: Specific entry point for premature commitment receive
    • Rationale: Quick anchor for premature commitment handling.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::FinalizeCommitments) - Line ~1190-1297
    • Content: Aggregation of valid premature commitments into final quorums
    • Rationale: Central to producing final commitments.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::FinalizeSingleCommitment) - Line ~1299-1355
    • Content: Single-node quorum finalization path
    • Rationale: Explains fallback/single-member signing scenario.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::MarkBadMember) - Line ~1366-1366
    • Content: Marking a member as bad and logging status
    • Rationale: Important for understanding how misbehaving members are tracked.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::GetMember) - Line ~1357-1357
    • Content: Lookup member by proTxHash
    • Rationale: Member lookup utility used throughout processing.
  • File: src/llmq/dkgsession.cpp

    • Snippet (CDKGSession::ShouldSimulateError) - Line ~53-60
    • Content: Determines whether to simulate DKG errors for test quorums
    • Rationale: Relevant for tests and understanding error injection
  • File: src/llmq/dkgsession.cpp

    • Snippet (SetSimulatedDKGErrorRate / GetSimulatedErrorRate) - Lines 41-51 and 47-47
    • Content: Global helpers to configure/get simulated error rates
    • Rationale: Context for how error rates are controlled in tests
  • File: src/llmq/signing_shares.h (contextual; not from dkgsession.h)

    • Snippet (CBatchedSigShares and SigShareMap usage)
    • Content: Structures used for batched signature shares
    • Rationale: Helpful for understanding how sigShares are aggregated in DKG flows
  • File: src/llmq/params.h (contextual)

    • Snippet (LLMQParams basics and available_llmqs)
    • Content: Definitions of LLMQ types, parameters, and rotation behavior
    • Rationale: Provides context for how DKG sessions are configured; relevant to interpretation of CDKGSession behavior

Note: If you want, I can extract and present any of these snippets in full from the provided references, or tailor a focused subset to a specific area of interest (e.g., contribution flow, verification flow, or finalization).


🧠 Learnings used
Learnt from: kwvg
Repo: dashpay/dash PR: 6543
File: src/wallet/receive.cpp:240-251
Timestamp: 2025-02-06T14:34:30.466Z
Learning: Pull request #6543 is focused on move-only changes and refactoring, specifically backporting from Bitcoin. Behavior changes should be proposed in separate PRs.

Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/wallet/wallet.cpp:0-0
Timestamp: 2025-07-29T14:33:01.040Z
Learning: In refactoring PRs like #6761, kwvg acknowledges code safety improvements (like null pointer checks and unused parameter warnings) but prefers to defer them to follow-up PRs to maintain focus on the primary refactoring objectives, avoiding scope creep.

Learnt from: kwvg
Repo: dashpay/dash PR: 6718
File: test/functional/test_framework/test_framework.py:2102-2102
Timestamp: 2025-06-09T16:43:20.996Z
Learning: In the test framework consolidation PR (#6718), user kwvg prefers to limit functional changes to those directly related to MasternodeInfo, avoiding scope creep even for minor improvements like error handling consistency.

#include <bls/bls.h>
#include <bls/bls_worker.h>
#include <llmq/dkgsessionhandler.h>
#include <llmq/dkgtypes.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include <llmq/dkgtypes.h>

Same here; forward declaration is enough for references and return's type

Comment on lines 8 to 15
#include <bls/bls.h>
#include <bls/bls_ies.h>
#include <consensus/params.h>
#include <hash.h>
#include <serialize.h>
#include <util/underlying.h>

#include <llmq/commitment.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include <bls/bls.h>
#include <bls/bls_ies.h>
#include <consensus/params.h>
#include <hash.h>
#include <serialize.h>
#include <util/underlying.h>
#include <llmq/commitment.h>
#include <bls/bls.h>
#include <bls/bls_ies.h>
#include <consensus/params.h>
#include <hash.h>
#include <llmq/commitment.h>
#include <serialize.h>
#include <util/underlying.h>

} // namespace llmq

#endif // BITCOIN_LLMQ_DKGTYPES_H

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: duplicated \n\n at the end

if (!VerifySigSharesInv(sessionInfo.llmqType, inv)) {
return false;
}
if (auto sessionInfo = GetSessionInfoByRecvId(pfrom.GetId(), inv.sessionId)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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


llmq::CRecoveredSig recSig;
if (!llmq_ctx.sigman->GetRecoveredSigForId(llmqType, id, recSig)) {
auto recSigOpt = llmq_ctx.sigman->GetRecoveredSigForId(llmqType, id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: could be const auto

@github-actions
Copy link

This pull request has conflicts, please rebase.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/llmq/dkgtypes.h (1)

23-72: Consider removing redundant access specifier.

Line 32 has a duplicate public: label (the class members are already public from line 25). While not incorrect, removing it improves readability.

Apply this diff to remove the redundant label:

     CBLSSignature sig;
-public:
     template<typename Stream>
     inline void SerializeWithoutSig(Stream& s) const

Note: This same pattern appears in the other three classes in this file.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1924476 and 5d6c64c.

📒 Files selected for processing (1)
  • src/llmq/dkgtypes.h (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: kwvg
Repo: dashpay/dash PR: 6543
File: src/wallet/receive.cpp:240-251
Timestamp: 2025-02-06T14:34:30.466Z
Learning: Pull request #6543 is focused on move-only changes and refactoring, specifically backporting from Bitcoin. Behavior changes should be proposed in separate PRs.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/wallet/wallet.cpp:0-0
Timestamp: 2025-07-29T14:33:01.040Z
Learning: In refactoring PRs like #6761, kwvg acknowledges code safety improvements (like null pointer checks and unused parameter warnings) but prefers to defer them to follow-up PRs to maintain focus on the primary refactoring objectives, avoiding scope creep.
Learnt from: kwvg
Repo: dashpay/dash PR: 6718
File: test/functional/test_framework/test_framework.py:2102-2102
Timestamp: 2025-06-09T16:43:20.996Z
Learning: In the test framework consolidation PR (#6718), user kwvg prefers to limit functional changes to those directly related to MasternodeInfo, avoiding scope creep even for minor improvements like error handling consistency.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.cpp:247-250
Timestamp: 2025-07-29T14:32:48.369Z
Learning: In PR #6761, kwvg acknowledged a null pointer check issue in ChainLockSigner::Cleanup() method but deferred it to follow-up, consistent with the pattern of avoiding scope creep in refactoring PRs.
🧬 Code graph analysis (1)
src/llmq/dkgtypes.h (3)
src/bls/bls.h (2)
  • CBLSSecretKey (273-277)
  • CBLSSignature (346-349)
test/functional/test_framework/messages.py (1)
  • CBLSPublicKey (1577-1589)
src/llmq/signing_shares.h (1)
  • GetSignHash (75-85)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: arm-linux-gnueabihf / Build depends
  • GitHub Check: Lint / Run linters
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: x86_64-w64-mingw32 / Build depends
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
🔇 Additional comments (1)
src/llmq/dkgtypes.h (1)

1-21: LGTM! Header structure and includes are correct.

The file properly includes all necessary headers, including <memory> for std::shared_ptr usage (addressing the previous critical issue). The header guard and namespace declarations follow conventions.

PastaPastaPasta and others added 9 commits November 19, 2025 09:06
…e methods

Updated methods in the CRecoveredSigsDb and CSigningManager classes to return std::optional types instead of using output parameters. This change simplifies error handling and improves code readability. Adjusted related logic in net_processing, signing, and RPC layers to accommodate the new return types.
…trieval

Refactored several methods in the DKG session and block processor classes to return std::optional types instead of using output parameters. This change enhances error handling and code clarity. Adjusted related logic in net processing and chain lock handling to accommodate the new return types.
Updated methods in CSigSharesNodeState and CSigSharesManager to return std::optional types instead of using output parameters for session information retrieval. This refactor enhances error handling and improves code clarity, aligning with recent changes in the codebase.
Updated the logging statement in CSigSharesManager to enhance readability by continuing the format string on a new line. This change maintains the existing logging functionality while improving code clarity.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/llmq/signing_shares.cpp (3)

355-377: Consider simplifying the early return per past review feedback.

The optional handling is correct—the code checks for presence before dereferencing and all subsequent uses of sessionInfo-> are safe. However, the early return could be simplified to a one-liner to match the style suggestion from past reviews.

Consider applying this diff to simplify the early return:

     auto sessionInfo = GetSessionInfoByRecvId(pfrom.GetId(), inv.sessionId);
-    if (!sessionInfo) {
-        return true;
-    }
+    if (!sessionInfo) return true;

Based on learnings


393-418: LGTM! Consider simplifying the early return.

The optional handling is correct. Same style note as the previous function: the early return could be simplified to a one-liner.

Consider applying this diff:

     auto sessionInfo = GetSessionInfoByRecvId(pfrom.GetId(), inv.sessionId);
-    if (!sessionInfo) {
-        return true;
-    }
+    if (!sessionInfo) return true;

Based on learnings


423-474: LGTM! Consider simplifying the early return.

The refactoring is correct. The optional is safely checked before dereferencing, and the value is properly passed to PreVerifyBatchedSigShares and RebuildSigShare. Same style note applies here.

Consider applying this diff:

     auto sessionInfo = GetSessionInfoByRecvId(pfrom.GetId(), batchedSigShares.sessionId);
-    if (!sessionInfo) {
-        return true;
-    }
+    if (!sessionInfo) return true;

Based on learnings

src/llmq/dkgtypes.h (1)

8-187: New DKG type header looks like a straight extraction of existing behavior

The four DKG structs (contribution, complaint, justification, premature commitment) are defined with the expected fields, serialization, and GetSignHash logic (including zeroed sigs and BuildCommitmentHash usage), and the header pulls in the right BLS/consensus/serialization dependencies. This aligns with the intent to centralize DKG types without altering their wire format or semantics.

If you ever touch this again, a small, non-blocking improvement would be to document or assert the invariant that CDKGContribution::vvec and contributions are non-null before use, just to make the assumptions explicit; no need to change that in this refactor.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d6c64c and 5b7c51e.

📒 Files selected for processing (22)
  • src/Makefile.am (1 hunks)
  • src/chainlock/chainlock.cpp (1 hunks)
  • src/chainlock/chainlock.h (2 hunks)
  • src/instantsend/instantsend.cpp (2 hunks)
  • src/instantsend/instantsend.h (2 hunks)
  • src/instantsend/signing.cpp (1 hunks)
  • src/llmq/blockprocessor.cpp (1 hunks)
  • src/llmq/blockprocessor.h (1 hunks)
  • src/llmq/dkgsession.h (1 hunks)
  • src/llmq/dkgsessionhandler.cpp (1 hunks)
  • src/llmq/dkgsessionhandler.h (2 hunks)
  • src/llmq/dkgsessionmgr.cpp (1 hunks)
  • src/llmq/dkgsessionmgr.h (2 hunks)
  • src/llmq/dkgtypes.h (1 hunks)
  • src/llmq/signing.cpp (8 hunks)
  • src/llmq/signing.h (4 hunks)
  • src/llmq/signing_shares.cpp (8 hunks)
  • src/llmq/signing_shares.h (2 hunks)
  • src/masternode/node.cpp (3 hunks)
  • src/masternode/node.h (2 hunks)
  • src/net_processing.cpp (1 hunks)
  • src/rpc/quorums.cpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/Makefile.am
  • src/llmq/dkgsessionmgr.h
  • src/rpc/quorums.cpp
  • src/instantsend/instantsend.h
  • src/masternode/node.h
  • src/llmq/dkgsessionmgr.cpp
🧰 Additional context used
🧠 Learnings (16)
📓 Common learnings
Learnt from: kwvg
Repo: dashpay/dash PR: 6543
File: src/wallet/receive.cpp:240-251
Timestamp: 2025-02-06T14:34:30.466Z
Learning: Pull request #6543 is focused on move-only changes and refactoring, specifically backporting from Bitcoin. Behavior changes should be proposed in separate PRs.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/wallet/wallet.cpp:0-0
Timestamp: 2025-07-29T14:33:01.040Z
Learning: In refactoring PRs like #6761, kwvg acknowledges code safety improvements (like null pointer checks and unused parameter warnings) but prefers to defer them to follow-up PRs to maintain focus on the primary refactoring objectives, avoiding scope creep.
Learnt from: kwvg
Repo: dashpay/dash PR: 6718
File: test/functional/test_framework/test_framework.py:2102-2102
Timestamp: 2025-06-09T16:43:20.996Z
Learning: In the test framework consolidation PR (#6718), user kwvg prefers to limit functional changes to those directly related to MasternodeInfo, avoiding scope creep even for minor improvements like error handling consistency.
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.cpp:247-250
Timestamp: 2025-07-29T14:32:48.369Z
Learning: In PR #6761, kwvg acknowledged a null pointer check issue in ChainLockSigner::Cleanup() method but deferred it to follow-up, consistent with the pattern of avoiding scope creep in refactoring PRs.
📚 Learning: 2025-07-29T14:33:01.040Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/wallet/wallet.cpp:0-0
Timestamp: 2025-07-29T14:33:01.040Z
Learning: In refactoring PRs like #6761, kwvg acknowledges code safety improvements (like null pointer checks and unused parameter warnings) but prefers to defer them to follow-up PRs to maintain focus on the primary refactoring objectives, avoiding scope creep.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-06-09T16:43:20.996Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6718
File: test/functional/test_framework/test_framework.py:2102-2102
Timestamp: 2025-06-09T16:43:20.996Z
Learning: In the test framework consolidation PR (#6718), user kwvg prefers to limit functional changes to those directly related to MasternodeInfo, avoiding scope creep even for minor improvements like error handling consistency.

Applied to files:

  • src/llmq/dkgsession.h
  • src/net_processing.cpp
📚 Learning: 2025-11-04T18:24:27.241Z
Learnt from: UdjinM6
Repo: dashpay/dash PR: 6933
File: src/llmq/utils.cpp:284-298
Timestamp: 2025-11-04T18:24:27.241Z
Learning: In consensus-critical code (such as quorum formation, block validation, or deployment activation logic), do not suggest changes to the logic itself even if the implementation appears theoretically incorrect or off-by-one. Consensus rules, once deployed on the Dash network, must be preserved exactly to avoid network forks. Refactoring PRs should maintain perfect behavioral equivalence. Only suggest logic changes if explicitly accompanied by a DIP (Dash Improvement Proposal) or if the maintainer indicates the consensus rule needs to be changed with appropriate activation logic.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-10-05T20:38:28.457Z
Learnt from: knst
Repo: dashpay/dash PR: 6871
File: contrib/guix/libexec/build.sh:358-360
Timestamp: 2025-10-05T20:38:28.457Z
Learning: In the Dash repository, when backporting code from Bitcoin Core, typos and minor issues in comments should be kept as-is to reduce merge conflicts in future backports, even if they remain unfixed in Bitcoin Core's master branch.

Applied to files:

  • src/llmq/dkgsession.h
  • src/llmq/signing_shares.cpp
📚 Learning: 2025-10-13T12:37:12.357Z
Learnt from: knst
Repo: dashpay/dash PR: 6883
File: src/rpc/rawtransaction.cpp:1088-1125
Timestamp: 2025-10-13T12:37:12.357Z
Learning: In backport pull requests (especially from Bitcoin Core), treat "moved" or refactored code as out-of-scope for content-level review. Focus validation on verifying that code is moved correctly: no fields added, no fields removed, no fields reordered, and no unexpected changes beyond whitespace adjustments. Pre-existing issues in the upstream code should be preserved to maintain fidelity to the original implementation.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-07-29T14:32:48.369Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.cpp:247-250
Timestamp: 2025-07-29T14:32:48.369Z
Learning: In PR #6761, kwvg acknowledged a null pointer check issue in ChainLockSigner::Cleanup() method but deferred it to follow-up, consistent with the pattern of avoiding scope creep in refactoring PRs.

Applied to files:

  • src/llmq/dkgsession.h
  • src/chainlock/chainlock.cpp
📚 Learning: 2025-07-23T09:28:32.783Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.cpp:15-250
Timestamp: 2025-07-23T09:28:32.783Z
Learning: In refactoring PRs like #6761, kwvg prefers to defer code formatting fixes to separate follow-up PRs when formatting is not the primary objective, to maintain focus on the structural changes and avoid scope creep.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-08-11T17:16:36.654Z
Learnt from: PastaPastaPasta
Repo: dashpay/dash PR: 6804
File: src/qt/proposalwizard.cpp:40-42
Timestamp: 2025-08-11T17:16:36.654Z
Learning: In the Dash repository, when a PR adds new files that are not from Bitcoin backports, these files must be added to the list in test/util/data/non-backported.txt. This applies to newly created files like qt/proposalwizard.{h,cpp} and forms/proposalwizard.ui. Limited exemptions may exist for subtrees and similar cases.

Applied to files:

  • src/llmq/dkgsession.h
  • src/llmq/signing_shares.cpp
📚 Learning: 2025-10-25T07:08:51.918Z
Learnt from: knst
Repo: dashpay/dash PR: 6916
File: src/univalue/include/univalue.h:81-88
Timestamp: 2025-10-25T07:08:51.918Z
Learning: For backport PRs from bitcoin/bitcoin, bitcoin-core/gui, etc., backported changes should match the original upstream PRs even if they appear strange, modify vendored code, or seem to violate coding guidelines. Still flag genuine issues like bugs, undefined behavior, crashes, compilation errors, or linter failures.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-07-17T15:48:29.418Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6752
File: src/wallet/load.cpp:164-164
Timestamp: 2025-07-17T15:48:29.418Z
Learning: In Dash Core, kwvg prefers using assert() statements to document expected behavior in code paths, especially when the called function also has internal asserts. This is used as a defensive programming pattern rather than requiring conditional error handling.

Applied to files:

  • src/llmq/dkgsession.h
📚 Learning: 2025-02-14T15:15:58.165Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6529
File: src/rpc/governance.cpp:1074-1089
Timestamp: 2025-02-14T15:15:58.165Z
Learning: Code blocks marked with `// clang-format off` and `// clang-format on` directives should be excluded from clang-format suggestions as they are intentionally formatted manually for better readability.

Applied to files:

  • src/llmq/signing_shares.cpp
📚 Learning: 2025-07-09T15:05:36.250Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6729
File: src/rpc/evo.cpp:1273-1273
Timestamp: 2025-07-09T15:05:36.250Z
Learning: When clang-format suggestions significantly harm readability (like splitting logical parameter groups across multiple lines), it's acceptable to use `// clang-format off` and `// clang-format on` directives to exclude the problematic section from automatic formatting, prioritizing code readability over strict line length compliance.

Applied to files:

  • src/llmq/signing_shares.cpp
📚 Learning: 2025-07-23T09:30:34.631Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6761
File: src/chainlock/signing.h:5-6
Timestamp: 2025-07-23T09:30:34.631Z
Learning: Dash Core uses BITCOIN_ prefix for header guards as the standard convention, inherited from Bitcoin Core. Only a few BLS-specific files in src/bls/ use DASH_ prefix. The vast majority of files (385+) use BITCOIN_ prefix.

Applied to files:

  • src/llmq/signing_shares.cpp
📚 Learning: 2025-10-02T18:29:54.756Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6840
File: src/net_processing.cpp:2882-2886
Timestamp: 2025-10-02T18:29:54.756Z
Learning: Across net_processing.cpp, once LLMQContext (m_llmq_ctx) is asserted non-null, its subcomponents (e.g., isman, qdkgsman, quorum_block_processor) are treated as initialized and used without extra null checks.

Applied to files:

  • src/net_processing.cpp
  • src/llmq/dkgsessionhandler.h
📚 Learning: 2025-05-10T00:54:15.597Z
Learnt from: kwvg
Repo: dashpay/dash PR: 6629
File: src/evo/deterministicmns.cpp:473-485
Timestamp: 2025-05-10T00:54:15.597Z
Learning: In the current implementation of `NetInfoEntry`, only `CService` is a valid type and `std::monostate` represents an invalid state. Entries that don't provide a valid `CService` through `GetAddrPort()` should be rejected with an exception, not silently skipped.

Applied to files:

  • src/masternode/node.cpp
🧬 Code graph analysis (10)
src/llmq/blockprocessor.h (1)
src/llmq/blockprocessor.cpp (2)
  • GetMineableCommitmentByHash (723-731)
  • GetMineableCommitmentByHash (723-723)
src/net_processing.cpp (2)
src/instantsend/net_instantsend.cpp (1)
  • inv (190-190)
src/llmq/dkgsession.cpp (4)
  • inv (301-301)
  • inv (609-609)
  • inv (820-820)
  • inv (1175-1175)
src/llmq/signing_shares.h (1)
src/llmq/signing_shares.cpp (4)
  • GetSessionInfoByRecvId (155-169)
  • GetSessionInfoByRecvId (155-155)
  • GetSessionInfoByRecvId (1385-1389)
  • GetSessionInfoByRecvId (1385-1385)
src/llmq/dkgsessionhandler.h (3)
src/llmq/dkgtypes.h (2)
  • CDKGContribution (23-41)
  • CDKGComplaint (86-87)
src/llmq/dkgsessionmgr.cpp (8)
  • GetContribution (206-221)
  • GetContribution (206-206)
  • GetComplaint (223-238)
  • GetComplaint (223-223)
  • GetJustification (240-255)
  • GetJustification (240-240)
  • GetPrematureCommitment (257-272)
  • GetPrematureCommitment (257-257)
src/llmq/dkgsessionhandler.cpp (8)
  • GetContribution (630-638)
  • GetContribution (630-630)
  • GetComplaint (640-648)
  • GetComplaint (640-640)
  • GetJustification (650-658)
  • GetJustification (650-650)
  • GetPrematureCommitment (660-668)
  • GetPrematureCommitment (660-660)
src/masternode/node.cpp (2)
src/net.cpp (2)
  • GetLocalAddress (231-234)
  • GetLocalAddress (231-231)
src/masternode/node.h (1)
  • cs (48-87)
src/chainlock/chainlock.h (2)
src/chainlock/clsig.h (1)
  • chainlock (15-38)
src/chainlock/chainlock.cpp (2)
  • GetChainLockByHash (97-107)
  • GetChainLockByHash (97-97)
src/llmq/dkgsessionhandler.cpp (1)
src/llmq/dkgsessionmgr.cpp (8)
  • GetContribution (206-221)
  • GetContribution (206-206)
  • GetComplaint (223-238)
  • GetComplaint (223-223)
  • GetJustification (240-255)
  • GetJustification (240-240)
  • GetPrematureCommitment (257-272)
  • GetPrematureCommitment (257-257)
src/llmq/signing.h (1)
src/llmq/signing.cpp (14)
  • GetRecoveredSigByHash (118-127)
  • GetRecoveredSigByHash (118-118)
  • GetRecoveredSigById (129-132)
  • GetRecoveredSigById (129-129)
  • GetVoteForId (277-285)
  • GetVoteForId (277-277)
  • GetVoteForId (718-721)
  • GetVoteForId (718-718)
  • ReadRecoveredSig (100-116)
  • ReadRecoveredSig (100-100)
  • GetRecoveredSigForGetData (367-379)
  • GetRecoveredSigForGetData (367-367)
  • GetRecoveredSigForId (697-700)
  • GetRecoveredSigForId (697-697)
src/chainlock/chainlock.cpp (1)
src/chainlock/chainlock.h (2)
  • cs (65-136)
  • cs (66-133)
src/llmq/dkgtypes.h (3)
src/bls/bls.h (2)
  • CBLSSecretKey (273-277)
  • CBLSSignature (346-349)
test/functional/test_framework/messages.py (1)
  • CBLSPublicKey (1577-1589)
src/llmq/signing_shares.h (1)
  • GetSignHash (76-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: linux64_sqlite-build / Build source
  • GitHub Check: linux64_ubsan-build / Build source
  • GitHub Check: linux64-build / Build source
  • GitHub Check: linux64_fuzz-build / Build source
  • GitHub Check: linux64_nowallet-build / Build source
  • GitHub Check: arm-linux-build / Build source
  • GitHub Check: win64-build / Build source
  • GitHub Check: ClangFormat
  • GitHub Check: Lint / Run linters
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
🔇 Additional comments (20)
src/instantsend/signing.cpp (1)

302-309: LGTM! Clean optional-based API refactoring.

The refactoring from bool+out-parameter to std::optional return is correctly implemented. The code properly checks that otherTxHashOpt has a value before dereferencing it on lines 303 and 305.

src/llmq/dkgsession.h (1)

9-9: Include is necessary for value semantics.

The include of llmq/dkgtypes.h is required because the class stores CDKGContribution, CDKGComplaint, CDKGJustification, and CDKGPrematureCommitment by value in member variables (lines 155-158). Forward declarations are insufficient when storing types by value in containers like std::map.

src/llmq/blockprocessor.cpp (1)

723-731: LGTM! Correct optional return implementation.

The refactoring correctly returns std::nullopt when the commitment is not found (line 728) and returns the commitment value directly when found (line 730). This is consistent with the updated method signature in the header.

src/chainlock/chainlock.h (1)

26-26: LGTM! Header changes align with implementation.

The addition of <optional> include and the updated method signature for GetChainLockByHash are consistent with the implementation changes in src/chainlock/chainlock.cpp (lines 97-107).

Also applies to: 95-95

src/chainlock/chainlock.cpp (1)

97-107: LGTM! Clean optional return pattern.

The implementation correctly returns std::nullopt when the requested chain lock hash doesn't match (line 103) and returns the bestChainLock value directly when it does match (line 106). The pattern is consistent with the broader refactoring across the codebase.

src/llmq/blockprocessor.h (1)

76-77: LGTM! Header signature matches implementation.

The updated method signature correctly reflects the implementation in src/llmq/blockprocessor.cpp (lines 723-731), returning std::optional<CFinalCommitment> instead of using a bool return with an out-parameter.

src/llmq/signing_shares.h (1)

348-348: LGTM! Consistent optional return pattern.

Both GetSessionInfoByRecvId methods correctly adopt the optional return pattern, removing the out-parameter approach. The implementations in src/llmq/signing_shares.cpp (lines 154-168 and 1384-1388) correctly return std::nullopt when the session is not found and return the SessionInfo value when found.

Also applies to: 481-482

src/llmq/dkgsessionhandler.h (2)

10-10: Include is necessary for optional return types.

The include of llmq/dkgtypes.h is required because the methods on lines 179-182 return std::optional<CDKGContribution>, std::optional<CDKGComplaint>, etc. by value. Returning std::optional<T> by value requires the complete type definition of T, as std::optional stores the value inline and needs to know its size. Forward declarations are insufficient for this use case.


179-182: LGTM! API refactoring is consistent.

The four method signatures correctly adopt the optional return pattern, replacing the previous bool+out-parameter approach. The implementations in src/llmq/dkgsessionhandler.cpp (lines 629-667) properly return std::nullopt when items are not found and return the values directly when found.

src/masternode/node.cpp (2)

126-131: LGTM! Correct optional handling.

The refactoring correctly handles the optional return value from GetLocalAddress(). The code properly checks for the presence of a value, safely dereferences it when present, and handles the absence case by setting an error state.


218-260: LGTM! Refactoring correctly implemented.

The conversion from bool + out-parameter to std::optional<CService> is correctly implemented. All return paths properly return either std::nullopt on failure or the constructed CService on success. The fallback logic (primary method → loopback → peer iteration) is preserved correctly.

src/llmq/signing_shares.cpp (3)

155-169: LGTM! Refactoring correctly implemented.

The conversion from bool + out-parameter to std::optional<SessionInfo> is correctly implemented. The function returns std::nullopt when the session is not found and returns the populated SessionInfo struct otherwise.


929-948: LGTM! Proper optional handling with ternary operator.

The code correctly handles the optional returned from GetVoteForId. The ternary operators on lines 944 and 947 safely handle both the present and absent cases when logging.


1385-1389: LGTM! Simple wrapper correctly forwards the optional.

The public wrapper correctly forwards to the node state's method and returns the optional result.

src/net_processing.cpp (1)

2886-2940: Optional-based GetData replies for quorum/CL/IS objects look correct and behavior-preserving

Each branch now calls a Get* that returns std::optional<T>, checks it with if (auto opt = ...), and only dereferences inside the if, setting push = true on success. When the optional is empty, control flow still falls through to the existing vNotFound handling, so semantics match the previous bool+out-param pattern, and lifetimes are safe since the value is copied into PushMessage. No changes needed.
Based on learnings

src/llmq/dkgsessionhandler.cpp (1)

630-668: Optional-based DKG getters preserve prior semantics

These four getters cleanly replace the old bool + out-param pattern with std::optional<T>, keep the existing locking (invCs) and lookup logic (including the validCommitments gate), and don’t alter copying behavior vs the previous implementation. Looks good and tightly scoped to the refactor intent.

src/instantsend/instantsend.cpp (1)

620-642: InstantSend lock lookup refactor is behaviorally neutral

Switching GetInstantSendLockByHash to std::optional<InstantSendLock> mirrors the old success/failure semantics (including the “IS disabled” path), keeps the DB + pending-locks lookup order and locking intact, and just replaces the out-parameter copy with a value-return copy. No issues spotted.

src/llmq/signing.h (1)

25-26: Recovered-sig/vote APIs now clearly model absence with std::optional

The header updates (adding <optional> and switching the various Get* methods to return std::optional instead of using out-parameters) are consistent with the implementations in signing.cpp and make the “not found / invalid” case explicit at the type level without changing behavior. This is a good, tightly scoped API improvement.

Also applies to: 139-155, 196-196, 238-242

src/llmq/signing.cpp (2)

26-27: CRecoveredSigsDb optional helpers are a faithful refactor

Using std::optional in ReadRecoveredSig, GetRecoveredSigByHash, GetRecoveredSigById, and GetVoteForId cleanly replaces the prior bool + out-param pattern. Missing keys and deserialization failures both surface as std::nullopt, which matches the old behavior, and RemoveRecoveredSig’s early-return on nullopt preserves the previous “nothing to remove” handling. Cache updates and cleanup paths stay unchanged.

Also applies to: 100-132, 171-178, 277-285


367-379: CSigningManager’s recovered-sig/vote lookups now use optionals consistently

GetRecoveredSigForGetData, ProcessRecoveredSig’s conflict handling, and the public GetRecoveredSigForId/GetVoteForId methods now work with std::optional, but retain the same semantics: only active-quorum sigs are returned for getdata, conflicts are still detected against any existing recovered sig, and callers can now rely on presence checks instead of implicit “success” booleans. The refactor is cohesive and doesn’t introduce behavioral changes.

Also applies to: 612-632, 697-700, 718-721

@github-actions
Copy link

This pull request has conflicts, please 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.

3 participants