Bitcoin Core  0.19.99
P2P Digital Currency
Functions | Variables
policy.h File Reference
#include <consensus/consensus.h>
#include <policy/feerate.h>
#include <script/interpreter.h>
#include <script/standard.h>
#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

CAmount GetDustThreshold (const CTxOut &txout, const CFeeRate &dustRelayFee)
 
bool IsDust (const CTxOut &txout, const CFeeRate &dustRelayFee)
 
bool IsStandard (const CScript &scriptPubKey, txnouttype &whichType)
 
bool IsStandardTx (const CTransaction &tx, 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)
 Check for standard transaction types. More...
 
bool IsWitnessStandard (const CTransaction &tx, const CCoinsViewCache &mapInputs)
 Check if the transaction is over standard P2WSH resources limit: 3600bytes witnessScript size, 80bytes per witness stack element, 100 witness stack elements These limits are adequate for multi-signature up to n-of-100 using OP_CHECKSIG, OP_ADD, and OP_EQUAL,. More...
 
int64_t GetVirtualTransactionSize (int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
 Compute the virtual transaction size (weight reinterpreted as bytes). More...
 
int64_t GetVirtualTransactionSize (const CTransaction &tx, int64_t nSigOpCost, unsigned int bytes_per_sigop)
 
int64_t GetVirtualTransactionInputSize (const CTxIn &tx, int64_t nSigOpCost, unsigned int bytes_per_sigop)
 
static int64_t GetVirtualTransactionSize (const CTransaction &tx)
 
static int64_t GetVirtualTransactionInputSize (const CTxIn &tx)
 

Variables

static const unsigned int DEFAULT_BLOCK_MAX_WEIGHT = MAX_BLOCK_WEIGHT - 4000
 Default for -blockmaxweight, which controls the range of block weights the mining code will create. More...
 
static const unsigned int DEFAULT_BLOCK_MIN_TX_FEE = 1000
 Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code. More...
 
static const unsigned int MAX_STANDARD_TX_WEIGHT = 400000
 The maximum weight for transactions we're willing to relay/mine. More...
 
static const unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE = 82
 The minimum non-witness size for transactions we're willing to relay/mine (1 segwit input + 1 P2WPKH output = 82 bytes) More...
 
static const unsigned int MAX_P2SH_SIGOPS = 15
 Maximum number of signature check operations in an IsStandard() P2SH script. More...
 
static const unsigned int MAX_STANDARD_TX_SIGOPS_COST = MAX_BLOCK_SIGOPS_COST/5
 The maximum number of sigops we're willing to relay/mine in a single tx. More...
 
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300
 Default for -maxmempool, maximum megabytes of mempool memory usage. More...
 
static const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE = 1000
 Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or BIP 125 replacement. More...
 
static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20
 Default for -bytespersigop. More...
 
static const bool DEFAULT_PERMIT_BAREMULTISIG = true
 Default for -permitbaremultisig. More...
 
static const unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS = 100
 The maximum number of witness stack items in a standard P2WSH script. More...
 
static const unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE = 80
 The maximum size of each witness stack item in a standard P2WSH script. More...
 
static const unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE = 3600
 The maximum size of a standard witnessScript. More...
 
static const unsigned int DUST_RELAY_TX_FEE = 3000
 Min feerate for defining dust. More...
 
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
 Standard script verification flags that standard transactions will comply with. More...
 
static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS
 For convenience, standard but not mandatory verify flags. More...
 
static constexpr unsigned int 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 
)

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 156 of file policy.cpp.

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

◆ GetDustThreshold()

CAmount GetDustThreshold ( const CTxOut txout,
const CFeeRate dustRelayFee 
)

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]

int64_t GetVirtualTransactionInputSize ( const CTxIn tx,
int64_t  nSigOpCost,
unsigned int  bytes_per_sigop 
)

Definition at line 248 of file policy.cpp.

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

◆ GetVirtualTransactionInputSize() [2/2]

static int64_t GetVirtualTransactionInputSize ( const CTxIn tx)
inlinestatic

Definition at line 113 of file policy.h.

Here is the call graph for this function:

◆ GetVirtualTransactionSize() [1/3]

int64_t GetVirtualTransactionSize ( int64_t  nWeight,
int64_t  nSigOpCost,
unsigned int  bytes_per_sigop 
)

Compute the virtual transaction size (weight reinterpreted as bytes).

Definition at line 238 of file policy.cpp.

Here is the caller graph for this function:

◆ GetVirtualTransactionSize() [2/3]

int64_t GetVirtualTransactionSize ( const CTransaction tx,
int64_t  nSigOpCost,
unsigned int  bytes_per_sigop 
)

Definition at line 243 of file policy.cpp.

Here is the call graph for this function:

◆ GetVirtualTransactionSize() [3/3]

