@@ -121,12 +121,25 @@ bool CalcCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindexPrev
121
121
int64_t nTime3 = GetTimeMicros (); nTimeSMNL += nTime3 - nTime2;
122
122
LogPrint (" bench" , " - CSimplifiedMNList: %.2fms [%.2fs]\n " , 0.001 * (nTime3 - nTime2), nTimeSMNL * 0.000001 );
123
123
124
+ static CSimplifiedMNList smlCached;
125
+ static uint256 merkleRootCached;
126
+ static bool mutatedCached{false };
127
+
128
+ if (sml.mnList == smlCached.mnList ) {
129
+ merkleRootRet = merkleRootCached;
130
+ return !mutatedCached;
131
+ }
132
+
124
133
bool mutated = false ;
125
134
merkleRootRet = sml.CalcMerkleRoot (&mutated);
126
135
127
136
int64_t nTime4 = GetTimeMicros (); nTimeMerkle += nTime4 - nTime3;
128
137
LogPrint (" bench" , " - CalcMerkleRoot: %.2fms [%.2fs]\n " , 0.001 * (nTime4 - nTime3), nTimeMerkle * 0.000001 );
129
138
139
+ smlCached = std::move (sml);
140
+ merkleRootCached = merkleRootRet;
141
+ mutatedCached = mutated;
142
+
130
143
return !mutated;
131
144
}
132
145
@@ -139,24 +152,33 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
139
152
140
153
int64_t nTime1 = GetTimeMicros ();
141
154
155
+ static std::map<Consensus::LLMQType, std::vector<const CBlockIndex*>> quorumsCached;
156
+ static std::map<Consensus::LLMQType, std::vector<uint256>> qcHashesCached;
157
+
142
158
auto quorums = llmq::quorumBlockProcessor->GetMinedAndActiveCommitmentsUntilBlock (pindexPrev);
143
159
std::map<Consensus::LLMQType, std::vector<uint256>> qcHashes;
144
160
size_t hashCount = 0 ;
145
161
146
162
int64_t nTime2 = GetTimeMicros (); nTimeMinedAndActive += nTime2 - nTime1;
147
163
LogPrint (" bench" , " - GetMinedAndActiveCommitmentsUntilBlock: %.2fms [%.2fs]\n " , 0.001 * (nTime2 - nTime1), nTimeMinedAndActive * 0.000001 );
148
164
149
- for (const auto & p : quorums) {
150
- auto & v = qcHashes[p.first ];
151
- v.reserve (p.second .size ());
152
- for (const auto & p2 : p.second ) {
153
- llmq::CFinalCommitment qc;
154
- uint256 minedBlockHash;
155
- bool found = llmq::quorumBlockProcessor->GetMinedCommitment (p.first , p2->GetBlockHash (), qc, minedBlockHash);
156
- assert (found);
157
- v.emplace_back (::SerializeHash (qc));
158
- hashCount++;
165
+ if (quorums == quorumsCached) {
166
+ qcHashes = qcHashesCached;
167
+ } else {
168
+ for (const auto & p : quorums) {
169
+ auto & v = qcHashes[p.first ];
170
+ v.reserve (p.second .size ());
171
+ for (const auto & p2 : p.second ) {
172
+ llmq::CFinalCommitment qc;
173
+ uint256 minedBlockHash;
174
+ bool found = llmq::quorumBlockProcessor->GetMinedCommitment (p.first , p2->GetBlockHash (), qc, minedBlockHash);
175
+ assert (found);
176
+ v.emplace_back (::SerializeHash (qc));
177
+ hashCount++;
178
+ }
159
179
}
180
+ quorumsCached = quorums;
181
+ qcHashesCached = qcHashes;
160
182
}
161
183
162
184
int64_t nTime3 = GetTimeMicros (); nTimeMined += nTime3 - nTime2;
0 commit comments