Bitcoin
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 <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/strencodings.h>
#include <util/system.h>
#include <util/validation.h>
#include <validation.h>
#include <validationinterface.h>
#include <versionbitsinfo.h>
#include <warnings.h>
#include <assert.h>
#include <stdint.h>
#include <univalue.h>
#include <boost/thread/thread.hpp>
#include <condition_variable>
#include <memory>
#include <mutex>

Classes

struct  CUpdatedBlock
 
struct  CCoinsStats
 
struct  CompareBlocksByHeight
 
class  CoinsViewScanReserver
 

Functions

double GetDifficulty (const CBlockIndex *blockindex)
 
static int ComputeNextBlockAndDepth (const CBlockIndex *tip, const CBlockIndex *blockindex, const CBlockIndex *&next)
 
UniValue blockheaderToJSON (const CBlockIndex *tip, const CBlockIndex *blockindex)
 
UniValue blockToJSON (const CBlock &block, const CBlockIndex *tip, const CBlockIndex *blockindex, bool txDetails)
 
static UniValue getblockcount (const JSONRPCRequest &request)
 
static UniValue getbestblockhash (const JSONRPCRequest &request)
 
void RPCNotifyBlockChange (bool ibd, const CBlockIndex *pindex)
 
static UniValue waitfornewblock (const JSONRPCRequest &request)
 
static UniValue waitforblock (const JSONRPCRequest &request)
 
static UniValue waitforblockheight (const JSONRPCRequest &request)
 
static UniValue syncwithvalidationinterfacequeue (const JSONRPCRequest &request)
 
static UniValue getdifficulty (const JSONRPCRequest &request)
 
static std::string EntryDescriptionString ()
 
static void entryToJSON (const CTxMemPool &pool, UniValue &info, const CTxMemPoolEntry &e) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
 
UniValue MempoolToJSON (const CTxMemPool &pool, bool verbose)
 
static UniValue getrawmempool (const JSONRPCRequest &request)
 
static UniValue getmempoolancestors (const JSONRPCRequest &request)
 
static UniValue getmempooldescendants (const JSONRPCRequest &request)
 
static UniValue getmempoolentry (const JSONRPCRequest &request)
 
static UniValue getblockhash (const JSONRPCRequest &request)
 
static UniValue getblockheader (const JSONRPCRequest &request)
 
static CBlock GetBlockChecked (const CBlockIndex *pblockindex)
 
static CBlockUndo GetUndoChecked (const CBlockIndex *pblockindex)
 
static UniValue getblock (const JSONRPCRequest &request)
 
static void ApplyStats (CCoinsStats &stats, CHashWriter &ss, const uint256 &hash, const std::map< uint32_t, Coin > &outputs)
 
static bool GetUTXOStats (CCoinsView *view, CCoinsStats &stats)
 Calculate statistics about the unspent transaction output set. More...
 
static UniValue pruneblockchain (const JSONRPCRequest &request)
 
static UniValue gettxoutsetinfo (const JSONRPCRequest &request)
 
UniValue gettxout (const JSONRPCRequest &request)
 
static UniValue verifychain (const JSONRPCRequest &request)
 
static UniValue SoftForkMajorityDesc (int version, const CBlockIndex *pindex, const Consensus::Params &consensusParams)
 
static UniValue SoftForkDesc (const std::string &name, int version, const CBlockIndex *pindex, const Consensus::Params &consensusParams)
 
static UniValue BIP9SoftForkDesc (const Consensus::Params &consensusParams, Consensus::DeploymentPos id)
 
static void BIP9SoftForkDescPushBack (UniValue &bip9_softforks, const Consensus::Params &consensusParams, Consensus::DeploymentPos id)
 
UniValue getblockchaininfo (const JSONRPCRequest &request)
 
static UniValue getchaintips (const JSONRPCRequest &request)
 
UniValue MempoolInfoToJSON (const CTxMemPool &pool)
 
