Skip to content

Commit 6b826d5

Browse files
authored
Merge pull request #1225 from psgreco/master-fix-assert-trim-rpc
RPC: Avoid assert by keeping a flag to identify trimmed dynafed blocks
2 parents 8c9268c + 8f16e00 commit 6b826d5

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/chain.h

+9
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ class CBlockIndex
200200
std::optional<CScriptWitness> m_signblock_witness{};
201201

202202
bool m_trimmed{false};
203+
bool m_trimmed_dynafed_block{false};
203204

204205
friend class CBlockTreeDB;
205206

@@ -210,6 +211,7 @@ class CBlockIndex
210211
void trim() {
211212
assert_untrimmed();
212213
m_trimmed = true;
214+
m_trimmed_dynafed_block = !m_dynafed_params.value().IsNull();
213215
proof = std::nullopt;
214216
m_dynafed_params = std::nullopt;
215217
m_signblock_witness = std::nullopt;
@@ -228,6 +230,13 @@ class CBlockIndex
228230
return proof.value();
229231
}
230232

233+
const bool dynafed_block() const {
234+
if (m_trimmed) {
235+
return m_trimmed_dynafed_block;
236+
}
237+
return !m_dynafed_params.value().IsNull();
238+
}
239+
231240
const DynaFedParams& dynafed_params() const {
232241
assert_untrimmed();
233242
return m_dynafed_params.value();

src/rpc/blockchain.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
248248
result.pushKV("difficulty", GetDifficulty(blockindex));
249249
result.pushKV("chainwork", blockindex->nChainWork.GetHex());
250250
} else {
251-
if (blockindex->dynafed_params().IsNull()) {
251+
if (!blockindex->dynafed_block()) {
252252
if (blockindex->trimmed()) {
253253
result.pushKV("signblock_witness_asm", "<trimmed>");
254254
result.pushKV("signblock_witness_hex", "<trimmed>");
@@ -280,13 +280,7 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
280280

281281
UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails)
282282
{
283-
UniValue result;
284-
if (blockindex->trimmed()) {
285-
CBlockIndex tmp = CBlockIndex(block.GetBlockHeader());
286-
result = blockheaderToJSON(tip, &tmp);
287-
} else {
288-
result = blockheaderToJSON(tip, blockindex);
289-
}
283+
UniValue result = blockheaderToJSON(tip, blockindex);
290284

291285
result.pushKV("strippedsize", (int)::GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS));
292286
result.pushKV("size", (int)::GetSerializeSize(block, PROTOCOL_VERSION));

src/txdb.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
389389
}
390390
} else {
391391
pindexNew->m_trimmed = true;
392+
pindexNew->m_trimmed_dynafed_block = !diskindex.m_dynafed_params.value().IsNull();
392393
}
393394

394395
pcursor->Next();

0 commit comments

Comments
 (0)