Skip to content

Commit cbb6828

Browse files
committed
refactor: access llmq::CQuorumManager through arg in MNHFTx, functions
1 parent e4c848b commit cbb6828

File tree

8 files changed

+32
-21
lines changed

8 files changed

+32
-21
lines changed

src/evo/chainhelper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
CChainstateHelper::CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, CGovernanceManager& govman,
1212
llmq::CQuorumBlockProcessor& qblockman, const Consensus::Params& consensus_params,
13-
const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler)
13+
const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler,
14+
const llmq::CQuorumManager& qman)
1415
: mn_payments{std::make_unique<CMNPaymentsProcessor>(dmnman, govman, consensus_params, mn_sync, sporkman)},
15-
special_tx{std::make_unique<CSpecialTxProcessor>(cpoolman, dmnman, mnhfman, qblockman, consensus_params, clhandler)}
16+
special_tx{std::make_unique<CSpecialTxProcessor>(cpoolman, dmnman, mnhfman, qblockman, consensus_params, clhandler, qman)}
1617
{}
1718

1819
CChainstateHelper::~CChainstateHelper() = default;

src/evo/chainhelper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ namespace Consensus { struct Params; }
2020
namespace llmq {
2121
class CChainLocksHandler;
2222
class CQuorumBlockProcessor;
23+
class CQuorumManager;
2324
}
2425

2526
class CChainstateHelper
2627
{
2728
public:
2829
explicit CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, CGovernanceManager& govman,
2930
llmq::CQuorumBlockProcessor& qblockman, const Consensus::Params& consensus_params,
30-
const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler);
31+
const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler,
32+
const llmq::CQuorumManager& qman);
3133
~CChainstateHelper();
3234

3335
CChainstateHelper() = delete;

src/evo/mnhftx.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ CMNHFManager::Signals CMNHFManager::GetSignalsStage(const CBlockIndex* const pin
8484
return signals;
8585
}
8686

