Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 2,271 Lines • ▼ Show 20 Lines | node.banman = std::make_unique<BanMan>( | ||||
args.GetDataDirNet() / "banlist.dat", config.GetChainParams(), | args.GetDataDirNet() / "banlist.dat", config.GetChainParams(), | ||||
&uiInterface, args.GetIntArg("-bantime", DEFAULT_MISBEHAVING_BANTIME)); | &uiInterface, args.GetIntArg("-bantime", DEFAULT_MISBEHAVING_BANTIME)); | ||||
assert(!node.connman); | assert(!node.connman); | ||||
node.connman = std::make_unique<CConnman>( | node.connman = std::make_unique<CConnman>( | ||||
config, GetRand(std::numeric_limits<uint64_t>::max()), | config, GetRand(std::numeric_limits<uint64_t>::max()), | ||||
GetRand(std::numeric_limits<uint64_t>::max()), *node.addrman, | GetRand(std::numeric_limits<uint64_t>::max()), *node.addrman, | ||||
args.GetBoolArg("-networkactive", true)); | args.GetBoolArg("-networkactive", true)); | ||||
assert(!node.mempool); | |||||
int check_ratio = std::min<int>( | |||||
std::max<int>( | |||||
args.GetIntArg("-checkmempool", | |||||
chainparams.DefaultConsistencyChecks() ? 1 : 0), | |||||
0), | |||||
1000000); | |||||
node.mempool = std::make_unique<CTxMemPool>(check_ratio); | |||||
assert(!node.chainman); | |||||
node.chainman = std::make_unique<ChainstateManager>(); | |||||
ChainstateManager &chainman = *node.chainman; | |||||
assert(!node.peerman); | |||||
node.peerman = PeerManager::make( | |||||
chainparams, *node.connman, *node.addrman, node.banman.get(), chainman, | |||||
*node.mempool, args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)); | |||||
RegisterValidationInterface(node.peerman.get()); | |||||
// sanitize comments per BIP-0014, format user agent and check total size | // sanitize comments per BIP-0014, format user agent and check total size | ||||
std::vector<std::string> uacomments; | std::vector<std::string> uacomments; | ||||
for (const std::string &cmt : args.GetArgs("-uacomment")) { | for (const std::string &cmt : args.GetArgs("-uacomment")) { | ||||
if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) { | if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) { | ||||
return InitError(strprintf( | return InitError(strprintf( | ||||
_("User Agent comment (%s) contains unsafe characters."), cmt)); | _("User Agent comment (%s) contains unsafe characters."), cmt)); | ||||
} | } | ||||
uacomments.push_back(cmt); | uacomments.push_back(cmt); | ||||
▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | #endif | ||||
} | } | ||||
LogPrintf("* Using %.1f MiB for chain state database\n", | LogPrintf("* Using %.1f MiB for chain state database\n", | ||||
cache_sizes.coins_db * (1.0 / 1024 / 1024)); | cache_sizes.coins_db * (1.0 / 1024 / 1024)); | ||||
LogPrintf("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of " | LogPrintf("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of " | ||||
"unused mempool space)\n", | "unused mempool space)\n", | ||||
cache_sizes.coins * (1.0 / 1024 / 1024), | cache_sizes.coins * (1.0 / 1024 / 1024), | ||||
nMempoolSizeMax * (1.0 / 1024 / 1024)); | nMempoolSizeMax * (1.0 / 1024 / 1024)); | ||||
assert(!node.mempool); | |||||
assert(!node.chainman); | |||||
int check_ratio = std::min<int>( | |||||
std::max<int>( | |||||
args.GetIntArg("-checkmempool", | |||||
chainparams.DefaultConsistencyChecks() ? 1 : 0), | |||||
0), | |||||
1000000); | |||||
bool fLoaded = false; | bool fLoaded = false; | ||||
while (!fLoaded && !ShutdownRequested()) { | while (!fLoaded && !ShutdownRequested()) { | ||||
node.mempool = std::make_unique<CTxMemPool>(check_ratio); | |||||
node.chainman = std::make_unique<ChainstateManager>(); | |||||
ChainstateManager &chainman = *node.chainman; | |||||
const bool fReset = fReindex; | const bool fReset = fReindex; | ||||
bilingual_str strLoadError; | bilingual_str strLoadError; | ||||
uiInterface.InitMessage(_("Loading block index...").translated); | uiInterface.InitMessage(_("Loading block index...").translated); | ||||
const int64_t load_block_index_start_time = GetTimeMillis(); | const int64_t load_block_index_start_time = GetTimeMillis(); | ||||
std::optional<ChainstateLoadingError> rv; | std::optional<ChainstateLoadingError> rv; | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | #endif | ||||
// requested to kill the GUI during the last operation. If so, exit. | // requested to kill the GUI during the last operation. If so, exit. | ||||
// As the program has not fully started yet, Shutdown() is possibly | // As the program has not fully started yet, Shutdown() is possibly | ||||
// overkill. | // overkill. | ||||
if (ShutdownRequested()) { | if (ShutdownRequested()) { | ||||
LogPrintf("Shutdown requested. Exiting.\n"); | LogPrintf("Shutdown requested. Exiting.\n"); | ||||
return false; | return false; | ||||
} | } | ||||
ChainstateManager &chainman = *Assert(node.chainman); | |||||
assert(!node.peerman); | |||||
node.peerman = PeerManager::make( | |||||
chainparams, *node.connman, *node.addrman, node.banman.get(), chainman, | |||||
*node.mempool, args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)); | |||||
RegisterValidationInterface(node.peerman.get()); | |||||
// Encoded addresses using cashaddr instead of base58. | // Encoded addresses using cashaddr instead of base58. | ||||
// We do this by default to avoid confusion with BTC addresses. | // We do this by default to avoid confusion with BTC addresses. | ||||
config.SetCashAddrEncoding(args.GetBoolArg("-usecashaddr", true)); | config.SetCashAddrEncoding(args.GetBoolArg("-usecashaddr", true)); | ||||
// Step 7.5 (I guess ?): Initialize Avalanche. | // Step 7.5 (I guess ?): Initialize Avalanche. | ||||
bilingual_str avalancheError; | bilingual_str avalancheError; | ||||
g_avalanche = avalanche::Processor::MakeProcessor( | g_avalanche = avalanche::Processor::MakeProcessor( | ||||
args, *node.chain, node.connman.get(), chainman, node.mempool.get(), | args, *node.chain, node.connman.get(), chainman, node.mempool.get(), | ||||
▲ Show 20 Lines • Show All 362 Lines • Show Last 20 Lines |