Modules

Structs

  • | Display status of an in-progress BIP9 | softfork |
  • | Undo information for a CBlock |
  • | CoinsView that brings transactions | from a mempool into view. | | It does not check for spendings by memory | pool transactions. | | Instead, it provides access to all Coins | which are either unspent in the base | CCoinsView, are outputs from any mempool | transaction, or are tracked temporarily | to allow transaction dependencies | in package validation. | | This allows transaction replacement | to work as expected, as you want to have | all inputs “available” to check signatures, | and any cycles in the dependency graph | are checked directly in AcceptToMemoryPool. | | It also allows you to sign a double-spend | directly in signrawtransactionwithkey | and signrawtransactionwithwallet, | as long as the conflicting transaction | is not yet confirmed. |
  • | Multi_index tag names |
  • | extracts a transaction hash from | | TxMemPoolEntry or CTransactionRef |
  • | extracts a transaction witness-hash | from TxMemPoolEntry or TransactionRef |
  • | Validation result for a single transaction | mempool acceptance. |
  • | Validation result for package mempool | acceptance. |
  • | Closure representing one script verification | | ———– | @note | | this stores references to the spending | transaction |
  • | Formatter for undo information for | a CTxIn | | Contains the prevout’s CTxOut being | spent, and its metadata as well (coinbase | or not, height). The serialization | contains a dummy value of zero. This | is compatible with older versions which | expect to see the transaction version | there. |
  • | TxMemPool stores | valid-according-to-the-current-best-chain | transactions that may be included in the next | block. | | Transactions are added when they are seen on | the network (or created by the local node), but | not all transactions seen are added to the | pool. For example, the following new | transactions will not be added to the mempool: | | - a transaction which doesn’t meet the minimum | fee requirements. | | - a new transaction that double-spends an input | of a transaction already in the pool where the | new transaction does not meet the | Replace-By-Fee requirements as defined in BIP | 125. | | - a non-standard transaction. | | TxMemPool::mapTx, and TxMemPoolEntry | bookkeeping: | | mapTx is a boost::multi_index that sorts the | mempool on 5 criteria: | | - transaction hash (txid) | | - witness-transaction hash (wtxid) | | - descendant feerate [we use max(feerate of tx, | feerate of tx with all descendants)] | | - time in mempool | | - ancestor feerate [we use min(feerate of tx, | feerate of tx with all unconfirmed ancestors)] | | Note: the term “descendant” refers to | in-mempool transactions that depend on this | one, while “ancestor” refers to in-mempool | transactions that a given transaction depends | on. | | In order for the feerate sort to remain | correct, we must update transactions in the | mempool when new descendants arrive. To | facilitate this, we track the set of in-mempool | direct parents and direct children in mapLinks. | Within each TxMemPoolEntry, we track the size | and fees of all descendants. | | Usually when a new transaction is added to the | mempool, it has no in-mempool children (because | any such children would be an orphan). So in | addUnchecked(), we: | | - update a new entry’s setMemPoolParents to | include all in-mempool parents | | - update the new entry’s direct parents to | include the new tx as a child | | - update all ancestors of the transaction to | include the new tx’s size/fee | | When a transaction is removed from the mempool, | we must: | | - update all in-mempool parents to not track | the tx in setMemPoolChildren | | - update all ancestors to not include the tx’s | size/fees in descendant state | | - update all in-mempool children to not include | it as a parent | | These happen in UpdateForRemoveFromMempool(). | (Note that when removing a transaction along | with its descendants, we must calculate | that set of transactions to be removed | before doing the removal, or else the | mempool can be in an inconsistent state | where it’s impossible to walk the ancestors | of a transaction.) | | In the event of a reorg, the assumption that | a newly added tx has no in-mempool children is | false.
    | | In particular, the mempool is in an | inconsistent state while new transactions are | being added, because there may be descendant | transactions of a tx coming from a disconnected | block that are unreachable from just looking at | transactions in the mempool (the linking | transactions may also be in the | disconnected block, waiting to be added). | | Because of this, there’s not much benefit in | trying to search for in-mempool children in | addUnchecked().
    | | Instead, in the special case of transactions | being added from a disconnected block, we | require the caller to clean up the state, to | account for in-mempool, out-of-block | descendants for all the in-block transactions | by calling UpdateTransactionsFromBlock().
    | | Note that until this is called, the mempool | state is not consistent, and in particular | mapLinks may not be correct (and therefore | functions like CalculateMemPoolAncestors() | and CalculateDescendants() that rely on | them to walk the mempool are not generally safe | to use). | | Computational limits: | | Updating all in-mempool ancestors of a newly | added transaction can be slow, if no bound | exists on how many in-mempool ancestors there | may be. | | CalculateMemPoolAncestors() takes configurable | limits that are designed to prevent these | calculations from being too CPU intensive. |
  • | Information about a mempool transaction. |
  • | Undo information for a CTransaction |
  • | Helpers for modifying TxMemPool::mapTx, | which is a boost multi_index. |


  • | BIP 9 allows multiple softforks to be | deployed in parallel. We cache per-period | state for every one of them. |
  • | Class to implement versionbits logic. |
  • | Threshold condition checker that triggers | when unknown versionbits are seen on | the network. |

