Skip to content

Commit 9f85bd0

Browse files
committed
refactor: migrate CInstantSendManager::ProcessMessage()
1 parent ef4a0bb commit 9f85bd0

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

src/instantsend/instantsend.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,53 +102,52 @@ void CInstantSendManager::Stop()
102102
}
103103
}
104104

105-
PeerMsgRet CInstantSendManager::ProcessMessage(const CNode& pfrom, PeerManager& peerman, std::string_view msg_type,
106-
CDataStream& vRecv)
107-
{
108-
if (IsInstantSendEnabled() && msg_type == NetMsgType::ISDLOCK) {
109-
const auto islock = std::make_shared<instantsend::InstantSendLock>();
110-
vRecv >> *islock;
111-
return ProcessMessageInstantSendLock(pfrom, peerman, islock);
112-
}
113-
return {};
114-
}
115-
116105
bool ShouldReportISLockTiming() {
117106
return g_stats_client->active() || LogAcceptDebug(BCLog::INSTANTSEND);
118107
}
119108

120-
PeerMsgRet CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom, PeerManager& peerman,
121-
const instantsend::InstantSendLockPtr& islock)
109+
MessageProcessingResult CInstantSendManager::ProcessMessage(NodeId from, std::string_view msg_type, CDataStream& vRecv)
122110
{
111+
if (!IsInstantSendEnabled() || msg_type != NetMsgType::ISDLOCK) {
112+
return {};
113+
}
114+
115+
const auto islock = std::make_shared<instantsend::InstantSendLock>();
116+
vRecv >> *islock;
117+
123118
auto hash = ::SerializeHash(*islock);
124119

125-
WITH_LOCK(::cs_main, peerman.EraseObjectRequest(pfrom.GetId(), CInv(MSG_ISDLOCK, hash)));
120+
MessageProcessingResult ret{};
121+
ret.m_to_erase = CInv{MSG_ISDLOCK, hash};
126122

127123
if (!islock->TriviallyValid()) {
128-
return tl::unexpected{100};
124+
ret.m_error = MisbehavingError{100};
125+
return ret;
129126
}
130127

131128
const auto blockIndex = WITH_LOCK(::cs_main, return m_chainstate.m_blockman.LookupBlockIndex(islock->cycleHash));
132129
if (blockIndex == nullptr) {
133130
// Maybe we don't have the block yet or maybe some peer spams invalid values for cycleHash
134-
return tl::unexpected{1};
131+
ret.m_error = MisbehavingError{1};
132+
return ret;
135133
}
136134

137135
// Deterministic islocks MUST use rotation based llmq
138136
auto llmqType = Params().GetConsensus().llmqTypeDIP0024InstantSend;
139137
const auto& llmq_params_opt = Params().GetLLMQ(llmqType);
140138
assert(llmq_params_opt);
141139
if (blockIndex->nHeight % llmq_params_opt->dkgInterval != 0) {
142-
return tl::unexpected{100};
140+
ret.m_error = MisbehavingError{100};
141+
return ret;
143142
}
144143

145144
if (WITH_LOCK(cs_pendingLocks, return pendingInstantSendLocks.count(hash) || pendingNoTxInstantSendLocks.count(hash)) ||
146145
db.KnownInstantSendLock(hash)) {
147-
return {};
146+
return ret;
148147
}
149148

150149
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: received islock, peer=%d\n", __func__,
151-
islock->txid.ToString(), hash.ToString(), pfrom.GetId());
150+
islock->txid.ToString(), hash.ToString(), from);
152151

153152
if (ShouldReportISLockTiming()) {
154153
auto time_diff = [&]() -> int64_t {
@@ -168,8 +167,8 @@ PeerMsgRet CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom
168167
}
169168

170169
LOCK(cs_pendingLocks);
171-
pendingInstantSendLocks.emplace(hash, std::make_pair(pfrom.GetId(), islock));
172-
return {};
170+
pendingInstantSendLocks.emplace(hash, std::make_pair(from, islock));
171+
return ret;
173172
}
174173

175174
bool CInstantSendManager::ProcessPendingInstantSendLocks(PeerManager& peerman)

src/instantsend/instantsend.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class CBlockIndex;
2525
class CChainState;
2626
class CDataStream;
2727
class CMasternodeSync;
28-
class CNode;
2928
class CSporkManager;
3029
class CTxMemPool;
3130
class PeerManager;
@@ -96,7 +95,6 @@ class CInstantSendManager final : public instantsend::InstantSendSignerParent
9695
void InterruptWorkerThread() { workInterrupt(); };
9796

9897
private:
99-
PeerMsgRet ProcessMessageInstantSendLock(const CNode& pfrom, PeerManager& peerman, const instantsend::InstantSendLockPtr& islock);
10098
bool ProcessPendingInstantSendLocks(PeerManager& peerman)
10199
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
102100

@@ -131,7 +129,7 @@ class CInstantSendManager final : public instantsend::InstantSendSignerParent
131129
bool IsWaitingForTx(const uint256& txHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs_pendingLocks);
132130
instantsend::InstantSendLockPtr GetConflictingLock(const CTransaction& tx) const override;
133131

134-
PeerMsgRet ProcessMessage(const CNode& pfrom, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv);
132+
[[nodiscard]] MessageProcessingResult ProcessMessage(NodeId from, std::string_view msg_type, CDataStream& vRecv);
135133

136134
void TransactionAddedToMempool(const CTransactionRef& tx)
137135
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5289,7 +5289,7 @@ void PeerManagerImpl::ProcessMessage(
52895289
return; // CLSIG
52905290
}
52915291

5292-
ProcessPeerMsgRet(m_llmq_ctx->isman->ProcessMessage(pfrom, *this, msg_type, vRecv), pfrom);
5292+
PostProcessMessage(m_llmq_ctx->isman->ProcessMessage(pfrom.GetId(), msg_type, vRecv), pfrom.GetId());
52935293
return;
52945294
}
52955295

0 commit comments

Comments
 (0)