interfaces: move getTip implementation to miner

This commit is contained in:
Sjors Provoost 2025-05-14 09:51:15 +02:00 committed by ismaelsadeeq
parent 720f201e65
commit c39ca9d4f7
No known key found for this signature in database
GPG Key ID: 0E3908F364989888
3 changed files with 15 additions and 4 deletions

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

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

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