Skip to content

Commit 7b20b41

Browse files
committed
Restore NODE_NETWORK functionality with trim_headers
1 parent eb8735b commit 7b20b41

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/init.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
987987
}
988988

989989
if (args.GetBoolArg("-trim_headers", false)) {
990-
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");
990+
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");
991991
fTrimHeaders = true;
992992
// This calculation is driven by GetValidFedpegScripts in pegins.cpp, which walks the chain
993993
// back to current epoch start, and then an additional total_valid_epochs on top of that.
@@ -1711,7 +1711,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17111711

17121712
// if pruning, unset the service bit and perform the initial blockstore prune
17131713
// after any wallet rescanning has taken place.
1714-
if (fPruneMode || fTrimHeaders) {
1714+
if (fPruneMode) {
17151715
LogPrintf("Unsetting NODE_NETWORK on prune mode\n");
17161716
nLocalServices = ServiceFlags(nLocalServices & ~NODE_NETWORK);
17171717
if (!fReindex) {
@@ -1723,11 +1723,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17231723
}
17241724
}
17251725

1726-
if (fTrimHeaders) {
1727-
LogPrintf("Unsetting NODE_NETWORK_LIMITED on header trim mode\n");
1728-
nLocalServices = ServiceFlags(nLocalServices & ~NODE_NETWORK_LIMITED);
1729-
}
1730-
17311726
if (DeploymentEnabled(chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT)) {
17321727
// Advertise witness capabilities.
17331728
// The option to not set NODE_WITNESS is only used in the tests and should be removed.

src/net_processing.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,12 +3183,13 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
31833183
for (; pindex; pindex = m_chainman.ActiveChain().Next(pindex))
31843184
{
31853185
if (pindex->trimmed()) {
3186-
// For simplicity, if any of the headers they're asking for are trimmed,
3187-
// just drop the request.
3188-
LogPrint(BCLog::NET, "%s: ignoring getheaders from peer=%i which would return at least one trimmed header\n", __func__, pfrom.GetId());
3189-
return;
3186+
// Header is trimmed, reload from disk before sending
3187+
CBlockIndex tmpBlockIndexFull;
3188+
const CBlockIndex* pindexfull = pindex->untrim_to(&tmpBlockIndexFull);
3189+
vHeaders.push_back(pindexfull->GetBlockHeader());
3190+
} else {
3191+
vHeaders.push_back(pindex->GetBlockHeader());
31903192
}
3191-
vHeaders.push_back(pindex->GetBlockHeader());
31923193
if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
31933194
break;
31943195
}

0 commit comments

Comments
 (0)