Bitcoin ABC 0.30.5
P2P Digital Currency
Functions | Variables
policy.h File Reference
#include <consensus/consensus.h>
#include <feerate.h>
#include <script/standard.h>
#include <optional>
#include <string>
Include dependency graph for policy.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static constexpr Amount DEFAULT_BLOCK_MIN_TX_FEE_PER_KB (1000 *SATOSHI)
 Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code. More...
 
static constexpr CFeeRate MEMPOOL_FULL_FEE_INCREMENT (1000 *SATOSHI)
 Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or BIP 125 replacement. More...
 
static constexpr Amount DUST_RELAY_TX_FEE (1000 *SATOSHI)
 Min feerate for defining dust. More...
 
static constexpr Amount DEFAULT_MIN_RELAY_TX_FEE_PER_KB (1000 *SATOSHI)
 Default for -minrelaytxfee, minimum relay fee for transactions. More...
 
Amount GetDustThreshold (const CTxOut &txout, const CFeeRate &dustRelayFee)
 
bool IsDust (const CTxOut &txout, const CFeeRate &dustRelayFee)
 
bool IsStandard (const CScript &scriptPubKey, const std::optional< unsigned > &max_datacarrier_bytes, TxoutType &whichType)
 
bool IsStandardTx (const CTransaction &tx, const std::optional< unsigned > &max_datacarrier_bytes, bool permit_bare_multisig, const CFeeRate &dust_relay_fee, std::string &reason)
 Check for standard transaction types. More...
 
bool AreInputsStandard (const CTransaction &tx, const CCoinsViewCache &mapInputs, uint32_t flags)
 Check for standard transaction types. More...
 
int64_t GetVirtualTransactionSize (int64_t nSize, int64_t nSigChecks, unsigned int bytes_per_sigCheck)
 Compute the virtual transaction size (size, or more if sigChecks are too dense). More...
 
int64_t GetVirtualTransactionSize (const CTransaction &tx, int64_t nSigChecks, unsigned int bytes_per_sigCheck)
 
int64_t GetVirtualTransactionInputSize (const CTxIn &txin, int64_t nSigChecks, unsigned int bytes_per_sigChecks)
 
static int64_t GetVirtualTransactionSize (const CTransaction &tx)
 
static int64_t GetVirtualTransactionInputSize (const CTxIn &tx)
 

Variables

static constexpr uint64_t DEFAULT_MAX_GENERATED_BLOCK_SIZE {2 * ONE_MEGABYTE}
 Default for -blockmaxsize, which controls the maximum size of block the mining code will create. More...
 
static constexpr unsigned int MAX_STANDARD_TX_SIZE {100000}
 The maximum size for transactions we're willing to relay/mine. More...
 
static constexpr unsigned int MAX_TX_IN_SCRIPT_SIG_SIZE {1650}
 Biggest 'standard' txin is a 15-of-15 P2SH multisig with compressed keys (remember the 520 byte limit on redeemScript size). More...
 
static constexpr unsigned int DEFAULT_BYTES_PER_SIGCHECK {50}
 Default for -bytespersigcheck . More...
 
static constexpr bool DEFAULT_PERMIT_BAREMULTISIG {true}
 Default for -permitbaremultisig. More...
 
static constexpr uint32_t MANDATORY_SCRIPT_VERIFY_FLAGS
 When transactions fail script evaluations under standard flags, this flagset influences the decision of whether to drop them or to also ban the originator (see CheckInputScripts). More...
 
static constexpr uint32_t STANDARD_SCRIPT_VERIFY_FLAGS
 Standard script verification flags that standard transactions will comply with. More...
 
static constexpr uint32_t STANDARD_NOT_MANDATORY_VERIFY_FLAGS
 For convenience, standard but not mandatory verify flags. More...
 
static constexpr uint32_t STANDARD_LOCKTIME_VERIFY_FLAGS
 Used as the flags parameter to sequence and nLocktime checks in non-consensus code. More...
 

Function Documentation

◆ AreInputsStandard()

bool AreInputsStandard ( const CTransaction tx,
const CCoinsViewCache mapInputs,
uint32_t  flags 
)

Check for standard transaction types.

Parameters
[in]mapInputsMap of previous transactions that have outputs we're spending
Returns
True if all inputs (scriptSigs) use only standard transaction forms

