@@ -210,8 +210,9 @@ static RPCHelpMan getblockcount()
210
210
},
211
211
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
212
212
{
213
+ ChainstateManager& chainman = EnsureAnyChainman (request.context );
213
214
LOCK (cs_main);
214
- return EnsureAnyChainman (request. context ) .ActiveChain ().Height ();
215
+ return chainman .ActiveChain ().Height ();
215
216
},
216
217
};
217
218
}
@@ -229,8 +230,9 @@ static RPCHelpMan getbestblockhash()
229
230
},
230
231
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
231
232
{
233
+ ChainstateManager& chainman = EnsureAnyChainman (request.context );
232
234
LOCK (cs_main);
233
- return EnsureAnyChainman (request. context ) .ActiveChain ().Tip ()->GetBlockHash ().GetHex ();
235
+ return chainman .ActiveChain ().Tip ()->GetBlockHash ().GetHex ();
234
236
},
235
237
};
236
238
}
@@ -410,8 +412,9 @@ static RPCHelpMan getdifficulty()
410
412
},
411
413
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
412
414
{
415
+ ChainstateManager& chainman = EnsureAnyChainman (request.context );
413
416
LOCK (cs_main);
414
- return GetDifficulty (EnsureAnyChainman (request. context ) .ActiveChain ().Tip ());
417
+ return GetDifficulty (chainman .ActiveChain ().Tip ());
415
418
},
416
419
};
417
420
}
@@ -775,8 +778,9 @@ static RPCHelpMan getblockhash()
775
778
},
776
779
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
777
780
{
781
+ ChainstateManager& chainman = EnsureAnyChainman (request.context );
778
782
LOCK (cs_main);
779
- const CChain& active_chain = EnsureAnyChainman (request. context ) .ActiveChain ();
783
+ const CChain& active_chain = chainman .ActiveChain ();
780
784
781
785
int nHeight = request.params [0 ].get_int ();
782
786
if (nHeight < 0 || nHeight > active_chain.Height ())
@@ -835,8 +839,8 @@ static RPCHelpMan getblockheader()
835
839
const CBlockIndex* pblockindex;
836
840
const CBlockIndex* tip;
837
841
{
838
- LOCK (cs_main);
839
842
ChainstateManager& chainman = EnsureAnyChainman (request.context );
843
+ LOCK (cs_main);
840
844
pblockindex = chainman.m_blockman .LookupBlockIndex (hash);
841
845
tip = chainman.ActiveChain ().Tip ();
842
846
}
@@ -960,8 +964,8 @@ static RPCHelpMan getblock()
960
964
const CBlockIndex* pblockindex;
961
965
const CBlockIndex* tip;
962
966
{
963
- LOCK (cs_main);
964
967
ChainstateManager& chainman = EnsureAnyChainman (request.context );
968
+ LOCK (cs_main);
965
969
pblockindex = chainman.m_blockman .LookupBlockIndex (hash);
966
970
tip = chainman.ActiveChain ().Tip ();
967
971
@@ -1003,8 +1007,8 @@ static RPCHelpMan pruneblockchain()
1003
1007
if (!fPruneMode )
1004
1008
throw JSONRPCError (RPC_MISC_ERROR, " Cannot prune blocks because node is not in prune mode." );
1005
1009
1006
- LOCK (cs_main);
1007
1010
ChainstateManager& chainman = EnsureAnyChainman (request.context );
1011
+ LOCK (cs_main);
1008
1012
1009
1013
int heightParam = request.params [0 ].get_int ();
1010
1014
if (heightParam < 0 )
@@ -1086,7 +1090,9 @@ static RPCHelpMan gettxoutsetinfo()
1086
1090
UniValue ret (UniValue::VOBJ);
1087
1091
1088
1092
CCoinsStats stats;
1089
- CChainState& active_chainstate = EnsureAnyChainman (request.context ).ActiveChainstate ();
1093
+ NodeContext& node = EnsureAnyNodeContext (request.context );
1094
+ ChainstateManager& chainman = EnsureChainman (node);
1095
+ CChainState& active_chainstate = chainman.ActiveChainstate ();
1090
1096
active_chainstate.ForceFlushStateToDisk ();
1091
1097
1092
1098
const CoinStatsHashType hash_type{request.params [0 ].isNull () ? CoinStatsHashType::HASH_SERIALIZED : ParseHashType (request.params [0 ].get_str ())};
@@ -1098,7 +1104,6 @@ static RPCHelpMan gettxoutsetinfo()
1098
1104
coins_view = &active_chainstate.CoinsDB ();
1099
1105
blockman = &active_chainstate.m_blockman ;
1100
1106
}
1101
- NodeContext& node = EnsureAnyNodeContext (request.context );
1102
1107
if (GetUTXOStats (coins_view, *blockman, stats, hash_type, node.rpc_interruption_point )) {
1103
1108
ret.pushKV (" height" , (int64_t )stats.nHeight );
1104
1109
ret.pushKV (" bestblock" , stats.hashBlock .GetHex ());
@@ -1158,6 +1163,8 @@ static RPCHelpMan gettxout()
1158
1163
},
1159
1164
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1160
1165
{
1166
+ NodeContext& node = EnsureAnyNodeContext (request.context );
1167
+ ChainstateManager& chainman = EnsureChainman (node);
1161
1168
LOCK (cs_main);
1162
1169
1163
1170
UniValue ret (UniValue::VOBJ);
@@ -1170,11 +1177,11 @@ static RPCHelpMan gettxout()
1170
1177
fMempool = request.params [2 ].get_bool ();
1171
1178
1172
1179
Coin coin;
1173
- CChainState& active_chainstate = EnsureAnyChainman (request. context ) .ActiveChainstate ();
1180
+ CChainState& active_chainstate = chainman .ActiveChainstate ();
1174
1181
CCoinsViewCache* coins_view = &active_chainstate.CoinsTip ();
1175
1182
1176
1183
if (fMempool ) {
1177
- const CTxMemPool& mempool = EnsureAnyMemPool (request. context );
1184
+ const CTxMemPool& mempool = EnsureMemPool (node );
1178
1185
LOCK (mempool.cs );
1179
1186
CCoinsViewMemPool view (coins_view, mempool);
1180
1187
if (!view.GetCoin (out, coin) || mempool.isSpent (out)) {
@@ -1224,9 +1231,10 @@ static RPCHelpMan verifychain()
1224
1231
const int check_level (request.params [0 ].isNull () ? DEFAULT_CHECKLEVEL : request.params [0 ].get_int ());
1225
1232
const int check_depth{request.params [1 ].isNull () ? DEFAULT_CHECKBLOCKS : request.params [1 ].get_int ()};
1226
1233
1234
+ ChainstateManager& chainman = EnsureAnyChainman (request.context );
1227
1235
LOCK (cs_main);
1228
1236
1229
- CChainState& active_chainstate = EnsureAnyChainman (request. context ) .ActiveChainstate ();
1237
+ CChainState& active_chainstate = chainman .ActiveChainstate ();
1230
1238
return CVerifyDB ().VerifyDB (Params (), active_chainstate, &active_chainstate.CoinsTip (), check_level, check_depth);
1231
1239
},
1232
1240
};
@@ -1353,8 +1361,8 @@ RPCHelpMan getblockchaininfo()
1353
1361
},
1354
1362
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1355
1363
{
1356
- LOCK (cs_main);
1357
1364
ChainstateManager& chainman = EnsureAnyChainman (request.context );
1365
+ LOCK (cs_main);
1358
1366
1359
1367
const CBlockIndex* tip = chainman.ActiveChain ().Tip ();
1360
1368
CHECK_NONFATAL (tip);
@@ -1893,8 +1901,8 @@ static RPCHelpMan getblockstats()
1893
1901
},
1894
1902
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1895
1903
{
1896
- LOCK (cs_main);
1897
1904
ChainstateManager& chainman = EnsureAnyChainman (request.context );
1905
+ LOCK (cs_main);
1898
1906
1899
1907
CBlockIndex* pindex;
1900
1908
if (request.params [0 ].isNum ()) {
@@ -2295,16 +2303,16 @@ static RPCHelpMan scantxoutset()
2295
2303
int64_t count = 0 ;
2296
2304
std::unique_ptr<CCoinsViewCursor> pcursor;
2297
2305
CBlockIndex* tip;
2306
+ NodeContext& node = EnsureAnyNodeContext (request.context );
2298
2307
{
2308
+ ChainstateManager& chainman = EnsureChainman (node);
2299
2309
LOCK (cs_main);
2300
- ChainstateManager& chainman = EnsureAnyChainman (request.context );
2301
2310
chainman.ActiveChainstate ().ForceFlushStateToDisk ();
2302
2311
pcursor = std::unique_ptr<CCoinsViewCursor>(chainman.ActiveChainstate ().CoinsDB ().Cursor ());
2303
2312
CHECK_NONFATAL (pcursor);
2304
2313
tip = chainman.ActiveChain ().Tip ();
2305
2314
CHECK_NONFATAL (tip);
2306
2315
}
2307
- NodeContext& node = EnsureAnyNodeContext (request.context );
2308
2316
bool res = FindScriptPubKey (g_scan_progress, g_should_abort_scan, count, pcursor.get (), needles, coins, node.rpc_interruption_point );
2309
2317
result.pushKV (" success" , res);
2310
2318
result.pushKV (" txouts" , count);
@@ -2377,8 +2385,9 @@ static RPCHelpMan getblockfilter()
2377
2385
const CBlockIndex* block_index;
2378
2386
bool block_was_connected;
2379
2387
{
2388
+ ChainstateManager& chainman = EnsureAnyChainman (request.context );
2380
2389
LOCK (cs_main);
2381
- block_index = EnsureAnyChainman (request. context ) .m_blockman .LookupBlockIndex (block_hash);
2390
+ block_index = chainman .m_blockman .LookupBlockIndex (block_hash);
2382
2391
if (!block_index) {
2383
2392
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found" );
2384
2393
}
0 commit comments