Bitcoin ABC 0.34.2
P2P Digital Currency
Functions | Variables
policy.h File Reference
#include <consensus/consensus.h>
#include <feerate.h>
#include <script/script_flags.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 const 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 (3000 *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 {16 * 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 bool DEFAULT_ACCEPT_DATACARRIER {true}
 Default for -datacarrier. More...
 
static constexpr unsigned int MAX_OP_RETURN_RELAY {223}
 Default setting for nMaxDatacarrierBytes. 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 147 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 ( 3000 *  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 in fees than the value of the output 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 182*dustRelayFee/1000 (in satoshis). 546 satoshis at the default rate of 3000 sat/kB.

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 163 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 178 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 159 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 172 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 167 of file policy.cpp.

Here is the caller graph for this function:

◆ IsDust()

bool IsDust ( const CTxOut &  txout,
const CFeeRate &  dustRelayFee 
)

Definition at line 36 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 40 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 68 of file policy.cpp.

Here is the call graph for this function:

◆ MEMPOOL_FULL_FEE_INCREMENT()

static const CFeeRate MEMPOOL_FULL_FEE_INCREMENT ( 1000 *  SATOSHI)
static

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_ACCEPT_DATACARRIER

constexpr bool DEFAULT_ACCEPT_DATACARRIER {true}
staticconstexpr

Default for -datacarrier.

Definition at line 72 of file policy.h.

◆ DEFAULT_BYTES_PER_SIGCHECK

constexpr unsigned int DEFAULT_BYTES_PER_SIGCHECK {50}
staticconstexpr

Default for -bytespersigcheck .

Definition at line 56 of file policy.h.

◆ DEFAULT_MAX_GENERATED_BLOCK_SIZE

constexpr uint64_t DEFAULT_MAX_GENERATED_BLOCK_SIZE {16 * ONE_MEGABYTE}
staticconstexpr

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

Definition at line 27 of file policy.h.

◆ DEFAULT_PERMIT_BAREMULTISIG

constexpr bool DEFAULT_PERMIT_BAREMULTISIG {true}
staticconstexpr

Default for -permitbaremultisig.

Definition at line 58 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 84 of file policy.h.

◆ MAX_OP_RETURN_RELAY

constexpr unsigned int MAX_OP_RETURN_RELAY {223}
staticconstexpr

Default setting for nMaxDatacarrierBytes.

220 bytes of data, +1 for OP_RETURN, +2 for the pushdata opcodes.

Definition at line 77 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 36 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 46 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 118 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:101

For convenience, standard but not mandatory verify flags.

Definition at line 111 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:84
@ 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 101 of file policy.h.