changeset 29720:b62f06d21df8

[consensus] Decouple max-tx-per-block from max-block-size
author Jeff Garzik <jeff@bloq.com>
date Mon, 05 Jun 2017 00:12:33 -0400
parents a8ede95eb427
children c738c6f8fa48
files src/blockencodings.cpp src/consensus/consensus.h src/merkleblock.cpp src/validation.cpp
diffstat 4 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/blockencodings.cpp	Mon May 29 00:28:46 2017 -0400
+++ b/src/blockencodings.cpp	Mon Jun 05 00:12:33 2017 -0400
@@ -15,8 +15,6 @@
 
 #include <unordered_map>
 
-#define MIN_TRANSACTION_BASE_SIZE (::GetSerializeSize(CTransaction(), SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS))
-
 CBlockHeaderAndShortTxIDs::CBlockHeaderAndShortTxIDs(const CBlock& block, bool fUseWTXID) :
         nonce(GetRand(std::numeric_limits<uint64_t>::max())),
         shorttxids(block.vtx.size() - 1), prefilledtxn(1), header(block) {
@@ -50,7 +48,7 @@
 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_VTX)
         return READ_STATUS_INVALID;
 
     assert(header.IsNull() && txn_available.empty());
--- a/src/consensus/consensus.h	Mon May 29 00:28:46 2017 -0400
+++ b/src/consensus/consensus.h	Mon Jun 05 00:12:33 2017 -0400
@@ -17,8 +17,12 @@
 /** The maximum allowed number of signature check operations in a block (network rule) */
 static const int64_t MAX_BLOCK_SIGOPS_COST = 80000;
 
+/** The minimum allowed size for a transaction */
+static const unsigned int MIN_TRANSACTION_BASE_SIZE = 10;
 /** The maximum allowed size for a transaction, excluding witness data, in bytes */
 static const unsigned int MAX_TX_BASE_SIZE = 1000000;
+/** The maximum allowed number of transactions per block */
+static const unsigned int MAX_BLOCK_VTX = (MAX_BLOCK_BASE_SIZE / MIN_TRANSACTION_BASE_SIZE);
 
 /** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
 static const int COINBASE_MATURITY = 100;
--- a/src/merkleblock.cpp	Mon May 29 00:28:46 2017 -0400
+++ b/src/merkleblock.cpp	Mon Jun 05 00:12:33 2017 -0400
@@ -153,7 +153,7 @@
     if (nTransactions == 0)
         return uint256();
     // check for excessively high numbers of transactions
-    if (nTransactions > MAX_BLOCK_BASE_SIZE / 60) // 60 is the lower bound for the size of a serialized CTransaction
+    if (nTransactions > MAX_BLOCK_VTX)
         return uint256();
     // there can never be more hashes provided than one for every txid
     if (vHash.size() > nTransactions)
--- a/src/validation.cpp	Mon May 29 00:28:46 2017 -0400
+++ b/src/validation.cpp	Mon Jun 05 00:12:33 2017 -0400
@@ -2880,7 +2880,7 @@
     // checks that use witness data may be performed here.
 
     // Size limits
-    if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_BASE_SIZE || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) > MAX_BLOCK_BASE_SIZE)
+    if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_VTX || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) > MAX_BLOCK_BASE_SIZE)
         return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, "size limits failed");
 
     // First transaction must be coinbase, the rest must not be