refactor: drop dependency of spork on net_processing#6893
refactor: drop dependency of spork on net_processing#6893PastaPastaPasta merged 1 commit intodashpay:developfrom
Conversation
✅ No Merge Conflicts DetectedThis PR currently has no conflicts with other open PRs. |
Walkthrough
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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. Comment |
There was a problem hiding this comment.
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 f170aed and 95de8a0734ce45d8e9860059900b67e63976637b.
📒 Files selected for processing (4)
src/rpc/node.cpp(2 hunks)src/spork.cpp(1 hunks)src/spork.h(1 hunks)test/lint/lint-circular-dependencies.py(0 hunks)
💤 Files with no reviewable changes (1)
- test/lint/lint-circular-dependencies.py
🧰 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/spork.cppsrc/spork.hsrc/rpc/node.cpp
🔇 Additional comments (3)
src/rpc/node.cpp (2)
22-22: LGTM! Include necessary for refactored relay pattern.The addition of
net_processing.his required to accessPeerManagerandEnsurePeermanfor the updated relay logic insporkupdate.
229-236: LGTM! Relay logic correctly moved to RPC layer.The updated logic properly handles the new API:
- Calls
UpdateSporkwhich returnsstd::optional<CInv>- Retrieves
PeerManageronly when relay is needed- Returns "success" on successful relay,
NullUniValueon failureThis successfully decouples Spork from
PeerManagerby moving network relay concerns to the RPC layer.src/spork.cpp (1)
208-238: LGTM! Refactor successfully removes PeerManager dependency.The implementation correctly:
- Removes
PeerManagerparameter from signature- Returns
std::optional<CInv>for external relay instead ofbool- Returns
std::nullopton signing failure or invalid keyID- Maintains proper locking with
csacquired first, thencs_cache- Creates and returns inventory message for the caller to relay
The nested locking pattern is safe as indicated by the
EXCLUSIVE_LOCKS_REQUIRED(!cs, !cs_cache)annotation.
95de8a0 to
f0a2cec
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
src/spork.h (1)
274-278: Documentation typo persists.The grammatical error flagged in a previous review remains: "It return nullopt" should be "It returns nullopt" or "Returns std::nullopt".
Apply this diff to fix the typo:
/** * UpdateSpork is used by the spork RPC command to set a new spork value, sign * and return the spork message, ready for network relay. - * It returns nullopt if nothing to relay + * It returns std::nullopt if nothing to relay */ std::optional<CInv> UpdateSpork(SporkId nSporkID, SporkValue nValue) EXCLUSIVE_LOCKS_REQUIRED(!cs, !cs_cache);
🧹 Nitpick comments (1)
src/spork.cpp (1)
231-233: Consider using nested scope for cache lock.The
LOCK(cs_cache)on line 231 is held until the function returns. While technically correct due to RAII, this pattern is inconsistent with the rest of the codebase. Compare toProcessSpork(lines 186-190), which uses an explicit scope block.Apply this diff for consistency:
mapSporksActive[nSporkID][*opt_keyIDSigner] = spork; // Clear cached values on new spork being processed -LOCK(cs_cache); -mapSporksCachedActive.erase(spork.nSporkID); -mapSporksCachedValues.erase(spork.nSporkID); - +{ + LOCK(cs_cache); + mapSporksCachedActive.erase(spork.nSporkID); + mapSporksCachedValues.erase(spork.nSporkID); +} CInv inv(MSG_SPORK, spork.GetHash()); return inv;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 95de8a0734ce45d8e9860059900b67e63976637b and f0a2cec.
📒 Files selected for processing (4)
src/rpc/node.cpp(2 hunks)src/spork.cpp(1 hunks)src/spork.h(1 hunks)test/lint/lint-circular-dependencies.py(0 hunks)
💤 Files with no reviewable changes (1)
- test/lint/lint-circular-dependencies.py
🚧 Files skipped from review as they are similar to previous changes (1)
- src/rpc/node.cpp
🧰 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/spork.hsrc/spork.cpp
🔇 Additional comments (1)
src/spork.cpp (1)
208-238: LGTM! Successful removal of PeerManager dependency.The refactoring correctly removes the PeerManager dependency by:
- Eliminating the
peermanparameter- Returning
std::optional<CInv>instead ofbool- Delegating relay responsibility to the caller
The logic is sound with proper early returns on failures and correct spork creation/storage.
Issue being fixed or feature implemented
Dependency of Spork on PeerManager (net_processing) is a blocker for kernel / chainstate project.
What was done?
Removed dependency of Spork on PeerManager by moving network code to rpc/node
How Has This Been Tested?
Run test/lint/lint-circular-dependencies.py
Breaking Changes
N/A
Checklist: