From ebb8215f23644f901c46fd4977b7d4b08fae5104 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Mon, 8 Jul 2024 19:08:11 +0200 Subject: [PATCH] Rename getTipHash() to getTip() and return BlockRef --- src/interfaces/mining.h | 5 +++-- src/node/interfaces.cpp | 6 ++++-- src/rpc/mining.cpp | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/interfaces/mining.h b/src/interfaces/mining.h index c73465bd2aa..ebda49bcc95 100644 --- a/src/interfaces/mining.h +++ b/src/interfaces/mining.h @@ -6,6 +6,7 @@ #define BITCOIN_INTERFACES_MINING_H #include // for CAmount +#include // for BlockRef #include // for BlockCreateOptions #include // for CBlock, CBlockHeader #include // for CTransactionRef @@ -55,8 +56,8 @@ public: //! Returns whether IBD is still in progress. virtual bool isInitialBlockDownload() = 0; - //! Returns the hash for the tip of this chain - virtual std::optional getTipHash() = 0; + //! Returns the hash and height for the tip of this chain + virtual std::optional getTip() = 0; /** * Construct a new block template diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 510541dfda9..60ff6d406a2 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,7 @@ #include +using interfaces::BlockRef; using interfaces::BlockTemplate; using interfaces::BlockTip; using interfaces::Chain; @@ -925,12 +927,12 @@ public: return chainman().IsInitialBlockDownload(); } - std::optional getTipHash() override + std::optional getTip() override { LOCK(::cs_main); CBlockIndex* tip{chainman().ActiveChain().Tip()}; if (!tip) return {}; - return tip->GetBlockHash(); + return BlockRef{tip->GetBlockHash(), tip->nHeight}; } bool processNewBlock(const std::shared_ptr& block, bool* new_block) override diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index b986c26e7a3..8f6828319ee 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -661,7 +661,7 @@ static RPCHelpMan getblocktemplate() ChainstateManager& chainman = EnsureChainman(node); Mining& miner = EnsureMining(node); LOCK(cs_main); - uint256 tip{CHECK_NONFATAL(miner.getTipHash()).value()}; + uint256 tip{CHECK_NONFATAL(miner.getTip()).value().hash}; std::string strMode = "template"; UniValue lpval = NullUniValue; @@ -776,7 +776,7 @@ static RPCHelpMan getblocktemplate() } ENTER_CRITICAL_SECTION(cs_main); - tip = CHECK_NONFATAL(miner.getTipHash()).value(); + tip = CHECK_NONFATAL(miner.getTip()).value().hash; if (!IsRPCRunning()) throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");