From 8cad8cda446a7648ae2e7128e31042bd2fc3ebb3 Mon Sep 17 00:00:00 2001 From: Glenn Willen Date: Wed, 4 Jan 2023 16:33:35 -0800 Subject: [PATCH] Further fixes from code review --- src/init.cpp | 15 +++++++++------ src/net_processing.cpp | 2 +- src/txdb.cpp | 8 ++++---- src/txdb.h | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 9f9ffbe5d6..0aa3c9b6cb 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -980,22 +980,25 @@ bool AppInitParameterInteraction(const ArgsManager& args) fPruneMode = true; } + uint32_t epoch_length = chainparams.GetConsensus().dynamic_epoch_length; + if (epoch_length == std::numeric_limits::max()) { + // That's the default value, for non-dynafed chains and some tests. Pick a more sensible default here. + epoch_length = 20160; + } + if (args.IsArgSet("-trim_headers")) { 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 // back to current epoch start, and then an additional total_valid_epochs on top of that. // We add one epoch here for the current partial epoch, and then another one for good luck. - // NB: If we're non-dynafed, then: - // - total_valid_epochs = 1 - // - dynamic_epoch_length = std::numeric_limits::max() - // So this will work out to an unhelpfully-large number. XXX: Is this a problem? - nMustKeepFullHeaders = (chainparams.GetConsensus().total_valid_epochs + 2) * (chainparams.GetConsensus().dynamic_epoch_length); + + nMustKeepFullHeaders = (chainparams.GetConsensus().total_valid_epochs + 2) * epoch_length; // This is the number of headers we can have in flight downloading at a time, beyond the // set of blocks we've already validated. Capping this is necessary to keep memory usage // bounded during IBD. } - nHeaderDownloadBuffer = chainparams.GetConsensus().dynamic_epoch_length * 2; + nHeaderDownloadBuffer = epoch_length * 2; nConnectTimeout = args.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT); if (nConnectTimeout <= 0) { diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 872e399d21..91abd6025f 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -911,7 +911,7 @@ bool PeerManagerImpl::TipMayBeStale() bool PeerManagerImpl::CanDirectFetch() { if(!m_chainman.ActiveChain().Tip()) { - LogPrint(BCLog::NET, "Startup crash avoided\n"); + LogPrint(BCLog::NET, "Tried to call CanDirectFetch with no currently-active chain.\n"); return false; } return m_chainman.ActiveChain().Tip()->GetBlockTime() > GetAdjustedTime() - m_chainparams.GetConsensus().nPowTargetSpacing * 20; diff --git a/src/txdb.cpp b/src/txdb.cpp index f5266c1889..0a08d68cfd 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -339,7 +339,7 @@ bool CBlockTreeDB::WalkBlockIndexGutsForMaxHeight(int* nHeight) { return true; } -bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function insertBlockIndex, int trim_below_height) +bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function insertBlockIndex, int trimBelowHeight) { std::unique_ptr pcursor(NewIterator()); @@ -371,10 +371,10 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, pindexNew->nTx = diskindex.nTx; n_total++; - if (diskindex.nHeight >= trim_below_height) { + if (diskindex.nHeight >= trimBelowHeight) { n_untrimmed++; - pindexNew->proof = diskindex.proof; - pindexNew->m_dynafed_params = diskindex.m_dynafed_params; + pindexNew->proof = diskindex.proof; + pindexNew->m_dynafed_params = diskindex.m_dynafed_params; pindexNew->m_signblock_witness = diskindex.m_signblock_witness; const uint256 block_hash = pindexNew->GetBlockHash(); diff --git a/src/txdb.h b/src/txdb.h index 4360e50933..9d2461d473 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -85,7 +85,7 @@ public: void ReadReindexing(bool &fReindexing); bool WriteFlag(const std::string &name, bool fValue); bool ReadFlag(const std::string &name, bool &fValue); - bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function insertBlockIndex, int trim_below_height); + bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function insertBlockIndex, int trimBelowHeight); // ELEMENTS: bool WalkBlockIndexGutsForMaxHeight(int* nHeight); bool ReadPAKList(std::vector >& offline_list, std::vector >& online_list, bool& reject);