Skip to content

Commit 578be36

Browse files
committed
merge bitcoin#25388: move policy constants to policy
1 parent aca2c0d commit 578be36

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
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 * 1000 >= MAX_STANDARD_TX_SIZE);
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: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,55 @@ class CFeeRate;
2020
class CScript;
2121

2222
/** Default for -blockmaxsize, which controls the maximum size of block the mining code will create **/
23-
static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 2000000;
23+
static constexpr unsigned int DEFAULT_BLOCK_MAX_SIZE{2000000};
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 size for transactions we're willing to relay/mine */
27-
static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
27+
static constexpr unsigned int MAX_STANDARD_TX_SIZE{100000};
2828
/** The minimum size for transactions we're willing to relay/mine (1 empty scriptSig input + 1 P2SH output = 83 bytes) */
29-
static const unsigned int MIN_STANDARD_TX_SIZE = 83;
29+
static constexpr unsigned int MIN_STANDARD_TX_SIZE{83};
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 = 4000;
33+
static constexpr unsigned int MAX_STANDARD_TX_SIGOPS{4000};
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 size of a standard ScriptSig */
43-
static const unsigned int MAX_STANDARD_SCRIPTSIG_SIZE = 1650;
43+
static constexpr unsigned int MAX_STANDARD_SCRIPTSIG_SIZE{1650};
4444
/** Min feerate for defining dust. Historically this has been based on the
4545
* minRelayTxFee, however changing the dust limit changes which transactions are
4646
* standard and should be done with care and ideally rarely. It makes sense to
4747
* only increase the dust limit after prior releases were already not creating
4848
* outputs below the new threshold */
49-
static const unsigned int DUST_RELAY_TX_FEE = 3000;
49+
static constexpr unsigned int DUST_RELAY_TX_FEE{3000};
5050
/** Default for -minrelaytxfee, minimum relay fee for transactions */
51-
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
51+
static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{1000};
52+
/** Default for -limitancestorcount, max number of in-mempool ancestors */
53+
static constexpr unsigned int DEFAULT_ANCESTOR_LIMIT{25};
54+
/** Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors */
55+
static constexpr unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT{101};
56+
/** Default for -limitdescendantcount, max number of in-mempool descendants */
57+
static constexpr unsigned int DEFAULT_DESCENDANT_LIMIT{25};
58+
/** Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants */
59+
static constexpr unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT{101};
60+
/**
61+
* An extra transaction can be added to a package, as long as it only has one
62+
* ancestor and is no larger than this. Not really any reason to make this
63+
* configurable as it doesn't materially change DoS parameters.
64+
*/
65+
static constexpr unsigned int EXTRA_DESCENDANT_TX_SIZE_LIMIT{10000};
5266
/**
5367
* Standard script verification flags that standard transactions will comply
5468
* with. However scripts violating these flags may still be present in valid
5569
* blocks and we must accept those blocks.
5670
*/
57-
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VERIFY_FLAGS |
71+
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS{MANDATORY_SCRIPT_VERIFY_FLAGS |
5872
SCRIPT_VERIFY_DERSIG |
5973
SCRIPT_VERIFY_STRICTENC |
6074
SCRIPT_VERIFY_MINIMALDATA |
@@ -65,13 +79,13 @@ static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VE
6579
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY |
6680
SCRIPT_VERIFY_CHECKSEQUENCEVERIFY |
6781
SCRIPT_VERIFY_LOW_S |
68-
SCRIPT_VERIFY_CONST_SCRIPTCODE;
82+
SCRIPT_VERIFY_CONST_SCRIPTCODE};
6983

7084
/** For convenience, standard but not mandatory verify flags. */
71-
static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS;
85+
static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS{STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS};
7286

7387
/** Used as the flags parameter to sequence and nLocktime checks in non-consensus code. */
74-
static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS = LOCKTIME_VERIFY_SEQUENCE;
88+
static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE};
7589

7690
CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);
7791

src/validation.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <node/blockstorage.h>
2020
#include <policy/feerate.h>
2121
#include <policy/packages.h>
22+
#include <policy/policy.h>
2223
#include <script/script_error.h>
2324
#include <serialize.h>
2425
#include <sync.h>
@@ -61,30 +62,6 @@ class CChainLocksHandler;
6162
class CInstantSendManager;
6263
} // namespace llmq
6364

64-
/** Default for -limitancestorcount, max number of in-mempool ancestors */
65-
static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
66-
/** Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors */
67-
static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
68-
/** Default for -limitdescendantcount, max number of in-mempool descendants */
69-
static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
70-
/** Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants */
71-
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
72-
/**
73-
* An extra transaction can be added to a package, as long as it only has one
74-
* ancestor and is no larger than this. Not really any reason to make this
75-
* configurable as it doesn't materially change DoS parameters.
76-
*/
77-
static const unsigned int EXTRA_DESCENDANT_TX_SIZE_LIMIT = 10000;
78-
79-
// If a package is submitted, it must be within the mempool's ancestor/descendant limits. Since a
80-
// submitted package must be child-with-unconfirmed-parents (all of the transactions are an ancestor
81-
// of the child), package limits are ultimately bounded by mempool package limits. Ensure that the
82-
// defaults reflect this constraint.
83-
static_assert(DEFAULT_DESCENDANT_LIMIT >= MAX_PACKAGE_COUNT);
84-
static_assert(DEFAULT_ANCESTOR_LIMIT >= MAX_PACKAGE_COUNT);
85-
static_assert(DEFAULT_ANCESTOR_SIZE_LIMIT >= MAX_PACKAGE_SIZE);
86-
static_assert(DEFAULT_DESCENDANT_SIZE_LIMIT >= MAX_PACKAGE_SIZE);
87-
8865
/** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
8966
static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
9067
/** Maximum number of dedicated script-checking threads allowed */

0 commit comments

Comments
 (0)