Skip to content
Open
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
6 changes: 4 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,16 @@ BITCOIN_CORE_H = \
llmq/dkgsessionhandler.h \
llmq/dkgsessionmgr.h \
llmq/ehf_signals.h \
llmq/net_dkg.h \
llmq/net_quorum.h \
llmq/net_signing.h \
llmq/observer.h \
llmq/options.h \
llmq/params.h \
llmq/quorums.h \
llmq/quorumsman.h \
llmq/signhash.h \
llmq/signing.h \
llmq/net_quorum.h \
llmq/net_signing.h \
llmq/signing_shares.h \
llmq/snapshot.h \
llmq/types.h \
Expand Down Expand Up @@ -553,6 +554,7 @@ libbitcoin_node_a_SOURCES = \
llmq/dkgsessionhandler.cpp \
llmq/dkgsessionmgr.cpp \
llmq/ehf_signals.cpp \
llmq/net_dkg.cpp \
llmq/net_quorum.cpp \
llmq/net_signing.cpp \
llmq/observer.cpp \
Expand Down
30 changes: 8 additions & 22 deletions src/active/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <active/context.h>

#include <active/dkgsessionhandler.h>
#include <active/masternode.h>
#include <bls/bls_worker.h>
#include <chainlock/handler.h>
Expand All @@ -26,19 +25,18 @@
#include <validationinterface.h>

