aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2023-12-19 10:30:14 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2024-01-15 10:28:20 -0300
commit97df4e38879d2644aeec34c1eef241fed627333e (patch)
treee959873dd17fbc306f8db99a078252be745073d1 /src/init.cpp
parentdd391944dc2d4e7dda9439647e603b41ba751b78 (diff)
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.
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 481d5d398d..f389ba2f9d 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -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));