Skip to content

Commit

Permalink
Merge #2949: Dash LLMQ backports part 4
Browse files Browse the repository at this point in the history
c7e2beb scripted-diff: Refactor llmq type consensus param names (dashpay#3093) (UdjinM6)
af7bb99 Re-verify invalid IS sigs when the active quorum set rotated (dashpay#3052) (Alexander Block)
be20a71 Remove recovered sigs from the LLMQ db when corresponding IS locks get confirmed (dashpay#3048) (Alexander Block)
802a933 Don't wake up select if it was already woken up (dashpay#2863) (Alexander Block)
436300d  Disable optimistic send in PushMessage by default (dashpay#2859) (Alexander Block)
44ad484 Optimize LLMQs sending of sig shares (dashpay#2704) (Alexander Block)
e01ad46 Fix db leaks in LLMQ db (dashpay#2914) (Alexander Block)
d2a2d15 Print inputs on which we voted and quorums used for signing (dashpay#2907) (Alexander Block)
dce46ad Bail out in few more places when blockchain is not synced yet (dashpay#2888) (UdjinM6)
965a4a7 Use lazy BLS signatures more often and don't always verify self-recovered sigs (dashpay#2860) (Alexander Block)
f4a5a04 cherry pick dashpay#2889 (UdjinM6)

Pull request description:

  each commit backports a different PR

ACKs for top commit: c7e2beb
  Duddino:
    utACK c7e2beb
  Liquid369:
    utACK c7e2beb

Tree-SHA512: 86425039d01990ff04eea95f5ea4bee4821eaa80c33bab147d5b9407589c799c8293c2da5d5faf10e7e66b65d568444318c87fc274f39b42d2b69b80abafb417
  • Loading branch information
Fuzzbawls committed Nov 15, 2024
2 parents a8fae51 + c7e2beb commit c6818fd
Show file tree
Hide file tree
Showing 13 changed files with 385 additions and 109 deletions.
6 changes: 3 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class CMainParams : public CChainParams

nLLMQConnectionRetryTimeout = 60;

consensus.llmqChainLocks = Consensus::LLMQ_400_60;
consensus.llmqTypeChainLocks = Consensus::LLMQ_400_60;

// Tier two
nFulfilledRequestExpireTime = 60 * 60; // fulfilled requests expire in 1 hour
Expand Down Expand Up @@ -505,7 +505,7 @@ class CTestNetParams : public CChainParams

nLLMQConnectionRetryTimeout = 60;

consensus.llmqChainLocks = Consensus::LLMQ_400_60;
consensus.llmqTypeChainLocks = Consensus::LLMQ_400_60;

// Tier two
nFulfilledRequestExpireTime = 60 * 60; // fulfilled requests expire in 1 hour
Expand Down Expand Up @@ -649,7 +649,7 @@ class CRegTestParams : public CChainParams
consensus.llmqs[Consensus::LLMQ_TEST] = llmq_test;
nLLMQConnectionRetryTimeout = 10;

consensus.llmqChainLocks = Consensus::LLMQ_TEST;
consensus.llmqTypeChainLocks = Consensus::LLMQ_TEST;

// Tier two
nFulfilledRequestExpireTime = 60 * 60; // fulfilled requests expire in 1 hour
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ struct Params {
// LLMQ
std::map<LLMQType, LLMQParams> llmqs;
Optional<LLMQParams> GetLLMQParams(uint8_t llmqtype) const;
LLMQType llmqChainLocks;
LLMQType llmqTypeChainLocks;
};
} // namespace Consensus

Expand Down
2 changes: 1 addition & 1 deletion src/evo/evonotificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void EvoNotificationInterface::AcceptedBlockHeader(const CBlockIndex* pindexNew)
void EvoNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
{
// background thread updates
llmq::chainLocksHandler->UpdatedBlockTip(pindexNew, pindexFork);
llmq::chainLocksHandler->UpdatedBlockTip(pindexNew);
llmq::quorumDKGSessionManager->UpdatedBlockTip(pindexNew, fInitialDownload);
llmq::quorumManager->UpdatedBlockTip(pindexNew, fInitialDownload);
}
Expand Down
3 changes: 2 additions & 1 deletion src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "quorums_commitment.h"
#include "quorums_dkgsessionmgr.h"
#include "shutdown.h"
#include "tiertwo/tiertwo_sync_state.h"
#include "univalue.h"
#include "validation.h"

Expand Down Expand Up @@ -165,7 +166,7 @@ CQuorumManager::CQuorumManager(CEvoDB& _evoDb, CBLSWorker& _blsWorker, CDKGSessi

void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitialDownload)
{
if (fInitialDownload || !activeMasternodeManager || !deterministicMNManager->IsDIP3Enforced(pindexNew->nHeight)) {
if (!g_tiertwo_sync_state.IsBlockchainSynced() || !activeMasternodeManager) {
return;
}

Expand Down
24 changes: 17 additions & 7 deletions src/llmq/quorums_chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "scheduler.h"
#include "spork.h"
#include "sporkid.h"
#include "tiertwo/tiertwo_sync_state.h"
#include "validation.h"

namespace llmq
Expand Down Expand Up @@ -108,7 +109,7 @@ void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLock

uint256 requestId = ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, clsig.nHeight));
uint256 msgHash = clsig.blockHash;
if (!quorumSigningManager->VerifyRecoveredSig(Params().GetConsensus().llmqChainLocks, clsig.nHeight, requestId, msgHash, clsig.sig)) {
if (!quorumSigningManager->VerifyRecoveredSig(Params().GetConsensus().llmqTypeChainLocks, clsig.nHeight, requestId, msgHash, clsig.sig)) {
LogPrintf("CChainLocksHandler::%s -- invalid CLSIG (%s), peer=%d\n", __func__, clsig.ToString(), from);
if (from != -1) {
LOCK(cs_main);
Expand Down Expand Up @@ -184,7 +185,7 @@ void CChainLocksHandler::AcceptedBlockHeader(const CBlockIndex* pindexNew)
}
}

void CChainLocksHandler::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork)
void CChainLocksHandler::UpdatedBlockTip(const CBlockIndex* pindexNew)
{
// don't call TrySignChainTip directly but instead let the scheduler call it. This way we ensure that cs_main is
// never locked and TrySignChainTip is not called twice in parallel. Also avoids recursive calls due to
Expand All @@ -207,15 +208,20 @@ void CChainLocksHandler::TrySignChainTip()
{
Cleanup();

if (!fMasterNode) {
return;
}

if (!g_tiertwo_sync_state.IsBlockchainSynced()) {
return;
}

const CBlockIndex* pindex;
{
LOCK(cs_main);
pindex = chainActive.Tip();
}

if (!fMasterNode) {
return;
}
if (!pindex->pprev) {
return;
}
Expand Down Expand Up @@ -264,7 +270,7 @@ void CChainLocksHandler::TrySignChainTip()
lastSignedMsgHash = msgHash;
}

quorumSigningManager->AsyncSignIfMember(Params().GetConsensus().llmqChainLocks, requestId, msgHash);
quorumSigningManager->AsyncSignIfMember(Params().GetConsensus().llmqTypeChainLocks, requestId, msgHash);
}

// WARNING: cs_main and cs should not be held!
Expand Down Expand Up @@ -345,7 +351,7 @@ void CChainLocksHandler::HandleNewRecoveredSig(const llmq::CRecoveredSig& recove

clsig.nHeight = lastSignedHeight;
clsig.blockHash = lastSignedMsgHash;
clsig.sig = recoveredSig.sig;
clsig.sig = recoveredSig.sig.Get();
}
ProcessNewChainLock(-1, clsig, ::SerializeHash(clsig));
}
Expand Down Expand Up @@ -440,6 +446,10 @@ bool CChainLocksHandler::InternalHasConflictingChainLock(int nHeight, const uint

void CChainLocksHandler::Cleanup()
{
if (!g_tiertwo_sync_state.IsBlockchainSynced()) {
return;
}

{
LOCK(cs);
if (GetTimeMillis() - lastCleanupTime < CLEANUP_INTERVAL) {
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums_chainlocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CChainLocksHandler : public CRecoveredSigsListener
void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);
void ProcessNewChainLock(NodeId from, const CChainLockSig& clsig, const uint256& hash);
void AcceptedBlockHeader(const CBlockIndex* pindexNew);
void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork);
void UpdatedBlockTip(const CBlockIndex* pindexNew);
void TrySignChainTip();
void EnforceBestChainLock();
virtual void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig);
Expand Down
2 changes: 0 additions & 2 deletions src/llmq/quorums_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class CEvoDB;
namespace llmq
{

extern CDBWrapper* llmqDb;

// Init/destroy LLMQ globals
void InitLLMQSystem(CEvoDB& evoDb, CScheduler* scheduler, bool unitTests);
void DestroyLLMQSystem();
Expand Down
Loading

0 comments on commit c6818fd

Please sign in to comment.