87-
bool MNHFTx::Verify(const uint256& quorumHash, const uint256& requestId, const uint256& msgHash, TxValidationState& state) const
87+
bool MNHFTx::Verify(const llmq::CQuorumManager& qman, const uint256& quorumHash, const uint256& requestId, const uint256& msgHash, TxValidationState& state) const
8888
{
8989
if (versionBit >= VERSIONBITS_NUM_BITS) {
9090
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-nbit-out-of-bounds");
9191
}
9292

9393
const Consensus::LLMQType& llmqType = Params().GetConsensus().llmqTypeMnhf;
94-
const auto quorum = llmq::quorumManager->GetQuorum(llmqType, quorumHash);
94+
const auto quorum = qman.GetQuorum(llmqType, quorumHash);
9595

9696
const uint256 signHash = llmq::BuildSignHash(llmqType, quorum->qc->quorumHash, requestId, msgHash);
9797
if (!sig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash)) {
@@ -101,7 +101,7 @@ bool MNHFTx::Verify(const uint256& quorumHash, const uint256& requestId, const u
101101
return true;
102102
}
103103

104-
bool CheckMNHFTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state)
104+
bool CheckMNHFTx(const llmq::CQuorumManager& qman, const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state)
105105
{
106106
if (!tx.IsSpecialTxVersion() || tx.nType != TRANSACTION_MNHF_SIGNAL) {
107107
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-type");
@@ -134,7 +134,7 @@ bool CheckMNHFTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValida
134134
uint256 msgHash = tx_copy.GetHash();
135135

136136

137-
if (!mnhfTx.signal.Verify(mnhfTx.signal.quorumHash, mnhfTx.GetRequestId(), msgHash, state)) {
137+
if (!mnhfTx.signal.Verify(qman, mnhfTx.signal.quorumHash, mnhfTx.GetRequestId(), msgHash, state)) {
138138
// set up inside Verify
139139
return false;
140140
}
@@ -160,7 +160,7 @@ std::optional<uint8_t> extractEHFSignal(const CTransaction& tx)
160160
return opt_mnhfTx->signal.versionBit;
161161
}
162162

163-
static bool extractSignals(const CBlock& block, const CBlockIndex* const pindex, std::vector<uint8_t>& new_signals, BlockValidationState& state)
163+
static bool extractSignals(const llmq::CQuorumManager& qman, const CBlock& block, const CBlockIndex* const pindex, std::vector<uint8_t>& new_signals, BlockValidationState& state)
164164
{
165165
// we skip the coinbase
166166
for (size_t i = 1; i < block.vtx.size(); ++i) {
@@ -172,7 +172,7 @@ static bool extractSignals(const CBlock& block, const CBlockIndex* const pindex,
172172
}
173173

174174
TxValidationState tx_state;
175-
if (!CheckMNHFTx(tx, pindex, tx_state)) {
175+
if (!CheckMNHFTx(qman, tx, pindex, tx_state)) {
176176
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, tx_state.GetRejectReason(), tx_state.GetDebugMessage());
177177
}
178178

@@ -194,7 +194,7 @@ std::optional<CMNHFManager::Signals> CMNHFManager::ProcessBlock(const CBlock& bl
194194
{
195195
try {
196196
std::vector<uint8_t> new_signals;
197-
if (!extractSignals(block, pindex, new_signals, state)) {
197+
if (!extractSignals(*Assert(llmq::quorumManager), block, pindex, new_signals, state)) {
198198
// state is set inside extractSignals
199199
return std::nullopt;
200200
}
@@ -246,7 +246,7 @@ bool CMNHFManager::UndoBlock(const CBlock& block, const CBlockIndex* const pinde
246246
{
247247
std::vector<uint8_t> excluded_signals;
248248
BlockValidationState state;
249-
if (!extractSignals(block, pindex, excluded_signals, state)) {
249+
if (!extractSignals(*Assert(llmq::quorumManager), block, pindex, excluded_signals, state)) {
250250
LogPrintf("CMNHFManager::%s: failed to extract signals\n", __func__);
251251
return false;
252252
}

src/evo/mnhftx.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class CBlock;
2222
class CBlockIndex;
2323
class CEvoDB;
2424
class TxValidationState;
25+
namespace llmq {
26+
class CQuorumManager;
27+
}
2528

2629
// mnhf signal special transaction
2730
class MNHFTx
@@ -32,7 +35,8 @@ class MNHFTx
3235
CBLSSignature sig{};
3336

3437
MNHFTx() = default;
35-
bool Verify(const uint256& quorumHash, const uint256& requestId, const uint256& msgHash, TxValidationState& state) const;
38+
bool Verify(const llmq::CQuorumManager& qman, const uint256& quorumHash, const uint256& requestId, const uint256& msgHash,
39+
TxValidationState& state) const;
3640

3741
SERIALIZE_METHODS(MNHFTx, obj)
3842
{
@@ -148,6 +152,6 @@ class CMNHFManager : public AbstractEHFManager
148152
};
149153

150154
std::optional<uint8_t> extractEHFSignal(const CTransaction& tx);
151-
bool CheckMNHFTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state);
155+
bool CheckMNHFTx(const llmq::CQuorumManager& qman, const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state);
152156

153157
#endif // BITCOIN_EVO_MNHFTX_H

src/evo/specialtxman.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#include <llmq/commitment.h>
1919
#include <primitives/block.h>
2020

21-
static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, const std::optional<CRangesSet>& indexes, bool check_sigs, TxValidationState& state)
21+
static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const llmq::CQuorumManager& qman, const CTransaction& tx, const CBlockIndex* pindexPrev,
22+
const CCoinsViewCache& view, const std::optional<CRangesSet>& indexes, bool check_sigs, TxValidationState& state)
2223
{
2324
AssertLockHeld(cs_main);
2425

@@ -48,7 +49,7 @@ static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const CTransact
4849
if (!DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_V20)) {
4950
return state.Invalid(TxValidationResult::TX_CONSENSUS, "mnhf-before-v20");
5051
}
51-
return CheckMNHFTx(tx, pindexPrev, state);
52+
return CheckMNHFTx(qman, tx, pindexPrev, state);
5253
case TRANSACTION_ASSET_LOCK:
5354
if (!DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_V20)) {
5455
return state.Invalid(TxValidationResult::TX_CONSENSUS, "assetlocks-before-v20");
@@ -75,7 +76,7 @@ static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const CTransact
7576
bool CSpecialTxProcessor::CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, bool check_sigs, TxValidationState& state)
7677
{
7778
AssertLockHeld(cs_main);
78-
return CheckSpecialTxInner(m_dmnman, tx, pindexPrev, view, std::nullopt, check_sigs, state);
79+
return CheckSpecialTxInner(m_dmnman, m_qman, tx, pindexPrev, view, std::nullopt, check_sigs, state);
7980
}
8081

8182
[[nodiscard]] bool CSpecialTxProcessor::ProcessSpecialTx(const CTransaction& tx, const CBlockIndex* pindex, TxValidationState& state)
@@ -154,7 +155,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
154155
TxValidationState tx_state;
155156
// At this moment CheckSpecialTx() and ProcessSpecialTx() may fail by 2 possible ways:
156157
// consensus failures and "TX_BAD_SPECIAL"
157-
if (!CheckSpecialTxInner(m_dmnman, *ptr_tx, pindex->pprev, view, creditPool.indexes, fCheckCbTxMerkleRoots, tx_state)) {
158+
if (!CheckSpecialTxInner(m_dmnman, m_qman, *ptr_tx, pindex->pprev, view, creditPool.indexes, fCheckCbTxMerkleRoots, tx_state)) {
158159
assert(tx_state.GetResult() == TxValidationResult::TX_CONSENSUS || tx_state.GetResult() == TxValidationResult::TX_BAD_SPECIAL);
159160
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, tx_state.GetRejectReason(),
160161
strprintf("Special Transaction check failed (tx hash %s) %s", ptr_tx->GetHash().ToString(), tx_state.GetDebugMessage()));

src/evo/specialtxman.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct MNListUpdates;
2424
namespace Consensus { struct Params; }
2525
namespace llmq {
2626
class CQuorumBlockProcessor;
27+
class CQuorumManager;
2728
class CChainLocksHandler;
2829
} // namespace llmq
2930

@@ -38,15 +39,17 @@ class CSpecialTxProcessor
3839
llmq::CQuorumBlockProcessor& m_qblockman;
3940
const Consensus::Params& m_consensus_params;
4041
const llmq::CChainLocksHandler& m_clhandler;
42+
const llmq::CQuorumManager& m_qman;
4143

4244
private:
4345
[[nodiscard]] bool ProcessSpecialTx(const CTransaction& tx, const CBlockIndex* pindex, TxValidationState& state);
4446
[[nodiscard]] bool UndoSpecialTx(const CTransaction& tx, const CBlockIndex* pindex);
4547

4648
public:
4749
explicit CSpecialTxProcessor(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, llmq::CQuorumBlockProcessor& qblockman,
48-
const Consensus::Params& consensus_params, const llmq::CChainLocksHandler& clhandler) :
49-
m_cpoolman(cpoolman), m_dmnman{dmnman}, m_mnhfman{mnhfman}, m_qblockman{qblockman}, m_consensus_params{consensus_params}, m_clhandler{clhandler} {}
50+
const Consensus::Params& consensus_params, const llmq::CChainLocksHandler& clhandler, const llmq::CQuorumManager& qman) :
51+
m_cpoolman(cpoolman), m_dmnman{dmnman}, m_mnhfman{mnhfman}, m_qblockman{qblockman}, m_consensus_params{consensus_params}, m_clhandler{clhandler},
52+
m_qman{qman} {}
5053

5154
bool CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, bool check_sigs, TxValidationState& state)
5255
EXCLUSIVE_LOCKS_REQUIRED(cs_main);

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1978,7 +1978,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
19781978

19791979
node.chain_helper.reset();
19801980
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor),
1981-
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler));
1981+
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman));
19821982

19831983
if (fReset) {
19841984
pblocktree->WriteReindexing(true);

src/test/util/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void DashTestSetup(NodeContext& node, const CChainParams& chainparams)
120120
node.llmq_ctx = std::make_unique<LLMQContext>(chainstate, *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool,
121121
/* mn_activeman = */ nullptr, *node.mn_sync, node.peerman, /* unit_tests = */ true, /* wipe = */ false);
122122
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor),
123-
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler));
123+
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman));
124124
}
125125

126126
void DashTestSetupClose(NodeContext& node)

0 commit comments

Comments
 (0)