Rename getTipHash() to getTip() and return BlockRef

This commit is contained in:
Sjors Provoost 2024-07-08 19:08:11 +02:00
parent 89a8f74bbb
commit ebb8215f23
No known key found for this signature in database
GPG key ID: 57FF9BDBCC301009
3 changed files with 9 additions and 6 deletions

View file

@ -6,6 +6,7 @@
#define BITCOIN_INTERFACES_MINING_H #define BITCOIN_INTERFACES_MINING_H
#include <consensus/amount.h> // for CAmount #include <consensus/amount.h> // for CAmount
#include <interfaces/types.h> // for BlockRef
#include <node/types.h> // for BlockCreateOptions #include <node/types.h> // for BlockCreateOptions
#include <primitives/block.h> // for CBlock, CBlockHeader #include <primitives/block.h> // for CBlock, CBlockHeader
#include <primitives/transaction.h> // for CTransactionRef #include <primitives/transaction.h> // for CTransactionRef
@ -55,8 +56,8 @@ public:
//! Returns whether IBD is still in progress. //! Returns whether IBD is still in progress.
virtual bool isInitialBlockDownload() = 0; virtual bool isInitialBlockDownload() = 0;
//! Returns the hash for the tip of this chain //! Returns the hash and height for the tip of this chain
virtual std::optional<uint256> getTipHash() = 0; virtual std::optional<BlockRef> getTip() = 0;
/** /**
* Construct a new block template * Construct a new block template

View file

@ -17,6 +17,7 @@
#include <interfaces/handler.h> #include <interfaces/handler.h>
#include <interfaces/mining.h> #include <interfaces/mining.h>
#include <interfaces/node.h> #include <interfaces/node.h>
#include <interfaces/types.h>
#include <interfaces/wallet.h> #include <interfaces/wallet.h>
#include <kernel/chain.h> #include <kernel/chain.h>
#include <kernel/context.h> #include <kernel/context.h>
@ -67,6 +68,7 @@
#include <boost/signals2/signal.hpp> #include <boost/signals2/signal.hpp>
using interfaces::BlockRef;
using interfaces::BlockTemplate; using interfaces::BlockTemplate;
using interfaces::BlockTip; using interfaces::BlockTip;
using interfaces::Chain; using interfaces::Chain;
@ -925,12 +927,12 @@ public:
return chainman().IsInitialBlockDownload(); return chainman().IsInitialBlockDownload();
} }
std::optional<uint256> getTipHash() override std::optional<BlockRef> getTip() override
{ {
LOCK(::cs_main); LOCK(::cs_main);
CBlockIndex* tip{chainman().ActiveChain().Tip()}; CBlockIndex* tip{chainman().ActiveChain().Tip()};
if (!tip) return {}; if (!tip) return {};
return tip->GetBlockHash(); return BlockRef{tip->GetBlockHash(), tip->nHeight};
} }
bool processNewBlock(const std::shared_ptr<const CBlock>& block, bool* new_block) override bool processNewBlock(const std::shared_ptr<const CBlock>& block, bool* new_block) override

View file

@ -661,7 +661,7 @@ static RPCHelpMan getblocktemplate()
ChainstateManager& chainman = EnsureChainman(node); ChainstateManager& chainman = EnsureChainman(node);
Mining& miner = EnsureMining(node); Mining& miner = EnsureMining(node);
LOCK(cs_main); LOCK(cs_main);
uint256 tip{CHECK_NONFATAL(miner.getTipHash()).value()}; uint256 tip{CHECK_NONFATAL(miner.getTip()).value().hash};
std::string strMode = "template"; std::string strMode = "template";
UniValue lpval = NullUniValue; UniValue lpval = NullUniValue;
@ -776,7 +776,7 @@ static RPCHelpMan getblocktemplate()
} }
ENTER_CRITICAL_SECTION(cs_main); ENTER_CRITICAL_SECTION(cs_main);
tip = CHECK_NONFATAL(miner.getTipHash()).value(); tip = CHECK_NONFATAL(miner.getTip()).value().hash;
if (!IsRPCRunning()) if (!IsRPCRunning())
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down"); throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");