aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2020-10-06 17:35:11 -0400
committerCarl Dong <contact@carldong.me>2021-06-10 15:05:25 -0400
commit6f994882deafe62e97f0a889d8bdb8c96dcf913d (patch)
treeb7146c5915735a43da76340c665928441137bd49
parent972c5166ee685447a6d4bf5e501b07a0871fba85 (diff)
downloadbitcoin-6f994882deafe62e97f0a889d8bdb8c96dcf913d.tar.xz
validation: Farewell, global Chainstate!
-rw-r--r--src/init.cpp6
-rw-r--r--src/node/context.cpp1
-rw-r--r--src/node/context.h2
-rw-r--r--src/rest.cpp2
-rw-r--r--src/test/util/setup_common.cpp4
-rw-r--r--src/validation.cpp15
-rw-r--r--src/validation.h13
7 files changed, 8 insertions, 35 deletions
diff --git a/src/init.cpp b/src/init.cpp
index dcc2a0ebcc..58d3553e8a 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -283,7 +283,7 @@ void Shutdown(NodeContext& node)
init::UnsetGlobals();
node.mempool.reset();
node.fee_estimator.reset();
- node.chainman = nullptr;
+ node.chainman.reset();
node.scheduler.reset();
try {
@@ -1179,8 +1179,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), check_ratio);
assert(!node.chainman);
- node.chainman = &g_chainman;
- ChainstateManager& chainman = *Assert(node.chainman);
+ node.chainman = std::make_unique<ChainstateManager>();
+ ChainstateManager& chainman = *node.chainman;
assert(!node.peerman);
node.peerman = PeerManager::make(chainparams, *node.connman, *node.addrman, node.banman.get(),
diff --git a/src/node/context.cpp b/src/node/context.cpp
index 6d22a6b110..9afadd09a9 100644
--- a/src/node/context.cpp
+++ b/src/node/context.cpp
@@ -12,6 +12,7 @@
#include <policy/fees.h>
#include <scheduler.h>
#include <txmempool.h>
+#include <validation.h>
NodeContext::NodeContext() {}
NodeContext::~NodeContext() {}
diff --git a/src/node/context.h b/src/node/context.h
index 06adb33a80..135f9ea1c6 100644
--- a/src/node/context.h
+++ b/src/node/context.h
@@ -44,7 +44,7 @@ struct NodeContext {
std::unique_ptr<CTxMemPool> mempool;
std::unique_ptr<CBlockPolicyEstimator> fee_estimator;
std::unique_ptr<PeerManager> peerman;
- ChainstateManager* chainman{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
+ std::unique_ptr<ChainstateManager> chainman;
std::unique_ptr<BanMan> banman;
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
std::unique_ptr<interfaces::Chain> chain;
diff --git a/src/rest.cpp b/src/rest.cpp
index 747c7aea19..d599f381e3 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -125,7 +125,7 @@ static ChainstateManager* GetChainman(const std::any& context, HTTPRequest* req)
__FILE__, __LINE__, __func__, PACKAGE_BUGREPORT));
return nullptr;
}
- return node_context->chainman;
+ return node_context->chainman.get();
}
static RetFormat ParseDataFormat(std::string& param, const std::string& strReq)
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index fcccf3fc49..028d200bfd 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -145,7 +145,7 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
m_node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
m_node.mempool = std::make_unique<CTxMemPool>(m_node.fee_estimator.get(), 1);
- m_node.chainman = &::g_chainman;
+ m_node.chainman = std::make_unique<ChainstateManager>();
// Start script-checking threads. Set g_parallel_script_checks to true so they are used.
constexpr int script_check_threads = 2;
@@ -167,7 +167,7 @@ ChainTestingSetup::~ChainTestingSetup()
m_node.mempool.reset();
m_node.scheduler.reset();
m_node.chainman->Reset();
- m_node.chainman = nullptr;
+ m_node.chainman.reset();
pblocktree.reset();
}
diff --git a/src/validation.cpp b/src/validation.cpp
index 8f2283e673..21785ba208 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -101,21 +101,6 @@ bool CBlockIndexWorkComparator::operator()(const CBlockIndex *pa, const CBlockIn
return false;
}
-ChainstateManager g_chainman;
-
-CChainState& ChainstateActive()
-{
- LOCK(::cs_main);
- assert(g_chainman.m_active_chainstate);
- return *g_chainman.m_active_chainstate;
-}
-
-CChain& ChainActive()
-{
- LOCK(::cs_main);
- return ::ChainstateActive().m_chain;
-}
-
/**
* Mutex to guard access to validation specific variables, such as reading
* or changing the chainstate.
diff --git a/src/validation.h b/src/validation.h
index a3ead9443e..5720ba8071 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -891,10 +891,6 @@ private:
CAutoFile& coins_file,
const SnapshotMetadata& metadata);
- // For access to m_active_chainstate.
- friend CChainState& ChainstateActive();
- friend CChain& ChainActive();
-
public:
std::thread m_load_block;
//! A single BlockManager instance is shared across each constructed
@@ -1025,15 +1021,6 @@ public:
}
};
-/** DEPRECATED! Please use node.chainman instead. May only be used in validation.cpp internally */
-extern ChainstateManager g_chainman GUARDED_BY(::cs_main);
-
-/** Please prefer the identical ChainstateManager::ActiveChainstate */
-CChainState& ChainstateActive();
-
-/** Please prefer the identical ChainstateManager::ActiveChain */
-CChain& ChainActive();
-
/** Global variable that points to the active block tree (protected by cs_main) */
extern std::unique_ptr<CBlockTreeDB> pblocktree;