Check for standard transaction types.

  1. scriptSigs with extra data stuffed into them, not consumed by scriptPubKey (or P2SH script)
  2. P2SH scripts with a crazy number of expensive CHECKSIG/CHECKMULTISIG operations

Why bother? To avoid denial-of-service attacks; an attacker can submit a standard HASH... OP_EQUAL transaction, which will get accepted into blocks. The redemption script can be anything; an attacker could use a very expensive-to-check-upon-redemption script like: DUP CHECKSIG DROP ... repeated 100 times... OP_1

Definition at line 145 of file policy.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DEFAULT_BLOCK_MIN_TX_FEE_PER_KB()

static constexpr Amount DEFAULT_BLOCK_MIN_TX_FEE_PER_KB ( 1000 *  SATOSHI)
staticconstexpr

Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code.

Here is the caller graph for this function:

◆ DEFAULT_MIN_RELAY_TX_FEE_PER_KB()

static constexpr Amount DEFAULT_MIN_RELAY_TX_FEE_PER_KB ( 1000 *  SATOSHI)
staticconstexpr

Default for -minrelaytxfee, minimum relay fee for transactions.

Here is the caller graph for this function:

◆ DUST_RELAY_TX_FEE()

static constexpr Amount DUST_RELAY_TX_FEE ( 1000 *  SATOSHI)
staticconstexpr

Min feerate for defining dust.

Changing the dust limit changes which transactions are standard and should be done with care and ideally rarely. It makes sense to only increase the dust limit after prior releases were already not creating outputs below the new threshold.

Here is the caller graph for this function:

◆ GetDustThreshold()

Amount GetDustThreshold ( const CTxOut txout,
const CFeeRate dustRelayFee 
)

"Dust" is defined in terms of dustRelayFee, which has units satoshis-per-kilobyte. If you'd pay more than 1/3 in fees to spend something, then we consider it dust. A typical spendable txout is 34 bytes big, and will need a CTxIn of at least 148 bytes to spend: so dust is a spendable txout less than 546*dustRelayFee/1000 (in satoshis).

Definition at line 14 of file policy.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetVirtualTransactionInputSize() [1/2]

static int64_t GetVirtualTransactionInputSize ( const CTxIn tx)
inlinestatic

Definition at line 153 of file policy.h.

Here is the call graph for this function:

◆ GetVirtualTransactionInputSize() [2/2]

int64_t GetVirtualTransactionInputSize ( const CTxIn txin,
int64_t  nSigChecks,
unsigned int  bytes_per_sigChecks 
)

Definition at line 176 of file policy.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetVirtualTransactionSize() [1/3]

static int64_t GetVirtualTransactionSize ( const CTransaction tx)
inlinestatic

Definition at line 149 of file policy.h.

Here is the call graph for this function:

◆ GetVirtualTransactionSize() [2/3]

int64_t GetVirtualTransactionSize ( const CTransaction tx,
int64_t  nSigChecks,
unsigned int  bytes_per_sigCheck 
)

Definition at line 170 of file policy.cpp.

Here is the call graph for this function:

◆ GetVirtualTransactionSize() [3/3]

int64_t GetVirtualTransactionSize ( int64_t  nSize,
int64_t  nSigChecks,
unsigned int  bytes_per_sigCheck 
)

Compute the virtual transaction size (size, or more if sigChecks are too dense).

Definition at line 165 of file policy.cpp.

Here is the caller graph for this function:

◆ IsDust()

bool IsDust ( const CTxOut txout,
const CFeeRate dustRelayFee 
)

Definition at line 34 of file policy.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsStandard()

bool IsStandard ( const CScript scriptPubKey,
const std::optional< unsigned > &  max_datacarrier_bytes,
TxoutType whichType 
)

Definition at line 38 of file policy.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsStandardTx()

bool IsStandardTx ( const CTransaction tx,
const std::optional< unsigned > &  max_datacarrier_bytes,
bool  permit_bare_multisig,
const CFeeRate dust_relay_fee,
std::string &  reason 
)

Check for standard transaction types.

Returns
True if all outputs (scriptPubKeys) use only standard transaction forms

Definition at line 66 of file policy.cpp.

Here is the call graph for this function:

◆ MEMPOOL_FULL_FEE_INCREMENT()

static constexpr CFeeRate MEMPOOL_FULL_FEE_INCREMENT ( 1000 *  SATOSHI)
staticconstexpr

Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or BIP 125 replacement.

Here is the caller graph for this function:

Variable Documentation

