-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: replace RecursiveMutex with Mutex in meta store/info and add thread-safety annotations; avoid re-entrant locking #6868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…add thread-safety annotations (LOCKS_EXCLUDED); avoid re-entrant locking
✅ No Merge Conflicts DetectedThis PR currently has no conflicts with other open PRs. |
WalkthroughAdds EXCLUSIVE_LOCKS_REQUIRED(!cs) annotations to multiple public methods in CMasternodeMetaMan and MasternodeMetaStore across src/masternode/meta.h and src/masternode/meta.cpp. Affected methods include GetMetaInfo, RemoveGovernanceObject, GetAndClearDirtyGovernanceObjectHashes, AlreadyHavePlatformBan, GetPlatformBan, RememberPlatformBan, ToString, and MasternodeMetaStore’s Serialize, Unserialize, and Clear. Also replaces Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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.
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
📒 Files selected for processing (2)
src/masternode/meta.cpp
(3 hunks)src/masternode/meta.h
(6 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/masternode/meta.cpp
src/masternode/meta.h
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/meta.cpp
src/masternode/meta.h
🧬 Code graph analysis (2)
src/masternode/meta.cpp (1)
src/masternode/meta.h (3)
cs
(54-79)cs
(56-56)cs
(137-252)
src/masternode/meta.h (1)
src/masternode/meta.cpp (11)
LOCKS_EXCLUDED
(69-81)LOCKS_EXCLUDED
(118-124)LOCKS_EXCLUDED
(126-131)LOCKS_EXCLUDED
(133-137)LOCKS_EXCLUDED
(139-148)LOCKS_EXCLUDED
(150-154)LOCKS_EXCLUDED
(156-160)GetMetaInfo
(69-69)RemoveGovernanceObject
(62-67)RemoveGovernanceObject
(62-62)RemoveGovernanceObject
(118-118)
🪛 GitHub Actions: Clang Diff Format Check
src/masternode/meta.h
[error] 133-144: Clang-format differences detected between before/after formatting. Run clang-format-diff.py -p1 or clang-format 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). (9)
- 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_tsan-build / Build source
- GitHub Check: mac-build / Build source
- GitHub Check: win64-build / Build source
- GitHub Check: arm-linux-build / Build source
- GitHub Check: linux64_nowallet-build / Build source
🔇 Additional comments (1)
src/masternode/meta.cpp (1)
69-154
: No externalLOCK(cs)
detected around these APIs—safe from deadlock.
for(const auto& p : metaInfos) { | ||
p.second->RemoveGovernanceObject(nGovernanceObjectHash); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run clang-format on this block.
CI flagged the formatting here (for(const …)
); please run clang-format so the spacing matches the project style.
🤖 Prompt for AI Agents
In src/masternode/meta.cpp around lines 121 to 123, the for-loop formatting
doesn't match project style (CI flagged spacing in "for(const auto& p :
metaInfos)"); run clang-format or reformat this block so spacing/indentation
follow the repository's style guide (e.g., add a space after 'for' and align
braces) and commit the formatted changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 41e4324
src/masternode/meta.h
Outdated
} | ||
|
||
std::string ToString() const; | ||
std::string ToString() const LOCKS_EXCLUDED(cs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We switched to using the stronger EXCLUSIVE_LOCKS_REQUIRED(!cs)
(negative capabilities) since dash#6001
…UIRED for various methods in meta store and info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, minor nit
} | ||
|
||
std::optional<PlatformBanMessage> CMasternodeMetaMan::GetPlatformBan(const uint256& inv_hash) const LOCKS_EXCLUDED(cs) | ||
std::optional<PlatformBanMessage> CMasternodeMetaMan::GetPlatformBan(const uint256& inv_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: duplicate annotation, annotation in header is sufficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 191c79c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 191c79c
Issue being fixed or feature implemented
Convert mutex from Recursive to non-recursive
What was done?
Describe your changes in detail
How Has This Been Tested?
Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran
to see how your change affects other areas of the code, etc.
Breaking Changes
Please describe any breaking changes your code introduces
Checklist:
Go over all the following points, and put an
x
in all the boxes that apply.