Skip to content

Commit c39ca9d

Browse files
Sjorsismaelsadeeq
authored andcommitted
interfaces: move getTip implementation to miner
1 parent 720f201 commit c39ca9d

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/node/interfaces.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -966,10 +966,7 @@ class MinerImpl : public Mining
966966

967967
std::optional<BlockRef> getTip() override
968968
{
969-
LOCK(::cs_main);
970-
CBlockIndex* tip{chainman().ActiveChain().Tip()};
971-
if (!tip) return {};
972-
return BlockRef{tip->GetBlockHash(), tip->nHeight};
969+
return GetTip(chainman());
973970
}
974971

975972
std::optional<BlockRef> waitTipChanged(uint256 current_tip, MillisecondsDouble timeout) override

src/node/miner.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,4 +539,12 @@ std::unique_ptr<CBlockTemplate> WaitAndCreateNewBlock(ChainstateManager& chainma
539539

540540
return nullptr;
541541
}
542+
543+
std::optional<BlockRef> GetTip(ChainstateManager& chainman)
544+
{
545+
LOCK(::cs_main);
546+
CBlockIndex* tip{chainman.ActiveChain().Tip()};
547+
if (!tip) return {};
548+
return BlockRef{tip->GetBlockHash(), tip->nHeight};
549+
}
542550
} // namespace node

src/node/miner.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef BITCOIN_NODE_MINER_H
77
#define BITCOIN_NODE_MINER_H
88

9+
#include <interfaces/types.h>
910
#include <node/types.h>
1011
#include <policy/policy.h>
1112
#include <primitives/block.h>
@@ -31,6 +32,8 @@ class ChainstateManager;
3132

3233
namespace Consensus { struct Params; };
3334

35+
using interfaces::BlockRef;
36+
3437
namespace node {
3538
class KernelNotifications;
3639

@@ -245,6 +248,9 @@ std::unique_ptr<CBlockTemplate> WaitAndCreateNewBlock(ChainstateManager& chainma
245248
const std::unique_ptr<CBlockTemplate>& block_template,
246249
const BlockWaitOptions& options,
247250
const BlockAssembler::Options& assemble_options);
251+
252+
/* Locks cs_main and returns the block hash and block height of the active chain if it exists; otherwise, returns nullopt.*/
253+
std::optional<BlockRef> GetTip(ChainstateManager& chainman);
248254
} // namespace node
249255

250256
#endif // BITCOIN_NODE_MINER_H

0 commit comments

Comments
 (0)