@@ -65,6 +65,8 @@ namespace node {
65
65
namespace {
66
66
class NodeImpl : public Node
67
67
{
68
+ private:
69
+ ChainstateManager& chainman () { return *Assert (m_context->chainman ); }
68
70
public:
69
71
explicit NodeImpl (NodeContext* context) { setContext (context); }
70
72
void initLogging () override { InitLogging (*Assert (m_context->args )); }
@@ -183,21 +185,28 @@ class NodeImpl : public Node
183
185
int getNumBlocks () override
184
186
{
185
187
LOCK (::cs_main);
186
- assert (std::addressof (::ChainActive ()) == std::addressof (m_context-> chainman -> ActiveChain ()));
187
- return m_context-> chainman -> ActiveChain ().Height ();
188
+ assert (std::addressof (::ChainActive ()) == std::addressof (chainman (). ActiveChain ()));
189
+ return chainman (). ActiveChain ().Height ();
188
190
}
189
191
uint256 getBestBlockHash () override
190
192
{
191
- assert (std::addressof (::ChainActive ()) == std::addressof (m_context->chainman ->ActiveChain ()));
192
- const CBlockIndex* tip = WITH_LOCK (::cs_main, return m_context->chainman ->ActiveChain ().Tip ());
193
+ const CBlockIndex* tip;
194
+ {
195
+ // TODO: Temporary scope to check correctness of refactored code.
196
+ // Should be removed manually after merge of
197
+ // https://github.com/bitcoin/bitcoin/pull/20158
198
+ LOCK (cs_main);
199
+ assert (std::addressof (::ChainActive ()) == std::addressof (chainman ().ActiveChain ()));
200
+ tip = chainman ().ActiveChain ().Tip ();
201
+ }
193
202
return tip ? tip->GetBlockHash () : Params ().GenesisBlock ().GetHash ();
194
203
}
195
204
int64_t getLastBlockTime () override
196
205
{
197
206
LOCK (::cs_main);
198
- assert (std::addressof (::ChainActive ()) == std::addressof (m_context-> chainman -> ActiveChain ()));
199
- if (m_context-> chainman -> ActiveChain ().Tip ()) {
200
- return m_context-> chainman -> ActiveChain ().Tip ()->GetBlockTime ();
207
+ assert (std::addressof (::ChainActive ()) == std::addressof (chainman (). ActiveChain ()));
208
+ if (chainman (). ActiveChain ().Tip ()) {
209
+ return chainman (). ActiveChain ().Tip ()->GetBlockTime ();
201
210
}
202
211
return Params ().GenesisBlock ().GetBlockTime (); // Genesis block's time of current network
203
212
}
@@ -206,14 +215,22 @@ class NodeImpl : public Node
206
215
const CBlockIndex* tip;
207
216
{
208
217
LOCK (::cs_main);
209
- assert (std::addressof (::ChainActive ()) == std::addressof (m_context-> chainman -> ActiveChain ()));
210
- tip = m_context-> chainman -> ActiveChain ().Tip ();
218
+ assert (std::addressof (::ChainActive ()) == std::addressof (chainman (). ActiveChain ()));
219
+ tip = chainman (). ActiveChain ().Tip ();
211
220
}
212
221
return GuessVerificationProgress (Params ().TxData (), tip);
213
222
}
214
223
bool isInitialBlockDownload () override {
215
- assert (std::addressof (::ChainstateActive ()) == std::addressof (m_context->chainman ->ActiveChainstate ()));
216
- return m_context->chainman ->ActiveChainstate ().IsInitialBlockDownload ();
224
+ const CChainState* active_chainstate;
225
+ {
226
+ // TODO: Temporary scope to check correctness of refactored code.
227
+ // Should be removed manually after merge of
228
+ // https://github.com/bitcoin/bitcoin/pull/20158
229
+ LOCK (::cs_main);
230
+ active_chainstate = &m_context->chainman ->ActiveChainstate ();
231
+ assert (std::addressof (::ChainstateActive ()) == std::addressof (*active_chainstate));
232
+ }
233
+ return active_chainstate->IsInitialBlockDownload ();
217
234
}
218
235
bool getReindex () override { return ::fReindex ; }
219
236
bool getImporting () override { return ::fImporting ; }
@@ -239,8 +256,8 @@ class NodeImpl : public Node
239
256
bool getUnspentOutput (const COutPoint& output, Coin& coin) override
240
257
{
241
258
LOCK (::cs_main);
242
- assert (std::addressof (::ChainstateActive ()) == std::addressof (m_context-> chainman -> ActiveChainstate ()));
243
- return m_context-> chainman -> ActiveChainstate ().CoinsTip ().GetCoin (output, coin);
259
+ assert (std::addressof (::ChainstateActive ()) == std::addressof (chainman (). ActiveChainstate ()));
260
+ return chainman (). ActiveChainstate ().CoinsTip ().GetCoin (output, coin);
244
261
}
245
262
WalletClient& walletClient () override
246
263
{
0 commit comments