Line data Source code
1 : // Copyright (c) 2018-2025 The Dash Core developers
2 : // Distributed under the MIT software license, see the accompanying
3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 :
5 : #ifndef BITCOIN_EVO_SPECIALTXMAN_H
6 : #define BITCOIN_EVO_SPECIALTXMAN_H
7 :
8 : #include <gsl/pointers.h>
9 : #include <sync.h>
10 : #include <threadsafety.h>
11 :
12 : #include <optional>
13 :
14 : class BlockValidationState;
15 : class CBlock;
16 : class CBlockIndex;
17 : class CCbTx;
18 : class CCoinsViewCache;
19 : class CCreditPoolManager;
20 : class CDeterministicMNList;
21 : class CDeterministicMNManager;
22 : class CTransaction;
23 : class ChainstateManager;
24 : class CMNHFManager;
25 : class TxValidationState;
26 : struct MNListUpdates;
27 :
28 : namespace chainlock {
29 : class Chainlocks;
30 : }
31 : namespace Consensus { struct Params; }
32 : namespace llmq {
33 : class CQuorumBlockProcessor;
34 : class CQuorumManager;
35 : class CQuorumSnapshotManager;
36 : } // namespace llmq
37 :
38 : extern RecursiveMutex cs_main; // NOLINT(readability-redundant-declaration)
39 :
40 : class CSpecialTxProcessor
41 : {
42 : private:
43 : CCreditPoolManager& m_cpoolman;
44 : CDeterministicMNManager& m_dmnman;
45 : CMNHFManager& m_mnhfman;
46 : llmq::CQuorumBlockProcessor& m_qblockman;
47 : llmq::CQuorumSnapshotManager& m_qsnapman;
48 : const ChainstateManager& m_chainman;
49 : const Consensus::Params& m_consensus_params;
50 : const chainlock::Chainlocks& m_chainlocks;
51 : const llmq::CQuorumManager& m_qman;
52 :
53 : public:
54 6126 : explicit CSpecialTxProcessor(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman,
55 : llmq::CQuorumBlockProcessor& qblockman, llmq::CQuorumSnapshotManager& qsnapman,
56 : const ChainstateManager& chainman, const Consensus::Params& consensus_params,
57 : const chainlock::Chainlocks& chainlocks, const llmq::CQuorumManager& qman) :
58 3063 : m_cpoolman(cpoolman),
59 3063 : m_dmnman{dmnman},
60 3063 : m_mnhfman{mnhfman},
61 3063 : m_qblockman{qblockman},
62 3063 : m_qsnapman{qsnapman},
63 3063 : m_chainman(chainman),
64 3063 : m_consensus_params{consensus_params},
65 3063 : m_chainlocks{chainlocks},
66 3063 : m_qman{qman}
67 3063 : {
68 6126 : }
69 :
70 : bool CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, bool check_sigs, TxValidationState& state)
71 : EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
72 : bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, const CCoinsViewCache& view, bool fJustCheck,
73 : bool fCheckCbTxMerkleRoots, BlockValidationState& state, std::optional<MNListUpdates>& updatesRet)
74 : EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
75 : bool UndoSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, std::optional<MNListUpdates>& updatesRet)
76 : EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
77 :
78 :
79 : // the returned list will not contain the correct block hash (we can't know it yet as the coinbase TX is not updated yet)
80 : bool BuildNewListFromBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindexPrev,
81 : const CCoinsViewCache& view, bool debugLogs, BlockValidationState& state,
82 : CDeterministicMNList& mnListRet) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
83 :
84 : // Variant that takes an explicit starting list instead of loading from GetListForBlock
85 : // Used for rebuilding diffs from trusted snapshots
86 : bool RebuildListFromBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindexPrev,
87 : const CDeterministicMNList& prevList, const CCoinsViewCache& view, bool debugLogs,
88 : BlockValidationState& state, CDeterministicMNList& mnListRet);
89 :
90 : private:
91 : bool CheckCreditPoolDiffForBlock(const CBlock& block, const CBlockIndex* pindex, const CCbTx& cbTx,
92 : BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
93 : };
94 :
95 :
96 : bool CheckProRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev,
97 : CDeterministicMNManager& dmnman, const CCoinsViewCache& view, const ChainstateManager& chainman,
98 : TxValidationState& state, bool check_sigs);
99 : bool CheckProUpServTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, CDeterministicMNManager& dmnman,
100 : const ChainstateManager& chainman, TxValidationState& state, bool check_sigs);
101 : bool CheckProUpRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev,
102 : CDeterministicMNManager& dmnman, const CCoinsViewCache& view, const ChainstateManager& chainman,
103 : TxValidationState& state, bool check_sigs);
104 : bool CheckProUpRevTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, CDeterministicMNManager& dmnman,
105 : const ChainstateManager& chainman, TxValidationState& state, bool check_sigs);
106 :
107 :
108 : /**
109 : * Asset lock transactions with more than 100 inputs (and so over ~20 kB) can not
110 : * be processed by Platform, so Dash Core nodes should not relay them: they are
111 : * marked non-standard, which keeps the network from propagating them over p2p.
112 : *
113 : * Asset lock v2 is enabled by the v24 fork, but Platform can not process it yet.
114 : * It is kept non-standard so it can be enabled later without another hard fork.
115 : *
116 : * These are relay/mempool checks only: a rejected transaction stays valid inside
117 : * a block.
118 : *
119 : * Returns false (with `reason` set) for a non-standard asset lock, and
120 : * true for any transaction that is not an asset lock or not special-tx.
121 : */
122 : bool IsStandardSpecialTx(const CTransaction& tx, std::string& reason);
123 : #endif // BITCOIN_EVO_SPECIALTXMAN_H
|