@@ -87,7 +87,7 @@ UniValue CQuorumRotationInfo::ToJson() const
8787bool BuildQuorumRotationInfo (CDeterministicMNManager& dmnman, CQuorumSnapshotManager& qsnapman,
8888 const ChainstateManager& chainman, const CQuorumManager& qman,
8989 const CQuorumBlockProcessor& qblockman, const CGetQuorumRotationInfo& request,
90- CQuorumRotationInfo& response, std::string& errorRet)
90+ bool use_legacy_construction, CQuorumRotationInfo& response, std::string& errorRet)
9191{
9292 AssertLockHeld (cs_main);
9393
@@ -112,19 +112,23 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan
112112 }
113113 baseBlockIndexes.push_back (blockIndex);
114114 }
115- std::sort (baseBlockIndexes.begin (), baseBlockIndexes.end (), [](const CBlockIndex* a, const CBlockIndex* b) {
116- return a->nHeight < b->nHeight ;
117- });
115+ if (use_legacy_construction) {
116+ std::sort (baseBlockIndexes.begin (), baseBlockIndexes.end (),
117+ [](const CBlockIndex* a, const CBlockIndex* b) { return a->nHeight < b->nHeight ; });
118+ }
118119 }
119120
120121 const CBlockIndex* tipBlockIndex = chainman.ActiveChain ().Tip ();
121122 if (!tipBlockIndex) {
122123 errorRet = strprintf (" tip block not found" );
123124 return false ;
124125 }
125- // Build MN list Diff always with highest baseblock
126- if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman, baseBlockIndexes.back ()->GetBlockHash (), tipBlockIndex->GetBlockHash (), response.mnListDiffTip , errorRet)) {
127- return false ;
126+ if (use_legacy_construction) {
127+ // Build MN list Diff always with highest baseblock
128+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman, baseBlockIndexes.back ()->GetBlockHash (),
129+ tipBlockIndex->GetBlockHash (), response.mnListDiffTip , errorRet)) {
130+ return false ;
131+ }
128132 }
129133
130134 const CBlockIndex* blockIndex = chainman.m_blockman .LookupBlockIndex (request.blockRequestHash );
@@ -149,15 +153,19 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan
149153 return false ;
150154 }
151155
152- const CBlockIndex* pWorkBlockIndex = hBlockIndex->GetAncestor (hBlockIndex->nHeight - workDiff);
153- if (!pWorkBlockIndex ) {
156+ const CBlockIndex* pWorkBlockHIndex = hBlockIndex->GetAncestor (hBlockIndex->nHeight - workDiff);
157+ if (!pWorkBlockHIndex ) {
154158 errorRet = strprintf (" Can not find work block H" );
155159 return false ;
156160 }
157161
158- // Build MN list Diff always with highest baseblock
159- if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman, GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockIndex), pWorkBlockIndex->GetBlockHash (), response.mnListDiffH , errorRet)) {
160- return false ;
162+ if (use_legacy_construction) {
163+ // Build MN list Diff always with highest baseblock
164+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman,
165+ GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHIndex, use_legacy_construction),
166+ pWorkBlockHIndex->GetBlockHash (), response.mnListDiffH , errorRet)) {
167+ return false ;
168+ }
161169 }
162170
163171 const CBlockIndex* pBlockHMinusCIndex = tipBlockIndex->GetAncestor (hBlockIndex->nHeight - cycleLength);
@@ -202,8 +210,12 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan
202210 const CBlockIndex* pWorkBlockHMinus4CIndex = pBlockHMinus4CIndex->GetAncestor (pBlockHMinus4CIndex->nHeight - workDiff);
203211 // Checked later if extraShare is on
204212
205- if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman, GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHMinusCIndex), pWorkBlockHMinusCIndex->GetBlockHash (), response.mnListDiffAtHMinusC , errorRet)) {
206- return false ;
213+ if (use_legacy_construction) {
214+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman,
215+ GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHMinusCIndex, use_legacy_construction),
216+ pWorkBlockHMinusCIndex->GetBlockHash (), response.mnListDiffAtHMinusC , errorRet)) {
217+ return false ;
218+ }
207219 }
208220
209221 auto snapshotHMinusC = qsnapman.GetSnapshotForBlock (llmqType, pBlockHMinusCIndex);
@@ -214,8 +226,13 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan
214226 response.quorumSnapshotAtHMinusC = std::move (snapshotHMinusC.value ());
215227 }
216228
217- if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman, GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHMinus2CIndex), pWorkBlockHMinus2CIndex->GetBlockHash (), response.mnListDiffAtHMinus2C , errorRet)) {
218- return false ;
229+ if (use_legacy_construction) {
230+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman,
231+ GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHMinus2CIndex,
232+ use_legacy_construction),
233+ pWorkBlockHMinus2CIndex->GetBlockHash (), response.mnListDiffAtHMinus2C , errorRet)) {
234+ return false ;
235+ }
219236 }
220237
221238 auto snapshotHMinus2C = qsnapman.GetSnapshotForBlock (llmqType, pBlockHMinus2CIndex);
@@ -226,8 +243,13 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan
226243 response.quorumSnapshotAtHMinus2C = std::move (snapshotHMinus2C.value ());
227244 }
228245
229- if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman, GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHMinus3CIndex), pWorkBlockHMinus3CIndex->GetBlockHash (), response.mnListDiffAtHMinus3C , errorRet)) {
230- return false ;
246+ if (use_legacy_construction) {
247+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman,
248+ GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHMinus3CIndex,
249+ use_legacy_construction),
250+ pWorkBlockHMinus3CIndex->GetBlockHash (), response.mnListDiffAtHMinus3C , errorRet)) {
251+ return false ;
252+ }
231253 }
232254
233255 auto snapshotHMinus3C = qsnapman.GetSnapshotForBlock (llmqType, pBlockHMinus3CIndex);
@@ -255,10 +277,15 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan
255277 }
256278
257279 CSimplifiedMNListDiff mn4c;
258- if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman, GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHMinus4CIndex), pWorkBlockHMinus4CIndex->GetBlockHash (), mn4c, errorRet)) {
280+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman,
281+ GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHMinus4CIndex,
282+ use_legacy_construction),
283+ pWorkBlockHMinus4CIndex->GetBlockHash (), mn4c, errorRet)) {
259284 return false ;
260285 }
261-
286+ if (!use_legacy_construction) {
287+ baseBlockIndexes.push_back (pWorkBlockHMinus4CIndex);
288+ }
262289 response.mnListDiffAtHMinus4C = std::move (mn4c);
263290 } else {
264291 response.extraShare = false ;
@@ -311,19 +338,65 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan
311338 }
312339
313340 CSimplifiedMNListDiff mnhneeded;
314- if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman, GetLastBaseBlockHash (baseBlockIndexes, pNeededWorkBlockIndex), pNeededWorkBlockIndex->GetBlockHash (), mnhneeded, errorRet)) {
341+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman,
342+ GetLastBaseBlockHash (baseBlockIndexes, pNeededWorkBlockIndex, use_legacy_construction),
343+ pNeededWorkBlockIndex->GetBlockHash (), mnhneeded, errorRet)) {
315344 return false ;
316345 }
317-
346+ if (!use_legacy_construction) {
347+ baseBlockIndexes.push_back (pNeededWorkBlockIndex);
348+ }
318349 response.mnListDiffList .push_back (mnhneeded);
319350 }
320351
352+ if (!use_legacy_construction) {
353+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman,
354+ GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHMinus3CIndex,
355+ use_legacy_construction),
356+ pWorkBlockHMinus3CIndex->GetBlockHash (), response.mnListDiffAtHMinus3C , errorRet)) {
357+ return false ;
358+ }
359+ baseBlockIndexes.push_back (pWorkBlockHMinus3CIndex);
360+
361+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman,
362+ GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHMinus2CIndex,
363+ use_legacy_construction),
364+ pWorkBlockHMinus2CIndex->GetBlockHash (), response.mnListDiffAtHMinus2C , errorRet)) {
365+ return false ;
366+ }
367+ baseBlockIndexes.push_back (pWorkBlockHMinus2CIndex);
368+
369+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman,
370+ GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHMinusCIndex, use_legacy_construction),
371+ pWorkBlockHMinusCIndex->GetBlockHash (), response.mnListDiffAtHMinusC , errorRet)) {
372+ return false ;
373+ }
374+ baseBlockIndexes.push_back (pWorkBlockHMinusCIndex);
375+
376+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman,
377+ GetLastBaseBlockHash (baseBlockIndexes, pWorkBlockHIndex, use_legacy_construction),
378+ pWorkBlockHIndex->GetBlockHash (), response.mnListDiffH , errorRet)) {
379+ return false ;
380+ }
381+ baseBlockIndexes.push_back (pWorkBlockHIndex);
382+
383+ if (!BuildSimplifiedMNListDiff (dmnman, chainman, qblockman, qman,
384+ GetLastBaseBlockHash (baseBlockIndexes, tipBlockIndex, use_legacy_construction),
385+ tipBlockIndex->GetBlockHash (), response.mnListDiffTip , errorRet)) {
386+ return false ;
387+ }
388+ }
321389 return true ;
322390}
323391
324- uint256 GetLastBaseBlockHash (Span<const CBlockIndex*> baseBlockIndexes, const CBlockIndex* blockIndex)
392+ uint256 GetLastBaseBlockHash (Span<const CBlockIndex*> baseBlockIndexes, const CBlockIndex* blockIndex,
393+ bool use_legacy_construction)
325394{
326395 uint256 hash;
396+ if (!use_legacy_construction) {
397+ std::sort (baseBlockIndexes.begin (), baseBlockIndexes.end (),
398+ [](const CBlockIndex* a, const CBlockIndex* b) { return a->nHeight < b->nHeight ; });
399+ }
327400 for (const auto baseBlock : baseBlockIndexes) {
328401 if (baseBlock->nHeight >= blockIndex->nHeight )
329402 break ;
0 commit comments