Skip to content

Commit 32a2543

Browse files
authored
refactor: trivial refactorings of llmq/ (#5486)
## Issue being fixed or feature implemented It splits from #5150 by @PastaPastaPasta request. ## What was done? See commits ## How Has This Been Tested? Run unit/functional tests ## Breaking Changes n/a ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
1 parent 3b3f717 commit 32a2543

File tree

8 files changed

+27
-31
lines changed

8 files changed

+27
-31
lines changed

src/evo/deterministicmns.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <base58.h>
1414
#include <chainparams.h>
1515
#include <consensus/validation.h>
16-
#include <core_io.h>
1716
#include <script/standard.h>
1817
#include <ui_interface.h>
1918
#include <validation.h>

src/llmq/blockprocessor.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525

2626
#include <map>
2727

28+
static void PreComputeQuorumMembers(const CBlockIndex* pindex, bool reset_cache = false)
29+
{
30+
for (const Consensus::LLMQParams& params : llmq::utils::GetEnabledQuorumParams(pindex->pprev)) {
31+
if (llmq::utils::IsQuorumRotationEnabled(params, pindex) && (pindex->nHeight % params.dkgInterval == 0)) {
32+
llmq::utils::GetAllQuorumMembers(params.type, pindex, reset_cache);
33+
}
34+
}
35+
}
36+
2837
namespace llmq
2938
{
3039

@@ -148,7 +157,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex*
148157
return true;
149158
}
150159

151-
llmq::utils::PreComputeQuorumMembers(pindex);
160+
PreComputeQuorumMembers(pindex);
152161

153162
std::multimap<Consensus::LLMQType, CFinalCommitment> qcs;
154163
if (!GetCommitmentsFromBlock(block, pindex, qcs, state)) {
@@ -304,7 +313,7 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, const CBlockIndex* pi
304313
{
305314
AssertLockHeld(cs_main);
306315

307-
llmq::utils::PreComputeQuorumMembers(pindex, true);
316+
PreComputeQuorumMembers(pindex, true);
308317

309318
std::multimap<Consensus::LLMQType, CFinalCommitment> qcs;
310319
BlockValidationState dummy;

src/llmq/chainlocks.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,8 @@ CChainLocksHandler::BlockTxs::mapped_type CChainLocksHandler::GetBlockTxs(const
447447
return ret;
448448
}
449449

450-
bool CChainLocksHandler::IsTxSafeForMining(const CInstantSendManager& isman, const uint256& txid) const
450+
bool CChainLocksHandler::IsTxSafeForMining(const uint256& txid) const
451451
{
452-
if (!isman.RejectConflictingBlocks() || !isman.IsInstantSendEnabled() || isman.IsLocked(txid)) {
453-
return true;
454-
}
455-
456452
int64_t txAge = 0;
457453
{
458454
LOCK(cs);

src/llmq/chainlocks.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class PeerManager;
2929

3030
namespace llmq
3131
{
32-
class CInstantSendManager;
3332
class CSigningManager;
3433
class CSigSharesManager;
3534

@@ -113,7 +112,7 @@ class CChainLocksHandler : public CRecoveredSigsListener
113112
bool HasConflictingChainLock(int nHeight, const uint256& blockHash) const LOCKS_EXCLUDED(cs);
114113
bool VerifyChainLock(const CChainLockSig& clsig) const;
115114

116-
bool IsTxSafeForMining(const CInstantSendManager& isman, const uint256& txid) const LOCKS_EXCLUDED(cs);
115+
bool IsTxSafeForMining(const uint256& txid) const LOCKS_EXCLUDED(cs);
117116

118117
private:
119118
// these require locks to be held already

src/llmq/utils.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ VersionBitsCache llmq_versionbitscache;
4040
namespace utils
4141

4242
{
43+
//QuorumMembers per quorumIndex at heights H-Cycle, H-2Cycles, H-3Cycles
44+
struct PreviousQuorumQuarters {
45+
std::vector<std::vector<CDeterministicMNCPtr>> quarterHMinusC;
46+
std::vector<std::vector<CDeterministicMNCPtr>> quarterHMinus2C;
47+
std::vector<std::vector<CDeterministicMNCPtr>> quarterHMinus3C;
48+
explicit PreviousQuorumQuarters(size_t s) :
49+
quarterHMinusC(s), quarterHMinus2C(s), quarterHMinus3C(s) {}
50+
};
51+
4352
// Forward declarations
4453
static std::vector<CDeterministicMNCPtr> ComputeQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex);
4554
static std::vector<std::vector<CDeterministicMNCPtr>> ComputeQuorumMembersByQuarterRotation(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex);
@@ -54,15 +63,6 @@ static void BuildQuorumSnapshot(const Consensus::LLMQParams& llmqParams, const C
5463

5564
static bool IsInstantSendLLMQTypeShared();
5665

57-
void PreComputeQuorumMembers(const CBlockIndex* pindex, bool reset_cache)
58-
{
59-
for (const Consensus::LLMQParams& params : GetEnabledQuorumParams(pindex->pprev)) {
60-
if (IsQuorumRotationEnabled(params, pindex) && (pindex->nHeight % params.dkgInterval == 0)) {
61-
GetAllQuorumMembers(params.type, pindex, reset_cache);
62-
}
63-
}
64-
}
65-
6666
uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex)
6767
{
6868
ASSERT_IF_DEBUG(pCycleQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval == 0);

src/llmq/utils.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,12 @@ enum class QvvecSyncMode {
4242
OnlyIfTypeMember = 1,
4343
};
4444

45-
//QuorumMembers per quorumIndex at heights H-Cycle, H-2Cycles, H-3Cycles
46-
struct PreviousQuorumQuarters {
47-
std::vector<std::vector<CDeterministicMNCPtr>> quarterHMinusC;
48-
std::vector<std::vector<CDeterministicMNCPtr>> quarterHMinus2C;
49-
std::vector<std::vector<CDeterministicMNCPtr>> quarterHMinus3C;
50-
explicit PreviousQuorumQuarters(size_t s) :
51-
quarterHMinusC(s), quarterHMinus2C(s), quarterHMinus3C(s) {}
52-
};
53-
5445
namespace utils
5546
{
5647

5748
// includes members which failed DKG
5849
std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, bool reset_cache = false);
5950

60-
void PreComputeQuorumMembers(const CBlockIndex* pindex, bool reset_cache = false);
6151
uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex);
6252
uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash, const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash);
6353
uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash);

src/miner.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& packa
286286
for (CTxMemPool::txiter it : package) {
287287
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
288288
return false;
289-
if (!m_clhandler.IsTxSafeForMining(m_isman, it->GetTx().GetHash())) {
289+
290+
const auto& txid = it->GetTx().GetHash();
291+
if (!m_isman.RejectConflictingBlocks() || !m_isman.IsInstantSendEnabled() || m_isman.IsLocked(txid)) continue;
292+
293+
if (!m_clhandler.IsTxSafeForMining(txid)) {
290294
return false;
291295
}
292296
}

test/lint/lint-circular-dependencies.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
5353
"qt/bitcoingui -> qt/guiutil -> qt/bitcoingui"
5454
"qt/guiutil -> qt/optionsdialog -> qt/guiutil"
5555
"qt/guiutil -> qt/qvalidatedlineedit -> qt/guiutil"
56-
"core_io -> evo/cbtx -> evo/deterministicmns -> core_io"
5756
"core_io -> evo/cbtx -> evo/simplifiedmns -> core_io"
5857
"evo/simplifiedmns -> llmq/blockprocessor -> net_processing -> evo/simplifiedmns"
5958
"llmq/dkgsession -> llmq/dkgsessionmgr -> llmq/dkgsessionhandler -> llmq/dkgsession"

0 commit comments

Comments
 (0)