ActiveContext::ActiveContext(CBLSWorker& bls_worker, ChainstateManager& chainman, CConnman& connman,
CDeterministicMNManager& dmnman, CGovernanceManager& govman, CMasternodeMetaMan& mn_metaman,
CSporkManager& sporkman, const chainlock::Chainlocks& chainlocks, CTxMemPool& mempool,
CDeterministicMNManager& dmnman, CGovernanceManager& govman, CSporkManager& sporkman,
const chainlock::Chainlocks& chainlocks, CTxMemPool& mempool,
chainlock::ChainlockHandler& clhandler, llmq::CInstantSendManager& isman,
llmq::CQuorumBlockProcessor& qblockman, llmq::CQuorumManager& qman,
llmq::CQuorumSnapshotManager& qsnapman, llmq::CSigningManager& sigman,
const CMasternodeSync& mn_sync, const CBLSSecretKey& operator_sk,
const util::DbWrapperParams& db_params, bool quorums_watch) :
llmq::CQuorumManager& qman, llmq::CQuorumSnapshotManager& qsnapman,
llmq::CSigningManager& sigman, const CMasternodeSync& mn_sync,
const CBLSSecretKey& operator_sk, const util::DbWrapperParams& db_params, bool quorums_watch) :
llmq::QuorumRole{qman},
m_bls_worker{bls_worker},
m_quorums_watch{quorums_watch},
nodeman{std::make_unique<CActiveMasternodeManager>(connman, dmnman, operator_sk)},
dkgdbgman{std::make_unique<llmq::CDKGDebugManager>(dmnman, qsnapman, chainman)},
qdkgsman{std::make_unique<llmq::CDKGSessionManager>(dmnman, qsnapman, chainman, sporkman, db_params, quorums_watch)},
qdkgsman{std::make_unique<llmq::CDKGSessionManager>(dmnman, qsnapman, chainman, sporkman, db_params)},
shareman{std::make_unique<llmq::CSigSharesManager>(connman, chainman, sigman, *nodeman, qman, sporkman)},
gov_signer{std::make_unique<GovernanceSigner>(connman, dmnman, govman, *nodeman, chainman, mn_sync)},
ehf_sighandler{std::make_unique<llmq::CEHFSignalsHandler>(chainman, sigman, *shareman, qman)},
Expand All @@ -47,23 +45,12 @@ ActiveContext::ActiveContext(CBLSWorker& bls_worker, ChainstateManager& chainman
is_signer{std::make_unique<instantsend::InstantSendSigner>(chainman.ActiveChainstate(), chainlocks, isman, sigman,
*shareman, qman, sporkman, mempool, mn_sync)}
{
qdkgsman->InitializeHandlers([&](const Consensus::LLMQParams& llmq_params,
int quorum_idx) -> std::unique_ptr<llmq::ActiveDKGSessionHandler> {
return std::make_unique<llmq::ActiveDKGSessionHandler>(bls_worker, dmnman, mn_metaman, *dkgdbgman, *qdkgsman,
qblockman, qsnapman, *nodeman, chainman, sporkman,
llmq_params, quorums_watch, quorum_idx);
});
m_qman.ConnectManagers(this, qdkgsman.get());
}

ActiveContext::~ActiveContext()
{
m_qman.DisconnectManagers();
}
ActiveContext::~ActiveContext() = default;

void ActiveContext::Start(CConnman& connman, PeerManager& peerman)
void ActiveContext::Start()
{
qdkgsman->StartThreads(connman, peerman);
cl_signer->Start();
cl_signer->RegisterRecoveryInterface();
is_signer->RegisterRecoveryInterface();
Expand All @@ -80,7 +67,6 @@ void ActiveContext::Stop()
is_signer->UnregisterRecoveryInterface();
cl_signer->UnregisterRecoveryInterface();
cl_signer->Stop();
qdkgsman->StopThreads();
}

CCoinJoinServer& ActiveContext::GetCJServer() const
Expand Down
15 changes: 6 additions & 9 deletions src/active/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ class CBLSWorker;
class CCoinJoinServer;
class CConnman;
class CGovernanceManager;
class CMasternodeMetaMan;
class CMasternodeSync;
class CMNHFManager;
class CSporkManager;
class CTxMemPool;
class GovernanceSigner;
class PeerManager;
namespace chainlock {
class Chainlocks;
class ChainlockHandler;
Expand Down Expand Up @@ -55,16 +53,15 @@ struct ActiveContext final : public llmq::QuorumRole, public CValidationInterfac
ActiveContext(const ActiveContext&) = delete;
ActiveContext& operator=(const ActiveContext&) = delete;
explicit ActiveContext(CBLSWorker& bls_worker, ChainstateManager& chainman, CConnman& connman,
CDeterministicMNManager& dmnman, CGovernanceManager& govman, CMasternodeMetaMan& mn_metaman,
CSporkManager& sporkman, const chainlock::Chainlocks& chainlocks, CTxMemPool& mempool,
CDeterministicMNManager& dmnman, CGovernanceManager& govman, CSporkManager& sporkman,
const chainlock::Chainlocks& chainlocks, CTxMemPool& mempool,
chainlock::ChainlockHandler& clhandler, llmq::CInstantSendManager& isman,
llmq::CQuorumBlockProcessor& qblockman, llmq::CQuorumManager& qman,
llmq::CQuorumSnapshotManager& qsnapman, llmq::CSigningManager& sigman,
const CMasternodeSync& mn_sync, const CBLSSecretKey& operator_sk,
const util::DbWrapperParams& db_params, bool quorums_watch);
llmq::CQuorumManager& qman, llmq::CQuorumSnapshotManager& qsnapman,
llmq::CSigningManager& sigman, const CMasternodeSync& mn_sync,
const CBLSSecretKey& operator_sk, const util::DbWrapperParams& db_params, bool quorums_watch);
~ActiveContext();

void Start(CConnman& connman, PeerManager& peerman);
void Start();
void Stop();

CCoinJoinServer& GetCJServer() const;
Expand Down
64 changes: 32 additions & 32 deletions src/active/dkgsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ ActiveDKGSession::ActiveDKGSession(CBLSWorker& bls_worker, CDeterministicMNManag

ActiveDKGSession::~ActiveDKGSession() = default;

void ActiveDKGSession::Contribute(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
std::optional<CDKGContribution> ActiveDKGSession::Contribute()
{
if (!AreWeMember()) {
return;
return std::nullopt;
}

assert(params.threshold > 1); // we should not get there with single-node-quorums
Expand All @@ -51,15 +51,15 @@ void ActiveDKGSession::Contribute(CDKGPendingMessages& pendingMessages, PeerMana
if (!blsWorker.GenerateContributions(params.threshold, memberIds, vvecContribution, m_sk_contributions)) {
// this should never happen actually
logger.Batch("GenerateContributions failed");
return;
return std::nullopt;
}
logger.Batch("generated contributions. time=%d", t1.count());
logger.Flush();

SendContributions(pendingMessages, peerman);
return SendContributions();
}

void ActiveDKGSession::SendContributions(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
std::optional<CDKGContribution> ActiveDKGSession::SendContributions()
{
CDKGLogger logger(*this, __func__, __LINE__);

Expand All @@ -69,7 +69,7 @@ void ActiveDKGSession::SendContributions(CDKGPendingMessages& pendingMessages, P

if (ShouldSimulateError(DKGError::type::CONTRIBUTION_OMIT)) {
logger.Batch("omitting");
return;
return std::nullopt;
}

CDKGContribution qc;
Expand All @@ -93,7 +93,7 @@ void ActiveDKGSession::SendContributions(CDKGPendingMessages& pendingMessages, P

if (!qc.contributions->Encrypt(i, m->dmn->pdmnState->pubKeyOperator.Get(), skContrib, PROTOCOL_VERSION)) {
logger.Batch("failed to encrypt contribution for %s", m->dmn->proTxHash.ToString());
return;
return std::nullopt;
}
}

Expand All @@ -108,7 +108,7 @@ void ActiveDKGSession::SendContributions(CDKGPendingMessages& pendingMessages, P
return true;
});

pendingMessages.PushPendingMessage(-1, qc, peerman);
return qc;
}

// Verifies all pending secret key contributions in one batch
Expand Down Expand Up @@ -170,10 +170,10 @@ void ActiveDKGSession::VerifyPendingContributions()
pendingContributionVerifications.clear();
}

void ActiveDKGSession::VerifyAndComplain(CConnman& connman, CDKGPendingMessages& pendingMessages, PeerManager& peerman)
std::optional<CDKGComplaint> ActiveDKGSession::VerifyAndComplain(CConnman& connman)
{
if (!AreWeMember()) {
return;
return std::nullopt;
}

{
Expand Down Expand Up @@ -208,7 +208,7 @@ void ActiveDKGSession::VerifyAndComplain(CConnman& connman, CDKGPendingMessages&

VerifyConnectionAndMinProtoVersions(connman);

SendComplaint(pendingMessages, peerman);
return SendComplaint();
}

void ActiveDKGSession::VerifyConnectionAndMinProtoVersions(CConnman& connman) const
Expand Down Expand Up @@ -255,7 +255,7 @@ void ActiveDKGSession::VerifyConnectionAndMinProtoVersions(CConnman& connman) co
}
}

void ActiveDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
std::optional<CDKGComplaint> ActiveDKGSession::SendComplaint()
{
CDKGLogger logger(*this, __func__, __LINE__);

Expand All @@ -280,7 +280,7 @@ void ActiveDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages, PeerM
}

if (badCount == 0 && complaintCount == 0) {
return;
return std::nullopt;
}

logger.Batch("sending complaint. badCount=%d, complaintCount=%d", badCount, complaintCount);
Expand All @@ -294,13 +294,13 @@ void ActiveDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages, PeerM
return true;
});

pendingMessages.PushPendingMessage(-1, qc, peerman);
return qc;
}

void ActiveDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
std::optional<CDKGJustification> ActiveDKGSession::VerifyAndJustify()
{
if (!AreWeMember()) {
return;
return std::nullopt;
}

CDKGLogger logger(*this, __func__, __LINE__);
Expand Down Expand Up @@ -333,13 +333,13 @@ void ActiveDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages, Pe
}

logger.Flush();
if (!justifyFor.empty()) {
SendJustification(pendingMessages, peerman, justifyFor);
if (justifyFor.empty()) {
return std::nullopt;
}
return SendJustification(justifyFor);
}

void ActiveDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, PeerManager& peerman,
const Uint256HashSet& forMembers)
std::optional<CDKGJustification> ActiveDKGSession::SendJustification(const Uint256HashSet& forMembers)
{
CDKGLogger logger(*this, __func__, __LINE__);

Expand Down Expand Up @@ -372,7 +372,7 @@ void ActiveDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, P

if (ShouldSimulateError(DKGError::type::JUSTIFY_OMIT)) {
logger.Batch("omitting");
return;
return std::nullopt;
}

qj.sig = m_mn_activeman.Sign(qj.GetSignHash(), m_use_legacy_bls);
Expand All @@ -384,13 +384,13 @@ void ActiveDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, P
return true;
});

