Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.h
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | public: | ||||
//! Interface for querying locked chain state, used by legacy code that | //! Interface for querying locked chain state, used by legacy code that | ||||
//! assumes state won't change between calls. New code should avoid using | //! assumes state won't change between calls. New code should avoid using | ||||
//! the Lock interface and instead call higher-level Chain methods | //! the Lock interface and instead call higher-level Chain methods | ||||
//! that return more information so the chain doesn't need to stay locked | //! that return more information so the chain doesn't need to stay locked | ||||
//! between calls. | //! between calls. | ||||
class Lock { | class Lock { | ||||
public: | public: | ||||
virtual ~Lock() {} | virtual ~Lock() {} | ||||
//! Check that the block is available on disk (i.e. has not been | |||||
//! pruned), and contains transactions. | |||||
virtual bool haveBlockOnDisk(int height) = 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. Also return the block hash as an optional | |||||
//! output parameter (to avoid the cost of a second lookup in case this | |||||
//! information is needed.) | |||||
virtual Optional<int> | |||||
findFirstBlockWithTimeAndHeight(int64_t time, int height, | |||||
BlockHash *hash) = 0; | |||||
//! Return height of the highest block on the chain that is an ancestor | |||||
//! of the specified block, or nullopt if no common ancestor is found. | |||||
//! Also return the height of the specified block as an optional output | |||||
//! parameter (to avoid the cost of a second hash lookup in case this | |||||
//! information is desired). | |||||
virtual Optional<int> findFork(const BlockHash &hash, | |||||
Optional<int> *height) = 0; | |||||
//! Get locator for the current chain tip. | |||||
virtual CBlockLocator getTipLocator() = 0; | |||||
//! Return height of the latest block common to locator and chain, which | |||||
//! is guaranteed to be an ancestor of the block used to create the | |||||
//! locator. | |||||
virtual Optional<int> findLocatorFork(const CBlockLocator &locator) = 0; | |||||
//! Check if transaction will be final given chain height current time. | |||||
virtual bool contextualCheckTransactionForCurrentBlock( | |||||
const Consensus::Params ¶ms, const CTransaction &tx, | |||||
TxValidationState &state) = 0; | |||||
}; | }; | ||||
//! Return Lock interface. Chain is locked when this is called, and | //! Return Lock interface. Chain is locked when this is called, and | ||||
//! unlocked when the returned interface is freed. | //! unlocked when the returned interface is freed. | ||||
virtual std::unique_ptr<Lock> lock(bool try_lock = false) = 0; | virtual std::unique_ptr<Lock> lock(bool try_lock = false) = 0; | ||||
//! Get current chain height, not including genesis block (returns 0 if | //! Get current chain height, not including genesis block (returns 0 if | ||||
//! chain only contains genesis block, nullopt if chain does not contain | //! chain only contains genesis block, nullopt if chain does not contain | ||||
//! any blocks) | //! any blocks) | ||||
virtual Optional<int> getHeight() = 0; | virtual Optional<int> getHeight() = 0; | ||||
//! Get block height above genesis block. Returns 0 for genesis block, | //! Get block height above genesis block. Returns 0 for genesis block, | ||||
//! 1 for following block, and so on. Returns nullopt for a block not | //! 1 for following block, and so on. Returns nullopt for a block not | ||||
//! included in the current chain. | //! included in the current chain. | ||||
virtual Optional<int> getBlockHeight(const BlockHash &hash) = 0; | virtual Optional<int> getBlockHeight(const BlockHash &hash) = 0; | ||||
//! Get block hash. Height must be valid or this function will abort. | //! Get block hash. Height must be valid or this function will abort. | ||||
virtual BlockHash getBlockHash(int height) = 0; | virtual BlockHash getBlockHash(int height) = 0; | ||||
//! Check that the block is available on disk (i.e. has not been | |||||
//! pruned), and contains transactions. | |||||
virtual bool haveBlockOnDisk(int height) = 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. Also return the block hash as an optional output | |||||
//! parameter (to avoid the cost of a second lookup in case this information | |||||
//! is needed.) | |||||
virtual Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, | |||||
int height, | |||||
BlockHash *hash) = 0; | |||||
//! Get locator for the current chain tip. | |||||
virtual CBlockLocator getTipLocator() = 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. | |||||
virtual Optional<int> findLocatorFork(const CBlockLocator &locator) = 0; | |||||
//! Check if transaction will be final given chain height current time. | |||||
virtual bool | |||||
contextualCheckTransactionForCurrentBlock(const CTransaction &tx, | |||||
TxValidationState &state) = 0; | |||||
//! Return whether node has the block and optionally return block metadata | //! Return whether node has the block and optionally return block metadata | ||||
//! or contents. | //! or contents. | ||||
virtual bool findBlock(const BlockHash &hash, | virtual bool findBlock(const BlockHash &hash, | ||||
const FoundBlock &block = {}) = 0; | const FoundBlock &block = {}) = 0; | ||||
//! Find first block in the chain with timestamp >= the given time | //! Find first block in the chain with timestamp >= the given time | ||||
//! and height >= than the given height, return false if there is no block | //! and height >= than the given height, return false if there is no block | ||||
//! with a high enough timestamp and height. Optionally return block | //! with a high enough timestamp and height. Optionally return block | ||||
▲ Show 20 Lines • Show All 203 Lines • Show Last 20 Lines |