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 403 void requestMempoolTransactions(Notifications& notifications)
override 408 notifications.transactionAddedToMempool(entry.
GetSharedTx(), 0 );
std::shared_ptr< const CTransaction > CTransactionRef
std::map< std::string, SettingsValue > rw_settings
Map of setting name to read-write file setting value.
static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT
Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors.
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
static const unsigned int DEFAULT_DESCENDANT_LIMIT
Default for -limitdescendantcount, max number of in-mempool descendants.
std::deque< CInv >::iterator it
int64_t GetBlockTime() const
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
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...
uint32_t nStatus
Verification status of this block. See enum BlockStatus.
CChain & ChainActive()
Please prefer the identical ChainstateManager::ActiveChain.
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE
Default for -maxmempool, maximum megabytes of mempool memory usage.
std::unique_ptr< CTxMemPool > mempool
bool fHavePruned
Pruning-related variables and constants.
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
void InitWarning(const bilingual_str &str)
Show warning message.
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
static const unsigned int DEFAULT_ANCESTOR_LIMIT
Default for -limitancestorcount, max number of in-mempool ancestors.
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the last common ancestor two blocks have.
int Height() const
Return the maximal height in the chain.
bool removeCommand(const std::string &name, const CRPCCommand *pcmd)
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr) const
Write settings file.
std::set< txiter, CompareIteratorByHash > setEntries
static auto & nullopt
Substitute for C++17 std::nullopt.
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Register subscriber.
void RPCRunLater(const std::string &name, std::function< void()> func, int64_t nSeconds)
Run func nSeconds from now.
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Unregister subscriber.
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
Implement this to subscribe to events generated in validation.
std::unique_ptr< Chain > MakeChain(NodeContext &node)
Return implementation of Chain interface.
RBFTransactionState
The rbf state of unconfirmed transactions.
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
int64_t CAmount
Amount in satoshis (Can be negative)
uint256 GetBlockHash() const
CBlockPolicyEstimator feeEstimator
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...
bool CheckFinalTx(const CTransaction &tx, int flags)
Transaction validation functions.
RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction &tx)
NodeContext struct containing references to chain state and connection state.
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
CFeeRate estimateSmartFee(int confTarget, FeeCalculation *feeCalc, bool conservative) const
Estimate feerate needed to get be included in a block within confTarget blocks.
CTransactionRef GetSharedTx() const
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT
Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants.
int64_t GetBlockTimeMax() const
const CRPCCommand * m_wrapped_command
bool InitError(const bilingual_str &str)
Show error message.
#define WAIT_LOCK(cs, name)
std::atomic_bool fImporting
Invalid wallet specified.
bool IsDeprecatedRPCEnabled(const std::string &method)
int64_t GetMedianTimePast() const
CFeeRate incrementalRelayFee
std::atomic_bool fReindex
CBlockIndex * LookupBlockIndex(const uint256 &hash)
unsigned int HighestTargetTracked(FeeEstimateHorizon horizon) const
Calculation of highest target that estimates are tracked for.
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.
CChainState & ChainstateActive()
Please prefer the identical ChainstateManager::ActiveChainstate.
The block chain is a tree shaped structure starting with the genesis block at the root...
const CChainParams & Params()
Return the currently selected parameters.
int RPCSerializationFlags()
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...
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
CBlockIndex * FindForkInGlobalIndex(const CChain &chain, const CBlockLocator &locator)
Find the last common block between the parameter chain and a locator.
int64_t GetAdjustedTime()
std::shared_ptr< Chain::Notifications > m_notifications
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.
void FindCoins(const NodeContext &node, std::map< COutPoint, Coin > &coins)
Look up unspent output information.
CBlockLocator GetLocator(const CBlockIndex *pindex=nullptr) const
Return a CBlockLocator that refers to a block in this chain (by default the tip). ...
Wrapper around std::unique_lock style lock for Mutex.
CClientUIInterface uiInterface
The basic transaction that is broadcasted on the network and contained in blocks. ...
int nHeight
height of the entry in the chain. The genesis block has height 0
boost::optional< T > Optional
Substitute for C++17 std::optional.
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
void LockSettings(Fn &&fn)
Access settings with lock held.
full block available in blk*.dat
std::shared_ptr< NotificationsProxy > m_proxy
unsigned int nTx
Number of transactions in this block.