-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: drop dependency of spork manager on network code #7303
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
Changes from all commits
bd2bff1
7c899a2
7460211
6a4ee52
4e6f844
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,28 +5,23 @@ | |||||||||||||||||||||||||||||||||||||||
| #ifndef BITCOIN_SPORK_H | ||||||||||||||||||||||||||||||||||||||||
| #define BITCOIN_SPORK_H | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #include <msg_result.h> | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #include <hash.h> | ||||||||||||||||||||||||||||||||||||||||
| #include <key.h> | ||||||||||||||||||||||||||||||||||||||||
| #include <net.h> | ||||||||||||||||||||||||||||||||||||||||
| #include <net_types.h> | ||||||||||||||||||||||||||||||||||||||||
| #include <pubkey.h> | ||||||||||||||||||||||||||||||||||||||||
| #include <saltedhasher.h> | ||||||||||||||||||||||||||||||||||||||||
| #include <sync.h> | ||||||||||||||||||||||||||||||||||||||||
| #include <uint256.h> | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #include <array> | ||||||||||||||||||||||||||||||||||||||||
| #include <optional> | ||||||||||||||||||||||||||||||||||||||||
| #include <string_view> | ||||||||||||||||||||||||||||||||||||||||
| #include <unordered_map> | ||||||||||||||||||||||||||||||||||||||||
| #include <vector> | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| class CConnman; | ||||||||||||||||||||||||||||||||||||||||
| template<typename T> | ||||||||||||||||||||||||||||||||||||||||
| class CFlatDB; | ||||||||||||||||||||||||||||||||||||||||
| class CNode; | ||||||||||||||||||||||||||||||||||||||||
| class CDataStream; | ||||||||||||||||||||||||||||||||||||||||
| class uint256; | ||||||||||||||||||||||||||||||||||||||||
| class CInv; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| class CSporkMessage; | ||||||||||||||||||||||||||||||||||||||||
| class CSporkManager; | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -249,26 +244,27 @@ class CSporkManager : public SporkStore | |||||||||||||||||||||||||||||||||||||||
| void CheckAndRemove() EXCLUSIVE_LOCKS_REQUIRED(!cs); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * ProcessMessage is used to call ProcessSpork and ProcessGetSporks. See below | ||||||||||||||||||||||||||||||||||||||||
| * GetValidSporkSigner validates signed time and recovers the signer pubkey. | ||||||||||||||||||||||||||||||||||||||||
| * Returns the signer's CKeyID on success, or std::nullopt if the spork is invalid | ||||||||||||||||||||||||||||||||||||||||
| * (peer should be punished in that case). | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| [[nodiscard]] MessageProcessingResult ProcessMessage(CNode& peer, CConnman& connman, std::string_view msg_type, | ||||||||||||||||||||||||||||||||||||||||
| CDataStream& vRecv) EXCLUSIVE_LOCKS_REQUIRED(!cs_cache); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| [[nodiscard]] std::optional<CKeyID> GetValidSporkSigner(const CSporkMessage& spork) const | ||||||||||||||||||||||||||||||||||||||||
| EXCLUSIVE_LOCKS_REQUIRED(!cs); | ||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * ProcessSpork is used to handle the 'spork' p2p message. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * For 'spork', it validates the spork and adds it to the internal spork storage and | ||||||||||||||||||||||||||||||||||||||||
| * performs any necessary processing. | ||||||||||||||||||||||||||||||||||||||||
| * ProcessSpork adds the spork to local state. Returns true if the spork was new or | ||||||||||||||||||||||||||||||||||||||||
| * updated and should be relayed. `keyIDSigner` must be the signer key previously | ||||||||||||||||||||||||||||||||||||||||
| * recovered via GetValidSporkSigner. `peer_log_suffix` is appended to log lines for | ||||||||||||||||||||||||||||||||||||||||
| * cross-referencing with the source peer (e.g. " peer=42"). | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| [[nodiscard]] MessageProcessingResult ProcessSpork(NodeId from, CDataStream& vRecv) | ||||||||||||||||||||||||||||||||||||||||
| [[nodiscard]] bool ProcessSpork(const CSporkMessage& spork, const CKeyID& keyIDSigner, | ||||||||||||||||||||||||||||||||||||||||
| std::string_view peer_log_suffix = {}) | ||||||||||||||||||||||||||||||||||||||||
| EXCLUSIVE_LOCKS_REQUIRED(!cs, !cs_cache); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
253
to
261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: ProcessSpork() has an undocumented validity precondition after the split The refactor split spork handling into IsSporkValid() and ProcessSpork(), but ProcessSpork() now asserts spork.GetSignerKeyID().has_value() at src/spork.cpp:147 and unconditionally dereferences the optional on the next line. That precondition is only satisfied if IsSporkValid() ran first and returned true. The single current caller in net_processing.cpp does this correctly, but two things make the new API a footgun for future use: (1) the Doxygen comment at src/spork.h:255 still claims "it validates the spork and adds it to the internal spork storage", which is no longer true; (2) since the stated goal of the refactor is to make spork management reusable outside the networking layer, a future caller is likely to copy this pattern incorrectly and either crash in debug builds or throw std::bad_optional_access in release. Either fold the validity check back into ProcessSpork(), update the comment to state the precondition explicitly, or change the signature to take a validated wrapper type so the unsafe call is unrepresentable. source: ['codex'] 🤖 Fix this with AI agents
Comment on lines
253
to
261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: ProcessSpork() doc comment is stale and hides an unsafe precondition The Doxygen comment claims ProcessSpork() "validates the spork and adds it to the internal spork storage," but after the refactor validation (timestamp window + signer-pubkey membership in setSporkPubKeyIDs) lives entirely in IsSporkValid(). ProcessSpork() now only checks 💡 Suggested change
Suggested change
source: ['claude', 'codex'] 🤖 Fix this with AI agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * ProcessGetSporks is used to handle the 'getsporks' p2p message. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * For 'getsporks', it sends active sporks to the requesting peer. | ||||||||||||||||||||||||||||||||||||||||
| * ActiveSporks returns a snapshot of currently active sporks indexed by SporkId then | ||||||||||||||||||||||||||||||||||||||||
| * signer CKeyID. Used by net_processing to answer the 'getsporks' p2p message. | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| void ProcessGetSporks(CNode& peer, CConnman& connman) EXCLUSIVE_LOCKS_REQUIRED(!cs); | ||||||||||||||||||||||||||||||||||||||||
| std::unordered_map<SporkId, std::map<CKeyID, CSporkMessage>> ActiveSporks() const EXCLUSIVE_LOCKS_REQUIRED(!cs); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * UpdateSpork is used by the spork RPC command to set a new spork value, sign | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.