Skip to content

Commit 7460211

Browse files
UdjinM6claude
authored andcommitted
refactor: address review feedback on spork ProcessMessage refactor
- Use __func__ in IsSporkValid log prefixes (was stale "ProcessSpork") - Mark IsSporkValid as const - Pass reason string to Misbehaving on invalid spork Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 7c899a2 commit 7460211

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5470,7 +5470,7 @@ void PeerManagerImpl::ProcessMessage(
54705470
CInv spork_inv{MSG_SPORK, hash};
54715471
WITH_LOCK(::cs_main, EraseObjectRequest(pfrom.GetId(), spork_inv));
54725472
if (!m_sporkman.IsSporkValid(spork)) {
5473-
Misbehaving(pfrom.GetId(), 100);
5473+
Misbehaving(pfrom.GetId(), 100, strprintf("invalid spork received. peer=%d", pfrom.GetId()));
54745474
return;
54755475
}
54765476
if (m_sporkman.ProcessSpork(spork)) {

src/spork.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ void CSporkManager::CheckAndRemove()
123123
}
124124
}
125125

126-
bool CSporkManager::IsSporkValid(const CSporkMessage& spork)
126+
bool CSporkManager::IsSporkValid(const CSporkMessage& spork) const
127127
{
128128
if (spork.nTimeSigned > GetAdjustedTime() + 2 * 60 * 60) {
129-
LogPrint(BCLog::SPORK, "CSporkManager::ProcessSpork -- ERROR: too far into the future\n");
129+
LogPrint(BCLog::SPORK, "CSporkManager::%s -- ERROR: too far into the future\n", __func__);
130130
return false;
131131
}
132132

133133
auto opt_keyIDSigner = spork.GetSignerKeyID();
134134

135135
if (opt_keyIDSigner == std::nullopt || WITH_LOCK(cs, return !setSporkPubKeyIDs.count(*opt_keyIDSigner))) {
136-
LogPrint(BCLog::SPORK, "CSporkManager::ProcessSpork -- ERROR: invalid signature\n");
136+
LogPrint(BCLog::SPORK, "CSporkManager::%s -- ERROR: invalid signature\n", __func__);
137137
return false;
138138
}
139139
return true;

src/spork.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class CSporkManager : public SporkStore
248248
* If these values mismatch function returns false [spork is invalid]
249249
* If spork validation failed, peer should be punished
250250
*/
251-
[[nodiscard]] bool IsSporkValid(const CSporkMessage& spork) EXCLUSIVE_LOCKS_REQUIRED(!cs);
251+
[[nodiscard]] bool IsSporkValid(const CSporkMessage& spork) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
252252
/**
253253
* ProcessSpork is used to handle the 'spork' p2p message.
254254
*

0 commit comments

Comments
 (0)