diff --git a/src/llmq/blockprocessor.cpp b/src/llmq/blockprocessor.cpp index 7e0246346b..98c827ef6c 100644 --- a/src/llmq/blockprocessor.cpp +++ b/src/llmq/blockprocessor.cpp @@ -138,7 +138,7 @@ PeerMsgRet CQuorumBlockProcessor::ProcessMessage(const CNode& peer, std::string_ LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- received commitment for quorum %s:%d, validMembers=%d, signers=%d, peer=%d\n", __func__, qc.quorumHash.ToString(), ToUnderlying(qc.llmqType), qc.CountValidMembers(), qc.CountSigners(), peer.GetId()); - AddMineableCommitment(qc); + AddMineableCommitmentAndRelay(qc); return {}; } @@ -636,7 +636,7 @@ bool CQuorumBlockProcessor::HasMineableCommitment(const uint256& hash) const return minableCommitments.count(hash) != 0; } -void CQuorumBlockProcessor::AddMineableCommitment(const CFinalCommitment& fqc) +std::optional CQuorumBlockProcessor::AddMineableCommitment(const CFinalCommitment& fqc) { const uint256 commitmentHash = ::SerializeHash(fqc); @@ -662,9 +662,15 @@ void CQuorumBlockProcessor::AddMineableCommitment(const CFinalCommitment& fqc) return false; }(); + return relay ? std::make_optional(commitmentHash) : std::nullopt; +} + +void CQuorumBlockProcessor::AddMineableCommitmentAndRelay(const CFinalCommitment& fqc) +{ + const auto commitmentHashOpt = AddMineableCommitment(fqc); // We only relay the new commitment if it's new or better then the old one - if (relay) { - CInv inv(MSG_QUORUM_FINAL_COMMITMENT, commitmentHash); + if (commitmentHashOpt) { + CInv inv(MSG_QUORUM_FINAL_COMMITMENT, *commitmentHashOpt); Assert(m_peerman)->RelayInv(inv); } } diff --git a/src/llmq/blockprocessor.h b/src/llmq/blockprocessor.h index 8d912b530b..2deeebfd90 100644 --- a/src/llmq/blockprocessor.h +++ b/src/llmq/blockprocessor.h @@ -59,7 +59,7 @@ public: bool ProcessBlock(const CBlock& block, gsl::not_null pindex, BlockValidationState& state, bool fJustCheck, bool fBLSChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main); bool UndoBlock(const CBlock& block, gsl::not_null pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); - void AddMineableCommitment(const CFinalCommitment& fqc); + void AddMineableCommitmentAndRelay(const CFinalCommitment& fqc); bool HasMineableCommitment(const uint256& hash) const; bool GetMineableCommitmentByHash(const uint256& commitmentHash, CFinalCommitment& ret) const; std::optional> GetMineableCommitments(const Consensus::LLMQParams& llmqParams, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); @@ -74,6 +74,8 @@ public: std::vector> GetLastMinedCommitmentsPerQuorumIndexUntilBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex, size_t cycle) const; std::optional GetLastMinedCommitmentsByQuorumIndexUntilBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex, int quorumIndex, size_t cycle) const; private: + //! it returns hash of commitment if it should be relay, otherwise nullopt + std::optional AddMineableCommitment(const CFinalCommitment& fqc); static bool GetCommitmentsFromBlock(const CBlock& block, gsl::not_null pindex, std::multimap& ret, BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main); bool ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, BlockValidationState& state, bool fJustCheck, bool fBLSChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main); static bool IsMiningPhase(const Consensus::LLMQParams& llmqParams, const CChain& active_chain, int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_main); diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index c0a500b1e3..e6f301cfa0 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -570,7 +570,7 @@ void CDKGSessionHandler::HandleDKGRound() auto finalCommitments = curSession->FinalizeCommitments(); for (const auto& fqc : finalCommitments) { - quorumBlockProcessor.AddMineableCommitment(fqc); + quorumBlockProcessor.AddMineableCommitmentAndRelay(fqc); } }