diff --git a/src/init.h b/src/init.h --- a/src/init.h +++ b/src/init.h @@ -18,6 +18,9 @@ class CWallet; class HTTPRPCRequestProcessor; struct NodeContext; +namespace interfaces { +struct BlockAndHeaderTipInfo; +} class RPCServer; namespace boost { @@ -74,7 +77,8 @@ */ bool AppInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor, - NodeContext &node); + NodeContext &node, + interfaces::BlockAndHeaderTipInfo *tip_info = nullptr); /** * Register all arguments with the ArgsManager diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -2115,7 +2116,8 @@ bool AppInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor, - NodeContext &node) { + NodeContext &node, + interfaces::BlockAndHeaderTipInfo *tip_info) { // Step 4a: application initialization const ArgsManager &args = *Assert(node.args); const CChainParams &chainparams = config.GetChainParams(); @@ -2907,6 +2909,19 @@ LOCK(cs_main); LogPrintf("block tree size = %u\n", chainman.BlockIndex().size()); chain_active_height = chainman.ActiveChain().Height(); + if (tip_info) { + tip_info->block_height = chain_active_height; + tip_info->block_time = + chainman.ActiveChain().Tip() + ? chainman.ActiveChain().Tip()->GetBlockTime() + : Params().GenesisBlock().GetBlockTime(); + tip_info->verification_progress = GuessVerificationProgress( + Params().TxData(), chainman.ActiveChain().Tip()); + } + if (tip_info && ::pindexBestHeader) { + tip_info->header_height = ::pindexBestHeader->nHeight; + tip_info->header_time = ::pindexBestHeader->GetBlockTime(); + } } LogPrintf("nBestHeight = %d\n", chain_active_height); diff --git a/src/interfaces/node.h b/src/interfaces/node.h --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -43,6 +43,15 @@ class Wallet; struct BlockTip; +//! Block and header tip information +struct BlockAndHeaderTipInfo { + int block_height; + int64_t block_time; + int header_height; + int64_t header_time; + double verification_progress; +}; + //! Top-level interface for a bitcoin node (bitcoind process). class Node { public: @@ -63,7 +72,8 @@ //! Start node. virtual bool appInitMain(Config &config, RPCServer &rpcServer, - HTTPRPCRequestProcessor &httpRPCRequestProcessor) = 0; + HTTPRPCRequestProcessor &httpRPCRequestProcessor, + interfaces::BlockAndHeaderTipInfo *tip_info = nullptr) = 0; //! Stop node. virtual void appShutdown() = 0; diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -78,12 +78,12 @@ AppInitParameterInteraction(config, gArgs) && AppInitSanityChecks() && AppInitLockDataDirectory(); } - bool - appInitMain(Config &config, RPCServer &rpcServer, - HTTPRPCRequestProcessor &httpRPCRequestProcessor) override { + bool appInitMain(Config &config, RPCServer &rpcServer, + HTTPRPCRequestProcessor &httpRPCRequestProcessor, + interfaces::BlockAndHeaderTipInfo *tip_info) override { m_context->chain = MakeChain(*m_context, config.GetChainParams()); return AppInitMain(config, rpcServer, httpRPCRequestProcessor, - *m_context); + *m_context, tip_info); } void appShutdown() override { Interrupt(*m_context);