Skip to content

Commit ebb8215

Browse files
committed
Rename getTipHash() to getTip() and return BlockRef
1 parent 89a8f74 commit ebb8215

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/interfaces/mining.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_INTERFACES_MINING_H
77

88
#include <consensus/amount.h> // for CAmount
9+
#include <interfaces/types.h> // for BlockRef
910
#include <node/types.h> // for BlockCreateOptions
1011
#include <primitives/block.h> // for CBlock, CBlockHeader
1112
#include <primitives/transaction.h> // for CTransactionRef
@@ -55,8 +56,8 @@ class Mining
5556
//! Returns whether IBD is still in progress.
5657
virtual bool isInitialBlockDownload() = 0;
5758

58-
//! Returns the hash for the tip of this chain
59-
virtual std::optional<uint256> getTipHash() = 0;
59+
//! Returns the hash and height for the tip of this chain
60+
virtual std::optional<BlockRef> getTip() = 0;
6061

6162
/**
6263
* Construct a new block template

src/node/interfaces.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <interfaces/handler.h>
1818
#include <interfaces/mining.h>
1919
#include <interfaces/node.h>
20+
#include <interfaces/types.h>
2021
#include <interfaces/wallet.h>
2122
#include <kernel/chain.h>
2223
#include <kernel/context.h>
@@ -67,6 +68,7 @@
6768

6869
#include <boost/signals2/signal.hpp>
6970

71+
using interfaces::BlockRef;
7072
using interfaces::BlockTemplate;
7173
using interfaces::BlockTip;
7274
using interfaces::Chain;
@@ -925,12 +927,12 @@ class MinerImpl : public Mining
925927
return chainman().IsInitialBlockDownload();
926928
}
927929

928-
std::optional<uint256> getTipHash() override
930+
std::optional<BlockRef> getTip() override
929931
{
930932
LOCK(::cs_main);
931933
CBlockIndex* tip{chainman().ActiveChain().Tip()};
932934
if (!tip) return {};
933-
return tip->GetBlockHash();
935+
return BlockRef{tip->GetBlockHash(), tip->nHeight};
934936
}
935937

936938
bool processNewBlock(const std::shared_ptr<const CBlock>& block, bool* new_block) override

src/rpc/mining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ static RPCHelpMan getblocktemplate()
661661
ChainstateManager& chainman = EnsureChainman(node);
662662
Mining& miner = EnsureMining(node);
663663
LOCK(cs_main);
664-
uint256 tip{CHECK_NONFATAL(miner.getTipHash()).value()};
664+
uint256 tip{CHECK_NONFATAL(miner.getTip()).value().hash};
665665

666666
std::string strMode = "template";
667667
UniValue lpval = NullUniValue;
@@ -776,7 +776,7 @@ static RPCHelpMan getblocktemplate()
776776
}
777777
ENTER_CRITICAL_SECTION(cs_main);
778778

779-
tip = CHECK_NONFATAL(miner.getTipHash()).value();
779+
tip = CHECK_NONFATAL(miner.getTip()).value().hash;
780780

781781
if (!IsRPCRunning())
782782
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");

0 commit comments

Comments
 (0)