Skip to content

Commit 1549daa

Browse files
Merge dashpay#6622: fix: efficient build mnlistdiffs in rotation info
03c15a3 fix: actually bump protocol version (pasta) 606719a nit: s/use_leagcy_construction/use_legacy_construction/ (pasta) 7432879 fmt: apply clang-format suggestions (pasta) bdfd597 feat: only use efficient qrinfo construction for new shared protocol version (pasta) 71112dc refactor: more clang-format (UdjinM6) ff16e68 refactor: clang-format (UdjinM6) 1f16cf4 fix: sort indexes in GetLastBaseBlockHash (UdjinM6) 810ecd8 fix: don't use `baseBlockIndexes.back()` for the tip (UdjinM6) ec78465 fix: move BuildSimplifiedMNListDiff for block h (UdjinM6) 2a12ff6 bump guix (Konstantin Akimov) e8bbfd2 fix(perf): build mnlistdiffs in rotation info using dynamically the highest known base block (Odysseas Gabrielides) Pull request description: ## Issue being fixed or feature implemented See dashpay#6587 for history ## Breaking Changes This should remain backwards compatible ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK 03c15a3 Tree-SHA512: d378b519fe614f047b031509b0ec764160ae8674f7417ef571ce7e6fd98d6c94966e6c94681e7bb9c66ac334ce3640492948aae6bb45737dfdf480f6f58b4472
2 parents 0f8c35a + 03c15a3 commit 1549daa

File tree

6 files changed

+108
-29
lines changed

6 files changed

+108
-29
lines changed

src/llmq/snapshot.cpp

Lines changed: 96 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ UniValue CQuorumRotationInfo::ToJson() const
8787
bool 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;

src/llmq/snapshot.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,10 @@ class CQuorumRotationInfo
210210
bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotManager& qsnapman,
211211
const ChainstateManager& chainman, const CQuorumManager& qman,
212212
const CQuorumBlockProcessor& qblockman, const CGetQuorumRotationInfo& request,
213-
CQuorumRotationInfo& response, std::string& errorRet) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
214-
uint256 GetLastBaseBlockHash(Span<const CBlockIndex*> baseBlockIndexes, const CBlockIndex* blockIndex);
213+
bool use_legacy_construction, CQuorumRotationInfo& response, std::string& errorRet)
214+
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
215+
uint256 GetLastBaseBlockHash(Span<const CBlockIndex*> baseBlockIndexes, const CBlockIndex* blockIndex,
216+
bool use_legacy_construction);
215217

216218
class CQuorumSnapshotManager
217219
{

src/net_processing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5203,7 +5203,8 @@ void PeerManagerImpl::ProcessMessage(
52035203

52045204
llmq::CQuorumRotationInfo quorumRotationInfoRet;
52055205
std::string strError;
5206-
if (BuildQuorumRotationInfo(*m_dmnman, *m_llmq_ctx->qsnapman, m_chainman, *m_llmq_ctx->qman, *m_llmq_ctx->quorum_block_processor, cmd, quorumRotationInfoRet, strError)) {
5206+
bool use_legacy_construction = pfrom.GetCommonVersion() < EFFICIENT_QRINFO_VERSION;;
5207+
if (BuildQuorumRotationInfo(*m_dmnman, *m_llmq_ctx->qsnapman, m_chainman, *m_llmq_ctx->qman, *m_llmq_ctx->quorum_block_processor, cmd, use_legacy_construction, quorumRotationInfoRet, strError)) {
52075208
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::QUORUMROTATIONINFO, quorumRotationInfoRet));
52085209
} else {
52095210
strError = strprintf("getquorumrotationinfo failed for size(baseBlockHashes)=%d, blockRequestHash=%s. error=%s", cmd.baseBlockHashes.size(), cmd.blockRequestHash.ToString(), strError);

src/rpc/quorums.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ static RPCHelpMan quorum_rotationinfo()
860860
LOCK(cs_main);
861861

862862
if (!BuildQuorumRotationInfo(*CHECK_NONFATAL(node.dmnman), *llmq_ctx.qsnapman, chainman, *llmq_ctx.qman,
863-
*llmq_ctx.quorum_block_processor, cmd, quorumRotationInfoRet, strError)) {
863+
*llmq_ctx.quorum_block_processor, cmd, false, quorumRotationInfoRet, strError)) {
864864
throw JSONRPCError(RPC_INVALID_REQUEST, strError);
865865
}
866866

src/version.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313

14-
static const int PROTOCOL_VERSION = 70235;
14+
static const int PROTOCOL_VERSION = 70236;
1515

1616
//! initial proto version, to be increased after version/verack negotiation
1717
static const int INIT_PROTO_VERSION = 209;
@@ -61,6 +61,9 @@ static const int DSQ_INV_VERSION = 70234;
6161
//! Maximum header count for HEADRES2 message was increased from 2000 to 8000 in this version
6262
static const int INCREASE_MAX_HEADERS2_VERSION = 70235;
6363

64+
//! Behavior of QRINFO is changed in this protocol version
65+
static const int EFFICIENT_QRINFO_VERSION = 70236;
66+
6467
// Make sure that none of the values above collide with `ADDRV2_FORMAT`.
6568

6669
#endif // BITCOIN_VERSION_H

test/functional/test_framework/p2p.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
MIN_P2P_VERSION_SUPPORTED = 60001
101101
# The P2P version that this test framework implements and sends in its `version` message
102102
# Version 70235 increased max header count for HEADERS2 message from 2000 to 8000
103-
P2P_VERSION = 70235
103+
P2P_VERSION = 70236
104104
# The services that this test framework offers in its `version` message
105105
P2P_SERVICES = NODE_NETWORK | NODE_HEADERS_COMPRESSED
106106
# The P2P user agent string that this test framework sends in its `version` message

0 commit comments

Comments
 (0)