diff --git a/src/main.cpp b/src/main.cpp index 4f156a6c04..92f747fbb7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3751,6 +3751,15 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn // } // } + // Size limits + unsigned int nMaxBlockSize = std::min( + (unsigned int)sporkManager.GetSporkValue(SPORK_105_MAX_BLOCK_SIZE), + MAX_BLOCK_SIZE_CURRENT + ); + + if (::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > nMaxBlockSize) + return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, "size limits failed"); + return true; } diff --git a/src/miner.cpp b/src/miner.cpp index 40fdecc29b..da9b38ec66 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -228,7 +228,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE); // Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity: unsigned int nBlockMaxSizeNetwork = MAX_BLOCK_SIZE_CURRENT; - nBlockMaxSize = std::max((unsigned int)1000, std::min((nBlockMaxSizeNetwork - 1000), nBlockMaxSize)); + nBlockMaxSize = std::max( + (unsigned int)1000, + std::min( + (unsigned int)sporkManager.GetSporkValue(SPORK_105_MAX_BLOCK_SIZE), + nBlockMaxSizeNetwork, + nBlockMaxSize)); // How much of the block should be dedicated to high-priority transactions, // included regardless of the fees they pay diff --git a/src/policy/policy.h b/src/policy/policy.h index f20381225d..872829751f 100644 --- a/src/policy/policy.h +++ b/src/policy/policy.h @@ -17,7 +17,7 @@ class CChainParams; class CCoinsViewCache; /** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/ -static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 750000; +static const unsigned int DEFAULT_BLOCK_MAX_SIZE = MAX_BLOCK_SIZE_CURRENT; static const unsigned int DEFAULT_BLOCK_MIN_SIZE = 0; /** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/ static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 50000; diff --git a/src/spork.cpp b/src/spork.cpp index e2a22c9a46..6ed7166b26 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -30,7 +30,8 @@ std::vector sporkDefs = { MAKE_SPORK_DEF(SPORK_101_SERVICES_ENFORCEMENT, 4070908800ULL), // OFF MAKE_SPORK_DEF(SPORK_102_FORCE_ENABLED_MASTERNODE, 4070908800ULL), // OFF MAKE_SPORK_DEF(SPORK_103_PING_MESSAGE_SALT, 4070908800ULL), // OFF - MAKE_SPORK_DEF(SPORK_104_MAX_BLOCK_TIME, 4070908800ULL), // OFF + MAKE_SPORK_DEF(SPORK_104_MAX_BLOCK_TIME, 4070908800ULL), // OFF + MAKE_SPORK_DEF(SPORK_105_MAX_BLOCK_SIZE, 4070908800ULL), // OFF // Unused dummy sporks. //TODO: Needed to be removed in the future when the old nodes cut from the network. diff --git a/src/sporkid.h b/src/sporkid.h index 0ada9268b5..9d54abea0d 100644 --- a/src/sporkid.h +++ b/src/sporkid.h @@ -34,6 +34,7 @@ enum SporkId : int32_t { SPORK_102_FORCE_ENABLED_MASTERNODE = 10101, SPORK_103_PING_MESSAGE_SALT = 10102, SPORK_104_MAX_BLOCK_TIME = 10103, + SPORK_105_MAX_BLOCK_SIZE = 10104, // Unused dummy sporks. //TODO needed to be removed in the future when the old nodes cut from the network.