Bitcoin ABC  0.24.7
P2P Digital Currency
Classes | Functions | Variables
blockchain.cpp File Reference
#include <rpc/blockchain.h>
#include <amount.h>
#include <blockdb.h>
#include <blockfilter.h>
#include <chain.h>
#include <chainparams.h>
#include <checkpoints.h>
#include <coins.h>
#include <config.h>
#include <consensus/validation.h>
#include <core_io.h>
#include <hash.h>
#include <index/blockfilterindex.h>
#include <network.h>
#include <node/coinstats.h>
#include <node/context.h>
#include <node/utxo_snapshot.h>
#include <policy/policy.h>
#include <primitives/transaction.h>
#include <rpc/server.h>
#include <rpc/util.h>
#include <script/descriptor.h>
#include <streams.h>
#include <txdb.h>
#include <txmempool.h>
#include <undo.h>
#include <util/ref.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <util/translation.h>
#include <validation.h>
#include <validationinterface.h>
#include <versionbitsinfo.h>
#include <warnings.h>
#include <condition_variable>
#include <cstdint>
#include <memory>
#include <mutex>
Include dependency graph for blockchain.cpp:

Go to the source code of this file.

Classes

struct  CUpdatedBlock
 
struct  CompareBlocksByHeight
 Comparison function for sorting the getchaintips heads. More...
 
class  CoinsViewScanReserver
 

Functions

static CUpdatedBlock latestblock GUARDED_BY (cs_blockchange)
 
NodeContextEnsureNodeContext (const util::Ref &context)
 
CTxMemPoolEnsureMemPool (const util::Ref &context)
 
ChainstateManagerEnsureChainman (const util::Ref &context)
 
double GetDifficulty (const CBlockIndex *blockindex)
 Calculate the difficulty for a given block index. More...
 
static int ComputeNextBlockAndDepth (const CBlockIndex *tip, const CBlockIndex *blockindex, const CBlockIndex *&next)
 
UniValue blockheaderToJSON (const CBlockIndex *tip, const CBlockIndex *blockindex)
 Block header to JSON. More...
 
UniValue blockToJSON (const CBlock &block, const CBlockIndex *tip, const CBlockIndex *blockindex, bool txDetails)
 Block description to JSON. More...
 
static RPCHelpMan getblockcount ()
 
static RPCHelpMan getbestblockhash ()
 
RPCHelpMan getfinalizedblockhash ()
 
void RPCNotifyBlockChange (const CBlockIndex *pindex)
 Callback for when block tip changed. More...
 
static RPCHelpMan waitfornewblock ()
 
static RPCHelpMan waitforblock ()
 
static RPCHelpMan waitforblockheight ()
 
static RPCHelpMan syncwithvalidationinterfacequeue ()
 
static RPCHelpMan getdifficulty ()
 
static std::vector< RPCResultMempoolEntryDescription ()
 
static void entryToJSON (const CTxMemPool &pool, UniValue &info, const CTxMemPoolEntry &e) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
 
UniValue MempoolToJSON (const CTxMemPool &pool, bool verbose, bool include_mempool_sequence)
 Mempool to JSON. More...
 
static RPCHelpMan getrawmempool ()
 
static RPCHelpMan getmempoolancestors ()
 
static RPCHelpMan getmempooldescendants ()
 
static RPCHelpMan getmempoolentry ()
 
static RPCHelpMan getblockhash ()
 
static RPCHelpMan getblockheader ()
 
static CBlock GetBlockChecked (const Config &config, const CBlockIndex *pblockindex)
 
static CBlockUndo GetUndoChecked (const CBlockIndex *pblockindex)
 
static RPCHelpMan getblock ()
 
static RPCHelpMan pruneblockchain ()
 
static RPCHelpMan gettxoutsetinfo ()
 
RPCHelpMan gettxout ()
 
static RPCHelpMan verifychain ()
 
static void BIP9SoftForkDescPushBack (UniValue &softforks, const Consensus::Params &consensusParams, Consensus::DeploymentPos id) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 
RPCHelpMan getblockchaininfo ()
 
static RPCHelpMan getchaintips ()
 
UniValue MempoolInfoToJSON (const CTxMemPool &pool)
 Mempool information to JSON. More...
 
static RPCHelpMan getmempoolinfo ()
 
static RPCHelpMan preciousblock ()
 
RPCHelpMan finalizeblock ()
 
static RPCHelpMan invalidateblock ()
 
RPCHelpMan parkblock ()
 
static RPCHelpMan reconsiderblock ()
 
RPCHelpMan unparkblock ()
 
static RPCHelpMan getchaintxstats ()
 
template<typename T >
static T CalculateTruncatedMedian (std::vector< T > &scores)
 