static UniValue getmempoolinfo (const JSONRPCRequest &request)
 
static UniValue preciousblock (const JSONRPCRequest &request)
 
static UniValue invalidateblock (const JSONRPCRequest &request)
 
static UniValue reconsiderblock (const JSONRPCRequest &request)
 
static UniValue getchaintxstats (const JSONRPCRequest &request)
 
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)
 
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 UniValue getblockstats (const JSONRPCRequest &request)
 
static UniValue savemempool (const JSONRPCRequest &request)
 
bool FindScriptPubKey (std::atomic< int > &scan_progress, const std::atomic< bool > &should_abort, int64_t &count, CCoinsViewCursor *cursor, const std::set< CScript > &needles, std::map< COutPoint, Coin > &out_results)
 Search for a given set of pubkey scripts. More...
 
UniValue scantxoutset (const JSONRPCRequest &request)
 
static UniValue getblockfilter (const JSONRPCRequest &request)
 
void RegisterBlockchainRPCCommands (CRPCTable &t)
 

Variables

static Mutex cs_blockchange
 
static std::condition_variable cond_blockchange
 
static CUpdatedBlock latestblock
 
static constexpr size_t PER_UTXO_OVERHEAD = sizeof(COutPoint) + sizeof(uint32_t) + sizeof(bool)
 
static std::mutex g_utxosetscan
 
static std::atomic< int > g_scan_progress
 
static std::atomic< bool > g_scan_in_progress
 
static std::atomic< bool > g_should_abort_scan
 
static const CRPCCommand commands []
 

Function Documentation

◆ ApplyStats()

static void ApplyStats ( CCoinsStats stats,
CHashWriter ss,
const uint256 hash,
const std::map< uint32_t, Coin > &  outputs 
)
static

◆ BIP9SoftForkDesc()

static UniValue BIP9SoftForkDesc ( const Consensus::Params consensusParams,
Consensus::DeploymentPos  id 
)
static

◆ BIP9SoftForkDescPushBack()

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

◆ blockheaderToJSON()

UniValue blockheaderToJSON ( const CBlockIndex tip,
const CBlockIndex blockindex 
)

Block header to JSON

◆ blockToJSON()

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

Block description to JSON

◆ 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

◆ CalculateTruncatedMedian()

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

◆ ComputeNextBlockAndDepth()

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

◆ EntryDescriptionString()

static std::string EntryDescriptionString ( )
static

◆ entryToJSON()

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

◆ FindScriptPubKey()

bool FindScriptPubKey ( std::atomic< int > &  scan_progress,
const std::atomic< bool > &  should_abort,
int64_t count,
CCoinsViewCursor cursor,
const std::set< CScript > &  needles,
std::map< COutPoint, Coin > &  out_results 
)

Search for a given set of pubkey scripts.

◆ getbestblockhash()

static UniValue getbestblockhash ( const JSONRPCRequest request)
static

◆ getblock()

static UniValue getblock ( const JSONRPCRequest request)
static

◆ getblockchaininfo()

UniValue getblockchaininfo ( const JSONRPCRequest request)

◆ GetBlockChecked()

static CBlock GetBlockChecked ( const CBlockIndex pblockindex)
static

◆ getblockcount()

static UniValue getblockcount ( const JSONRPCRequest request)
static

◆ getblockfilter()

static UniValue getblockfilter ( const JSONRPCRequest request)
static

◆ getblockhash()

static UniValue getblockhash ( const JSONRPCRequest request)
static

◆ getblockheader()

static UniValue getblockheader ( const JSONRPCRequest request)
static

◆ getblockstats()

static UniValue getblockstats ( const JSONRPCRequest request)
static

◆ getchaintips()

static UniValue getchaintips ( const JSONRPCRequest request)
static

◆ getchaintxstats()

static UniValue getchaintxstats ( const JSONRPCRequest request)
static

◆ 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).

◆ getdifficulty()

static UniValue getdifficulty ( const JSONRPCRequest request)
static

