Bitcoin Core  0.20.99
P2P Digital Currency
Classes | Public Member Functions | List of all members
interfaces::Chain Class Referenceabstract

Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to access to the chain state, receive notifications, estimate fees, and submit transactions. More...

#include <chain.h>

Classes

class  Notifications
 Chain notifications. More...
 

Public Member Functions

virtual ~Chain ()
 
virtual Optional< int > getHeight ()=0
 Get current chain height, not including genesis block (returns 0 if chain only contains genesis block, nullopt if chain does not contain any blocks) More...
 
virtual Optional< int > getBlockHeight (const uint256 &hash)=0
 Get block height above genesis block. More...
 
virtual uint256 getBlockHash (int height)=0
 Get block hash. Height must be valid or this function will abort. More...
 
virtual bool haveBlockOnDisk (int height)=0
 Check that the block is available on disk (i.e. More...
 
virtual Optional< int > findFirstBlockWithTimeAndHeight (int64_t time, int height, uint256 *hash)=0
 Return height of the first block in the chain with timestamp equal or greater than the given time and height equal or greater than the given height, or nullopt if there is no block with a high enough timestamp and height. More...
 
virtual CBlockLocator getTipLocator ()=0
 Get locator for the current chain tip. More...
 
virtual Optional< int > findLocatorFork (const CBlockLocator &locator)=0
 Return height of the highest block on chain in common with the locator, which will either be the original block used to create the locator, or one of its ancestors. More...
 
virtual bool checkFinalTx (const CTransaction &tx)=0
 Check if transaction will be final given chain height current time. More...
 
virtual bool findBlock (const uint256 &hash, const FoundBlock &block={})=0
 Return whether node has the block and optionally return block metadata or contents. More...
 
virtual bool findFirstBlockWithTimeAndHeight (int64_t min_time, int min_height, const FoundBlock &block={})=0
 Find first block in the chain with timestamp >= the given time and height >= than the given height, return false if there is no block with a high enough timestamp and height. More...
 
virtual bool findNextBlock (const uint256 &block_hash, int block_height, const FoundBlock &next={}, bool *reorg=nullptr)=0
 Find next block if block is part of current chain. More...
 
virtual bool findAncestorByHeight (const uint256 &block_hash, int ancestor_height, const FoundBlock &ancestor_out={})=0
 Find ancestor of block at specified height and optionally return ancestor information. More...
 
virtual bool findAncestorByHash (const uint256 &block_hash, const uint256 &ancestor_hash, const FoundBlock &ancestor_out={})=0
 Return whether block descends from a specified ancestor, and optionally return ancestor information. More...
 
virtual bool findCommonAncestor (const uint256 &block_hash1, const uint256 &block_hash2, const FoundBlock &ancestor_out={}, const FoundBlock &block1_out={}, const FoundBlock &block2_out={})=0
 Find most recent common ancestor between two blocks and optionally return block information. More...
 
virtual void findCoins (std::map< COutPoint, Coin > &coins)=0
 Look up unspent output information. More...
 
virtual double guessVerificationProgress (const uint256 &block_hash)=0
 Estimate fraction of total transactions verified if blocks up to the specified block hash are verified. More...
 
virtual bool hasBlocks (const uint256 &block_hash, int min_height=0, Optional< int > max_height={})=0
 Return true if data is available for all blocks in the specified range of blocks. More...
 
virtual RBFTransactionState isRBFOptIn (const CTransaction &tx)=0
 Check if transaction is RBF opt in. More...
 
virtual bool hasDescendantsInMempool (const uint256 &txid)=0
 Check if transaction has descendants in mempool. More...
 
virtual bool broadcastTransaction (const CTransactionRef &tx, const CAmount &max_tx_fee, bool relay, std::string &err_string)=0
 Transaction is added to memory pool, if the transaction fee is below the amount specified by max_tx_fee, and broadcast to all peers if relay is set to true. More...
 
virtual void getTransactionAncestry (const uint256 &txid, size_t &ancestors, size_t &descendants)=0
 Calculate mempool ancestor and descendant counts for the given transaction. More...
 
virtual void getPackageLimits (unsigned int &limit_ancestor_count, unsigned int &limit_descendant_count)=0
 Get the node's package limits. More...
 
virtual bool checkChainLimits (const CTransactionRef &tx)=0
 Check if transaction will pass the mempool's chain limits. More...
 
virtual CFeeRate estimateSmartFee (int num_blocks, bool conservative, FeeCalculation *calc=nullptr)=0
 Estimate smart fee. More...
 
virtual unsigned int estimateMaxBlocks ()=0
 Fee estimator max target. More...
 
virtual CFeeRate mempoolMinFee ()=0
 Mempool minimum fee. More...
 
virtual CFeeRate relayMinFee ()=0
 Relay current minimum fee (from -minrelaytxfee and -incrementalrelayfee settings). More...
 
virtual CFeeRate relayIncrementalFee ()=0
 Relay incremental fee setting (-incrementalrelayfee), reflecting cost of relay. More...
 
virtual CFeeRate relayDustFee ()=0
 Relay dust fee setting (-dustrelayfee), reflecting lowest rate it's economical to spend. More...
 
virtual bool havePruned ()=0
 Check if any block has been pruned. More...
 
virtual bool isReadyToBroadcast ()=0
 Check if the node is ready to broadcast transactions. More...
 
virtual bool isInitialBlockDownload ()=0
 Check if in IBD. More...
 
virtual bool shutdownRequested ()=0
 Check if shutdown requested. More...
 
virtual int64_t getAdjustedTime ()=0
 Get adjusted time. More...
 
virtual void initMessage (const std::string &message)=0
 Send init message. More...
 
virtual void initWarning (const bilingual_str &message)=0
 Send init warning. More...
 
virtual void initError (const bilingual_str &message)=0
 Send init error. More...
 
virtual void showProgress (const std::string &title, int progress, bool resume_possible)=0
 Send progress indicator. More...
 
virtual std::unique_ptr< HandlerhandleNotifications (std::shared_ptr< Notifications > notifications)=0
 Register handler for notifications. More...
 
virtual void waitForNotificationsIfTipChanged (const uint256 &old_tip)=0
 Wait for pending notifications to be processed unless block hash points to the current chain tip. More...
 
virtual std::unique_ptr< HandlerhandleRpc (const CRPCCommand &command)=0
 Register handler for RPC. More...
 
virtual bool rpcEnableDeprecated (const std::string &method)=0
 Check if deprecated RPC is enabled. More...
 
virtual void rpcRunLater (const std::string &name, std::function< void()> fn, int64_t seconds)=0
 Run function after given number of seconds. Cancel any previous calls with same name. More...
 
virtual int rpcSerializationFlags ()=0
 Current RPC serialization flags. More...
 
virtual void requestMempoolTransactions (Notifications &notifications)=0
 Synchronously send transactionAddedToMempool notifications about all current mempool transactions to the specified handler and return after the last one is sent. More...
 

Detailed Description

Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to access to the chain state, receive notifications, estimate fees, and submit transactions.

TODO: Current chain methods are too low level, exposing too much of the internal workings of the bitcoin node, and not being very convenient to use. Chain methods should be cleaned up and simplified over time. Examples:

Definition at line 82 of file chain.h.

Constructor & Destructor Documentation

◆ ~Chain()

virtual interfaces::Chain::~Chain ( )
inlinevirtual

Definition at line 85 of file chain.h.

Here is the call graph for this function:

Member Function Documentation

◆ broadcastTransaction()

virtual bool interfaces::Chain::broadcastTransaction ( const CTransactionRef tx,
const CAmount max_tx_fee,
bool  relay,
std::string &  err_string 
)
pure virtual

Transaction is added to memory pool, if the transaction fee is below the amount specified by max_tx_fee, and broadcast to all peers if relay is set to true.

Return false if the transaction could not be added due to the fee or for another reason.

◆ checkChainLimits()

virtual bool interfaces::Chain::checkChainLimits ( const CTransactionRef tx)
pure virtual

Check if transaction will pass the mempool's chain limits.

◆ checkFinalTx()

virtual bool interfaces::Chain::checkFinalTx ( const CTransaction tx)
pure virtual

Check if transaction will be final given chain height current time.

◆ estimateMaxBlocks()

virtual unsigned int interfaces::Chain::estimateMaxBlocks ( )
pure virtual

Fee estimator max target.

Here is the caller graph for this function:

◆ estimateSmartFee()

virtual CFeeRate interfaces::Chain::estimateSmartFee ( int  num_blocks,
bool  conservative,
FeeCalculation calc = nullptr 
)
pure virtual

Estimate smart fee.

Here is the caller graph for this function:

◆ findAncestorByHash()

virtual bool interfaces::Chain::findAncestorByHash ( const uint256 block_hash,
const uint256 ancestor_hash,
const FoundBlock ancestor_out = {} 
)
pure virtual

Return whether block descends from a specified ancestor, and optionally return ancestor information.

Here is the caller graph for this function:

◆ findAncestorByHeight()

virtual bool interfaces::Chain::findAncestorByHeight ( const uint256 block_hash,
int  ancestor_height,
const FoundBlock ancestor_out = {} 
)
pure virtual

Find ancestor of block at specified height and optionally return ancestor information.

Here is the caller graph for this function:

◆ findBlock()

virtual bool interfaces::Chain::findBlock ( const uint256 hash,
const FoundBlock block = {} 
)
pure virtual

Return whether node has the block and optionally return block metadata or contents.

Here is the caller graph for this function:

◆ findCoins()

virtual void interfaces::Chain::findCoins ( std::map< COutPoint, Coin > &  coins)
pure virtual

Look up unspent output information.

Returns coins in the mempool and in the current chain UTXO set. Iterates through all the keys in the map and populates the values.

Here is the caller graph for this function:

◆ findCommonAncestor()

virtual bool interfaces::Chain::findCommonAncestor ( const uint256 block_hash1,
const uint256 block_hash2,
const FoundBlock ancestor_out = {},
const FoundBlock block1_out = {},
const FoundBlock block2_out = {} 
)
pure virtual

Find most recent common ancestor between two blocks and optionally return block information.

Here is the caller graph for this function:

◆ findFirstBlockWithTimeAndHeight() [1/2]

virtual Optional<int> interfaces::Chain::findFirstBlockWithTimeAndHeight ( int64_t  time,
int  height,
uint256 hash 
)
pure virtual

Return height of the first block in the chain with timestamp equal or greater than the given time and height equal or greater than the given height, or nullopt if there is no block with a high enough timestamp and height.

Also return the block hash as an optional output parameter (to avoid the cost of a second lookup in case this information is needed.)

Here is the caller graph for this function:

◆ findFirstBlockWithTimeAndHeight() [2/2]

virtual bool interfaces::Chain::findFirstBlockWithTimeAndHeight ( int64_t  min_time,
int  min_height,
const FoundBlock block = {} 
)
pure virtual

Find first block in the chain with timestamp >= the given time and height >= than the given height, return false if there is no block with a high enough timestamp and height.

Optionally return block information.

◆ findLocatorFork()

virtual Optional<int> interfaces::Chain::findLocatorFork ( const CBlockLocator locator)
pure virtual

Return height of the highest block on chain in common with the locator, which will either be the original block used to create the locator, or one of its ancestors.

Here is the caller graph for this function:

◆ findNextBlock()

virtual bool interfaces::Chain::findNextBlock ( const uint256 block_hash,
int  block_height,
const FoundBlock next = {},
bool *  reorg = nullptr 
)
pure virtual

Find next block if block is part of current chain.

Also flag if there was a reorg and the specified block hash is no longer in the current chain, and optionally return block information.

◆ getAdjustedTime()

virtual int64_t interfaces::Chain::getAdjustedTime ( )
pure virtual

Get adjusted time.

◆ getBlockHash()

virtual uint256 interfaces::Chain::getBlockHash ( int  height)
pure virtual

Get block hash. Height must be valid or this function will abort.

Here is the caller graph for this function:

◆ getBlockHeight()

virtual Optional<int> interfaces::Chain::getBlockHeight ( const uint256 hash)
pure virtual

Get block height above genesis block.

Returns 0 for genesis block, 1 for following block, and so on. Returns nullopt for a block not included in the current chain.

◆ getHeight()

virtual Optional<int> interfaces::Chain::getHeight ( )
pure virtual

Get current chain height, not including genesis block (returns 0 if chain only contains genesis block, nullopt if chain does not contain any blocks)

Here is the caller graph for this function:

◆ getPackageLimits()

virtual void interfaces::Chain::getPackageLimits ( unsigned int &  limit_ancestor_count,
unsigned int &  limit_descendant_count 
)
pure virtual

Get the node's package limits.

Currently only returns the ancestor and descendant count limits, but could be enhanced to return more policy settings.

◆ getTipLocator()

virtual CBlockLocator interfaces::Chain::getTipLocator ( )
pure virtual

Get locator for the current chain tip.

Here is the caller graph for this function:

◆ getTransactionAncestry()

virtual void interfaces::Chain::getTransactionAncestry ( const uint256 txid,
size_t &  ancestors,
size_t &  descendants 
)
pure virtual

Calculate mempool ancestor and descendant counts for the given transaction.

◆ guessVerificationProgress()

virtual double interfaces::Chain::guessVerificationProgress ( const uint256 block_hash)
pure virtual

Estimate fraction of total transactions verified if blocks up to the specified block hash are verified.

◆ handleNotifications()

virtual std::unique_ptr<Handler> interfaces::Chain::handleNotifications ( std::shared_ptr< Notifications notifications)
pure virtual

Register handler for notifications.

◆ handleRpc()

virtual std::unique_ptr<Handler> interfaces::Chain::handleRpc ( const CRPCCommand command)
pure virtual

Register handler for RPC.

Command is not copied, so reference needs to remain valid until Handler is disconnected.

◆ hasBlocks()

virtual bool interfaces::Chain::hasBlocks ( const uint256 block_hash,
int  min_height = 0,
Optional< int >  max_height = {} 
)
pure virtual

Return true if data is available for all blocks in the specified range of blocks.

This checks all blocks that are ancestors of block_hash in the height range from min_height to max_height, inclusive.

Here is the caller graph for this function:

◆ hasDescendantsInMempool()

virtual bool interfaces::Chain::hasDescendantsInMempool ( const uint256 txid)
pure virtual

Check if transaction has descendants in mempool.

◆ haveBlockOnDisk()

virtual bool interfaces::Chain::haveBlockOnDisk ( int  height)
pure virtual

Check that the block is available on disk (i.e.

has not been pruned), and contains transactions.

Here is the caller graph for this function:

◆ havePruned()

virtual bool interfaces::Chain::havePruned ( )
pure virtual

Check if any block has been pruned.

Here is the caller graph for this function:

◆ initError()

virtual void interfaces::Chain::initError ( const bilingual_str message)
pure virtual

Send init error.

Here is the caller graph for this function:

◆ initMessage()

virtual void interfaces::Chain::initMessage ( const std::string &  message)
pure virtual

Send init message.

Here is the caller graph for this function:

◆ initWarning()

virtual void interfaces::Chain::initWarning ( const bilingual_str message)
pure virtual

Send init warning.

Here is the caller graph for this function:

◆ isInitialBlockDownload()

virtual bool interfaces::Chain::isInitialBlockDownload ( )
pure virtual

Check if in IBD.

Here is the caller graph for this function:

◆ isRBFOptIn()

virtual RBFTransactionState interfaces::Chain::isRBFOptIn ( const CTransaction tx)
pure virtual

Check if transaction is RBF opt in.

Here is the caller graph for this function:

◆ isReadyToBroadcast()

virtual bool interfaces::Chain::isReadyToBroadcast ( )
pure virtual

Check if the node is ready to broadcast transactions.

◆ mempoolMinFee()

virtual CFeeRate interfaces::Chain::mempoolMinFee ( )
pure virtual

Mempool minimum fee.

Here is the caller graph for this function:

◆ relayDustFee()

virtual CFeeRate interfaces::Chain::relayDustFee ( )
pure virtual

Relay dust fee setting (-dustrelayfee), reflecting lowest rate it's economical to spend.

Here is the caller graph for this function:

◆ relayIncrementalFee()

virtual CFeeRate interfaces::Chain::relayIncrementalFee ( )
pure virtual

Relay incremental fee setting (-incrementalrelayfee), reflecting cost of relay.

Here is the caller graph for this function:

◆ relayMinFee()

virtual CFeeRate interfaces::Chain::relayMinFee ( )
pure virtual

Relay current minimum fee (from -minrelaytxfee and -incrementalrelayfee settings).

Here is the caller graph for this function:

◆ requestMempoolTransactions()

virtual void interfaces::Chain::requestMempoolTransactions ( Notifications notifications)
pure virtual

Synchronously send transactionAddedToMempool notifications about all current mempool transactions to the specified handler and return after the last one is sent.

These notifications aren't coordinated with async notifications sent by handleNotifications, so out of date async notifications from handleNotifications can arrive during and after synchronous notifications from requestMempoolTransactions. Clients need to be prepared to handle this by ignoring notifications about unknown removed transactions and already added new transactions.

◆ rpcEnableDeprecated()

virtual bool interfaces::Chain::rpcEnableDeprecated ( const std::string &  method)
pure virtual

Check if deprecated RPC is enabled.

◆ rpcRunLater()

virtual void interfaces::Chain::rpcRunLater ( const std::string &  name,
std::function< void()>  fn,
int64_t  seconds 
)
pure virtual

Run function after given number of seconds. Cancel any previous calls with same name.

Here is the caller graph for this function:

◆ rpcSerializationFlags()

virtual int interfaces::Chain::rpcSerializationFlags ( )
pure virtual

Current RPC serialization flags.

Here is the caller graph for this function:

◆ showProgress()

virtual void interfaces::Chain::showProgress ( const std::string &  title,
int  progress,
bool  resume_possible 
)
pure virtual

Send progress indicator.

Here is the caller graph for this function:

◆ shutdownRequested()

virtual bool interfaces::Chain::shutdownRequested ( )
pure virtual

Check if shutdown requested.

◆ waitForNotificationsIfTipChanged()

virtual void interfaces::Chain::waitForNotificationsIfTipChanged ( const uint256 old_tip)
pure virtual

Wait for pending notifications to be processed unless block hash points to the current chain tip.


The documentation for this class was generated from the following file: