0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-04 13:55:23 -05:00

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
#include <consensus/amount.h> // for CAmount
#include <interfaces/types.h> // for BlockRef
#include <node/types.h> // for BlockCreateOptions
#include <primitives/block.h> // for CBlock, CBlockHeader
#include <primitives/transaction.h> // 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<uint256> getTipHash() = 0;
//! Returns the hash and height for the tip of this chain
virtual std::optional<BlockRef> getTip() = 0;
/**
* Construct a new block template

View file

@ -17,6 +17,7 @@
#include <interfaces/handler.h>
#include <interfaces/mining.h>
#include <interfaces/node.h>
#include <interfaces/types.h>
#include <interfaces/wallet.h>
#include <kernel/chain.h>
#include <kernel/context.h>
@ -67,6 +68,7 @@
#include <boost/signals2/signal.hpp>
using interfaces::BlockRef;
using interfaces::BlockTemplate;
using interfaces::BlockTip;
using interfaces::Chain;
@ -925,12 +927,12 @@ public:
return chainman().IsInitialBlockDownload();
}
std::optional<uint256> getTipHash() override
std::optional<BlockRef> 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<const CBlock>& block, bool* new_block) override

View file

@ -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");