From d6d8b6bd70d7f436d764468b9f8f158ca0ae19b7 Mon Sep 17 00:00:00 2001 From: Pablo Greco Date: Wed, 14 Jun 2023 16:30:09 -0700 Subject: [PATCH 1/6] Fix bug enabling trim_headers --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index eafaac9d2d6..962a2009962 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -986,7 +986,7 @@ bool AppInitParameterInteraction(const ArgsManager& args) epoch_length = 20160; } - if (args.IsArgSet("-trim_headers")) { + if (args.GetBoolArg("-trim_headers", false)) { LogPrintf("Configured for header-trimming mode. This will reduce memory usage substantially, but we will be unable to serve as a full P2P peer, and certain header fields may be missing from JSON RPC output.\n"); fTrimHeaders = true; // This calculation is driven by GetValidFedpegScripts in pegins.cpp, which walks the chain From e0267bc900f6842cd61b8189d924cc1b633166b3 Mon Sep 17 00:00:00 2001 From: Pablo Greco Date: Mon, 12 Jun 2023 16:41:15 -0700 Subject: [PATCH 2/6] Fix 'ignored-qualifiers' compile warning --- src/chain.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chain.h b/src/chain.h index 231113534ae..916e331373c 100644 --- a/src/chain.h +++ b/src/chain.h @@ -230,7 +230,7 @@ class CBlockIndex return proof.value(); } - const bool dynafed_block() const { + bool dynafed_block() const { if (m_trimmed) { return m_trimmed_dynafed_block; } From 3b477248bdeb0381060fa409ed24f802f2221e25 Mon Sep 17 00:00:00 2001 From: Pablo Greco Date: Mon, 12 Jun 2023 16:41:45 -0700 Subject: [PATCH 3/6] Fix double ; typo --- src/chain.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chain.h b/src/chain.h index 916e331373c..03c06b40e92 100644 --- a/src/chain.h +++ b/src/chain.h @@ -450,7 +450,7 @@ class CDiskBlockIndex : public CBlockIndex } READWRITE(nVersion); } - bool is_dyna = obj.RemoveDynaFedMaskOnSerialize(ser_action.ForRead());; + bool is_dyna = obj.RemoveDynaFedMaskOnSerialize(ser_action.ForRead()); READWRITE(obj.hashPrev); READWRITE(obj.hashMerkleRoot); From c87c8acabe6d397a08e79315ab470d9635d590f1 Mon Sep 17 00:00:00 2001 From: Pablo Greco Date: Fri, 14 Jul 2023 20:37:57 -0700 Subject: [PATCH 4/6] Rename dynafed_block method for clarity --- src/chain.h | 2 +- src/rpc/blockchain.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chain.h b/src/chain.h index 03c06b40e92..9d73ea5ef01 100644 --- a/src/chain.h +++ b/src/chain.h @@ -230,7 +230,7 @@ class CBlockIndex return proof.value(); } - bool dynafed_block() const { + bool is_dynafed_block() const { if (m_trimmed) { return m_trimmed_dynafed_block; } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 6bc6a996150..61713f1ee18 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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_block()) { + if (!blockindex->is_dynafed_block()) { if (blockindex->trimmed()) { result.pushKV("signblock_witness_asm", ""); result.pushKV("signblock_witness_hex", ""); From d02efe889fa9ad132787038d75a354722f399bfd Mon Sep 17 00:00:00 2001 From: Pablo Greco Date: Mon, 12 Jun 2023 16:42:21 -0700 Subject: [PATCH 5/6] Avoid assert flushing to disk with trim_headers enabled --- src/chain.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chain.h b/src/chain.h index 9d73ea5ef01..19ca287bd8e 100644 --- a/src/chain.h +++ b/src/chain.h @@ -417,12 +417,12 @@ class CDiskBlockIndex : public CBlockIndex nVersion = ~CBlockHeader::DYNAFED_HF_MASK & nVersion; return is_dyna; } else { - return !dynafed_params().IsNull(); + return is_dynafed_block(); } } bool RemoveDynaFedMaskOnSerialize(bool for_read) const { assert(!for_read); - return !dynafed_params().IsNull(); + return is_dynafed_block(); } SERIALIZE_METHODS(CDiskBlockIndex, obj) @@ -445,7 +445,7 @@ class CDiskBlockIndex : public CBlockIndex READWRITE(obj.nVersion); } else { int32_t nVersion = obj.nVersion; - if (!obj.dynafed_params().IsNull()) { + if (obj.is_dynafed_block()) { nVersion |= CBlockHeader::DYNAFED_HF_MASK; } READWRITE(nVersion); From 88c3b6f8cfad987718d636a3ee90c991369ccd12 Mon Sep 17 00:00:00 2001 From: Pablo Greco Date: Thu, 29 Jun 2023 10:37:53 -0700 Subject: [PATCH 6/6] Make trim checks inline --- src/chain.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chain.h b/src/chain.h index 19ca287bd8e..40ec115728e 100644 --- a/src/chain.h +++ b/src/chain.h @@ -217,11 +217,11 @@ class CBlockIndex m_signblock_witness = std::nullopt; } - bool trimmed() const { + inline bool trimmed() const { return m_trimmed; } - void assert_untrimmed() const { + inline void assert_untrimmed() const { assert(!m_trimmed); }