Remove confusing MAX_BLOCK_BASE_SIZE. #10618

Merged
merged 1 commit into from Jul 15, 2017

Conversation

Projects
None yet
7 participants
Member

gmaxwell commented Jun 17, 2017

Some people keep thinking that MAX_BLOCK_BASE_SIZE is a separate
size limit from the weight limit when it fact it is superfluous,
and used in early tests before the witness data has been
validated or just to compute worst case sizes. The size checks
that use it would not behave any differently consensus wise
if they were eliminated completely.

Its correct value is not independently settable but is a function
of the weight limit and weight formula.

This patch just eliminates it and uses the scale factor as
required to compute the worse case constants. It's an alternative
to another PR that adds a long comment that seemingly was still
not sufficient.

src/blockencodings.cpp
@@ -50,7 +50,7 @@ uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const uint256& txhash) const {
ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<uint256, CTransactionRef>>& extra_txn) {
if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty()))
return READ_STATUS_INVALID;
- if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > MAX_BLOCK_BASE_SIZE / MIN_TRANSACTION_BASE_SIZE)
+ if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > MAX_BLOCK_WEIGHT / (WITNESS_SCALE_FACTOR * MIN_TRANSACTION_BASE_SIZE))
@sipa

sipa Jun 17, 2017

Owner

Probably easier to rewrite this expression using a separate constant MIN_TRANSACTION_WEIGHT

src/coins.cpp
@@ -237,7 +237,7 @@ bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const
return true;
}
-static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_BASE_SIZE / ::GetSerializeSize(CTxOut(), SER_NETWORK, PROTOCOL_VERSION); // TODO: merge with similar definition in undo.h.
+static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / (WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut(), SER_NETWORK, PROTOCOL_VERSION)); // TODO: merge with similar definition in undo.h.
@sipa

sipa Jun 17, 2017

Owner

Similarly, this is probably easier to write using a MIN_TRANSACTION_OUTPUT_WEIGHT.

Member

jtimon commented Jun 25, 2017

utACK, but needs rebase.

Why isn't WITNESS_SCALE_FACTOR in consensus/consensus.h ?

Thank you very much for this, sometimes I've explained that the max size is superflous once you replace it with the max weight, and often people don't believe me and some times they even link to the max size constant as a "proof" that I am wrong.

Owner

laanwj commented Jun 25, 2017

Needs rebase after #10608

Owner

sipa commented Jun 25, 2017

Why isn't WITNESS_SCALE_FACTOR in consensus/consensus.h ?

The weight calculations are currently in primtives/transaction.h, and I don't think that file should depend on consensus.h. Perhaps all weight based calculations can be moved to consensus/*, though.

Member

jtimon commented Jun 25, 2017

The weight calculations are currently in primtives/transaction.h, and I don't think that file should depend on consensus.h.

Why not? consensus/consensus.h it's just consensus constants. Anyway, not a big deal, there with MIN_TRANSACTION_WEIGHT isn't bad.

Perhaps all weight based calculations can be moved to consensus/*, though.

Do you mean moving primitives/* to consensus/ ? I proposed that in the past, I'm all for it, but that's definitely out of scope for this PR.

Owner

sipa commented Jun 25, 2017

No, just moving the weight calculations to consensus. Primitives is data structures and serialization, and shouldn't depend on consensus validity rules.

Member

gmaxwell commented Jul 13, 2017

@sipa I did as you requested! I think it makes more sense moved out of primitives, care to review?

Member

jtimon commented Jul 13, 2017

Fast re-review ACK cf88f5d

Owner

sipa commented Jul 13, 2017

utACK cf88f5d

@gmaxwell gmaxwell Remove confusing MAX_BLOCK_BASE_SIZE.
Some people keep thinking that MAX_BLOCK_BASE_SIZE is a separate
 size limit from the weight limit when it fact it is superfluous,
 and used in early tests before the witness data has been
 validated or just to compute worst case sizes.  The size checks
 that use it would not behave any differently consensus wise
 if they were eliminated completely.

Its correct value is not independently settable but is a function
 of the weight limit and weight formula.

This patch just eliminates it and uses the scale factor as
 required to compute the worse case constants.

It also moves the weight factor out of primitives into consensus,
 which is a more logical place for it.
3babbcb
Contributor

TheBlueMatt commented Jul 14, 2017

utACK 3babbcb

Contributor

TheBlueMatt commented Jul 14, 2017

Would be nice for 15, given the level of apparent confusion that still persists about this.

Owner

sipa commented Jul 14, 2017

utACK 3babbcb

Contributor

achow101 commented Jul 15, 2017

utACK 3babbcb

@sipa sipa merged commit 3babbcb into bitcoin:master Jul 15, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@sipa sipa added a commit that referenced this pull request Jul 15, 2017

@sipa sipa Merge #10618: Remove confusing MAX_BLOCK_BASE_SIZE.
3babbcb Remove confusing MAX_BLOCK_BASE_SIZE. (Gregory Maxwell)

Tree-SHA512: 361293fc4e1e379cd5a0908ed0866a00e1c7a771bdf02fded158fca21b492a29c7a67fea0d13dc40b2a04204c89823bf1836fe5b63a17c9747751b9c845a3527
f90603a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment