Skip to content

Commit de0ce4e

Browse files
committed
refactor: extract masternode-mode specific SetSecretKeyShare()
Also: - Drop avoidable `CActiveMasternodeManager&` arg by taking ref of hash we care about
1 parent 201ccfc commit de0ce4e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/llmq/quorums.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ bool CQuorum::SetVerificationVector(const std::vector<CBLSPublicKey>& quorumVecI
9494
return true;
9595
}
9696

97-
bool CQuorum::SetSecretKeyShare(const CBLSSecretKey& secretKeyShare, const CActiveMasternodeManager& mn_activeman)
97+
bool CQuorum::SetSecretKeyShare(const CBLSSecretKey& secretKeyShare, const uint256& protx_hash)
9898
{
99-
if (!secretKeyShare.IsValid() || (secretKeyShare.GetPublicKey() != GetPubKeyShare(GetMemberIndex(mn_activeman.GetProTxHash())))) {
99+
if (!secretKeyShare.IsValid() || (secretKeyShare.GetPublicKey() != GetPubKeyShare(GetMemberIndex(protx_hash)))) {
100100
return false;
101101
}
102102
LOCK(cs_vvec_shShare);
@@ -460,7 +460,7 @@ bool CQuorumManager::BuildQuorumContributions(const CFinalCommitmentPtr& fqc, co
460460
// allows to use the quorum as a non-member (verification through the quorum pub key)
461461
return false;
462462
}
463-
if (!quorum->SetSecretKeyShare(blsWorker.AggregateSecretKeys(skContributions), *m_mn_activeman)) {
463+
if (m_mn_activeman && !SetQuorumSecretKeyShare(*quorum, skContributions)) {
464464
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- failed to build skShare\n", __func__);
465465
// We don't bail out here as this is not a fatal error and still allows us to recover public key shares (as we
466466
// have a valid quorum vvec at this point)
@@ -472,6 +472,12 @@ bool CQuorumManager::BuildQuorumContributions(const CFinalCommitmentPtr& fqc, co
472472
return true;
473473
}
474474

475+
bool CQuorumManager::SetQuorumSecretKeyShare(CQuorum& quorum, Span<CBLSSecretKey> skContributions) const
476+
{
477+
assert(m_mn_activeman);
478+
return quorum.SetSecretKeyShare(blsWorker.AggregateSecretKeys(skContributions), m_mn_activeman->GetProTxHash());
479+
}
480+
475481
bool CQuorumManager::HasQuorum(Consensus::LLMQType llmqType, const CQuorumBlockProcessor& quorum_block_processor, const uint256& quorumHash)
476482
{
477483
return quorum_block_processor.HasMinedCommitment(llmqType, quorumHash);
@@ -758,8 +764,7 @@ MessageProcessingResult CQuorumManager::ProcessContribQDATA(CNode& pfrom, CDataS
758764
}
759765
}
760766

761-
CBLSSecretKey secretKeyShare = blsWorker.AggregateSecretKeys(vecSecretKeys);
762-
if (!quorum.SetSecretKeyShare(secretKeyShare, *m_mn_activeman)) {
767+
if (!quorum.SetSecretKeyShare(blsWorker.AggregateSecretKeys(vecSecretKeys), m_mn_activeman->GetProTxHash())) {
763768
return MisbehavingError{10, "invalid secret key share received"};
764769
}
765770
}

src/llmq/quorums.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class CQuorum
208208
LOCK(cs_vvec_shShare);
209209
quorumVvec = std::move(vvec_in);
210210
}
211-
bool SetSecretKeyShare(const CBLSSecretKey& secretKeyShare, const CActiveMasternodeManager& mn_activeman)
211+
bool SetSecretKeyShare(const CBLSSecretKey& secretKeyShare, const uint256& protx_hash)
212212
EXCLUSIVE_LOCKS_REQUIRED(!cs_vvec_shShare);
213213

214214
bool HasVerificationVector() const EXCLUSIVE_LOCKS_REQUIRED(!cs_vvec_shShare);
@@ -342,6 +342,7 @@ class CQuorumManager
342342
gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex,
343343
bool populate_cache) const EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_map_quorums);
344344
bool BuildQuorumContributions(const CFinalCommitmentPtr& fqc, const std::shared_ptr<CQuorum>& quorum) const;
345+
bool SetQuorumSecretKeyShare(CQuorum& quorum, Span<CBLSSecretKey> skContributions) const;
345346

346347
CQuorumCPtr GetQuorum(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pindex,
347348
bool populate_cache = true) const EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_map_quorums);

0 commit comments

Comments
 (0)