Skip to content

Commit f2ce216

Browse files
Merge branch 'develop' of https://github.com/dashpay/dash into develop
2 parents 31f3032 + bcd14b0 commit f2ce216

17 files changed

+248
-144
lines changed

src/interfaces/wallet.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class Wallet
134134
std::string* purpose) = 0;
135135

136136
//! Get wallet address list.
137-
virtual std::vector<WalletAddress> getAddresses() = 0;
137+
virtual std::vector<WalletAddress> getAddresses() const = 0;
138138

139139
//! Get receive requests.
140140
virtual std::vector<std::string> getAddressReceiveRequests() = 0;

src/llmq/snapshot.cpp

+99-26
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,22 +338,68 @@ 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
{
326-
uint256 hash;
395+
if (!use_legacy_construction) {
396+
std::sort(baseBlockIndexes.begin(), baseBlockIndexes.end(),
397+
[](const CBlockIndex* a, const CBlockIndex* b) { return a->nHeight < b->nHeight; });
398+
}
399+
// default to genesis block
400+
uint256 hash{Params().GenesisBlock().GetHash()};
327401
for (const auto baseBlock : baseBlockIndexes) {
328-
if (baseBlock->nHeight >= blockIndex->nHeight)
329-
break;
402+
if (baseBlock->nHeight > blockIndex->nHeight) break;
330403
hash = baseBlock->GetBlockHash();
331404
}
332405
return hash;

src/llmq/snapshot.h

+4-2
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

+2-1
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

+1-1
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

+4-1
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

src/wallet/bdb.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,6 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const bool read_only, b
324324
env = database.env.get();
325325
pdb = database.m_db.get();
326326
strFile = database.strFile;
327-
if (!Exists(std::string("version"))) {
328-
bool fTmp = fReadOnly;
329-
fReadOnly = false;
330-
Write(std::string("version"), CLIENT_VERSION);
331-
fReadOnly = fTmp;
332-
}
333327
}
334328

335329
void BerkeleyDatabase::Open()

src/wallet/interfaces.cpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -205,29 +205,27 @@ class WalletImpl : public Wallet
205205
std::string* purpose) override
206206
{
207207
LOCK(m_wallet->cs_wallet);
208-
auto it = m_wallet->m_address_book.find(dest);
209-
if (it == m_wallet->m_address_book.end() || it->second.IsChange()) {
210-
return false;
211-
}
208+
const auto& entry = m_wallet->FindAddressBookEntry(dest, /*allow_change=*/false);
209+
if (!entry) return false; // addr not found
212210
if (name) {
213-
*name = it->second.GetLabel();
211+
*name = entry->GetLabel();
214212
}
215213
if (is_mine) {
216214
*is_mine = m_wallet->IsMine(dest);
217215
}
218216
if (purpose) {
219-
*purpose = it->second.purpose;
217+
*purpose = entry->purpose;
220218
}
221219
return true;
222220
}
223-
std::vector<WalletAddress> getAddresses() override
221+
std::vector<WalletAddress> getAddresses() const override
224222
{
225223
LOCK(m_wallet->cs_wallet);
226224
std::vector<WalletAddress> result;
227-
for (const auto& item : m_wallet->m_address_book) {
228-
if (item.second.IsChange()) continue;
229-
result.emplace_back(item.first, m_wallet->IsMine(item.first), item.second.GetLabel(), item.second.purpose);
230-
}
225+
m_wallet->ForEachAddrBookEntry([&](const CTxDestination& dest, const std::string& label, const std::string& purpose, bool is_change) EXCLUSIVE_LOCKS_REQUIRED(m_wallet->cs_wallet) {
226+
if (is_change) return;
227+
result.emplace_back(dest, m_wallet->IsMine(dest), label, purpose);
228+
});
231229
return result;
232230
}
233231
std::vector<std::string> getAddressReceiveRequests() override {

0 commit comments

Comments
 (0)