◆ DEFAULT_BYTES_PER_SIGCHECK

constexpr unsigned int DEFAULT_BYTES_PER_SIGCHECK {50}
staticconstexpr

Default for -bytespersigcheck .

Definition at line 54 of file policy.h.

◆ DEFAULT_MAX_GENERATED_BLOCK_SIZE

constexpr uint64_t DEFAULT_MAX_GENERATED_BLOCK_SIZE {2 * ONE_MEGABYTE}
staticconstexpr

Default for -blockmaxsize, which controls the maximum size of block the mining code will create.

Definition at line 25 of file policy.h.

◆ DEFAULT_PERMIT_BAREMULTISIG

constexpr bool DEFAULT_PERMIT_BAREMULTISIG {true}
staticconstexpr

Default for -permitbaremultisig.

Definition at line 56 of file policy.h.

◆ MANDATORY_SCRIPT_VERIFY_FLAGS

constexpr uint32_t MANDATORY_SCRIPT_VERIFY_FLAGS
staticconstexpr
Initial value:

When transactions fail script evaluations under standard flags, this flagset influences the decision of whether to drop them or to also ban the originator (see CheckInputScripts).

Definition at line 74 of file policy.h.

◆ MAX_STANDARD_TX_SIZE

constexpr unsigned int MAX_STANDARD_TX_SIZE {100000}
staticconstexpr

The maximum size for transactions we're willing to relay/mine.

Definition at line 34 of file policy.h.

◆ MAX_TX_IN_SCRIPT_SIG_SIZE

constexpr unsigned int MAX_TX_IN_SCRIPT_SIG_SIZE {1650}
staticconstexpr

Biggest 'standard' txin is a 15-of-15 P2SH multisig with compressed keys (remember the 520 byte limit on redeemScript size).

That works out to a (15*(33+1))+3=513 byte redeemScript, 513+1+15*(73+1)+3=1627 bytes of scriptSig, which we round off to 1650 bytes for some minor future-proofing. That's also enough to spend a 20-of-20 CHECKMULTISIG scriptPubKey, though such a scriptPubKey is not considered standard.

Definition at line 44 of file policy.h.

◆ STANDARD_LOCKTIME_VERIFY_FLAGS

constexpr uint32_t STANDARD_LOCKTIME_VERIFY_FLAGS
staticconstexpr
Initial value:
{
static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE
Flags for nSequence and nLockTime locks.
Definition: consensus.h:38

Used as the flags parameter to sequence and nLocktime checks in non-consensus code.

Definition at line 108 of file policy.h.

◆ STANDARD_NOT_MANDATORY_VERIFY_FLAGS

constexpr uint32_t STANDARD_NOT_MANDATORY_VERIFY_FLAGS
staticconstexpr
Initial value:
{
STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS}
static constexpr uint32_t STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
Definition: policy.h:91

For convenience, standard but not mandatory verify flags.

Definition at line 101 of file policy.h.

◆ STANDARD_SCRIPT_VERIFY_FLAGS

constexpr uint32_t STANDARD_SCRIPT_VERIFY_FLAGS
staticconstexpr
Initial value:
{
static constexpr uint32_t MANDATORY_SCRIPT_VERIFY_FLAGS
When transactions fail script evaluations under standard flags, this flagset influences the decision ...
Definition: policy.h:74
@ SCRIPT_VERIFY_SIGPUSHONLY
Definition: script_flags.h:35
@ SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
Definition: script_flags.h:68
@ SCRIPT_VERIFY_DERSIG
Definition: script_flags.h:26
@ SCRIPT_VERIFY_CLEANSTACK
Definition: script_flags.h:63
@ SCRIPT_DISALLOW_SEGWIT_RECOVERY
Definition: script_flags.h:93
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS
Definition: script_flags.h:53
@ SCRIPT_VERIFY_CHECKSEQUENCEVERIFY
Definition: script_flags.h:73
@ SCRIPT_VERIFY_INPUT_SIGCHECKS
Definition: script_flags.h:103

Standard script verification flags that standard transactions will comply with.

However scripts violating these flags may still be present in valid blocks and we must accept those blocks.

Note that the actual mempool validation flags may be slightly different (see GetStandardScriptFlags), however this constant should be set to the most restrictive flag set that applies in the current / next upgrade, since it is used in numerous parts of the codebase that are unable to access the contextual information of which upgrades are currently active.

Definition at line 91 of file policy.h.