template<typename T >
static bool SetHasKeys (const std::set< T > &set)
 
template<typename T , typename Tk , typename... Args>
static bool SetHasKeys (const std::set< T > &set, const Tk &key, const Args &... args)
 
static RPCHelpMan getblockstats ()
 
static RPCHelpMan savemempool ()
 
static RPCHelpMan scantxoutset ()
 
static RPCHelpMan getblockfilter ()
 
static RPCHelpMan dumptxoutset ()
 Serialize the UTXO set to a file for loading elsewhere. More...
 
void RegisterBlockchainRPCCommands (CRPCTable &t)
 Register block chain RPC commands. More...
 

Variables

static Mutex cs_blockchange
 
static std::condition_variable cond_blockchange
 
static constexpr size_t PER_UTXO_OVERHEAD
 
static std::atomic< int > g_scan_progress
 RAII object to prevent concurrency issue when scanning the txout set. More...
 
static std::atomic< bool > g_scan_in_progress
 
static std::atomic< bool > g_should_abort_scan
 

Function Documentation

◆ BIP9SoftForkDescPushBack()

static void BIP9SoftForkDescPushBack ( UniValue softforks,
const Consensus::Params consensusParams,
Consensus::DeploymentPos  id 
)
static

Definition at line 1433 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ blockheaderToJSON()

UniValue blockheaderToJSON ( const CBlockIndex tip,
const CBlockIndex blockindex 
)

Block header to JSON.

Definition at line 112 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ blockToJSON()

UniValue blockToJSON ( const CBlock block,
const CBlockIndex tip,
const CBlockIndex blockindex,
bool  txDetails 
)

Block description to JSON.

Definition at line 146 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalculateTruncatedMedian()

template<typename T >
static T CalculateTruncatedMedian ( std::vector< T > &  scores)
static

Definition at line 2217 of file blockchain.cpp.

Here is the caller graph for this function:

◆ ComputeNextBlockAndDepth()

static int ComputeNextBlockAndDepth ( const CBlockIndex tip,
const CBlockIndex blockindex,
const CBlockIndex *&  next 
)
static

Definition at line 101 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dumptxoutset()

static RPCHelpMan dumptxoutset ( )
static

Serialize the UTXO set to a file for loading elsewhere.

See also
SnapshotMetadata

Definition at line 2945 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnsureChainman()

ChainstateManager& EnsureChainman ( const util::Ref context)

Definition at line 72 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnsureMemPool()

CTxMemPool& EnsureMemPool ( const util::Ref context)

Definition at line 63 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnsureNodeContext()

NodeContext& EnsureNodeContext ( const util::Ref context)

Definition at line 56 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ entryToJSON()

static void entryToJSON ( const CTxMemPool pool,
UniValue info,
const CTxMemPoolEntry e 
)
static

Definition at line 540 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finalizeblock()

RPCHelpMan finalizeblock ( )

Definition at line 1897 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getbestblockhash()

static RPCHelpMan getbestblockhash ( )
static

Definition at line 209 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getblock()

static RPCHelpMan getblock ( )
static

Definition at line 1031 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getblockchaininfo()

RPCHelpMan getblockchaininfo ( )

Definition at line 1495 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBlockChecked()

static CBlock GetBlockChecked ( const Config config,
const CBlockIndex pblockindex 
)
static

Definition at line 999 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getblockcount()

static RPCHelpMan getblockcount ( )
static

Definition at line 192 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getblockfilter()

static RPCHelpMan getblockfilter ( )
static

Definition at line 2846 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getblockhash()

static RPCHelpMan getblockhash ( )
static

Definition at line 880 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getblockheader()

static RPCHelpMan getblockheader ( )
static

Definition at line 907 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getblockstats()

static RPCHelpMan getblockstats ( )
static

Definition at line 2244 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getchaintips()

static RPCHelpMan getchaintips ( )
static

Idea: The set of chain tips is the active chain tip, plus orphan blocks which do not have another orphan building off of them. Algorithm:

  • Make one pass through BlockIndex(), picking out the orphan blocks, and also storing a set of the orphan block's pprev pointers.
  • Iterate through the orphan blocks. If the block isn't pointed to by another orphan, it is a chain tip.
  • Add the active chain tip

Definition at line 1674 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getchaintxstats()

static RPCHelpMan getchaintxstats ( )
static

Definition at line 2106 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getdifficulty()

static RPCHelpMan getdifficulty ( )
static

Definition at line 452 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDifficulty()

double GetDifficulty ( const CBlockIndex blockindex)

Calculate the difficulty for a given block index.

Get the required difficulty of the next block w/r/t the given block index.

Definition at line 83 of file blockchain.cpp.

