refactor: HandleNewRecoveredSig return PostProcessingMessage

This commit is contained in:
Konstantin Akimov 2024-09-26 20:01:56 +07:00
parent 09565fe6cc
commit 538342138c
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
10 changed files with 21 additions and 16 deletions

View File

@ -525,10 +525,10 @@ void CChainLocksHandler::EnforceBestChainLock()
uiInterface.NotifyChainLock(clsig->getBlockHash().ToString(), clsig->getHeight()); uiInterface.NotifyChainLock(clsig->getBlockHash().ToString(), clsig->getHeight());
} }
void CChainLocksHandler::HandleNewRecoveredSig(const llmq::CRecoveredSig& recoveredSig) MessageProcessingResult CChainLocksHandler::HandleNewRecoveredSig(const llmq::CRecoveredSig& recoveredSig)
{ {
if (!isEnabled) { if (!isEnabled) {
return; return {};
} }
CChainLockSig clsig; CChainLockSig clsig;
@ -537,17 +537,18 @@ void CChainLocksHandler::HandleNewRecoveredSig(const llmq::CRecoveredSig& recove
if (recoveredSig.getId() != lastSignedRequestId || recoveredSig.getMsgHash() != lastSignedMsgHash) { if (recoveredSig.getId() != lastSignedRequestId || recoveredSig.getMsgHash() != lastSignedMsgHash) {
// this is not what we signed, so lets not create a CLSIG for it // this is not what we signed, so lets not create a CLSIG for it
return; return {};
} }
if (bestChainLock.getHeight() >= lastSignedHeight) { if (bestChainLock.getHeight() >= lastSignedHeight) {
// already got the same or a better CLSIG through the CLSIG message // already got the same or a better CLSIG through the CLSIG message
return; return {};
} }
clsig = CChainLockSig(lastSignedHeight, lastSignedMsgHash, recoveredSig.sig.Get()); clsig = CChainLockSig(lastSignedHeight, lastSignedMsgHash, recoveredSig.sig.Get());
} }
ProcessNewChainLock(-1, clsig, ::SerializeHash(clsig)); ProcessNewChainLock(-1, clsig, ::SerializeHash(clsig));
return {};
} }
bool CChainLocksHandler::HasChainLock(int nHeight, const uint256& blockHash) const bool CChainLocksHandler::HasChainLock(int nHeight, const uint256& blockHash) const

View File

@ -111,7 +111,7 @@ public:
void CheckActiveState() EXCLUSIVE_LOCKS_REQUIRED(!cs); void CheckActiveState() EXCLUSIVE_LOCKS_REQUIRED(!cs);
void TrySignChainTip() EXCLUSIVE_LOCKS_REQUIRED(!cs); void TrySignChainTip() EXCLUSIVE_LOCKS_REQUIRED(!cs);
void EnforceBestChainLock() EXCLUSIVE_LOCKS_REQUIRED(!cs); void EnforceBestChainLock() EXCLUSIVE_LOCKS_REQUIRED(!cs);
void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override EXCLUSIVE_LOCKS_REQUIRED(!cs); [[nodiscard]] MessageProcessingResult HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override EXCLUSIVE_LOCKS_REQUIRED(!cs);
bool HasChainLock(int nHeight, const uint256& blockHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs); bool HasChainLock(int nHeight, const uint256& blockHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
bool HasConflictingChainLock(int nHeight, const uint256& blockHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs); bool HasConflictingChainLock(int nHeight, const uint256& blockHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);

View File

@ -94,7 +94,7 @@ void CEHFSignalsHandler::trySignEHFSignal(int bit, const CBlockIndex* const pind
sigman.AsyncSignIfMember(llmqType, shareman, requestId, msgHash, quorum->qc->quorumHash, false, true); sigman.AsyncSignIfMember(llmqType, shareman, requestId, msgHash, quorum->qc->quorumHash, false, true);
} }
void CEHFSignalsHandler::HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) MessageProcessingResult CEHFSignalsHandler::HandleNewRecoveredSig(const CRecoveredSig& recoveredSig)
{ {
if (g_txindex) { if (g_txindex) {
g_txindex->BlockUntilSyncedToCurrentChain(); g_txindex->BlockUntilSyncedToCurrentChain();
@ -102,7 +102,7 @@ void CEHFSignalsHandler::HandleNewRecoveredSig(const CRecoveredSig& recoveredSig
if (WITH_LOCK(cs, return ids.find(recoveredSig.getId()) == ids.end())) { if (WITH_LOCK(cs, return ids.find(recoveredSig.getId()) == ids.end())) {
// Do nothing, it's not for this handler // Do nothing, it's not for this handler
return; return {};
} }
const auto ehfSignals = mnhfman.GetSignalsStage(WITH_LOCK(cs_main, return chainstate.m_chain.Tip())); const auto ehfSignals = mnhfman.GetSignalsStage(WITH_LOCK(cs_main, return chainstate.m_chain.Tip()));
@ -137,5 +137,6 @@ void CEHFSignalsHandler::HandleNewRecoveredSig(const CRecoveredSig& recoveredSig
} }
break; break;
} }
return {};
} }
} // namespace llmq } // namespace llmq

View File

