Bitcoin Core  0.20.99
P2P Digital Currency
Classes | Functions | Variables
blockchain.cpp File Reference
#include <rpc/blockchain.h>
#include <amount.h>
#include <blockfilter.h>
#include <chain.h>
#include <chainparams.h>
#include <coins.h>
#include <consensus/validation.h>
#include <core_io.h>
#include <hash.h>
#include <index/blockfilterindex.h>
#include <node/coinstats.h>
#include <node/context.h>
#include <node/utxo_snapshot.h>
#include <policy/feerate.h>
#include <policy/policy.h>
#include <policy/rbf.h>
#include <primitives/transaction.h>
#include <rpc/server.h>
#include <rpc/util.h>
#include <script/descriptor.h>
#include <streams.h>
#include <sync.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 <warnings.h>
#include <stdint.h>
#include <univalue.h>
#include <condition_variable>
#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)
 Get the difficulty of the net wrt to the 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 ()
 
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 CBlockIndex *pblockindex)
 
static CBlockUndo GetUndoChecked (const CBlockIndex *pblockindex)
 
static RPCHelpMan getblock ()
 
static RPCHelpMan pruneblockchain ()
 
static RPCHelpMan gettxoutsetinfo ()
 
static RPCHelpMan gettxout ()
 
static RPCHelpMan verifychain ()
 
static void BuriedForkDescPushBack (UniValue &softforks, const std::string &name, int height) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 
static void BIP9SoftForkDescPushBack (UniValue &softforks, const std::string &name, 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 ()
 
static RPCHelpMan invalidateblock ()
 
static RPCHelpMan reconsiderblock ()
 
static RPCHelpMan getchaintxstats ()
 
template<typename T >
static T CalculateTruncatedMedian (std::vector< T > &scores)
 
void CalculatePercentilesByWeight (CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector< std::pair< CAmount, int64_t >> &scores, int64_t total_weight)
 Used by getblockstats to get feerates at different percentiles by weight. More...
 
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 = sizeof(COutPoint) + sizeof(uint32_t) + sizeof(bool)
 
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 std::string &  name,
const Consensus::Params consensusParams,
Consensus::DeploymentPos  id 
)
static

Definition at line 1214 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 118 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 147 of file blockchain.cpp.

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

◆ BuriedForkDescPushBack()

static void BuriedForkDescPushBack ( UniValue softforks,
const std::string &  name,
int  height 
)
static

Definition at line 1196 of file blockchain.cpp.

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

◆ CalculatePercentilesByWeight()

void CalculatePercentilesByWeight ( CAmount  result[NUM_GETBLOCKSTATS_PERCENTILES],
std::vector< std::pair< CAmount, int64_t >> &  scores,
int64_t  total_weight 
)

Used by getblockstats to get feerates at different percentiles by weight.

Definition at line 1736 of file blockchain.cpp.

Here is the caller graph for this function:

◆ CalculateTruncatedMedian()

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

Definition at line 1721 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 108 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 2360 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 75 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 66 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 58 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 441 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 212 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 883 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 1262 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 CBlockIndex pblockindex)
static

Definition at line 852 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 2277 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 756 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 783 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 1776 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

Definition at line 1381 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 1641 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)

Get the difficulty of the net wrt to the given block index.

Returns
A floating point number that is a multiple of the main net minimum difficulty (4295032833 hashes).

Definition at line 86 of file blockchain.cpp.

Here is the caller graph for this function:

◆ getdifficulty()

static RPCHelpMan getdifficulty ( )
static

Definition at line 393 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 594 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 658 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 723 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 1495 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 544 of file blockchain.cpp.

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

◆ gettxout()

static RPCHelpMan gettxout ( )
static

Definition at line 1088 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 1034 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 869 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 1562 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 412 of file blockchain.cpp.

Here is the caller graph for this function:

◆ MempoolInfoToJSON()

UniValue MempoolInfoToJSON ( const CTxMemPool pool)

Mempool information to JSON.

Definition at line 1478 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 503 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 1523 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 977 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 1602 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 2463 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 )

Callback for when block tip changed.

Definition at line 231 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 2037 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 2123 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 1766 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 1768 of file blockchain.cpp.

Here is the call graph for this function:

◆ syncwithvalidationinterfacequeue()

static RPCHelpMan syncwithvalidationinterfacequeue ( )
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:

◆ verifychain()

static RPCHelpMan verifychain ( )
static

Definition at line 1169 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 283 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 329 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 241 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 55 of file blockchain.cpp.

◆ cs_blockchange

Mutex cs_blockchange
static

Definition at line 54 of file blockchain.cpp.

◆ g_scan_in_progress

std::atomic<bool> g_scan_in_progress
static

Definition at line 2098 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 2097 of file blockchain.cpp.

◆ g_should_abort_scan

std::atomic<bool> g_should_abort_scan
static

Definition at line 2099 of file blockchain.cpp.

◆ PER_UTXO_OVERHEAD

constexpr size_t PER_UTXO_OVERHEAD = sizeof(COutPoint) + sizeof(uint32_t) + sizeof(bool)
static

Definition at line 1774 of file blockchain.cpp.