mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
net: store best block tip time inside PeerManager
And implement 'ApproximateBestBlockDepth()' to estimate the distance, in blocks, between the best-known block and the network chain tip. Utilizing the best-block time and the chainparams blocks spacing to approximate it.
This commit is contained in:
@@ -1754,13 +1754,15 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
// ********************************************************* Step 12: start node
|
||||
|
||||
//// debug print
|
||||
int64_t best_block_time{};
|
||||
{
|
||||
LOCK(cs_main);
|
||||
LogPrintf("block tree size = %u\n", chainman.BlockIndex().size());
|
||||
chain_active_height = chainman.ActiveChain().Height();
|
||||
best_block_time = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockTime() : chainman.GetParams().GenesisBlock().GetBlockTime();
|
||||
if (tip_info) {
|
||||
tip_info->block_height = chain_active_height;
|
||||
tip_info->block_time = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockTime() : chainman.GetParams().GenesisBlock().GetBlockTime();
|
||||
tip_info->block_time = best_block_time;
|
||||
tip_info->verification_progress = GuessVerificationProgress(chainman.GetParams().TxData(), chainman.ActiveChain().Tip());
|
||||
}
|
||||
if (tip_info && chainman.m_best_header) {
|
||||
@@ -1769,7 +1771,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
}
|
||||
}
|
||||
LogPrintf("nBestHeight = %d\n", chain_active_height);
|
||||
if (node.peerman) node.peerman->SetBestHeight(chain_active_height);
|
||||
if (node.peerman) node.peerman->SetBestBlock(chain_active_height, std::chrono::seconds{best_block_time});
|
||||
|
||||
// Map ports with UPnP or NAT-PMP.
|
||||
StartMapPort(args.GetBoolArg("-upnp", DEFAULT_UPNP), args.GetBoolArg("-natpmp", DEFAULT_NATPMP));
|
||||
|
||||
Reference in New Issue
Block a user