Skip to content

Commit 57a491b

Browse files
committed
Merge bitcoin/bitcoin#25388: refactor: move policy constants to policy
0d8e68d refactor: move DEFAULT_*_LIMIT assertions from validation to policy (fanquake) 9c94f3b refactor: move EXTRA_DESCENDANT_TX_SIZE_LIMIT to policy/policy.h (fanquake) 39c6036 refactor: use braced initialization in policy/policy.h (fanquake) 01ccfbe scripted-diff: use static constexpr in policy/policy.h (fanquake) 62d56bb refactor: Move DEFAULT_DESCENDANT_SIZE_LIMIT to policy/policy.h (fanquake) a34aa4c refactor: Move DEFAULT_DESCENDANT_LIMIT to policy/policy.h (fanquake) 05fc5fd refactor: Move DEFAULT_ANCESTOR_SIZE_LIMIT to policy/policy.h (fanquake) da8d304 refactor: Move DEFAULT_ANCESTOR_LIMIT to policy/policy.h (CAnon) Pull request description: Picks up #25295. Which was a follow up to [a comment in #25254](bitcoin/bitcoin#25254 (comment)). Moves policy constants from validation.h to policy.h. ACKs for top commit: laanwj: Code review ACK 0d8e68d w0xlt: reACK bitcoin/bitcoin@0d8e68d darosior: ACK 0d8e68d Tree-SHA512: 79900b09dc3a8020b5053ec734f462cb6e8184ed2b76e9d8afae7fe5331bbc906daaa42c0f622782797d971aaf5698aa0155511ec1d15582cc7675c271664a8d
2 parents a09033e + 0d8e68d commit 57a491b

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

src/policy/packages.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ static constexpr uint32_t MAX_PACKAGE_COUNT{25};
1919
static constexpr uint32_t MAX_PACKAGE_SIZE{101};
2020
static_assert(MAX_PACKAGE_SIZE * WITNESS_SCALE_FACTOR * 1000 >= MAX_STANDARD_TX_WEIGHT);
2121

22+
// If a package is submitted, it must be within the mempool's ancestor/descendant limits. Since a
23+
// submitted package must be child-with-unconfirmed-parents (all of the transactions are an ancestor
24+
// of the child), package limits are ultimately bounded by mempool package limits. Ensure that the
25+
// defaults reflect this constraint.
26+
static_assert(DEFAULT_DESCENDANT_LIMIT >= MAX_PACKAGE_COUNT);
27+
static_assert(DEFAULT_ANCESTOR_LIMIT >= MAX_PACKAGE_COUNT);
28+
static_assert(DEFAULT_ANCESTOR_SIZE_LIMIT >= MAX_PACKAGE_SIZE);
29+
static_assert(DEFAULT_DESCENDANT_SIZE_LIMIT >= MAX_PACKAGE_SIZE);
30+
2231
/** A "reason" why a package was invalid. It may be that one or more of the included
2332
* transactions is invalid or the package itself violates our rules.
2433
* We don't distinguish between consensus and policy violations right now.

src/policy/policy.h

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,63 @@ class CFeeRate;
2020
class CScript;
2121

2222
/** Default for -blockmaxweight, which controls the range of block weights the mining code will create **/
23-
static const unsigned int DEFAULT_BLOCK_MAX_WEIGHT = MAX_BLOCK_WEIGHT - 4000;
23+
static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{MAX_BLOCK_WEIGHT - 4000};
2424
/** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/
25-
static const unsigned int DEFAULT_BLOCK_MIN_TX_FEE = 1000;
25+
static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE{1000};
2626
/** The maximum weight for transactions we're willing to relay/mine */
27-
static const unsigned int MAX_STANDARD_TX_WEIGHT = 400000;
27+
static constexpr unsigned int MAX_STANDARD_TX_WEIGHT{400000};
2828
/** The minimum non-witness size for transactions we're willing to relay/mine (1 segwit input + 1 P2WPKH output = 82 bytes) */
29-
static const unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE = 82;
29+
static constexpr unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE{82};
3030
/** Maximum number of signature check operations in an IsStandard() P2SH script */
31-
static const unsigned int MAX_P2SH_SIGOPS = 15;
31+
static constexpr unsigned int MAX_P2SH_SIGOPS{15};
3232
/** The maximum number of sigops we're willing to relay/mine in a single tx */
33-
static const unsigned int MAX_STANDARD_TX_SIGOPS_COST = MAX_BLOCK_SIGOPS_COST/5;
33+
static constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST{MAX_BLOCK_SIGOPS_COST/5};
3434
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
35-
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
35+
static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE{300};
3636
/** Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or BIP 125 replacement **/
37-
static const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE = 1000;
37+
static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE{1000};
3838
/** Default for -bytespersigop */
39-
static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20;
39+
static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP{20};
4040
/** Default for -permitbaremultisig */
41-
static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
41+
static constexpr bool DEFAULT_PERMIT_BAREMULTISIG{true};
4242
/** The maximum number of witness stack items in a standard P2WSH script */
43-
static const unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS = 100;
43+
static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS{100};
4444
/** The maximum size in bytes of each witness stack item in a standard P2WSH script */
45-
static const unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE = 80;
45+
static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE{80};
4646
/** The maximum size in bytes of each witness stack item in a standard BIP 342 script (Taproot, leaf version 0xc0) */
47-
static const unsigned int MAX_STANDARD_TAPSCRIPT_STACK_ITEM_SIZE = 80;
47+
static constexpr unsigned int MAX_STANDARD_TAPSCRIPT_STACK_ITEM_SIZE{80};
4848
/** The maximum size in bytes of a standard witnessScript */
49-
static const unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE = 3600;
49+
static constexpr unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE{3600};
5050
/** The maximum size of a standard ScriptSig */
51-
static const unsigned int MAX_STANDARD_SCRIPTSIG_SIZE = 1650;
51+
static constexpr unsigned int MAX_STANDARD_SCRIPTSIG_SIZE{1650};
5252
/** Min feerate for defining dust. Historically this has been based on the
5353
* minRelayTxFee, however changing the dust limit changes which transactions are
5454
* standard and should be done with care and ideally rarely. It makes sense to
5555
* only increase the dust limit after prior releases were already not creating
5656
* outputs below the new threshold */
57-
static const unsigned int DUST_RELAY_TX_FEE = 3000;
57+
static constexpr unsigned int DUST_RELAY_TX_FEE{3000};
5858
/** Default for -minrelaytxfee, minimum relay fee for transactions */
59-
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
59+
static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{1000};
60+
/** Default for -limitancestorcount, max number of in-mempool ancestors */
61+
static constexpr unsigned int DEFAULT_ANCESTOR_LIMIT{25};
62+
/** Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors */
63+
static constexpr unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT{101};
64+
/** Default for -limitdescendantcount, max number of in-mempool descendants */
65+
static constexpr unsigned int DEFAULT_DESCENDANT_LIMIT{25};
66+
/** Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants */
67+
static constexpr unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT{101};
68+
/**
69+
* An extra transaction can be added to a package, as long as it only has one
70+
* ancestor and is no larger than this. Not really any reason to make this
71+
* configurable as it doesn't materially change DoS parameters.
72+
*/
73+
static constexpr unsigned int EXTRA_DESCENDANT_TX_SIZE_LIMIT{10000};
6074
/**
6175
* Standard script verification flags that standard transactions will comply
6276
* with. However scripts violating these flags may still be present in valid
6377
* blocks and we must accept those blocks.
6478
*/
65-
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VERIFY_FLAGS |
79+
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS{MANDATORY_SCRIPT_VERIFY_FLAGS |
6680
SCRIPT_VERIFY_DERSIG |
6781
SCRIPT_VERIFY_STRICTENC |
6882
SCRIPT_VERIFY_MINIMALDATA |
@@ -81,14 +95,14 @@ static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VE
8195
SCRIPT_VERIFY_TAPROOT |
8296
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION |
8397
SCRIPT_VERIFY_DISCOURAGE_OP_SUCCESS |
84-
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE;
98+
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE};
8599