pendingMessages.PushPendingMessage(-1, qj, peerman);
return qj;
}

void ActiveDKGSession::VerifyAndCommit(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
std::optional<CDKGPrematureCommitment> ActiveDKGSession::VerifyAndCommit()
{
if (!AreWeMember()) {
return;
return std::nullopt;
}

CDKGLogger logger(*this, __func__, __LINE__);
Expand Down Expand Up @@ -429,10 +429,10 @@ void ActiveDKGSession::VerifyAndCommit(CDKGPendingMessages& pendingMessages, Pee

logger.Flush();

SendCommitment(pendingMessages, peerman);
return SendCommitment();
}

void ActiveDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
std::optional<CDKGPrematureCommitment> ActiveDKGSession::SendCommitment()
{
CDKGLogger logger(*this, __func__, __LINE__);

Expand All @@ -454,12 +454,12 @@ void ActiveDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages, Peer

if (qc.CountValidMembers() < params.minSize) {
logger.Batch("not enough valid members. not sending commitment");
return;
return std::nullopt;
}

if (ShouldSimulateError(DKGError::type::COMMIT_OMIT)) {
logger.Batch("omitting");
return;
return std::nullopt;
}

cxxtimer::Timer timerTotal(true);
Expand All @@ -470,21 +470,21 @@ void ActiveDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages, Peer
std::vector<CBLSSecretKey> skContributions;
if (!dkgManager.GetVerifiedContributions(params.type, m_quorum_base_block_index, qc.validMembers, memberIndexes, vvecs, skContributions)) {
logger.Batch("failed to get valid contributions");
return;
return std::nullopt;
}

BLSVerificationVectorPtr vvec = cache.BuildQuorumVerificationVector(::SerializeHash(memberIndexes), vvecs);
if (vvec == nullptr) {
logger.Batch("failed to build quorum verification vector");
return;
return std::nullopt;
}
t1.stop();

cxxtimer::Timer t2(true);
CBLSSecretKey skShare = cache.AggregateSecretKeys(::SerializeHash(memberIndexes), skContributions);
if (!skShare.IsValid()) {
logger.Batch("failed to build own secret share");
return;
return std::nullopt;
}
t2.stop();

Expand Down Expand Up @@ -541,7 +541,7 @@ void ActiveDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages, Peer
return true;
});

pendingMessages.PushPendingMessage(-1, qc, peerman);
return qc;
}

std::vector<CFinalCommitment> ActiveDKGSession::FinalizeCommitments()
Expand Down
Loading
Loading