@@ -104,20 +104,22 @@ bool CSimplifiedMNList::operator==(const CSimplifiedMNList& rhs) const
104104 );
105105}
106106
107- bool CalcCbTxMerkleRootMNList (uint256& merkleRootRet, CSimplifiedMNList&& sml , BlockValidationState& state)
107+ bool CalcCbTxMerkleRootMNList (uint256& merkleRootRet, const CDeterministicMNList& mn_list , BlockValidationState& state)
108108{
109109 try {
110110 static std::atomic<int64_t > nTimeMerkle = 0 ;
111111
112112 int64_t nTime1 = GetTimeMicros ();
113113
114114 static Mutex cached_mutex;
115- static CSimplifiedMNList smlCached GUARDED_BY (cached_mutex);
115+ static std::shared_ptr<const CSimplifiedMNList> cached_sml GUARDED_BY (cached_mutex){
116+ std::make_shared<const CSimplifiedMNList>()};
116117 static uint256 merkleRootCached GUARDED_BY (cached_mutex);
117118 static bool mutatedCached GUARDED_BY (cached_mutex){false };
118119
120+ std::shared_ptr<const CSimplifiedMNList> sml{mn_list.GetSML ()};
119121 LOCK (cached_mutex);
120- if (sml == smlCached ) {
122+ if (sml == cached_sml || *sml == *cached_sml ) {
121123 merkleRootRet = merkleRootCached;
122124 if (mutatedCached) {
123125 return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " mutated-cached-calc-cb-mnmerkleroot" );
@@ -126,14 +128,14 @@ bool CalcCbTxMerkleRootMNList(uint256& merkleRootRet, CSimplifiedMNList&& sml, B
126128 }
127129
128130 bool mutated = false ;
129- merkleRootRet = sml. CalcMerkleRoot (&mutated);
131+ merkleRootRet = sml-> CalcMerkleRoot (&mutated);
130132
131133 int64_t nTime2 = GetTimeMicros ();
132134 nTimeMerkle += nTime2 - nTime1;
133135 LogPrint (BCLog::BENCHMARK, " - CalcMerkleRoot: %.2fms [%.2fs]\n " , 0.001 * (nTime2 - nTime1),
134136 nTimeMerkle * 0.000001 );
135137
136- smlCached = std::move ( sml) ;
138+ cached_sml = sml;
137139 merkleRootCached = merkleRootRet;
138140 mutatedCached = mutated;
139141
0 commit comments