86100
/** For convenience, standard but not mandatory verify flags. */
87-
static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS;
101+
static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS{STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS};
88102

89103
/** Used as the flags parameter to sequence and nLocktime checks in non-consensus code. */
90-
static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS = LOCKTIME_VERIFY_SEQUENCE |
91-
LOCKTIME_MEDIAN_TIME_PAST;
104+
static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE |
105+
LOCKTIME_MEDIAN_TIME_PAST};
92106

93107
CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);
94108

src/validation.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,6 @@ using node::UnlinkPrunedFiles;
8181
#define MICRO 0.000001
8282
#define MILLI 0.001
8383

84-
/**
85-
* An extra transaction can be added to a package, as long as it only has one
86-
* ancestor and is no larger than this. Not really any reason to make this
87-
* configurable as it doesn't materially change DoS parameters.
88-
*/
89-
static const unsigned int EXTRA_DESCENDANT_TX_SIZE_LIMIT = 10000;
9084
/** Maximum kilobytes for transactions to store for processing during reorg */
9185
static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000;
9286
/** Time to wait between writing blocks/block index to disk. */

src/validation.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <node/blockstorage.h>
2222
#include <policy/feerate.h>
2323
#include <policy/packages.h>
24+
#include <policy/policy.h>
2425
#include <script/script_error.h>
2526
#include <sync.h>
2627
#include <txdb.h>
@@ -58,24 +59,6 @@ namespace Consensus {
5859
struct Params;
5960
} // namespace Consensus
6061

61-
/** Default for -limitancestorcount, max number of in-mempool ancestors */
62-
static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
63-
/** Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors */
64-
static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
65-
/** Default for -limitdescendantcount, max number of in-mempool descendants */
66-
static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
67-
/** Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants */
68-
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
69-
70-
// If a package is submitted, it must be within the mempool's ancestor/descendant limits. Since a
71-
// submitted package must be child-with-unconfirmed-parents (all of the transactions are an ancestor
72-
// of the child), package limits are ultimately bounded by mempool package limits. Ensure that the
73-
// defaults reflect this constraint.
74-
static_assert(DEFAULT_DESCENDANT_LIMIT >= MAX_PACKAGE_COUNT);
75-
static_assert(DEFAULT_ANCESTOR_LIMIT >= MAX_PACKAGE_COUNT);
76-
static_assert(DEFAULT_ANCESTOR_SIZE_LIMIT >= MAX_PACKAGE_SIZE);
77-
static_assert(DEFAULT_DESCENDANT_SIZE_LIMIT >= MAX_PACKAGE_SIZE);
78-
7962
/** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
8063
static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
8164
/** Maximum number of dedicated script-checking threads allowed */

0 commit comments

Comments
 (0)