interfaces: move getTip implementation to miner

This commit is contained in:
Sjors Provoost authored and ismaelsadeeq committed 2025-05-14 13:55:05 +01:00
1 parent 720f201e65
commit c39ca9d4f7
3 files changed
+15 -4

No files matched your search

+1 -4
View File
@@ -966,10 +966,7 @@ public:
std::optional<BlockRef> getTip() override
{
LOCK(::cs_main);
CBlockIndex* tip{chainman().ActiveChain().Tip()};
if (!tip) return {};
return BlockRef{tip->GetBlockHash(), tip->nHeight};
return GetTip(chainman());
}
std::optional<BlockRef> waitTipChanged(uint256 current_tip, MillisecondsDouble timeout) override
+8
View File
@@ -539,4 +539,12 @@ std::unique_ptr<CBlockTemplate> WaitAndCreateNewBlock(ChainstateManager& chainma
return nullptr;
}
std::optional<BlockRef> GetTip(ChainstateManager& chainman)
{
LOCK(::cs_main);
CBlockIndex* tip{chainman.ActiveChain().Tip()};
if (!tip) return {};
return BlockRef{tip->GetBlockHash(), tip->nHeight};
}
} // namespace node
+6
View File
@@ -6,6 +6,7 @@
#ifndef BITCOIN_NODE_MINER_H
#define BITCOIN_NODE_MINER_H
#include <interfaces/types.h>
#include <node/types.h>
#include <policy/policy.h>
#include <primitives/block.h>
@@ -31,6 +32,8 @@ class ChainstateManager;
namespace Consensus { struct Params; };
using interfaces::BlockRef;
namespace node {
class KernelNotifications;
@@ -245,6 +248,9 @@ std::unique_ptr<CBlockTemplate> WaitAndCreateNewBlock(ChainstateManager& chainma
const std::unique_ptr<CBlockTemplate>& block_template,
const BlockWaitOptions& options,
const BlockAssembler::Options& assemble_options);
/* Locks cs_main and returns the block hash and block height of the active chain if it exists; otherwise, returns nullopt.*/
std::optional<BlockRef> GetTip(ChainstateManager& chainman);
} // namespace node
#endif // BITCOIN_NODE_MINER_H