Skip to content

Commit

Permalink
Use custom cache size anchor and SPV DBs (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar authored Aug 2, 2022
1 parent 3313a76 commit 503b628
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1322,10 +1322,10 @@ bool AppInitLockDataDirectory()
return true;
}

void SetupAnchorSPVDatabases(bool resync) {
void SetupAnchorSPVDatabases(bool resync, int64_t customCache) {
// Close and open database
panchors.reset();
panchors = std::make_unique<CAnchorIndex>(nDefaultDbCache << 20, false, gArgs.GetBoolArg("-spv", true) && resync);
panchors = std::make_unique<CAnchorIndex>(customCache, false, gArgs.GetBoolArg("-spv", true) && resync);

// load anchors after spv due to spv (and spv height) not set before (no last height yet)
if (gArgs.GetBoolArg("-spv", true)) {
Expand All @@ -1336,9 +1336,9 @@ void SetupAnchorSPVDatabases(bool resync) {
if (Params().NetworkIDString() == "regtest") {
spv::pspv = std::make_unique<spv::CFakeSpvWrapper>();
} else if (Params().NetworkIDString() == "test" || Params().NetworkIDString() == "devnet") {
spv::pspv = std::make_unique<spv::CSpvWrapper>(false, nMinDbCache << 20, false, resync);
spv::pspv = std::make_unique<spv::CSpvWrapper>(false, customCache, false, resync);
} else {
spv::pspv = std::make_unique<spv::CSpvWrapper>(true, nMinDbCache << 20, false, resync);
spv::pspv = std::make_unique<spv::CSpvWrapper>(true, customCache, false, resync);
}
}
}
Expand Down Expand Up @@ -1907,11 +1907,11 @@ bool AppInitMain(InitInterfaces& interfaces)
panchorauths = std::make_unique<CAnchorAuthIndex>();
panchorAwaitingConfirms.reset();
panchorAwaitingConfirms = std::make_unique<CAnchorAwaitingConfirms>();
SetupAnchorSPVDatabases(gArgs.GetBoolArg("-spv_resync", fReindex || fReindexChainState));
SetupAnchorSPVDatabases(gArgs.GetBoolArg("-spv_resync", fReindex || fReindexChainState), nCustomCacheSize);

// Check if DB version changed
if (spv::pspv && SPV_DB_VERSION != spv::pspv->GetDBVersion()) {
SetupAnchorSPVDatabases(true);
SetupAnchorSPVDatabases(true, nCustomCacheSize);
assert(spv::pspv->SetDBVersion() == SPV_DB_VERSION);
LogPrintf("Cleared anchor and SPV dasebase. SPV DB version set to %d\n", SPV_DB_VERSION);
}
Expand Down

0 comments on commit 503b628

Please sign in to comment.