Skip to content

Commit

Permalink
adds spork for block size limit
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphire-pt committed Jan 9, 2021
1 parent df8f051 commit 292b2c1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 6 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ std::vector<CSporkDef> 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.
Expand Down
1 change: 1 addition & 0 deletions src/sporkid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 292b2c1

Please sign in to comment.