Skip to content

Commit ba206d2

Browse files
committed
Deprecate confusing blockmaxsize, fix getmininginfo output
* This removes block-size-limiting code in favor of GBT clients doing the limiting themselves (if at all). * -blockmaxsize is deprecated and only used to calculate an implied blockmaxweight, addressing confusion from multiple users. * getmininginfo's currentblocksize return value was returning garbage values, and has been removed, also removing a GetSerializeSize call in some block generation inner loops and potentially addressing some performance edge cases.
1 parent 31e72b2 commit ba206d2

File tree

7 files changed

+13
-46
lines changed

7 files changed

+13
-46
lines changed

src/init.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ std::string HelpMessage(HelpMessageMode mode)
484484

485485
strUsage += HelpMessageGroup(_("Block creation options:"));
486486
strUsage += HelpMessageOpt("-blockmaxweight=<n>", strprintf(_("Set maximum BIP141 block weight (default: %d)"), DEFAULT_BLOCK_MAX_WEIGHT));
487-
strUsage += HelpMessageOpt("-blockmaxsize=<n>", strprintf(_("Set maximum block size in bytes (default: %d)"), DEFAULT_BLOCK_MAX_SIZE));
487+
strUsage += HelpMessageOpt("-blockmaxsize=<n>", _("Set maximum BIP141 block weight to this * 4. Deprecated, use blockmaxweight"));
488488
strUsage += HelpMessageOpt("-blockmintxfee=<amt>", strprintf(_("Set lowest fee rate (in %s/kB) for transactions to be included in block creation. (default: %s)"), CURRENCY_UNIT, FormatMoney(DEFAULT_BLOCK_MIN_TX_FEE)));
489489
if (showDebug)
490490
strUsage += HelpMessageOpt("-blockversion=<n>", "Override block version to test forking scenarios");
@@ -785,6 +785,15 @@ void InitParameterInteraction()
785785
if (gArgs.SoftSetBoolArg("-whitelistrelay", true))
786786
LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n", __func__);
787787
}
788+
789+
if (gArgs.IsArgSet("-blockmaxsize")) {
790+
unsigned int max_size = gArgs.GetArg("-blockmaxsize", 0);
791+
if (gArgs.SoftSetArg("blockmaxweight", strprintf("%d", max_size * WITNESS_SCALE_FACTOR))) {
792+
LogPrintf("%s: parameter interaction: -blockmaxsize=%d -> setting -blockmaxweight=%d (-blockmaxsize is deprecated!)\n", __func__, max_size, max_size * WITNESS_SCALE_FACTOR);
793+
} else {
794+
LogPrintf("%s: Ignoring blockmaxsize setting which is overridden by blockmaxweight", __func__);
795+
}
796+
}
788797
}
789798

790799
static std::string ResolveErrMsg(const char * const optname, const std::string& strBind)

src/miner.cpp

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
// its ancestors.
4444

4545
uint64_t nLastBlockTx = 0;
46-
uint64_t nLastBlockSize = 0;
4746
uint64_t nLastBlockWeight = 0;
4847

4948
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
@@ -64,18 +63,13 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
6463
BlockAssembler::Options::Options() {
6564
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
6665
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
67-
nBlockMaxSize = DEFAULT_BLOCK_MAX_SIZE;
6866
}
6967

7068
BlockAssembler::BlockAssembler(const CChainParams& params, const Options& options) : chainparams(params)
7169
{
7270
blockMinFeeRate = options.blockMinFeeRate;
7371
// Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
7472
nBlockMaxWeight = std::max<size_t>(4000, std::min<size_t>(MAX_BLOCK_WEIGHT - 4000, options.nBlockMaxWeight));
75-
// Limit size to between 1K and MAX_BLOCK_SERIALIZED_SIZE-1K for sanity:
76-
nBlockMaxSize = std::max<size_t>(1000, std::min<size_t>(MAX_BLOCK_SERIALIZED_SIZE - 1000, options.nBlockMaxSize));
77-
// Whether we need to account for byte usage (in addition to weight usage)
78-
fNeedSizeAccounting = (nBlockMaxSize < MAX_BLOCK_SERIALIZED_SIZE - 1000);
7973
}
8074

8175
static BlockAssembler::Options DefaultOptions(const CChainParams& params)
@@ -85,20 +79,7 @@ static BlockAssembler::Options DefaultOptions(const CChainParams& params)
8579
// If only one is given, only restrict the specified resource.
8680
// If both are given, restrict both.
8781
BlockAssembler::Options options;
88-
options.nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
89-
options.nBlockMaxSize = DEFAULT_BLOCK_MAX_SIZE;
90-
bool fWeightSet = false;
91-
if (gArgs.IsArgSet("-blockmaxweight")) {
92-
options.nBlockMaxWeight = gArgs.GetArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT);
93-
options.nBlockMaxSize = MAX_BLOCK_SERIALIZED_SIZE;
94-
fWeightSet = true;
95-
}
96-
if (gArgs.IsArgSet("-blockmaxsize")) {
97-
options.nBlockMaxSize = gArgs.GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
98-
if (!fWeightSet) {
99-
options.nBlockMaxWeight = options.nBlockMaxSize * WITNESS_SCALE_FACTOR;
100-
}
101-
}
82+
options.nBlockMaxWeight = gArgs.GetArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT);
10283
if (gArgs.IsArgSet("-blockmintxfee")) {
10384
CAmount n = 0;
10485
ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n);
@@ -116,7 +97,6 @@ void BlockAssembler::resetBlock()
11697
inBlock.clear();
11798

