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 LLMQ backports part 4 #2949

Merged
merged 11 commits into from
Nov 15, 2024
Merged
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: 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
Loading