Merge pull request #1225 from psgreco/master-fix-assert-trim-rpc

RPC: Avoid assert by keeping a flag to identify trimmed dynafed blocks
This commit is contained in:
Byron Hambly 2023-03-17 16:09:39 +02:00 committed by GitHub
commit 6b826d5004
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 deletions

View file

@ -200,6 +200,7 @@ protected:
std::optional<CScriptWitness> m_signblock_witness{};
bool m_trimmed{false};
bool m_trimmed_dynafed_block{false};
friend class CBlockTreeDB;
@ -210,6 +211,7 @@ public:
void trim() {
assert_untrimmed();
m_trimmed = true;
m_trimmed_dynafed_block = !m_dynafed_params.value().IsNull();
proof = std::nullopt;
m_dynafed_params = std::nullopt;
m_signblock_witness = std::nullopt;
@ -228,6 +230,13 @@ public:
return proof.value();
}
const bool dynafed_block() const {
if (m_trimmed) {
return m_trimmed_dynafed_block;
}
return !m_dynafed_params.value().IsNull();
}
const DynaFedParams& dynafed_params() const {
assert_untrimmed();
return m_dynafed_params.value();

View file

@ -248,7 +248,7 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
result.pushKV("difficulty", GetDifficulty(blockindex));
result.pushKV("chainwork", blockindex->nChainWork.GetHex());
} else {
if (blockindex->dynafed_params().IsNull()) {
if (!blockindex->dynafed_block()) {
if (blockindex->trimmed()) {
result.pushKV("signblock_witness_asm", "<trimmed>");
result.pushKV("signblock_witness_hex", "<trimmed>");
@ -280,13 +280,7 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails)
{
UniValue result;
if (blockindex->trimmed()) {
CBlockIndex tmp = CBlockIndex(block.GetBlockHeader());
result = blockheaderToJSON(tip, &tmp);
} else {
result = blockheaderToJSON(tip, blockindex);
}
UniValue result = blockheaderToJSON(tip, blockindex);
result.pushKV("strippedsize", (int)::GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS));
result.pushKV("size", (int)::GetSerializeSize(block, PROTOCOL_VERSION));

View file

@ -389,6 +389,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
}
} else {
pindexNew->m_trimmed = true;
pindexNew->m_trimmed_dynafed_block = !diskindex.m_dynafed_params.value().IsNull();
}
pcursor->Next();