Skip to content

Commit d42cb79

Browse files
committed
Optionally populate BlockAndHeaderTipInfo during AppInitMain
1 parent b354a14 commit d42cb79

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/init.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <index/blockfilterindex.h>
2525
#include <index/txindex.h>
2626
#include <interfaces/chain.h>
27+
#include <interfaces/node.h>
2728
#include <key.h>
2829
#include <miner.h>
2930
#include <net.h>
@@ -1242,7 +1243,7 @@ bool AppInitLockDataDirectory()
12421243
return true;
12431244
}
12441245

1245-
bool AppInitMain(const util::Ref& context, NodeContext& node)
1246+
bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
12461247
{
12471248
const CChainParams& chainparams = Params();
12481249
// ********************************************************* Step 4a: application initialization
@@ -1877,6 +1878,15 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
18771878
LOCK(cs_main);
18781879
LogPrintf("block tree size = %u\n", chainman.BlockIndex().size());
18791880
chain_active_height = chainman.ActiveChain().Height();
1881+
if (tip_info) {
1882+
tip_info->block_height = chain_active_height;
1883+
tip_info->block_time = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockTime() : Params().GenesisBlock().GetBlockTime();
1884+
tip_info->verification_progress = GuessVerificationProgress(Params().TxData(), chainman.ActiveChain().Tip());
1885+
}
1886+
if (tip_info && ::pindexBestHeader) {
1887+
tip_info->header_height = ::pindexBestHeader->nHeight;
1888+
tip_info->header_time = ::pindexBestHeader->GetBlockTime();
1889+
}
18801890
}
18811891
LogPrintf("nBestHeight = %d\n", chain_active_height);
18821892

src/init.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <util/system.h>
1212

1313
struct NodeContext;
14+
namespace interfaces {
15+
struct BlockAndHeaderTipInfo;
16+
}
1417
namespace boost {
1518
class thread_group;
1619
} // namespace boost
@@ -54,7 +57,7 @@ bool AppInitLockDataDirectory();
5457
* @note This should only be done after daemonization. Call Shutdown() if this function fails.
5558
* @pre Parameters should be parsed and config file should be read, AppInitLockDataDirectory should have been called.
5659
*/
57-
bool AppInitMain(const util::Ref& context, NodeContext& node);
60+
bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
5861

5962
/**
6063
* Register all arguments with the ArgsManager

0 commit comments

Comments
 (0)