mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Merge 80a699fda9 into merged_master (Bitcoin PR #21525)
This commit is contained in:
commit
bc51e4e896
15 changed files with 150 additions and 117 deletions
|
|
@ -65,6 +65,8 @@ namespace node {
|
|||
namespace {
|
||||
class NodeImpl : public Node
|
||||
{
|
||||
private:
|
||||
ChainstateManager& chainman() { return *Assert(m_context->chainman); }
|
||||
public:
|
||||
explicit NodeImpl(NodeContext* context) { setContext(context); }
|
||||
void initLogging() override { InitLogging(*Assert(m_context->args)); }
|
||||
|
|
@ -183,21 +185,28 @@ public:
|
|||
int getNumBlocks() override
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
|
||||
return m_context->chainman->ActiveChain().Height();
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(chainman().ActiveChain()));
|
||||
return chainman().ActiveChain().Height();
|
||||
}
|
||||
uint256 getBestBlockHash() override
|
||||
{
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
|
||||
const CBlockIndex* tip = WITH_LOCK(::cs_main, return m_context->chainman->ActiveChain().Tip());
|
||||
const CBlockIndex* tip;
|
||||
{
|
||||
// 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);
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(chainman().ActiveChain()));
|
||||
tip = chainman().ActiveChain().Tip();
|
||||
}
|
||||
return tip ? tip->GetBlockHash() : Params().GenesisBlock().GetHash();
|
||||
}
|
||||
int64_t getLastBlockTime() override
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
|
||||
if (m_context->chainman->ActiveChain().Tip()) {
|
||||
return m_context->chainman->ActiveChain().Tip()->GetBlockTime();
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(chainman().ActiveChain()));
|
||||
if (chainman().ActiveChain().Tip()) {
|
||||
return chainman().ActiveChain().Tip()->GetBlockTime();
|
||||
}
|
||||
return Params().GenesisBlock().GetBlockTime(); // Genesis block's time of current network
|
||||
}
|
||||
|
|
@ -206,14 +215,22 @@ public:
|
|||
const CBlockIndex* tip;
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
|
||||
tip = m_context->chainman->ActiveChain().Tip();
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(chainman().ActiveChain()));
|
||||
tip = chainman().ActiveChain().Tip();
|
||||
}
|
||||
return GuessVerificationProgress(tip, Params().GetConsensus().nPowTargetSpacing);
|
||||
}
|
||||
bool isInitialBlockDownload() override {
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(m_context->chainman->ActiveChainstate()));
|
||||
return m_context->chainman->ActiveChainstate().IsInitialBlockDownload();
|
||||
const CChainState* active_chainstate;
|
||||
{
|
||||
// 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 = &m_context->chainman->ActiveChainstate();
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(*active_chainstate));
|
||||
}
|
||||
return active_chainstate->IsInitialBlockDownload();
|
||||
}
|
||||
bool getReindex() override { return ::fReindex; }
|
||||
bool getImporting() override { return ::fImporting; }
|
||||
|
|
@ -239,8 +256,8 @@ public:
|
|||
bool getUnspentOutput(const COutPoint& output, Coin& coin) override
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(m_context->chainman->ActiveChainstate()));
|
||||
return m_context->chainman->ActiveChainstate().CoinsTip().GetCoin(output, coin);
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(chainman().ActiveChainstate()));
|
||||
return chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin);
|
||||
}
|
||||
WalletClient& walletClient() override
|
||||
{
|
||||
|
|
@ -414,6 +431,8 @@ public:
|
|||
|
||||
class ChainImpl : public Chain
|
||||
{
|
||||
private:
|
||||
ChainstateManager& chainman() { return *Assert(m_node.chainman); }
|
||||
public:
|
||||
explicit ChainImpl(NodeContext& node) : m_node(node) {}
|
||||
std::optional<int> getHeight() override
|
||||
|
|
@ -450,8 +469,8 @@ public:
|
|||
bool checkFinalTx(const CTransaction& tx) override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(m_node.chainman->ActiveChain()));
|
||||
return CheckFinalTx(m_node.chainman->ActiveChain().Tip(), tx);
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(chainman().ActiveChain()));
|
||||
return CheckFinalTx(chainman().ActiveChain().Tip(), tx);
|
||||
}
|
||||
std::optional<int> findLocatorFork(const CBlockLocator& locator) override
|
||||
{
|
||||
|
|
@ -516,8 +535,8 @@ public:
|
|||
double guessVerificationProgress(const uint256& block_hash) override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
|
||||
return GuessVerificationProgress(m_node.chainman->m_blockman.LookupBlockIndex(block_hash), Params().GetConsensus().nPowTargetSpacing);
|
||||
assert(std::addressof(g_chainman.m_blockman) == std::addressof(chainman().m_blockman));
|
||||
return GuessVerificationProgress(chainman().m_blockman.LookupBlockIndex(block_hash), Params().GetConsensus().nPowTargetSpacing);
|
||||
}
|
||||
bool hasBlocks(const uint256& block_hash, int min_height, std::optional<int> max_height) override
|
||||
{
|
||||
|
|
@ -529,8 +548,8 @@ public:
|
|||
// 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.
|
||||
LOCK(::cs_main);
|
||||
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
|
||||
if (CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash)) {
|
||||
assert(std::addressof(g_chainman.m_blockman) == std::addressof(chainman().m_blockman));
|
||||
if (CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash)) {
|
||||
if (max_height && block->nHeight >= *max_height) block = block->GetAncestor(*max_height);
|
||||
for (; block->nStatus & BLOCK_HAVE_DATA; block = block->pprev) {
|
||||
// Check pprev to not segfault if min_height is too low
|
||||
|
|
@ -622,8 +641,16 @@ public:
|
|||
}
|
||||
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); }
|
||||
bool isInitialBlockDownload() override {
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(m_node.chainman->ActiveChainstate()));
|
||||
return m_node.chainman->ActiveChainstate().IsInitialBlockDownload();
|
||||
const CChainState* active_chainstate;
|
||||
{
|
||||
// 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(); }
|
||||
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue