llmq|rpc: Avoid some quorum data related copying (#3974)

* llmq|rpc: Return const reference in CQuorum::GetSkShare

* llmq: Refactor BuildQuorumContributions
This commit is contained in:
dustinface 2021-02-01 16:24:51 +01:00 committed by GitHub
parent edc286be46
commit d9105d8de1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 14 deletions

View File

@ -105,7 +105,7 @@ CBLSPublicKey CQuorum::GetPubKeyShare(size_t memberIdx) const
return blsCache.BuildPubKeyShare(m->proTxHash, quorumVvec, CBLSId(m->proTxHash));
}
CBLSSecretKey CQuorum::GetSkShare() const
const CBLSSecretKey& CQuorum::GetSkShare() const
{
return skShare;
}
@ -286,19 +286,17 @@ bool CQuorumManager::BuildQuorumContributions(const CFinalCommitment& fqc, std::
return false;
}
BLSVerificationVectorPtr quorumVvec;
CBLSSecretKey skShare;
cxxtimer::Timer t2(true);
quorumVvec = blsWorker.BuildQuorumVerificationVector(vvecs);
if (quorumVvec == nullptr) {
quorum->quorumVvec = blsWorker.BuildQuorumVerificationVector(vvecs);
if (quorum->quorumVvec == nullptr) {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- failed to build quorumVvec\n", __func__);
// without the quorum vvec, there can't be a skShare, so we fail here. Failure is not fatal here, as it still
// allows to use the quorum as a non-member (verification through the quorum pub key)
return false;
}
skShare = blsWorker.AggregateSecretKeys(skContributions);
if (!skShare.IsValid()) {
quorum->skShare = blsWorker.AggregateSecretKeys(skContributions);
if (!quorum->skShare.IsValid()) {
quorum->skShare.Reset();
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- failed to build skShare\n", __func__);
// We don't bail out here as this is not a fatal error and still allows us to recover public key shares (as we
// have a valid quorum vvec at this point)
@ -307,9 +305,6 @@ bool CQuorumManager::BuildQuorumContributions(const CFinalCommitment& fqc, std::
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- built quorum vvec and skShare. time=%d\n", __func__, t2.count());
quorum->quorumVvec = quorumVvec;
quorum->skShare = skShare;
return true;
}

View File

@ -165,7 +165,7 @@ public:
int GetMemberIndex(const uint256& proTxHash) const;
CBLSPublicKey GetPubKeyShare(size_t memberIdx) const;
CBLSSecretKey GetSkShare() const;
const CBLSSecretKey& GetSkShare() const;
private:
void WriteContributions(CEvoDB& evoDb);

View File

@ -1569,7 +1569,7 @@ CSigShare CSigSharesManager::CreateSigShare(const CQuorumCPtr& quorum, const uin
return {};
}
CBLSSecretKey skShare = quorum->GetSkShare();
const CBLSSecretKey& skShare = quorum->GetSkShare();
if (!skShare.IsValid()) {
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- we don't have our skShare for quorum %s\n", __func__, quorum->qc.quorumHash.ToString());
return {};

View File

@ -111,7 +111,7 @@ UniValue BuildQuorumInfo(const llmq::CQuorumCPtr& quorum, bool includeMembers, b
ret.pushKV("members", membersArr);
}
ret.pushKV("quorumPublicKey", quorum->qc.quorumPublicKey.ToString());
CBLSSecretKey skShare = quorum->GetSkShare();
const CBLSSecretKey& skShare = quorum->GetSkShare();
if (includeSkShare && skShare.IsValid()) {
ret.pushKV("secretKeyShare", skShare.ToString());
}