Skip to content

RPC: Avoid assert by keeping a flag to identify trimmed dynafed blocks #1225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class CBlockIndex
std::optional<CScriptWitness> m_signblock_witness{};

bool m_trimmed{false};
bool m_trimmed_dynafed_block{false};

friend class CBlockTreeDB;

Expand All @@ -210,6 +211,7 @@ class CBlockIndex
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;
Expand All @@ -228,6 +230,13 @@ class CBlockIndex
return proof.value();
}

const bool dynafed_block() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang says

'const' type qualifier on return type has no effect

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this warning has been annoying me, I thought it was fixed on the 22.x branch but it is not

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for posting this, but it has no effect on my RPI4 even though I have the latest version. On startup I get the same assert error. Any tips for me?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you see the assertion on startup, it usually means that you started IBD without trim_headers and then enabled trim_headers without finishing IBD, so the headers chain is much longer than the blocks. Either way, let's continue that conversation in #1240

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();
Expand Down
10 changes: 2 additions & 8 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>");
Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down