44
55#include < consensus/validation.h>
66#include < evo/cbtx.h>
7+ #include < evo/deterministicmns.h>
78#include < evo/simplifiedmns.h>
89#include < evo/specialtx.h>
910#include < llmq/blockprocessor.h>
@@ -47,16 +48,16 @@ bool CheckCbTx(const CCbTx& cbTx, const CBlockIndex* pindexPrev, TxValidationSta
4748
4849// This can only be done after the block has been fully processed, as otherwise we won't have the finished MN list
4950bool CheckCbTxMerkleRoots (const CBlock& block, const CCbTx& cbTx, const CBlockIndex* pindex,
50- const llmq::CQuorumBlockProcessor& quorum_block_processor, CSimplifiedMNList&& sml,
51- BlockValidationState& state)
51+ const llmq::CQuorumBlockProcessor& quorum_block_processor,
52+ const CDeterministicMNList& mn_list, BlockValidationState& state)
5253{
5354 if (pindex) {
5455 static int64_t nTimeMerkleMNL = 0 ;
5556 static int64_t nTimeMerkleQuorum = 0 ;
5657
5758 int64_t nTime1 = GetTimeMicros ();
5859 uint256 calculatedMerkleRoot;
59- if (!CalcCbTxMerkleRootMNList (calculatedMerkleRoot, std::move (sml) , state)) {
60+ if (!CalcCbTxMerkleRootMNList (calculatedMerkleRoot, mn_list , state)) {
6061 // pass the state returned by the function above
6162 return false ;
6263 }
@@ -88,20 +89,22 @@ bool CheckCbTxMerkleRoots(const CBlock& block, const CCbTx& cbTx, const CBlockIn
8889 return true ;
8990}
9091
91- bool CalcCbTxMerkleRootMNList (uint256& merkleRootRet, CSimplifiedMNList&& sml , BlockValidationState& state)
92+ bool CalcCbTxMerkleRootMNList (uint256& merkleRootRet, const CDeterministicMNList& mn_list , BlockValidationState& state)
9293{
9394 try {
9495 static std::atomic<int64_t > nTimeMerkle = 0 ;
9596
9697 int64_t nTime1 = GetTimeMicros ();
9798
9899 static Mutex cached_mutex;
99- static CSimplifiedMNList smlCached GUARDED_BY (cached_mutex);
100+ static std::shared_ptr<const CSimplifiedMNList> cached_sml GUARDED_BY (cached_mutex){
101+ std::make_shared<const CSimplifiedMNList>()};
100102 static uint256 merkleRootCached GUARDED_BY (cached_mutex);
101103 static bool mutatedCached GUARDED_BY (cached_mutex) {false };
102104
105+ std::shared_ptr<const CSimplifiedMNList> sml{mn_list.GetSML ()};
103106 LOCK (cached_mutex);
104- if (sml == smlCached ) {
107+ if (sml == cached_sml || *sml == *cached_sml ) {
105108 merkleRootRet = merkleRootCached;
106109 if (mutatedCached) {
107110 return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " mutated-cached-calc-cb-mnmerkleroot" );
@@ -110,14 +113,14 @@ bool CalcCbTxMerkleRootMNList(uint256& merkleRootRet, CSimplifiedMNList&& sml, B
110113 }
111114
112115 bool mutated = false ;
113- merkleRootRet = sml. CalcMerkleRoot (&mutated);
116+ merkleRootRet = sml-> CalcMerkleRoot (&mutated);
114117
115118 int64_t nTime2 = GetTimeMicros ();
116119 nTimeMerkle += nTime2 - nTime1;
117120 LogPrint (BCLog::BENCHMARK, " - CalcMerkleRoot: %.2fms [%.2fs]\n " , 0.001 * (nTime2 - nTime1),
118121 nTimeMerkle * 0.000001 );
119122
120- smlCached = std::move ( sml) ;
123+ cached_sml = sml;
121124 merkleRootCached = merkleRootRet;
122125 mutatedCached = mutated;
123126
0 commit comments