@@ -1009,6 +1009,8 @@ static RPCHelpMan pruneblockchain()
1009
1009
1010
1010
ChainstateManager& chainman = EnsureAnyChainman (request.context );
1011
1011
LOCK (cs_main);
1012
+ CChainState& active_chainstate = chainman.ActiveChainstate ();
1013
+ CChain& active_chain = active_chainstate.m_chain ;
1012
1014
1013
1015
int heightParam = request.params [0 ].get_int ();
1014
1016
if (heightParam < 0 )
@@ -1018,15 +1020,15 @@ static RPCHelpMan pruneblockchain()
1018
1020
// too low to be a block time (corresponds to timestamp from Sep 2001).
1019
1021
if (heightParam > 1000000000 ) {
1020
1022
// Add a 2 hour buffer to include blocks which might have had old timestamps
1021
- CBlockIndex* pindex = chainman. ActiveChain () .FindEarliestAtLeast (heightParam - TIMESTAMP_WINDOW, 0 );
1023
+ CBlockIndex* pindex = active_chain .FindEarliestAtLeast (heightParam - TIMESTAMP_WINDOW, 0 );
1022
1024
if (!pindex) {
1023
1025
throw JSONRPCError (RPC_INVALID_PARAMETER, " Could not find block with at least the specified timestamp." );
1024
1026
}
1025
1027
heightParam = pindex->nHeight ;
1026
1028
}
1027
1029
1028
1030
unsigned int height = (unsigned int ) heightParam;
1029
- unsigned int chainHeight = (unsigned int ) chainman. ActiveChain () .Height ();
1031
+ unsigned int chainHeight = (unsigned int ) active_chain .Height ();
1030
1032
if (chainHeight < Params ().PruneAfterHeight ())
1031
1033
throw JSONRPCError (RPC_MISC_ERROR, " Blockchain is too short for pruning." );
1032
1034
else if (height > chainHeight)
@@ -1036,8 +1038,8 @@ static RPCHelpMan pruneblockchain()
1036
1038
height = chainHeight - MIN_BLOCKS_TO_KEEP;
1037
1039
}
1038
1040
1039
- PruneBlockFilesManual (chainman. ActiveChainstate () , height);
1040
- const CBlockIndex* block = chainman. ActiveChain () .Tip ();
1041
+ PruneBlockFilesManual (active_chainstate , height);
1042
+ const CBlockIndex* block = active_chain .Tip ();
1041
1043
CHECK_NONFATAL (block);
1042
1044
while (block->pprev && (block->pprev ->nStatus & BLOCK_HAVE_DATA)) {
1043
1045
block = block->pprev ;
@@ -1363,8 +1365,9 @@ RPCHelpMan getblockchaininfo()
1363
1365
{
1364
1366
ChainstateManager& chainman = EnsureAnyChainman (request.context );
1365
1367
LOCK (cs_main);
1368
+ CChainState& active_chainstate = chainman.ActiveChainstate ();
1366
1369
1367
- const CBlockIndex* tip = chainman. ActiveChain () .Tip ();
1370
+ const CBlockIndex* tip = active_chainstate. m_chain .Tip ();
1368
1371
CHECK_NONFATAL (tip);
1369
1372
const int height = tip->nHeight ;
1370
1373
UniValue obj (UniValue::VOBJ);
@@ -1375,7 +1378,7 @@ RPCHelpMan getblockchaininfo()
1375
1378
obj.pushKV (" difficulty" , (double )GetDifficulty (tip));
1376
1379
obj.pushKV (" mediantime" , (int64_t )tip->GetMedianTimePast ());
1377
1380
obj.pushKV (" verificationprogress" , GuessVerificationProgress (Params ().TxData (), tip));
1378
- obj.pushKV (" initialblockdownload" , chainman. ActiveChainstate () .IsInitialBlockDownload ());
1381
+ obj.pushKV (" initialblockdownload" , active_chainstate .IsInitialBlockDownload ());
1379
1382
obj.pushKV (" chainwork" , tip->nChainWork .GetHex ());
1380
1383
obj.pushKV (" size_on_disk" , CalculateCurrentUsage ());
1381
1384
obj.pushKV (" pruned" , fPruneMode );
@@ -1457,6 +1460,7 @@ static RPCHelpMan getchaintips()
1457
1460
{
1458
1461
ChainstateManager& chainman = EnsureAnyChainman (request.context );
1459
1462
LOCK (cs_main);
1463
+ CChain& active_chain = chainman.ActiveChain ();
1460
1464
1461
1465
/*
1462
1466
* Idea: The set of chain tips is the active chain tip, plus orphan blocks which do not have another orphan building off of them.
@@ -1470,7 +1474,7 @@ static RPCHelpMan getchaintips()
1470
1474
std::set<const CBlockIndex*> setPrevs;
1471
1475
1472
1476
for (const std::pair<const uint256, CBlockIndex*>& item : chainman.BlockIndex ()) {
1473
- if (!chainman. ActiveChain () .Contains (item.second )) {
1477
+ if (!active_chain .Contains (item.second )) {
1474
1478
setOrphans.insert (item.second );
1475
1479
setPrevs.insert (item.second ->pprev );
1476
1480
}
@@ -1483,7 +1487,7 @@ static RPCHelpMan getchaintips()
1483
1487
}
1484
1488
1485
1489
// Always report the currently active tip.
1486
- setTips.insert (chainman. ActiveChain () .Tip ());
1490
+ setTips.insert (active_chain .Tip ());
1487
1491
1488
1492
/* Construct the output array. */
1489
1493
UniValue res (UniValue::VARR);
@@ -1492,11 +1496,11 @@ static RPCHelpMan getchaintips()
1492
1496
obj.pushKV (" height" , block->nHeight );
1493
1497
obj.pushKV (" hash" , block->phashBlock ->GetHex ());
1494
1498
1495
- const int branchLen = block->nHeight - chainman. ActiveChain () .FindFork (block)->nHeight ;
1499
+ const int branchLen = block->nHeight - active_chain .FindFork (block)->nHeight ;
1496
1500
obj.pushKV (" branchlen" , branchLen);
1497
1501
1498
1502
std::string status;
1499
- if (chainman. ActiveChain () .Contains (block)) {
1503
+ if (active_chain .Contains (block)) {
1500
1504
// This block is part of the currently active chain.
1501
1505
status = " active" ;
1502
1506
} else if (block->nStatus & BLOCK_FAILED_MASK) {
@@ -1903,26 +1907,27 @@ static RPCHelpMan getblockstats()
1903
1907
{
1904
1908
ChainstateManager& chainman = EnsureAnyChainman (request.context );
1905
1909
LOCK (cs_main);
1910
+ CChain& active_chain = chainman.ActiveChain ();
1906
1911
1907
1912
CBlockIndex* pindex;
1908
1913
if (request.params [0 ].isNum ()) {
1909
1914
const int height = request.params [0 ].get_int ();
1910
- const int current_tip = chainman. ActiveChain () .Height ();
1915
+ const int current_tip = active_chain .Height ();
1911
1916
if (height < 0 ) {
1912
1917
throw JSONRPCError (RPC_INVALID_PARAMETER, strprintf (" Target block height %d is negative" , height));
1913
1918
}
1914
1919
if (height > current_tip) {
1915
1920
throw JSONRPCError (RPC_INVALID_PARAMETER, strprintf (" Target block height %d after current tip %d" , height, current_tip));
1916
1921
}
1917
1922
1918
- pindex = chainman. ActiveChain () [height];
1923
+ pindex = active_chain [height];
1919
1924
} else {
1920
1925
const uint256 hash (ParseHashV (request.params [0 ], " hash_or_height" ));
1921
1926
pindex = chainman.m_blockman .LookupBlockIndex (hash);
1922
1927
if (!pindex) {
1923
1928
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found" );
1924
1929
}
1925
- if (!chainman. ActiveChain () .Contains (pindex)) {
1930
+ if (!active_chain .Contains (pindex)) {
1926
1931
throw JSONRPCError (RPC_INVALID_PARAMETER, strprintf (" Block is not in chain %s" , Params ().NetworkIDString ()));
1927
1932
}
1928
1933
}
@@ -2307,10 +2312,11 @@ static RPCHelpMan scantxoutset()
2307
2312
{
2308
2313
ChainstateManager& chainman = EnsureChainman (node);
2309
2314
LOCK (cs_main);
2310
- chainman.ActiveChainstate ().ForceFlushStateToDisk ();
2311
- pcursor = std::unique_ptr<CCoinsViewCursor>(chainman.ActiveChainstate ().CoinsDB ().Cursor ());
2315
+ CChainState& active_chainstate = chainman.ActiveChainstate ();
2316
+ active_chainstate.ForceFlushStateToDisk ();
2317
+ pcursor = std::unique_ptr<CCoinsViewCursor>(active_chainstate.CoinsDB ().Cursor ());
2312
2318
CHECK_NONFATAL (pcursor);
2313
- tip = chainman. ActiveChain () .Tip ();
2319
+ tip = active_chainstate. m_chain .Tip ();
2314
2320
CHECK_NONFATAL (tip);
2315
2321
}
2316
2322
bool res = FindScriptPubKey (g_scan_progress, g_should_abort_scan, count, pcursor.get (), needles, coins, node.rpc_interruption_point );
0 commit comments