Enums

  • | Reason why a transaction was removed | from the mempool, this is passed to the | notification signal. |
  • | Used to indicate the results of mempool | validation. |
  • | BIP 9 defines a finite-state-machine | to deploy a softfork in multiple stages. | | State transitions happen during retarget | period if conditions are met | | In case of reorg, transitions can go | backward. Without transition, state | is inherited between periods. All blocks | of a period share the same state. |
  • | A “reason” why a transaction was invalid, | suitable for determining whether the | provider of the transaction should | be banned/ignored/disconnected/etc. |

Constants

Traits

Functions

  • | Private helper function that concatenates | warning messages. |
  • | Restore the UTXO in a Coin at a given OutPoint | | ———– | @param undo | | The Coin to be restored. | ––––– | @param view | | The coins view to which to apply the changes. | ––––– | @param out | | The out point that corresponds to the | tx input. | | ———– | @return | | A DisconnectResult as an int |
  • | Calculates the block height and previous | block’s median time past at which the | transaction will be considered final | in the context of BIP 68. | | Also removes from the vector of input | heights any entries which did not correspond | to sequence locked inputs as they do | not affect the calculation. |
  • | Context-independent validity checks |
  • | Check if transaction will be final in | the next block to be created. | | Calls IsFinalTx() with current block | height and appropriate block time. | | See consensus/consensus.h for flag | definitions. |
  • | Check whether all of this transaction’s | input scripts succeed. | | This involves ECDSA signature checks | so can be computationally intensive. | This function should only be called | after the cheap sanity checks in | | CheckTxInputs passed. | | If pvChecks is not nullptr, script checks | are pushed onto it instead of being performed | inline. Any script checks which are | not necessary (eg due to script execution | cache hits) are, obviously, not pushed | onto pvChecks/run. | | Setting cacheSigStore/cacheFullScriptStore | to false will remove elements from the | corresponding cache which are matched. | This is useful for checking blocks where | we will likely never need the cache entry | again. | | ———– | @note | | we may set state.reason to | | NOT_STANDARD for extra soft-fork flags | in flags, block-checking callers should | probably reset it to CONSENSUS in such | cases. | | Non-static (and re-declared) in src/test/txvalidationcache_tests.cpp |
  • | Checks to avoid mempool polluting consensus | critical paths since cached signature | and script validity results will be | reused if we validate this transaction | again during block validation. |
  • | Check if transaction will be BIP68 final | in the next block to be created on top | of tip. | | ———– | @param[in] tip | | Chain tip to check tx sequence locks | against. For example, the tip of the | current active chain. | ––––– | @param[in] coins_view | | Any CCoinsView that provides access | to the relevant coins for checking sequence | locks. For example, it can be a CCoinsViewCache | that isn’t connected to anything but | contains all the relevant coins, or | a CCoinsViewMemPool that is connected | to the mempool and chainstate UTXO set. | In the latter case, the caller is responsible | for holding the appropriate locks to | ensure that calls to GetCoin() return | correct coins. | | Simulates calling SequenceLocks() | with data from the tip passed in. | | Optionally stores in LockPoints the | resulting height and time calculated | and the hash of the block needed for calculation | or skips the calculation and uses the | LockPoints passed in for evaluation. | | The LockPoints should not be considered | valid if CheckSequenceLocks returns | false. | | See consensus/consensus.h for flag | definitions. |
  • | Context-independent transaction | checking code that can be called outside | the bitcoin server and doesn’t depend | on chain or mempool state. Transaction | verification code that does call server | functions or depend on server state | belongs in tx_verify.h/cpp instead. |
  • | Check whether all inputs of this transaction | are valid (no double spends and amounts) | | This does not modify the UTXO set. This | does not check scripts and sigs. | | ———– | @param[out] txfee | | Set to the transaction fee if successful. | | Preconditions: tx.IsCoinBase() is | false. |
  • | @note | | This function is not currently invoked | by ConnectBlock(), so we should consider | upgrade issues if we change which consensus | rules are enforced in this function | (eg by adding a new consensus rule). | See comment in ConnectBlock(). | ––––– | @note | | -reindex-chainstate skips the validation | that happens here! |
  • | Dump the mempool to disk. |
  • | Check the intersection between two | sets of transactions (a set of mempool | entries and a set of txids) to make sure | they are disjoint. | | ———– | @param[in] ancestors | | Set of mempool entries corresponding | to ancestors of the replacement transactions. | ––––– | @param[in] direct_conflicts | | Set of txids corresponding to the mempool | conflicts (candidates to be replaced). | ––––– | @param[in] txid | | Transaction ID, included in the error | message if violation occurs. | | ———– | @return | | error message if the sets intersect, | std::nullopt if they are disjoint. |
  • | … TODO move fully to blockstorage |
  • | Produce the necessary coinbase commitment | for a block (modifies the hash, don’t | call for mined blocks). |
  • | Returns the script flags which should | be checked for a given block |
  • | Get all descendants of iters_conflicting. | Also enforce BIP125 Rule #5, “The number | of original transactions to be replaced | and their descendant transactions | which will be evicted from the mempool | must not exceed a total of 100 transactions.” | Quit as early as possible. There cannot | be more than MAX_BIP125_REPLACEMENT_CANDIDATES | potential entries. | | ———– | @param[in] iters_conflicting | | The set of iterators to mempool entries. | ––––– | @param[out] all_conflicts | | Populated with all the mempool entries | that would be replaced, which includes | descendants of iters_conflicting. | Not cleared at the start; any existing | mempool entries will remain in the set. | | ———– | @return | | an error message if Rule #5 is broken, | otherwise a std::nullopt. |
  • | Count ECDSA signature operations the | old-fashioned (pre-0.6) way | | | ———– | @return | | number of sigops this transaction’s | outputs will produce when spent @see | CTransaction::FetchInputs |
  • | Count ECDSA signature operations in | pay-to-script-hash inputs. | | ———– | @param[in] mapInputs | | Map of previous transactions that have | outputs we’re spending | | ———– | @return | | maximum number of sigops required to | validate this transaction’s inputs | @see CTransaction::FetchInputs |
  • | Compute total signature operation | cost of a transaction. | | ———– | @param[in] tx | | Transaction for which we are computing | the cost | ––––– | @param[in] inputs | | Map of previous transactions that have | outputs we’re spending | ––––– | @param[in] flags | | Script verification flags | | ———– | @return | | Total signature operation cost of tx |
  • | These implement the weight = (stripped_size | * 4) + witness_size formula, using only | serialization with and without witness data. As | witness_size is equal to total_size | - stripped_size, this formula is identical to: | weight = (stripped_size * 3) + total_size.
  • | Compute at which vout of the block’s | coinbase transaction the witness commitment | occurs, or -1 if not found |
  • | BIP125 Rule #2: “The replacement transaction | may only include an unconfirmed input if that | input was included in one of the original | transactions.” | | ———– | @return | | error message if Rule #2 is broken, otherwise | std::nullopt. |
  • | Initializes the script-execution | cache |
  • | Check if transaction is final and can | be included in a block with the specified | height and time. Consensus critical. |
  • | Determine whether an unconfirmed transaction | is signaling opt-in to RBF according | to BIP 125 | | This involves checking sequence numbers | of the transaction, as well as the sequence | numbers of all in-mempool ancestors. | | ———– | @param tx | | The unconfirmed transaction | ––––– | @param pool | | The mempool, which may contain the tx | | ———– | @return | | The rbf state |
  • | Check that the feerate of the replacement | transaction(s) is higher than the feerate | of each of the transactions in iters_conflicting. | | ———– | @param[in] iters_conflicting | | The set of mempool entries. | | ———– | @return | | error message if fees insufficient, | otherwise std::nullopt. |
  • | Check if transaction is final per BIP | 68 sequence numbers and can be included | in a block. | | Consensus critical. Takes as input | a list of heights at which tx’s inputs | (in order) confirmed. |
  • | Run instances of script checking worker | threads |
  • | Stop all of the script checking worker | threads |
  • | Update uncommitted block structures | (currently: only the witness reserved | value). This is safe for submitted blocks. |

Type Definitions