@ -49,7 +49,8 @@ public:
*/ */
void UpdatedBlockTip(const CBlockIndex* const pindexNew, bool is_masternode) EXCLUSIVE_LOCKS_REQUIRED(!cs); void UpdatedBlockTip(const CBlockIndex* const pindexNew, bool is_masternode) EXCLUSIVE_LOCKS_REQUIRED(!cs);
void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override EXCLUSIVE_LOCKS_REQUIRED(!cs); [[nodiscard]] MessageProcessingResult HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override
EXCLUSIVE_LOCKS_REQUIRED(!cs);
private: private:
void trySignEHFSignal(int bit, const CBlockIndex* const pindex) EXCLUSIVE_LOCKS_REQUIRED(!cs); void trySignEHFSignal(int bit, const CBlockIndex* const pindex) EXCLUSIVE_LOCKS_REQUIRED(!cs);

View File

@ -622,14 +622,14 @@ bool CInstantSendManager::CheckCanLock(const COutPoint& outpoint, bool printDebu
return true; return true;
} }
void CInstantSendManager::HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) MessageProcessingResult CInstantSendManager::HandleNewRecoveredSig(const CRecoveredSig& recoveredSig)
{ {
if (!IsInstantSendEnabled()) { if (!IsInstantSendEnabled()) {
return; return {};
} }
if (Params().GetConsensus().llmqTypeDIP0024InstantSend == Consensus::LLMQType::LLMQ_NONE) { if (Params().GetConsensus().llmqTypeDIP0024InstantSend == Consensus::LLMQType::LLMQ_NONE) {
return; return {};
} }
uint256 txid; uint256 txid;
@ -641,6 +641,7 @@ void CInstantSendManager::HandleNewRecoveredSig(const CRecoveredSig& recoveredSi
} else if (/*isInstantSendLock=*/ WITH_LOCK(cs_creating, return creatingInstantSendLocks.count(recoveredSig.getId()))) { } else if (/*isInstantSendLock=*/ WITH_LOCK(cs_creating, return creatingInstantSendLocks.count(recoveredSig.getId()))) {
HandleNewInstantSendLockRecoveredSig(recoveredSig); HandleNewInstantSendLockRecoveredSig(recoveredSig);
} }
return {};
} }
void CInstantSendManager::HandleNewInputLockRecoveredSig(const CRecoveredSig& recoveredSig, const uint256& txid) void CInstantSendManager::HandleNewInputLockRecoveredSig(const CRecoveredSig& recoveredSig, const uint256& txid)

View File

@ -330,7 +330,7 @@ public:
bool IsWaitingForTx(const uint256& txHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs_pendingLocks); bool IsWaitingForTx(const uint256& txHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs_pendingLocks);
CInstantSendLockPtr GetConflictingLock(const CTransaction& tx) const; CInstantSendLockPtr GetConflictingLock(const CTransaction& tx) const;
void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override [[nodiscard]] MessageProcessingResult HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override
EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_inputReqests, !cs_pendingLocks); EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_inputReqests, !cs_pendingLocks);
PeerMsgRet ProcessMessage(const CNode& pfrom, std::string_view msg_type, CDataStream& vRecv); PeerMsgRet ProcessMessage(const CNode& pfrom, std::string_view msg_type, CDataStream& vRecv);

View File

@ -829,7 +829,7 @@ void CSigningManager::ProcessRecoveredSig(const std::shared_ptr<const CRecovered
auto listeners = WITH_LOCK(cs_listeners, return recoveredSigsListeners); auto listeners = WITH_LOCK(cs_listeners, return recoveredSigsListeners);
for (auto& l : listeners) { for (auto& l : listeners) {
l->HandleNewRecoveredSig(*recoveredSig); Assert(m_peerman)->PostProcessMessage(l->HandleNewRecoveredSig(*recoveredSig));
} }
GetMainSignals().NotifyRecoveredSig(recoveredSig); GetMainSignals().NotifyRecoveredSig(recoveredSig);

View File

@ -154,7 +154,7 @@ class CRecoveredSigsListener
public: public:
virtual ~CRecoveredSigsListener() = default; virtual ~CRecoveredSigsListener() = default;
virtual void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) = 0; [[nodiscard]] virtual MessageProcessingResult HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) = 0;
}; };
class CSigningManager class CSigningManager

View File

@ -1553,10 +1553,11 @@ void CSigSharesManager::ForceReAnnouncement(const CQuorumCPtr& quorum, Consensus
} }
} }
void CSigSharesManager::HandleNewRecoveredSig(const llmq::CRecoveredSig& recoveredSig) MessageProcessingResult CSigSharesManager::HandleNewRecoveredSig(const llmq::CRecoveredSig& recoveredSig)
{ {
LOCK(cs); LOCK(cs);
RemoveSigSharesForSession(recoveredSig.buildSignHash()); RemoveSigSharesForSession(recoveredSig.buildSignHash());
return {};
} }
} // namespace llmq } // namespace llmq

View File

@ -432,7 +432,7 @@ public:
std::optional<CSigShare> CreateSigShare(const CQuorumCPtr& quorum, const uint256& id, const uint256& msgHash) const; std::optional<CSigShare> CreateSigShare(const CQuorumCPtr& quorum, const uint256& id, const uint256& msgHash) const;
void ForceReAnnouncement(const CQuorumCPtr& quorum, Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash); void ForceReAnnouncement(const CQuorumCPtr& quorum, Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash);
void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override; [[nodiscard]] MessageProcessingResult HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override;
static CDeterministicMNCPtr SelectMemberForRecovery(const CQuorumCPtr& quorum, const uint256& id, int attempt); static CDeterministicMNCPtr SelectMemberForRecovery(const CQuorumCPtr& quorum, const uint256& id, int attempt);