Skip to content

Commit 6f99488

Browse files
committed
validation: Farewell, global Chainstate!
1 parent 972c516 commit 6f99488

File tree

7 files changed

+8
-35
lines changed

7 files changed

+8
-35
lines changed

src/init.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void Shutdown(NodeContext& node)
283283
init::UnsetGlobals();
284284
node.mempool.reset();
285285
node.fee_estimator.reset();
286-
node.chainman = nullptr;
286+
node.chainman.reset();
287287
node.scheduler.reset();
288288

289289
try {
@@ -1179,8 +1179,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
11791179
node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), check_ratio);
11801180

11811181
assert(!node.chainman);
1182-
node.chainman = &g_chainman;
1183-
ChainstateManager& chainman = *Assert(node.chainman);
1182+
node.chainman = std::make_unique<ChainstateManager>();
1183+
ChainstateManager& chainman = *node.chainman;
11841184

11851185
assert(!node.peerman);
11861186
node.peerman = PeerManager::make(chainparams, *node.connman, *node.addrman, node.banman.get(),

src/node/context.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <policy/fees.h>
1313
#include <scheduler.h>
1414
#include <txmempool.h>
15+
#include <validation.h>
1516

1617
NodeContext::NodeContext() {}
1718
NodeContext::~NodeContext() {}

src/node/context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct NodeContext {
4444
std::unique_ptr<CTxMemPool> mempool;
4545
std::unique_ptr<CBlockPolicyEstimator> fee_estimator;
4646
std::unique_ptr<PeerManager> peerman;
47-
ChainstateManager* chainman{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
47+
std::unique_ptr<ChainstateManager> chainman;
4848
std::unique_ptr<BanMan> banman;
4949
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
5050
std::unique_ptr<interfaces::Chain> chain;

src/rest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static ChainstateManager* GetChainman(const std::any& context, HTTPRequest* req)
125125
__FILE__, __LINE__, __func__, PACKAGE_BUGREPORT));
126126
return nullptr;
127127
}
128-
return node_context->chainman;
128+
return node_context->chainman.get();
129129
}
130130

131131
static RetFormat ParseDataFormat(std::string& param, const std::string& strReq)

src/test/util/setup_common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
145145
m_node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
146146
m_node.mempool = std::make_unique<CTxMemPool>(m_node.fee_estimator.get(), 1);
147147

148-
m_node.chainman = &::g_chainman;
148+
m_node.chainman = std::make_unique<ChainstateManager>();
149149

150150
// Start script-checking threads. Set g_parallel_script_checks to true so they are used.
151151
constexpr int script_check_threads = 2;
@@ -167,7 +167,7 @@ ChainTestingSetup::~ChainTestingSetup()
167167
m_node.mempool.reset();
168168
m_node.scheduler.reset();
169169
m_node.chainman->Reset();
170-
m_node.chainman = nullptr;
170+
m_node.chainman.reset();
171171
pblocktree.reset();
172172
}
173173

src/validation.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,6 @@ bool CBlockIndexWorkComparator::operator()(const CBlockIndex *pa, const CBlockIn
101101
return false;
102102
}
103103

104-
ChainstateManager g_chainman;
105-
106-
CChainState& ChainstateActive()
107-
{
108-
LOCK(::cs_main);
109-
assert(g_chainman.m_active_chainstate);
110-
return *g_chainman.m_active_chainstate;
111-
}
112-
113-
CChain& ChainActive()
114-
{
115-
LOCK(::cs_main);
116-
return ::ChainstateActive().m_chain;
117-
}
118-
119104
/**
120105
* Mutex to guard access to validation specific variables, such as reading
121106
* or changing the chainstate.

src/validation.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,6 @@ class ChainstateManager
891891
CAutoFile& coins_file,
892892
const SnapshotMetadata& metadata);
893893

894-
// For access to m_active_chainstate.
895-
friend CChainState& ChainstateActive();
896-
friend CChain& ChainActive();
897-
898894
public:
899895
std::thread m_load_block;
900896
//! A single BlockManager instance is shared across each constructed
@@ -1025,15 +1021,6 @@ class ChainstateManager
10251021
}
10261022
};
10271023

1028-
/** DEPRECATED! Please use node.chainman instead. May only be used in validation.cpp internally */
1029-
extern ChainstateManager g_chainman GUARDED_BY(::cs_main);
1030-
1031-
/** Please prefer the identical ChainstateManager::ActiveChainstate */
1032-
CChainState& ChainstateActive();
1033-
1034-
/** Please prefer the identical ChainstateManager::ActiveChain */
1035-
CChain& ChainActive();
1036-
10371024
/** Global variable that points to the active block tree (protected by cs_main) */
10381025
extern std::unique_ptr<CBlockTreeDB> pblocktree;
10391026

0 commit comments

Comments
 (0)