@@ -84,7 +84,7 @@ BlockAssembler::BlockAssembler(const CChainParams& _chainparams)
84
84
bool fWeightSet = false ;
85
85
if (IsArgSet (" -blockmaxweight" )) {
86
86
nBlockMaxWeight = GetArg (" -blockmaxweight" , DEFAULT_BLOCK_MAX_WEIGHT);
87
- nBlockMaxSize = MAX_BLOCK_SERIALIZED_SIZE ;
87
+ nBlockMaxSize = MaxBlockSerSize ( fWitnessSeasoned ) ;
88
88
fWeightSet = true ;
89
89
}
90
90
if (IsArgSet (" -blockmaxsize" )) {
@@ -102,11 +102,11 @@ BlockAssembler::BlockAssembler(const CChainParams& _chainparams)
102
102
}
103
103
104
104
// Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
105
- nBlockMaxWeight = std::max ((unsigned int )4000 , std::min ((unsigned int )(MaxBlockWeight (false )-4000 ), nBlockMaxWeight));
105
+ nBlockMaxWeight = std::max ((unsigned int )4000 , std::min ((unsigned int )(MaxBlockWeight (fWitnessSeasoned )-4000 ), nBlockMaxWeight));
106
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));
107
+ nBlockMaxSize = std::max ((unsigned int )1000 , std::min ((unsigned int )(MaxBlockSerSize ( fWitnessSeasoned ) -1000 ), nBlockMaxSize));
108
108
// Whether we need to account for byte usage (in addition to weight usage)
109
- fNeedSizeAccounting = (nBlockMaxSize < MAX_BLOCK_SERIALIZED_SIZE -1000 );
109
+ fNeedSizeAccounting = (nBlockMaxSize < MaxBlockSerSize ( fWitnessSeasoned ) -1000 );
110
110
}
111
111
112
112
void BlockAssembler::resetBlock ()
@@ -118,6 +118,7 @@ void BlockAssembler::resetBlock()
118
118
nBlockWeight = 4000 ;
119
119
nBlockSigOpsCost = 400 ;
120
120
fIncludeWitness = false ;
121
+ fWitnessSeasoned = false ;
121
122
122
123
// These counters do not include coinbase tx
123
124
nBlockTx = 0 ;
@@ -168,6 +169,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
168
169
// TODO: replace this with a call to main to assess validity of a mempool
169
170
// transaction (which in most cases can be a no-op).
170
171
fIncludeWitness = IsWitnessEnabled (pindexPrev, chainparams.GetConsensus ()) && fMineWitnessTx ;
172
+ fWitnessSeasoned = IsWitnessSeasoned (pindexPrev, chainparams.GetConsensus ());
171
173
172
174
addPriorityTxs ();
173
175
int nPackagesSelected = 0 ;
@@ -242,7 +244,7 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
242
244
// TODO: switch to weight-based accounting for packages instead of vsize-based accounting.
243
245
if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight)
244
246
return false ;
245
- if (nBlockSigOpsCost + packageSigOpsCost >= (uint64_t )MaxBlockSigOpsCost (fIncludeWitness )) // note - excludes bip102 buffer
247
+ if (nBlockSigOpsCost + packageSigOpsCost >= (uint64_t )MaxBlockSigOpsCost (fWitnessSeasoned ))
246
248
return false ;
247
249
return true ;
248
250
}
@@ -302,7 +304,7 @@ bool BlockAssembler::TestForBlock(CTxMemPool::txiter iter)
302
304
}
303
305
}
304
306
305
- uint64_t sigOpMax = MaxBlockSigOpsCost (fIncludeWitness ); // excludes bip102 buffer
307
+ uint64_t sigOpMax = MaxBlockSigOpsCost (fWitnessSeasoned );
306
308
if (nBlockSigOpsCost + iter->GetSigOpCost () >= sigOpMax) {
307
309
// If the block has room for no more sig ops then
308
310
// flag that the block is finished
0 commit comments