From 6367320f70ff4c2de80662693bfea92c130d3935 Mon Sep 17 00:00:00 2001 From: Pablo Greco Date: Thu, 29 Jun 2023 12:26:22 -0700 Subject: [PATCH] Restore NODE_NETWORK functionality with trim_headers --- src/init.cpp | 9 ++------- src/net_processing.cpp | 11 ++++++----- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index fe772e5899..f3098e7f4b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1011,7 +1011,7 @@ bool AppInitParameterInteraction(const ArgsManager& args) } 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"); + LogPrintf("Configured for header-trimming mode. This will reduce memory usage substantially, but will increase IO usage when the headers need to be temporarily untrimmed.\n"); node::fTrimHeaders = true; // This calculation is driven by GetValidFedpegScripts in pegins.cpp, which walks the chain // back to current epoch start, and then an additional total_valid_epochs on top of that. @@ -1713,7 +1713,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) // if pruning, unset the service bit and perform the initial blockstore prune // after any wallet rescanning has taken place. - if (fPruneMode || node::fTrimHeaders) { + if (fPruneMode) { LogPrintf("Unsetting NODE_NETWORK on prune mode\n"); nLocalServices = ServiceFlags(nLocalServices & ~NODE_NETWORK); if (!fReindex) { @@ -1725,11 +1725,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) } } - if (node::fTrimHeaders) { - LogPrintf("Unsetting NODE_NETWORK_LIMITED on header trim mode\n"); - nLocalServices = ServiceFlags(nLocalServices & ~NODE_NETWORK_LIMITED); - } - // ********************************************************* Step 11: import blocks if (!CheckDiskSpace(gArgs.GetDataDirNet())) { diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 8f62280b6a..8ab454d3e0 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3305,12 +3305,13 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, for (; pindex; pindex = m_chainman.ActiveChain().Next(pindex)) { if (pindex->trimmed()) { - // For simplicity, if any of the headers they're asking for are trimmed, - // just drop the request. - LogPrint(BCLog::NET, "%s: ignoring getheaders from peer=%i which would return at least one trimmed header\n", __func__, pfrom.GetId()); - return; + // Header is trimmed, reload from disk before sending + CBlockIndex tmpBlockIndexFull; + const CBlockIndex* pindexfull = pindex->untrim_to(&tmpBlockIndexFull); + vHeaders.push_back(pindexfull->GetBlockHeader()); + } else { + vHeaders.push_back(pindex->GetBlockHeader()); } - vHeaders.push_back(pindex->GetBlockHeader()); if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop) break; }