static int64_t GetVirtualTransactionSize ( const CTransaction tx)
inlinestatic

Definition at line 108 of file policy.h.

Here is the call graph for this function:

◆ IsDust()

bool IsDust ( const CTxOut txout,
const CFeeRate dustRelayFee 
)

Definition at line 48 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,
txnouttype whichType 
)

Definition at line 53 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,
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 76 of file policy.cpp.

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

◆ IsWitnessStandard()

bool IsWitnessStandard ( const CTransaction tx,
const CCoinsViewCache mapInputs 
)

Check if the transaction is over standard P2WSH resources limit: 3600bytes witnessScript size, 80bytes per witness stack element, 100 witness stack elements These limits are adequate for multi-signature up to n-of-100 using OP_CHECKSIG, OP_ADD, and OP_EQUAL,.

Definition at line 186 of file policy.cpp.

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

Variable Documentation

◆ DEFAULT_BLOCK_MAX_WEIGHT

const unsigned int DEFAULT_BLOCK_MAX_WEIGHT = MAX_BLOCK_WEIGHT - 4000
static

Default for -blockmaxweight, which controls the range of block weights the mining code will create.

Definition at line 20 of file policy.h.

◆ DEFAULT_BLOCK_MIN_TX_FEE

const unsigned int DEFAULT_BLOCK_MIN_TX_FEE = 1000
static

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

Definition at line 22 of file policy.h.

◆ DEFAULT_BYTES_PER_SIGOP

const unsigned int DEFAULT_BYTES_PER_SIGOP = 20
static

Default for -bytespersigop.

Definition at line 36 of file policy.h.

◆ DEFAULT_INCREMENTAL_RELAY_FEE

const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE = 1000
static

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

Definition at line 34 of file policy.h.

◆ DEFAULT_MAX_MEMPOOL_SIZE

const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300
static

Default for -maxmempool, maximum megabytes of mempool memory usage.

Definition at line 32 of file policy.h.

◆ DEFAULT_PERMIT_BAREMULTISIG

const bool DEFAULT_PERMIT_BAREMULTISIG = true
static

Default for -permitbaremultisig.

Definition at line 38 of file policy.h.

◆ DUST_RELAY_TX_FEE

const unsigned int DUST_RELAY_TX_FEE = 3000
static

Min feerate for defining dust.

Historically this has been based on the minRelayTxFee, however 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

Definition at line 50 of file policy.h.

◆ MAX_P2SH_SIGOPS

const unsigned int MAX_P2SH_SIGOPS = 15
static

Maximum number of signature check operations in an IsStandard() P2SH script.

Definition at line 28 of file policy.h.

◆ MAX_STANDARD_P2WSH_SCRIPT_SIZE

const unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE = 3600
static

The maximum size of a standard witnessScript.

Definition at line 44 of file policy.h.

◆ MAX_STANDARD_P2WSH_STACK_ITEM_SIZE

const unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE = 80
static

The maximum size of each witness stack item in a standard P2WSH script.

Definition at line 42 of file policy.h.

◆ MAX_STANDARD_P2WSH_STACK_ITEMS

const unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS = 100
static

The maximum number of witness stack items in a standard P2WSH script.

Definition at line 40 of file policy.h.

◆ MAX_STANDARD_TX_SIGOPS_COST

const unsigned int MAX_STANDARD_TX_SIGOPS_COST = MAX_BLOCK_SIGOPS_COST/5
static

The maximum number of sigops we're willing to relay/mine in a single tx.

Definition at line 30 of file policy.h.

◆ MAX_STANDARD_TX_WEIGHT

const unsigned int MAX_STANDARD_TX_WEIGHT = 400000
static

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

Definition at line 24 of file policy.h.

◆ MIN_STANDARD_TX_NONWITNESS_SIZE

const unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE = 82
static

The minimum non-witness size for transactions we're willing to relay/mine (1 segwit input + 1 P2WPKH output = 82 bytes)

Definition at line 26 of file policy.h.

◆ STANDARD_LOCKTIME_VERIFY_FLAGS

constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS
static
Initial value:
static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE
Flags for nSequence and nLockTime locks.
Definition: consensus.h:28
static constexpr unsigned int LOCKTIME_MEDIAN_TIME_PAST
Use GetMedianTimePast() instead of nTime for end point timestamp.
Definition: consensus.h:30

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

Definition at line 77 of file policy.h.

◆ STANDARD_NOT_MANDATORY_VERIFY_FLAGS

constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS
static

For convenience, standard but not mandatory verify flags.

Definition at line 74 of file policy.h.

◆ STANDARD_SCRIPT_VERIFY_FLAGS

constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
static
Initial value:
static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS
Mandatory script verification flags that all new blocks must comply with for them to be valid...
Definition: standard.h:53

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.

Definition at line 56 of file policy.h.