32 #include <validation.h>
43 if (!index)
return false;
45 if (block.m_height) *block.m_height = index->
nHeight;
59 explicit NotificationsProxy(std::shared_ptr<Chain::Notifications> notifications)
61 virtual ~NotificationsProxy() =
default;
62 void TransactionAddedToMempool(
const CTransactionRef& tx, uint64_t mempool_sequence)
override
68 m_notifications->transactionRemovedFromMempool(tx, reason, mempool_sequence);
70 void BlockConnected(
const std::shared_ptr<const CBlock>& block,
const CBlockIndex* index)
override
74 void BlockDisconnected(
const std::shared_ptr<const CBlock>& block,
const CBlockIndex* index)
override
86 class NotificationsHandlerImpl :
public Handler
89 explicit NotificationsHandlerImpl(std::shared_ptr<Chain::Notifications> notifications)
90 :
m_proxy(std::make_shared<NotificationsProxy>(std::move(notifications)))
94 ~NotificationsHandlerImpl()
override { disconnect(); }
95 void disconnect()
override
105 class RpcHandlerImpl :
public Handler
130 void disconnect() final
138 ~RpcHandlerImpl()
override { disconnect(); }
144 class ChainImpl :
public Chain
166 uint256 getBlockHash(
int height)
override
173 bool haveBlockOnDisk(
int height)
override
203 return fork->nHeight;
207 bool findBlock(
const uint256& hash,
const FoundBlock& block)
override
212 bool findFirstBlockWithTimeAndHeight(int64_t min_time,
int min_height,
const FoundBlock& block)
override
215 return FillBlock(
ChainActive().FindEarliestAtLeast(min_time, min_height), block, lock);
217 bool findNextBlock(
const uint256& block_hash,
int block_height,
const FoundBlock& next,
bool* reorg)
override {
220 if (block && block->
GetBlockHash() != block_hash) block =
nullptr;
221 if (reorg) *reorg = !block;
222 return FillBlock(block ?
ChainActive()[block_height + 1] :
nullptr, next, lock);
224 bool findAncestorByHeight(
const uint256& block_hash,
int ancestor_height,
const FoundBlock& ancestor_out)
override
229 return FillBlock(ancestor, ancestor_out, lock);
232 return FillBlock(
nullptr, ancestor_out, lock);
234 bool findAncestorByHash(
const uint256& block_hash,
const uint256& ancestor_hash,
const FoundBlock& ancestor_out)
override
239 if (block && ancestor && block->
GetAncestor(ancestor->
nHeight) != ancestor) ancestor =
nullptr;
240 return FillBlock(ancestor, ancestor_out, lock);
242 bool findCommonAncestor(
const uint256& block_hash1,
const uint256& block_hash2,
const FoundBlock& ancestor_out,
const FoundBlock& block1_out,
const FoundBlock& block2_out)
override
250 return FillBlock(ancestor, ancestor_out, lock) & FillBlock(block1, block1_out, lock) & FillBlock(block2, block2_out, lock);
252 void findCoins(std::map<COutPoint, Coin>& coins)
override {
return FindCoins(
m_node, coins); }
253 double guessVerificationProgress(
const uint256& block_hash)
override
269 if (max_height && block->
nHeight >= *max_height) block = block->
GetAncestor(*max_height);
272 if (block->
nHeight <= min_height || !block->
pprev)
return true;
283 bool hasDescendantsInMempool(
const uint256& txid)
override
288 return it && (*it)->GetCountWithDescendants() > 1;
293 std::string& err_string)
override
301 void getTransactionAncestry(
const uint256& txid,
size_t& ancestors,
size_t& descendants)
override
303 ancestors = descendants = 0;
305 m_node.
mempool->GetTransactionAncestry(txid, ancestors, descendants);
307 void getPackageLimits(
unsigned int& limit_ancestor_count,
unsigned int& limit_descendant_count)
override
322 std::string unused_error_string;
325 entry, ancestors, limit_ancestor_count, limit_ancestor_size,
326 limit_descendant_count, limit_descendant_size, unused_error_string);
332 unsigned int estimateMaxBlocks()
override
344 bool havePruned()
override
353 void initMessage(
const std::string& message)
override {
::uiInterface.InitMessage(message); }
356 void showProgress(
const std::string& title,
int progress,
bool resume_possible)
override
358 ::uiInterface.ShowProgress(title, progress, resume_possible);
360 std::unique_ptr<Handler> handleNotifications(std::shared_ptr<Notifications> notifications)
override
362 return MakeUnique<NotificationsHandlerImpl>(std::move(notifications));
364 void waitForNotificationsIfTipChanged(
const uint256& old_tip)
override
368 if (old_tip == ::
ChainActive().Tip()->GetBlockHash())
return;
372 std::unique_ptr<Handler> handleRpc(
const CRPCCommand& command)
override
374 return MakeUnique<RpcHandlerImpl>(command);
377 void rpcRunLater(
const std::string&
name, std::function<
void()> fn, int64_t seconds)
override
396 settings.rw_settings.erase(name);
398 settings.rw_settings[name] = value;
403 void requestMempoolTransactions(Notifications& notifications)
override
408 notifications.transactionAddedToMempool(entry.
GetSharedTx(), 0 );
int64_t CAmount
Amount in satoshis (Can be negative)
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the last common ancestor two blocks have.
@ BLOCK_HAVE_DATA
full block available in blk*.dat
const CChainParams & Params()
Return the currently selected parameters.
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr) const
Write settings file.
void LockSettings(Fn &&fn)
Access settings with lock held.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
uint256 GetBlockHash() const
int64_t GetBlockTime() const
int64_t GetMedianTimePast() const
int64_t GetBlockTimeMax() const
unsigned int nTx
Number of transactions in this block.
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
int nHeight
height of the entry in the chain. The genesis block has height 0
uint32_t nStatus
Verification status of this block. See enum BlockStatus.
CFeeRate estimateSmartFee(int confTarget, FeeCalculation *feeCalc, bool conservative) const
Estimate feerate needed to get be included in a block within confTarget blocks.
unsigned int HighestTargetTracked(FeeEstimateHorizon horizon) const
Calculation of highest target that estimates are tracked for.
CBlockLocator GetLocator(const CBlockIndex *pindex=nullptr) const
Return a CBlockLocator that refers to a block in this chain (by default the tip).
CBlockIndex * FindEarliestAtLeast(int64_t nTime, int height) const
Find the earliest block with timestamp equal or greater than the given time and height equal or great...
int Height() const
Return the maximal height in the chain.
bool IsInitialBlockDownload() const
Check whether we are doing an initial block download (synchronizing from disk or network)
Fee rate in satoshis per kilobyte: CAmount / kB.
bool removeCommand(const std::string &name, const CRPCCommand *pcmd)
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
The basic transaction that is broadcasted on the network and contained in blocks.
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
CTransactionRef GetSharedTx() const
std::set< txiter, CompareIteratorByHash > setEntries
Implement this to subscribe to events generated in validation.
Wrapper around std::unique_lock style lock for Mutex.
void FindCoins(const NodeContext &node, std::map< COutPoint, Coin > &coins)
Look up unspent output information.
std::shared_ptr< Chain::Notifications > m_notifications
const CRPCCommand * m_wrapped_command
std::shared_ptr< NotificationsProxy > m_proxy
std::unique_ptr< Chain > MakeChain(NodeContext &node)
Return implementation of Chain interface.
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
std::deque< CInv >::iterator it
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
TransactionError BroadcastTransaction(NodeContext &node, const CTransactionRef tx, std::string &err_string, const CAmount &max_tx_fee, bool relay, bool wait_callback)
Submit a transaction to the mempool and (optionally) relay it to all P2P peers.
static auto & nullopt
Substitute for C++17 std::nullopt.
boost::optional< T > Optional
Substitute for C++17 std::optional.
RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction &tx)
RBFTransactionState IsRBFOptIn(const CTransaction &tx, const CTxMemPool &pool)
Determine whether an unconfirmed transaction is signaling opt-in to RBF according to BIP 125 This inv...
RBFTransactionState
The rbf state of unconfirmed transactions.
CFeeRate incrementalRelayFee
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE
Default for -maxmempool, maximum megabytes of mempool memory usage.
std::shared_ptr< const CTransaction > CTransactionRef
@ RPC_WALLET_NOT_FOUND
Invalid wallet specified.
bool IsDeprecatedRPCEnabled(const std::string &method)
void RPCRunLater(const std::string &name, std::function< void()> func, int64_t nSeconds)
Run func nSeconds from now.
int RPCSerializationFlags()
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
NodeContext struct containing references to chain state and connection state.
std::unique_ptr< CTxMemPool > mempool
std::map< std::string, SettingsValue > rw_settings
Map of setting name to read-write file setting value.
#define WAIT_LOCK(cs, name)
int64_t GetAdjustedTime()
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
CClientUIInterface uiInterface
void InitWarning(const bilingual_str &str)
Show warning message.
bool InitError(const bilingual_str &str)
Show error message.
CBlockPolicyEstimator feeEstimator
double GuessVerificationProgress(const ChainTxData &data, const CBlockIndex *pindex)
Guess how far we are in the verification process at the given block index require cs_main if pindex h...
bool fHavePruned
Pruning-related variables and constants.
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)
CChain & ChainActive()
Please prefer the identical ChainstateManager::ActiveChain.
bool CheckFinalTx(const CTransaction &tx, int flags)
Transaction validation functions.
CChainState & ChainstateActive()
Please prefer the identical ChainstateManager::ActiveChainstate.
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
CBlockIndex * LookupBlockIndex(const uint256 &hash)
CBlockIndex * FindForkInGlobalIndex(const CChain &chain, const CBlockLocator &locator)
Find the last common block between the parameter chain and a locator.
std::atomic_bool fReindex
static const unsigned int DEFAULT_DESCENDANT_LIMIT
Default for -limitdescendantcount, max number of in-mempool descendants.
std::atomic_bool fImporting
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT
Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants.
static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT
Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors.
static const unsigned int DEFAULT_ANCESTOR_LIMIT
Default for -limitancestorcount, max number of in-mempool ancestors.
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Unregister subscriber.
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Register subscriber.