Skip to content

Commit 8cad8cd

Browse files
committed
Further fixes from code review
1 parent b9b7f65 commit 8cad8cd

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

src/init.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -980,22 +980,25 @@ bool AppInitParameterInteraction(const ArgsManager& args)
980980
fPruneMode = true;
981981
}
982982

983+
uint32_t epoch_length = chainparams.GetConsensus().dynamic_epoch_length;
984+
if (epoch_length == std::numeric_limits<uint32_t>::max()) {
985+
// That's the default value, for non-dynafed chains and some tests. Pick a more sensible default here.
986+
epoch_length = 20160;
987+
}
988+
983989
if (args.IsArgSet("-trim_headers")) {
984990
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");
985991
fTrimHeaders = true;
986992
// This calculation is driven by GetValidFedpegScripts in pegins.cpp, which walks the chain
987993
// back to current epoch start, and then an additional total_valid_epochs on top of that.
988994
// We add one epoch here for the current partial epoch, and then another one for good luck.
989-
// NB: If we're non-dynafed, then:
990-
// - total_valid_epochs = 1
991-
// - dynamic_epoch_length = std::numeric_limits<uint32_t>::max()
992-
// So this will work out to an unhelpfully-large number. XXX: Is this a problem?
993-
nMustKeepFullHeaders = (chainparams.GetConsensus().total_valid_epochs + 2) * (chainparams.GetConsensus().dynamic_epoch_length);
995+
996+
nMustKeepFullHeaders = (chainparams.GetConsensus().total_valid_epochs + 2) * epoch_length;
994997
// This is the number of headers we can have in flight downloading at a time, beyond the
995998
// set of blocks we've already validated. Capping this is necessary to keep memory usage
996999
// bounded during IBD.
9971000
}
998-
nHeaderDownloadBuffer = chainparams.GetConsensus().dynamic_epoch_length * 2;
1001+
nHeaderDownloadBuffer = epoch_length * 2;
9991002

10001003
nConnectTimeout = args.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT);
10011004
if (nConnectTimeout <= 0) {

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ bool PeerManagerImpl::TipMayBeStale()
911911
bool PeerManagerImpl::CanDirectFetch()
912912
{
913913
if(!m_chainman.ActiveChain().Tip()) {
914-
LogPrint(BCLog::NET, "Startup crash avoided\n");
914+
LogPrint(BCLog::NET, "Tried to call CanDirectFetch with no currently-active chain.\n");
915915
return false;
916916
}
917917
return m_chainman.ActiveChain().Tip()->GetBlockTime() > GetAdjustedTime() - m_chainparams.GetConsensus().nPowTargetSpacing * 20;

src/txdb.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ bool CBlockTreeDB::WalkBlockIndexGutsForMaxHeight(int* nHeight) {
339339
return true;
340340
}
341341

342-
bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, int trim_below_height)
342+
bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, int trimBelowHeight)
343343
{
344344
std::unique_ptr<CDBIterator> pcursor(NewIterator());
345345

@@ -371,10 +371,10 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
371371
pindexNew->nTx = diskindex.nTx;
372372

373373
n_total++;
374-
if (diskindex.nHeight >= trim_below_height) {
374+
if (diskindex.nHeight >= trimBelowHeight) {
375375
n_untrimmed++;
376-
pindexNew->proof = diskindex.proof;
377-
pindexNew->m_dynafed_params = diskindex.m_dynafed_params;
376+
pindexNew->proof = diskindex.proof;
377+
pindexNew->m_dynafed_params = diskindex.m_dynafed_params;
378378
pindexNew->m_signblock_witness = diskindex.m_signblock_witness;
379379

380380
const uint256 block_hash = pindexNew->GetBlockHash();

src/txdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class CBlockTreeDB : public CDBWrapper
8585
void ReadReindexing(bool &fReindexing);
8686
bool WriteFlag(const std::string &name, bool fValue);
8787
bool ReadFlag(const std::string &name, bool &fValue);
88-
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, int trim_below_height);
88+
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, int trimBelowHeight);
8989
// ELEMENTS:
9090
bool WalkBlockIndexGutsForMaxHeight(int* nHeight);
9191
bool ReadPAKList(std::vector<std::vector<unsigned char> >& offline_list, std::vector<std::vector<unsigned char> >& online_list, bool& reject);

0 commit comments

Comments
 (0)