@@ -92,27 +92,49 @@ bool CalcCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindexPrev
92
92
93
93
CSimplifiedMNList sml (tmpMNList);
94
94
95
+ static CSimplifiedMNList smlCached;
96
+ static uint256 merkleRootCached;
97
+ static bool mutatedCached{false };
98
+
99
+ if (sml.mnList == smlCached.mnList ) {
100
+ merkleRootRet = merkleRootCached;
101
+ return !mutatedCached;
102
+ }
103
+
95
104
bool mutated = false ;
96
105
merkleRootRet = sml.CalcMerkleRoot (&mutated);
106
+ smlCached = std::move (sml);
107
+ merkleRootCached = merkleRootRet;
108
+ mutatedCached = mutated;
109
+
97
110
return !mutated;
98
111
}
99
112
100
113
bool CalcCbTxMerkleRootQuorums (const CBlock& block, const CBlockIndex* pindexPrev, uint256& merkleRootRet, CValidationState& state)
101
114
{
115
+ static std::map<Consensus::LLMQType, std::vector<const CBlockIndex*>> quorumsCached;
116
+ static std::map<Consensus::LLMQType, std::vector<uint256>> qcHashesCached;
117
+
102
118
auto quorums = llmq::quorumBlockProcessor->GetMinedAndActiveCommitmentsUntilBlock (pindexPrev);
103
119
std::map<Consensus::LLMQType, std::vector<uint256>> qcHashes;
104
120
size_t hashCount = 0 ;
105
- for (const auto & p : quorums) {
106
- auto & v = qcHashes[p.first ];
107
- v.reserve (p.second .size ());
108
- for (const auto & p2 : p.second ) {
109
- llmq::CFinalCommitment qc;
110
- uint256 minedBlockHash;
111
- bool found = llmq::quorumBlockProcessor->GetMinedCommitment (p.first , p2->GetBlockHash (), qc, minedBlockHash);
112
- assert (found);
113
- v.emplace_back (::SerializeHash (qc));
114
- hashCount++;
121
+ if (quorums == quorumsCached) {
122
+ qcHashes = qcHashesCached;
123
+ } else {
124
+ for (const auto & p : quorums) {
125
+ auto & v = qcHashes[p.first ];
126
+ v.reserve (p.second .size ());
127
+ for (const auto & p2 : p.second ) {
128
+ llmq::CFinalCommitment qc;
129
+ uint256 minedBlockHash;
130
+ bool found = llmq::quorumBlockProcessor->GetMinedCommitment (p.first , p2->GetBlockHash (), qc, minedBlockHash);
131
+ assert (found);
132
+ v.emplace_back (::SerializeHash (qc));
133
+ hashCount++;
134
+ }
115
135
}
136
+ quorumsCached = quorums;
137
+ qcHashesCached = qcHashes;
116
138
}
117
139
118
140
// now add the commitments from the current block, which are not returned by GetMinedAndActiveCommitmentsUntilBlock
0 commit comments