◆ getmempoolancestors()

static UniValue getmempoolancestors ( const JSONRPCRequest request)
static

◆ getmempooldescendants()

static UniValue getmempooldescendants ( const JSONRPCRequest request)
static

◆ getmempoolentry()

static UniValue getmempoolentry ( const JSONRPCRequest request)
static

◆ getmempoolinfo()

static UniValue getmempoolinfo ( const JSONRPCRequest request)
static

◆ getrawmempool()

static UniValue getrawmempool ( const JSONRPCRequest request)
static

◆ gettxout()

UniValue gettxout ( const JSONRPCRequest request)

◆ gettxoutsetinfo()

static UniValue gettxoutsetinfo ( const JSONRPCRequest request)
static

◆ GetUndoChecked()

static CBlockUndo GetUndoChecked ( const CBlockIndex pblockindex)
static

◆ GetUTXOStats()

static bool GetUTXOStats ( CCoinsView view,
CCoinsStats stats 
)
static

Calculate statistics about the unspent transaction output set.

◆ invalidateblock()

static UniValue invalidateblock ( const JSONRPCRequest request)
static

◆ MempoolInfoToJSON()

UniValue MempoolInfoToJSON ( const CTxMemPool pool)

Mempool information to JSON

◆ MempoolToJSON()

UniValue MempoolToJSON ( const CTxMemPool pool,
bool  verbose = false 
)

Mempool to JSON

◆ preciousblock()

static UniValue preciousblock ( const JSONRPCRequest request)
static

◆ pruneblockchain()

static UniValue pruneblockchain ( const JSONRPCRequest request)
static

◆ reconsiderblock()

static UniValue reconsiderblock ( const JSONRPCRequest request)
static

◆ RegisterBlockchainRPCCommands()

void RegisterBlockchainRPCCommands ( CRPCTable tableRPC)

Register block chain RPC commands

◆ RPCNotifyBlockChange()

void RPCNotifyBlockChange ( bool  ibd,
const CBlockIndex  
)

Callback for when block tip changed.

◆ savemempool()

static UniValue savemempool ( const JSONRPCRequest request)
static

◆ scantxoutset()

UniValue scantxoutset ( const JSONRPCRequest request)

◆ SetHasKeys() [1/2]

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

◆ 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

◆ SoftForkDesc()

static UniValue SoftForkDesc ( const std::string &  name,
int  version,
const CBlockIndex pindex,
const Consensus::Params consensusParams 
)
static

◆ SoftForkMajorityDesc()

static UniValue SoftForkMajorityDesc ( int  version,
const CBlockIndex pindex,
const Consensus::Params consensusParams 
)
static

Implementation of IsSuperMajority with better feedback

◆ syncwithvalidationinterfacequeue()

static UniValue syncwithvalidationinterfacequeue ( const JSONRPCRequest request)
static

◆ verifychain()

static UniValue verifychain ( const JSONRPCRequest request)
static

◆ waitforblock()

static UniValue waitforblock ( const JSONRPCRequest request)
static

◆ waitforblockheight()

static UniValue waitforblockheight ( const JSONRPCRequest request)
static

◆ waitfornewblock()

static UniValue waitfornewblock ( const JSONRPCRequest request)
static

Variable Documentation

◆ commands

const CRPCCommand commands[]
static

◆ cond_blockchange

std::condition_variable cond_blockchange
static

◆ cs_blockchange

Mutex cs_blockchange
static

◆ g_scan_in_progress

std::atomic<bool> g_scan_in_progress
static

◆ g_scan_progress

std::atomic<int> g_scan_progress
static

◆ g_should_abort_scan

std::atomic<bool> g_should_abort_scan
static

◆ g_utxosetscan

std::mutex g_utxosetscan
static

RAII object to prevent concurrency issue when scanning the txout set

◆ latestblock

CUpdatedBlock latestblock
static

◆ PER_UTXO_OVERHEAD

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