mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
refactor: access llmq::CQuorumManager
through arg in MNHFTx
, functions
This commit is contained in:
parent
e4c848baf2
commit
cbb6828ec7
@ -10,9 +10,10 @@
|
||||
|
||||
CChainstateHelper::CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, CGovernanceManager& govman,
|
||||
llmq::CQuorumBlockProcessor& qblockman, const Consensus::Params& consensus_params,
|
||||
const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler)
|
||||
const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler,
|
||||
const llmq::CQuorumManager& qman)
|
||||
: mn_payments{std::make_unique<CMNPaymentsProcessor>(dmnman, govman, consensus_params, mn_sync, sporkman)},
|
||||
special_tx{std::make_unique<CSpecialTxProcessor>(cpoolman, dmnman, mnhfman, qblockman, consensus_params, clhandler)}
|
||||
special_tx{std::make_unique<CSpecialTxProcessor>(cpoolman, dmnman, mnhfman, qblockman, consensus_params, clhandler, qman)}
|
||||
{}
|
||||
|
||||
CChainstateHelper::~CChainstateHelper() = default;
|
||||
|
@ -20,6 +20,7 @@ namespace Consensus { struct Params; }
|
||||
namespace llmq {
|
||||
class CChainLocksHandler;
|
||||
class CQuorumBlockProcessor;
|
||||
class CQuorumManager;
|
||||
}
|
||||
|
||||
class CChainstateHelper
|
||||
@ -27,7 +28,8 @@ class CChainstateHelper
|
||||
public:
|
||||
explicit CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, CGovernanceManager& govman,
|
||||
llmq::CQuorumBlockProcessor& qblockman, const Consensus::Params& consensus_params,
|
||||
const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler);
|
||||
const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler,
|
||||
const llmq::CQuorumManager& qman);
|
||||
~CChainstateHelper();
|
||||
|
||||
CChainstateHelper() = delete;
|
||||
|
@ -84,14 +84,14 @@ CMNHFManager::Signals CMNHFManager::GetSignalsStage(const CBlockIndex* const pin
|
||||
return signals;
|
||||
}
|
||||
|
||||
bool MNHFTx::Verify(const uint256& quorumHash, const uint256& requestId, const uint256& msgHash, TxValidationState& state) const
|
||||
bool MNHFTx::Verify(const llmq::CQuorumManager& qman, const uint256& quorumHash, const uint256& requestId, const uint256& msgHash, TxValidationState& state) const
|
||||
{
|
||||
if (versionBit >= VERSIONBITS_NUM_BITS) {
|
||||
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-nbit-out-of-bounds");
|
||||
}
|
||||
|
||||
const Consensus::LLMQType& llmqType = Params().GetConsensus().llmqTypeMnhf;
|
||||
const auto quorum = llmq::quorumManager->GetQuorum(llmqType, quorumHash);
|
||||
const auto quorum = qman.GetQuorum(llmqType, quorumHash);
|
||||
|
||||
const uint256 signHash = llmq::BuildSignHash(llmqType, quorum->qc->quorumHash, requestId, msgHash);
|
||||
if (!sig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash)) {
|
||||
@ -101,7 +101,7 @@ bool MNHFTx::Verify(const uint256& quorumHash, const uint256& requestId, const u
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CheckMNHFTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state)
|
||||
bool CheckMNHFTx(const llmq::CQuorumManager& qman, const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state)
|
||||
{
|
||||
if (!tx.IsSpecialTxVersion() || tx.nType != TRANSACTION_MNHF_SIGNAL) {
|
||||
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-type");
|
||||
@ -134,7 +134,7 @@ bool CheckMNHFTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValida
|
||||
uint256 msgHash = tx_copy.GetHash();
|
||||
|
||||
|
||||
if (!mnhfTx.signal.Verify(mnhfTx.signal.quorumHash, mnhfTx.GetRequestId(), msgHash, state)) {
|
||||
if (!mnhfTx.signal.Verify(qman, mnhfTx.signal.quorumHash, mnhfTx.GetRequestId(), msgHash, state)) {
|
||||
// set up inside Verify
|
||||
return false;
|
||||
}
|
||||
@ -160,7 +160,7 @@ std::optional<uint8_t> extractEHFSignal(const CTransaction& tx)
|
||||
return opt_mnhfTx->signal.versionBit;
|
||||
}
|
||||
|
||||
static bool extractSignals(const CBlock& block, const CBlockIndex* const pindex, std::vector<uint8_t>& new_signals, BlockValidationState& state)
|
||||
static bool extractSignals(const llmq::CQuorumManager& qman, const CBlock& block, const CBlockIndex* const pindex, std::vector<uint8_t>& new_signals, BlockValidationState& state)
|
||||
{
|
||||
// we skip the coinbase
|
||||
for (size_t i = 1; i < block.vtx.size(); ++i) {
|
||||
@ -172,7 +172,7 @@ static bool extractSignals(const CBlock& block, const CBlockIndex* const pindex,
|
||||
}
|
||||
|
||||
TxValidationState tx_state;
|
||||
if (!CheckMNHFTx(tx, pindex, tx_state)) {
|
||||
if (!CheckMNHFTx(qman, tx, pindex, tx_state)) {
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, tx_state.GetRejectReason(), tx_state.GetDebugMessage());
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ std::optional<CMNHFManager::Signals> CMNHFManager::ProcessBlock(const CBlock& bl
|
||||
{
|
||||
try {
|
||||
std::vector<uint8_t> new_signals;
|
||||
if (!extractSignals(block, pindex, new_signals, state)) {
|
||||
if (!extractSignals(*Assert(llmq::quorumManager), block, pindex, new_signals, state)) {
|
||||
// state is set inside extractSignals
|
||||
return std::nullopt;
|
||||
}
|
||||
@ -246,7 +246,7 @@ bool CMNHFManager::UndoBlock(const CBlock& block, const CBlockIndex* const pinde
|
||||
{
|
||||
std::vector<uint8_t> excluded_signals;
|
||||
BlockValidationState state;
|
||||
if (!extractSignals(block, pindex, excluded_signals, state)) {
|
||||
if (!extractSignals(*Assert(llmq::quorumManager), block, pindex, excluded_signals, state)) {
|
||||
LogPrintf("CMNHFManager::%s: failed to extract signals\n", __func__);
|
||||
return false;
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ class CBlock;
|
||||
class CBlockIndex;
|
||||
class CEvoDB;
|
||||
class TxValidationState;
|
||||
namespace llmq {
|
||||
class CQuorumManager;
|
||||
}
|
||||
|
||||
// mnhf signal special transaction
|
||||
class MNHFTx
|
||||
@ -32,7 +35,8 @@ public:
|
||||
CBLSSignature sig{};
|
||||
|
||||
MNHFTx() = default;
|
||||
bool Verify(const uint256& quorumHash, const uint256& requestId, const uint256& msgHash, TxValidationState& state) const;
|
||||
bool Verify(const llmq::CQuorumManager& qman, const uint256& quorumHash, const uint256& requestId, const uint256& msgHash,
|
||||
TxValidationState& state) const;
|
||||
|
||||
SERIALIZE_METHODS(MNHFTx, obj)
|
||||
{
|
||||
@ -148,6 +152,6 @@ private:
|
||||
};
|
||||
|
||||
std::optional<uint8_t> extractEHFSignal(const CTransaction& tx);
|
||||
bool CheckMNHFTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state);
|
||||
bool CheckMNHFTx(const llmq::CQuorumManager& qman, const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state);
|
||||
|
||||
#endif // BITCOIN_EVO_MNHFTX_H
|
||||
|
@ -18,7 +18,8 @@
|
||||
#include <llmq/commitment.h>
|
||||
#include <primitives/block.h>
|
||||
|
||||
static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, const std::optional<CRangesSet>& indexes, bool check_sigs, TxValidationState& state)
|
||||
static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const llmq::CQuorumManager& qman, const CTransaction& tx, const CBlockIndex* pindexPrev,
|
||||
const CCoinsViewCache& view, const std::optional<CRangesSet>& indexes, bool check_sigs, TxValidationState& state)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
@ -48,7 +49,7 @@ static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const CTransact
|
||||
if (!DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_V20)) {
|
||||
return state.Invalid(TxValidationResult::TX_CONSENSUS, "mnhf-before-v20");
|
||||
}
|
||||
return CheckMNHFTx(tx, pindexPrev, state);
|
||||
return CheckMNHFTx(qman, tx, pindexPrev, state);
|
||||
case TRANSACTION_ASSET_LOCK:
|
||||
if (!DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_V20)) {
|
||||
return state.Invalid(TxValidationResult::TX_CONSENSUS, "assetlocks-before-v20");
|
||||
@ -75,7 +76,7 @@ static bool CheckSpecialTxInner(CDeterministicMNManager& dmnman, const CTransact
|
||||
bool CSpecialTxProcessor::CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, bool check_sigs, TxValidationState& state)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
return CheckSpecialTxInner(m_dmnman, tx, pindexPrev, view, std::nullopt, check_sigs, state);
|
||||
return CheckSpecialTxInner(m_dmnman, m_qman, tx, pindexPrev, view, std::nullopt, check_sigs, state);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool CSpecialTxProcessor::ProcessSpecialTx(const CTransaction& tx, const CBlockIndex* pindex, TxValidationState& state)
|
||||
@ -154,7 +155,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
|
||||
TxValidationState tx_state;
|
||||
// At this moment CheckSpecialTx() and ProcessSpecialTx() may fail by 2 possible ways:
|
||||
// consensus failures and "TX_BAD_SPECIAL"
|
||||
if (!CheckSpecialTxInner(m_dmnman, *ptr_tx, pindex->pprev, view, creditPool.indexes, fCheckCbTxMerkleRoots, tx_state)) {
|
||||
if (!CheckSpecialTxInner(m_dmnman, m_qman, *ptr_tx, pindex->pprev, view, creditPool.indexes, fCheckCbTxMerkleRoots, tx_state)) {
|
||||
assert(tx_state.GetResult() == TxValidationResult::TX_CONSENSUS || tx_state.GetResult() == TxValidationResult::TX_BAD_SPECIAL);
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, tx_state.GetRejectReason(),
|
||||
strprintf("Special Transaction check failed (tx hash %s) %s", ptr_tx->GetHash().ToString(), tx_state.GetDebugMessage()));
|
||||
|
@ -24,6 +24,7 @@ struct MNListUpdates;
|
||||
namespace Consensus { struct Params; }
|
||||
namespace llmq {
|
||||
class CQuorumBlockProcessor;
|
||||
class CQuorumManager;
|
||||
class CChainLocksHandler;
|
||||
} // namespace llmq
|
||||
|
||||
@ -38,6 +39,7 @@ private:
|
||||
llmq::CQuorumBlockProcessor& m_qblockman;
|
||||
const Consensus::Params& m_consensus_params;
|
||||
const llmq::CChainLocksHandler& m_clhandler;
|
||||
const llmq::CQuorumManager& m_qman;
|
||||
|
||||
private:
|
||||
[[nodiscard]] bool ProcessSpecialTx(const CTransaction& tx, const CBlockIndex* pindex, TxValidationState& state);
|
||||
@ -45,8 +47,9 @@ private:
|
||||
|
||||
public:
|
||||
explicit CSpecialTxProcessor(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, llmq::CQuorumBlockProcessor& qblockman,
|
||||
const Consensus::Params& consensus_params, const llmq::CChainLocksHandler& clhandler) :
|
||||
m_cpoolman(cpoolman), m_dmnman{dmnman}, m_mnhfman{mnhfman}, m_qblockman{qblockman}, m_consensus_params{consensus_params}, m_clhandler{clhandler} {}
|
||||
const Consensus::Params& consensus_params, const llmq::CChainLocksHandler& clhandler, const llmq::CQuorumManager& qman) :
|
||||
m_cpoolman(cpoolman), m_dmnman{dmnman}, m_mnhfman{mnhfman}, m_qblockman{qblockman}, m_consensus_params{consensus_params}, m_clhandler{clhandler},
|
||||
m_qman{qman} {}
|
||||
|
||||
bool CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, bool check_sigs, TxValidationState& state)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
@ -1978,7 +1978,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
|
||||
|
||||
node.chain_helper.reset();
|
||||
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor),
|
||||
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler));
|
||||
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman));
|
||||
|
||||
if (fReset) {
|
||||
pblocktree->WriteReindexing(true);
|
||||
|
@ -120,7 +120,7 @@ void DashTestSetup(NodeContext& node, const CChainParams& chainparams)
|
||||
node.llmq_ctx = std::make_unique<LLMQContext>(chainstate, *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool,
|
||||
/* mn_activeman = */ nullptr, *node.mn_sync, node.peerman, /* unit_tests = */ true, /* wipe = */ false);
|
||||
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor),
|
||||
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler));
|
||||
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman));
|
||||
}
|
||||
|
||||
void DashTestSetupClose(NodeContext& node)
|
||||
|
Loading…
Reference in New Issue
Block a user