11899
// Reserve space for coinbase tx
119-
nBlockSize = 1000;
120100
nBlockWeight = 4000;
121101
nBlockSigOpsCost = 400;
122102
fIncludeWitness = false;
@@ -176,7 +156,6 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
176156
int64_t nTime1 = GetTimeMicros();
177157

178158
nLastBlockTx = nBlockTx;
179-
nLastBlockSize = nBlockSize;
180159
nLastBlockWeight = nBlockWeight;
181160

182161
// Create coinbase transaction.
@@ -191,8 +170,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
191170
pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
192171
pblocktemplate->vTxFees[0] = -nFees;
193172

194-
uint64_t nSerializeSize = GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION);
195-
LogPrintf("CreateNewBlock(): total size: %u block weight: %u txs: %u fees: %ld sigops %d\n", nSerializeSize, GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost);
173+
LogPrintf("CreateNewBlock(): block weight: %u txs: %u fees: %ld sigops %d\n", GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost);
196174

197175
// Fill in header
198176
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
@@ -239,22 +217,13 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
239217
// - transaction finality (locktime)
240218
// - premature witness (in case segwit transactions are added to mempool before
241219
// segwit activation)
242-
// - serialized size (in case -blockmaxsize is in use)
243220
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package)
244221
{
245-
uint64_t nPotentialBlockSize = nBlockSize; // only used with fNeedSizeAccounting
246222
for (const CTxMemPool::txiter it : package) {
247223
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
248224
return false;
249225
if (!fIncludeWitness && it->GetTx().HasWitness())
250226
return false;
251-
if (fNeedSizeAccounting) {
252-
uint64_t nTxSize = ::GetSerializeSize(it->GetTx(), SER_NETWORK, PROTOCOL_VERSION);
253-
if (nPotentialBlockSize + nTxSize >= nBlockMaxSize) {
254-
return false;
255-
}
256-
nPotentialBlockSize += nTxSize;
257-
}
258227
}
259228
return true;
260229
}
@@ -264,9 +233,6 @@ void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
264233
pblock->vtx.emplace_back(iter->GetSharedTx());
265234
pblocktemplate->vTxFees.push_back(iter->GetFee());
266235
pblocktemplate->vTxSigOpsCost.push_back(iter->GetSigOpCost());
267-
if (fNeedSizeAccounting) {
268-
nBlockSize += ::GetSerializeSize(iter->GetTx(), SER_NETWORK, PROTOCOL_VERSION);
269-
}
270236
nBlockWeight += iter->GetTxWeight();
271237
++nBlockTx;
272238
nBlockSigOpsCost += iter->GetSigOpCost();

src/miner.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,11 @@ class BlockAssembler
139139

140140
// Configuration parameters for the block size
141141
bool fIncludeWitness;
142-
unsigned int nBlockMaxWeight, nBlockMaxSize;
143-
bool fNeedSizeAccounting;
142+
unsigned int nBlockMaxWeight;
144143
CFeeRate blockMinFeeRate;
145144

146145
// Information on the current status of the block
147146
uint64_t nBlockWeight;
148-
uint64_t nBlockSize;
149147
uint64_t nBlockTx;
150148
uint64_t nBlockSigOpsCost;
151149
CAmount nFees;

src/policy/policy.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
class CCoinsViewCache;
1717
class CTxOut;
1818

19-
/** Default for -blockmaxsize, which controls the maximum size of block the mining code will create **/
20-
static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 750000;
2119
/** Default for -blockmaxweight, which controls the range of block weights the mining code will create **/
2220
static const unsigned int DEFAULT_BLOCK_MAX_WEIGHT = 3000000;
2321
/** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/

src/rpc/mining.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ UniValue getmininginfo(const JSONRPCRequest& request)
196196
"\nResult:\n"
197197
"{\n"
198198
" \"blocks\": nnn, (numeric) The current block\n"
199-
" \"currentblocksize\": nnn, (numeric) The last block size\n"
200199
" \"currentblockweight\": nnn, (numeric) The last block weight\n"
201200
" \"currentblocktx\": nnn, (numeric) The last block transaction\n"
202201
" \"difficulty\": xxx.xxxxx (numeric) The current difficulty\n"
@@ -215,7 +214,6 @@ UniValue getmininginfo(const JSONRPCRequest& request)
215214

216215
UniValue obj(UniValue::VOBJ);
217216
obj.push_back(Pair("blocks", (int)chainActive.Height()));
218-
obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
219217
obj.push_back(Pair("currentblockweight", (uint64_t)nLastBlockWeight));
220218
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
221219
obj.push_back(Pair("difficulty", (double)GetDifficulty()));

src/validation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ extern CTxMemPool mempool;
161161
typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
162162
extern BlockMap mapBlockIndex;
163163
extern uint64_t nLastBlockTx;
164-
extern uint64_t nLastBlockSize;
165164
extern uint64_t nLastBlockWeight;
166165
extern const std::string strMessageMagic;
167166
extern CWaitableCriticalSection csBestBlock;

test/functional/mining.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def run_test(self):
3838
mining_info = node.getmininginfo()
3939
assert_equal(mining_info['blocks'], 200)
4040
assert_equal(mining_info['chain'], 'regtest')
41-
assert_equal(mining_info['currentblocksize'], 0)
4241
assert_equal(mining_info['currentblocktx'], 0)
4342
assert_equal(mining_info['currentblockweight'], 0)
4443
assert_equal(mining_info['difficulty'], Decimal('4.656542373906925E-10'))

0 commit comments

Comments
 (0)