@@ -72,43 +72,56 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
72
72
return nNewTime - nOldTime;
73
73
}
74
74
75
- BlockAssembler::BlockAssembler (const CChainParams& _chainparams)
76
- : chainparams(_chainparams)
75
+ BlockAssembler::Options::Options () {
76
+ blockMinFeeRate = CFeeRate (DEFAULT_BLOCK_MIN_TX_FEE);
77
+ nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
78
+ nBlockMaxSize = DEFAULT_BLOCK_MAX_SIZE;
79
+ }
80
+
81
+ BlockAssembler::BlockAssembler (const CChainParams& params, const Options& options) : chainparams(params)
82
+ {
83
+ blockMinFeeRate = options.blockMinFeeRate ;
84
+ // Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
85
+ nBlockMaxWeight = std::max<size_t >(4000 , std::min<size_t >(MAX_BLOCK_WEIGHT - 4000 , options.nBlockMaxWeight ));
86
+ // Limit size to between 1K and MAX_BLOCK_SERIALIZED_SIZE-1K for sanity:
87
+ nBlockMaxSize = std::max<size_t >(1000 , std::min<size_t >(MAX_BLOCK_SERIALIZED_SIZE - 1000 , options.nBlockMaxSize ));
88
+ // Whether we need to account for byte usage (in addition to weight usage)
89
+ fNeedSizeAccounting = (nBlockMaxSize < MAX_BLOCK_SERIALIZED_SIZE - 1000 );
90
+ }
91
+
92
+ static BlockAssembler::Options DefaultOptions (const CChainParams& params)
77
93
{
78
94
// Block resource limits
79
95
// If neither -blockmaxsize or -blockmaxweight is given, limit to DEFAULT_BLOCK_MAX_*
80
96
// If only one is given, only restrict the specified resource.
81
97
// If both are given, restrict both.
82
- nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
83
- nBlockMaxSize = DEFAULT_BLOCK_MAX_SIZE;
98
+ BlockAssembler::Options options;
99
+ options.nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
100
+ options.nBlockMaxSize = DEFAULT_BLOCK_MAX_SIZE;
84
101
bool fWeightSet = false ;
85
102
if (IsArgSet (" -blockmaxweight" )) {
86
- nBlockMaxWeight = GetArg (" -blockmaxweight" , DEFAULT_BLOCK_MAX_WEIGHT);
87
- nBlockMaxSize = MAX_BLOCK_SERIALIZED_SIZE;
103
+ options. nBlockMaxWeight = GetArg (" -blockmaxweight" , DEFAULT_BLOCK_MAX_WEIGHT);
104
+ options. nBlockMaxSize = MAX_BLOCK_SERIALIZED_SIZE;
88
105
fWeightSet = true ;
89
106
}
90
107
if (IsArgSet (" -blockmaxsize" )) {
91
- nBlockMaxSize = GetArg (" -blockmaxsize" , DEFAULT_BLOCK_MAX_SIZE);
108
+ options. nBlockMaxSize = GetArg (" -blockmaxsize" , DEFAULT_BLOCK_MAX_SIZE);
92
109
if (!fWeightSet ) {
93
- nBlockMaxWeight = nBlockMaxSize * WITNESS_SCALE_FACTOR;
110
+ options. nBlockMaxWeight = options. nBlockMaxSize * WITNESS_SCALE_FACTOR;
94
111
}
95
112
}
96
113
if (IsArgSet (" -blockmintxfee" )) {
97
114
CAmount n = 0 ;
98
115
ParseMoney (GetArg (" -blockmintxfee" , " " ), n);
99
- blockMinFeeRate = CFeeRate (n);
116
+ options. blockMinFeeRate = CFeeRate (n);
100
117
} else {
101
- blockMinFeeRate = CFeeRate (DEFAULT_BLOCK_MIN_TX_FEE);
118
+ options. blockMinFeeRate = CFeeRate (DEFAULT_BLOCK_MIN_TX_FEE);
102
119
}
103
-
104
- // Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
105
- nBlockMaxWeight = std::max ((unsigned int )4000 , std::min ((unsigned int )(MAX_BLOCK_WEIGHT-4000 ), nBlockMaxWeight));
106
- // Limit size to between 1K and MAX_BLOCK_SERIALIZED_SIZE-1K for sanity:
107
- nBlockMaxSize = std::max ((unsigned int )1000 , std::min ((unsigned int )(MAX_BLOCK_SERIALIZED_SIZE-1000 ), nBlockMaxSize));
108
- // Whether we need to account for byte usage (in addition to weight usage)
109
- fNeedSizeAccounting = (nBlockMaxSize < MAX_BLOCK_SERIALIZED_SIZE-1000 );
120
+ return options;
110
121
}
111
122
123
+ BlockAssembler::BlockAssembler (const CChainParams& params) : BlockAssembler(params, DefaultOptions(params)) {}
124
+
112
125
void BlockAssembler::resetBlock ()
113
126
{
114
127
inBlock.clear ();
0 commit comments