Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dash backport #2947

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "quorums.h"

#include "activemasternode.h"
#include "chain.h"
#include "chainparams.h"
#include "cxxtimer.h"
#include "evo/deterministicmns.h"
Expand Down Expand Up @@ -33,7 +34,7 @@ static uint256 MakeQuorumKey(const CQuorum& q)
{
CHashWriter hw(SER_NETWORK, 0);
hw << (uint8_t)q.params.type;
hw << q.pindexQuorum->GetBlockHash();
hw << q.qc.quorumHash;
for (const auto& dmn : q.members) {
hw << dmn->proTxHash;
}
Expand All @@ -51,13 +52,13 @@ CQuorum::~CQuorum()
}
}

void CQuorum::Init(const uint256& _minedBlockHash, const CBlockIndex* _pindexQuorum, const std::vector<CDeterministicMNCPtr>& _members, const std::vector<bool>& _validMembers, const CBLSPublicKey& _quorumPublicKey)
void CQuorum::Init(const CFinalCommitment& _qc, const CBlockIndex* _pindexQuorum, int _height, const uint256& _minedBlockHash, const std::vector<CDeterministicMNCPtr>& _members)
{
minedBlockHash = _minedBlockHash;
qc = _qc;
height = _height;
pindexQuorum = _pindexQuorum;
members = _members;
validMembers = _validMembers;
quorumPublicKey = _quorumPublicKey;
minedBlockHash = _minedBlockHash;
}

bool CQuorum::IsMember(const uint256& proTxHash) const
Expand All @@ -74,15 +75,15 @@ bool CQuorum::IsValidMember(const uint256& proTxHash) const
{
for (size_t i = 0; i < members.size(); i++) {
if (members[i]->proTxHash == proTxHash) {
return validMembers[i];
return qc.validMembers[i];
}
}
return false;
}

CBLSPublicKey CQuorum::GetPubKeyShare(size_t memberIdx) const
{
if (quorumVvec == nullptr || memberIdx >= members.size() || !validMembers[memberIdx]) {
if (quorumVvec == nullptr || memberIdx >= members.size() || !qc.validMembers[memberIdx]) {
return CBLSPublicKey();
}
auto& m = members[memberIdx];
Expand Down Expand Up @@ -141,17 +142,17 @@ void CQuorum::StartCachePopulatorThread(std::shared_ptr<CQuorum> _this)
}

cxxtimer::Timer t(true);
LogPrintf("CQuorum::StartCachePopulatorThread -- start\n");
LogPrint(BCLog::LLMQ, "CQuorum::StartCachePopulatorThread -- start\n");

// this thread will exit after some time
// when then later some other thread tries to get keys, it will be much faster
_this->cachePopulatorThread = std::thread(&TraceThread<std::function<void()> >, "quorum-cachepop", [_this, t] {
for (size_t i = 0; i < _this->members.size() && !_this->stopCachePopulatorThread && !ShutdownRequested(); i++) {
if (_this->validMembers[i]) {
if (_this->qc.validMembers[i]) {
_this->GetPubKeyShare(i);
}
}
LogPrintf("CQuorum::StartCachePopulatorThread -- done. time=%d\n", t.count());
LogPrint(BCLog::LLMQ, "CQuorum::StartCachePopulatorThread -- done. time=%d\n", t.count());
});
}

Expand All @@ -178,14 +179,13 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial
}
}


bool CQuorumManager::BuildQuorumFromCommitment(const CFinalCommitment& qc, const CBlockIndex* pindexQuorum, const uint256& minedBlockHash, std::shared_ptr<CQuorum>& quorum) const
{
assert(pindexQuorum);
assert(qc.quorumHash == pindexQuorum->GetBlockHash());

auto members = deterministicMNManager->GetAllQuorumMembers((Consensus::LLMQType)qc.llmqType, pindexQuorum);
quorum->Init(minedBlockHash, pindexQuorum, members, qc.validMembers, qc.quorumPublicKey);
quorum->Init(qc, pindexQuorum, pindexQuorum->nHeight, minedBlockHash, members);

bool hasValidVvec = false;
if (quorum->ReadContributions(evoDb)) {
Expand All @@ -195,7 +195,7 @@ bool CQuorumManager::BuildQuorumFromCommitment(const CFinalCommitment& qc, const
quorum->WriteContributions(evoDb);
hasValidVvec = true;
} else {
LogPrintf("CQuorumManager::%s -- quorum.ReadContributions and BuildQuorumContributions for block %s failed\n", __func__, qc.quorumHash.ToString());
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- quorum.ReadContributions and BuildQuorumContributions for block %s failed\n", __func__, qc.quorumHash.ToString());
}
}

Expand Down Expand Up @@ -224,20 +224,20 @@ bool CQuorumManager::BuildQuorumContributions(const CFinalCommitment& fqc, std::
cxxtimer::Timer t2(true);
quorumVvec = blsWorker.BuildQuorumVerificationVector(vvecs);
if (quorumVvec == nullptr) {
LogPrintf("CQuorumManager::%s -- failed to build quorumVvec\n", __func__);
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()) {
LogPrintf("CQuorumManager::%s -- failed to build skShare\n", __func__);
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)
}
t2.stop();

LogPrintf("CQuorumManager::%s -- built quorum vvec and skShare. time=%d\n", __func__, t2.count());
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- built quorum vvec and skShare. time=%d\n", __func__, t2.count());

quorum->quorumVvec = quorumVvec;
quorum->skShare = skShare;
Expand Down
9 changes: 5 additions & 4 deletions src/llmq/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef PIVX_LLMQ_QUORUMS_H
#define PIVX_LLMQ_QUORUMS_H

#include "llmq/quorums_commitment.h"
#include "bls/bls_worker.h"
#include "bls/bls_wrapper.h"
#include "consensus/params.h"
Expand Down Expand Up @@ -35,11 +36,11 @@ class CQuorum

public:
const Consensus::LLMQParams& params;
uint256 minedBlockHash;
const CBlockIndex* pindexQuorum;
CFinalCommitment qc;
int height;
uint256 minedBlockHash;
std::vector<CDeterministicMNCPtr> members;
std::vector<bool> validMembers;
CBLSPublicKey quorumPublicKey;

// These are only valid when we either participated in the DKG or fully watched it
BLSVerificationVectorPtr quorumVvec;
Expand All @@ -55,7 +56,7 @@ class CQuorum
public:
CQuorum(const Consensus::LLMQParams& _params, CBLSWorker& _blsWorker) : params(_params), blsCache(_blsWorker), stopCachePopulatorThread(false) {}
~CQuorum();
void Init(const uint256& minedBlockHash, const CBlockIndex* pindexQuorum, const std::vector<CDeterministicMNCPtr>& members, const std::vector<bool>& validMembers, const CBLSPublicKey& quorumPublicKey);
void Init(const CFinalCommitment& _qc, const CBlockIndex* pindexQuorum, int _height, const uint256& _minedBlockHash, const std::vector<CDeterministicMNCPtr>& _members);

bool IsMember(const uint256& proTxHash) const;
bool IsValidMember(const uint256& proTxHash) const;
Expand Down
Loading
Loading