mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-05-17 23:56:39 +00:00
node/ifaces: ChainImpl: Use an accessor for ChainMan
This commit is contained in:
parent
98c4e252f0
commit
693414d271
@ -431,6 +431,8 @@ public:
|
|||||||
|
|
||||||
class ChainImpl : public Chain
|
class ChainImpl : public Chain
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
ChainstateManager& chainman() { return *Assert(m_node.chainman); }
|
||||||
public:
|
public:
|
||||||
explicit ChainImpl(NodeContext& node) : m_node(node) {}
|
explicit ChainImpl(NodeContext& node) : m_node(node) {}
|
||||||
std::optional<int> getHeight() override
|
std::optional<int> getHeight() override
|
||||||
@ -467,8 +469,8 @@ public:
|
|||||||
bool checkFinalTx(const CTransaction& tx) override
|
bool checkFinalTx(const CTransaction& tx) override
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
assert(std::addressof(::ChainActive()) == std::addressof(m_node.chainman->ActiveChain()));
|
assert(std::addressof(::ChainActive()) == std::addressof(chainman().ActiveChain()));
|
||||||
return CheckFinalTx(m_node.chainman->ActiveChain().Tip(), tx);
|
return CheckFinalTx(chainman().ActiveChain().Tip(), tx);
|
||||||
}
|
}
|
||||||
std::optional<int> findLocatorFork(const CBlockLocator& locator) override
|
std::optional<int> findLocatorFork(const CBlockLocator& locator) override
|
||||||
{
|
{
|
||||||
@ -533,8 +535,8 @@ public:
|
|||||||
double guessVerificationProgress(const uint256& block_hash) override
|
double guessVerificationProgress(const uint256& block_hash) override
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
|
assert(std::addressof(g_chainman.m_blockman) == std::addressof(chainman().m_blockman));
|
||||||
return GuessVerificationProgress(Params().TxData(), m_node.chainman->m_blockman.LookupBlockIndex(block_hash));
|
return GuessVerificationProgress(Params().TxData(), chainman().m_blockman.LookupBlockIndex(block_hash));
|
||||||
}
|
}
|
||||||
bool hasBlocks(const uint256& block_hash, int min_height, std::optional<int> max_height) override
|
bool hasBlocks(const uint256& block_hash, int min_height, std::optional<int> max_height) override
|
||||||
{
|
{
|
||||||
@ -546,8 +548,8 @@ public:
|
|||||||
// used to limit the range, and passing min_height that's too low or
|
// used to limit the range, and passing min_height that's too low or
|
||||||
// max_height that's too high will not crash or change the result.
|
// max_height that's too high will not crash or change the result.
|
||||||
LOCK(::cs_main);
|
LOCK(::cs_main);
|
||||||
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
|
assert(std::addressof(g_chainman.m_blockman) == std::addressof(chainman().m_blockman));
|
||||||
if (CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash)) {
|
if (CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash)) {
|
||||||
if (max_height && block->nHeight >= *max_height) block = block->GetAncestor(*max_height);
|
if (max_height && block->nHeight >= *max_height) block = block->GetAncestor(*max_height);
|
||||||
for (; block->nStatus & BLOCK_HAVE_DATA; block = block->pprev) {
|
for (; block->nStatus & BLOCK_HAVE_DATA; block = block->pprev) {
|
||||||
// Check pprev to not segfault if min_height is too low
|
// Check pprev to not segfault if min_height is too low
|
||||||
@ -638,8 +640,16 @@ public:
|
|||||||
}
|
}
|
||||||
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); }
|
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); }
|
||||||
bool isInitialBlockDownload() override {
|
bool isInitialBlockDownload() override {
|
||||||
assert(std::addressof(::ChainstateActive()) == std::addressof(m_node.chainman->ActiveChainstate()));
|
const CChainState* active_chainstate;
|
||||||
return m_node.chainman->ActiveChainstate().IsInitialBlockDownload();
|
{
|
||||||
|
// TODO: Temporary scope to check correctness of refactored code.
|
||||||
|
// Should be removed manually after merge of
|
||||||
|
// https://github.com/bitcoin/bitcoin/pull/20158
|
||||||
|
LOCK(::cs_main);
|
||||||
|
active_chainstate = &chainman().ActiveChainstate();
|
||||||
|
assert(std::addressof(::ChainstateActive()) == std::addressof(*active_chainstate));
|
||||||
|
}
|
||||||
|
return active_chainstate->IsInitialBlockDownload();
|
||||||
}
|
}
|
||||||
bool shutdownRequested() override { return ShutdownRequested(); }
|
bool shutdownRequested() override { return ShutdownRequested(); }
|
||||||
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
|
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user