Here is the caller graph for this function:

◆ getfinalizedblockhash()

RPCHelpMan getfinalizedblockhash ( )

Definition at line 226 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getmempoolancestors()

static RPCHelpMan getmempoolancestors ( )
static

Definition at line 699 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getmempooldescendants()

static RPCHelpMan getmempooldescendants ( )
static

Definition at line 774 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getmempoolentry()

static RPCHelpMan getmempoolentry ( )
static

Definition at line 848 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getmempoolinfo()

static RPCHelpMan getmempoolinfo ( )
static

Definition at line 1819 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getrawmempool()

static RPCHelpMan getrawmempool ( )
static

Definition at line 633 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gettxout()

RPCHelpMan gettxout ( )

Definition at line 1304 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gettxoutsetinfo()

static RPCHelpMan gettxoutsetinfo ( )
static

Definition at line 1235 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetUndoChecked()

static CBlockUndo GetUndoChecked ( const CBlockIndex pblockindex)
static

Definition at line 1017 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GUARDED_BY()

static CUpdatedBlock latestblock GUARDED_BY ( cs_blockchange  )
static

◆ invalidateblock()

static RPCHelpMan invalidateblock ( )
static

Definition at line 1942 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MempoolEntryDescription()

static std::vector<RPCResult> MempoolEntryDescription ( )
static

Definition at line 471 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MempoolInfoToJSON()

UniValue MempoolInfoToJSON ( const CTxMemPool pool)

Mempool information to JSON.

Definition at line 1800 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MempoolToJSON()

UniValue MempoolToJSON ( const CTxMemPool pool,
bool  verbose,
bool  include_mempool_sequence 
)

Mempool to JSON.

Definition at line 589 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parkblock()

RPCHelpMan parkblock ( )

Definition at line 1983 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ preciousblock()

static RPCHelpMan preciousblock ( )
static

Definition at line 1856 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pruneblockchain()

static RPCHelpMan pruneblockchain ( )
static

Definition at line 1160 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconsiderblock()

static RPCHelpMan reconsiderblock ( )
static

Definition at line 2024 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterBlockchainRPCCommands()

void RegisterBlockchainRPCCommands ( CRPCTable t)

Register block chain RPC commands.

Definition at line 3058 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPCNotifyBlockChange()

void RPCNotifyBlockChange ( const CBlockIndex pindex)

Callback for when block tip changed.

Definition at line 247 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ savemempool()

static RPCHelpMan savemempool ( )
static

Definition at line 2541 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scantxoutset()

static RPCHelpMan scantxoutset ( )
static

Definition at line 2635 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetHasKeys() [1/2]

template<typename T >
static bool SetHasKeys ( const std::set< T > &  set)
inlinestatic

Definition at line 2231 of file blockchain.cpp.

Here is the caller graph for this function:

◆ SetHasKeys() [2/2]

template<typename T , typename Tk , typename... Args>
static bool SetHasKeys ( const std::set< T > &  set,
const Tk &  key,
const Args &...  args 
)
inlinestatic

Definition at line 2235 of file blockchain.cpp.

Here is the call graph for this function:

◆ syncwithvalidationinterfacequeue()

static RPCHelpMan syncwithvalidationinterfacequeue ( )
static

Definition at line 435 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unparkblock()

RPCHelpMan unparkblock ( )

Definition at line 2064 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verifychain()

static RPCHelpMan verifychain ( )
static

Definition at line 1399 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitforblock()

static RPCHelpMan waitforblock ( )
static

Definition at line 313 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitforblockheight()

static RPCHelpMan waitforblockheight ( )
static

Definition at line 375 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitfornewblock()

static RPCHelpMan waitfornewblock ( )
static

Definition at line 256 of file blockchain.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cond_blockchange

std::condition_variable cond_blockchange
static

Definition at line 53 of file blockchain.cpp.

◆ cs_blockchange

Mutex cs_blockchange
static

Definition at line 52 of file blockchain.cpp.

◆ g_scan_in_progress

std::atomic<bool> g_scan_in_progress
static

Definition at line 2610 of file blockchain.cpp.

◆ g_scan_progress

std::atomic<int> g_scan_progress
static

RAII object to prevent concurrency issue when scanning the txout set.

Definition at line 2609 of file blockchain.cpp.

◆ g_should_abort_scan

std::atomic<bool> g_should_abort_scan
static

Definition at line 2611 of file blockchain.cpp.

◆ PER_UTXO_OVERHEAD

constexpr size_t PER_UTXO_OVERHEAD
staticconstexpr
Initial value:
=
sizeof(COutPoint) + sizeof(uint32_t) + sizeof(bool)

Definition at line 2241 of file blockchain.cpp.

COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22