New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2M base block size increase #11

Merged
merged 7 commits into from Jun 16, 2017

[consensus] Add 3-month minimum seasoning requirement for SegWit

before changing base block size.
  • Loading branch information...
jgarzik committed Jun 15, 2017
commit e024d5c8fbc09d42e7c4594ca658727d79ecb197
Copy path View file
@@ -10,15 +10,16 @@

/** BIP102 block size increase height */
static const unsigned int BIP102_FORK_MIN_HEIGHT = 485218;
static const unsigned int BIP102_FORK_BUFFER = (144 * 90);

/** The maximum allowed size for a serialized block, in bytes (only for buffer size limits) */
static const unsigned int MAX_BLOCK_SERIALIZED_SIZE = 4000000;
/** The maximum allowed weight for a block, see BIP 141 (network rule) */
static const unsigned int MAX_BLOCK_WEIGHT = 4000000;
/** The maximum allowed size for a block excluding witness data, in bytes (network rule) */
static inline bool BIP102active(int nHeight, bool fSegWitActive)
static inline bool BIP102active(int nHeight, bool fSegwitSeasoned)
{
if (!fSegWitActive)
if (!fSegwitSeasoned)
return false;

if (nHeight < (int)BIP102_FORK_MIN_HEIGHT)
@@ -28,9 +29,9 @@ static inline bool BIP102active(int nHeight, bool fSegWitActive)
}

static const unsigned int MAX_LEGACY_BLOCK_SIZE = (1 * 1000 * 1000);
inline unsigned int MaxBlockBaseSize(int nHeight, bool fSegWitActive)
inline unsigned int MaxBlockBaseSize(int nHeight, bool fSegwitSeasoned)
{
if (!BIP102active(nHeight, fSegWitActive))
if (!BIP102active(nHeight, fSegwitSeasoned))
return MAX_LEGACY_BLOCK_SIZE;

return (2 * 1000 * 1000);
@@ -44,9 +45,9 @@ inline unsigned int MaxBlockBaseSize()

/** The maximum allowed number of signature check operations in a block (network rule) */
static const uint64_t MAX_BLOCK_BASE_SIGOPS = 20000;
inline int64_t MaxBlockSigOpsCost(int nHeight, bool fSegWitActive)
inline int64_t MaxBlockSigOpsCost(int nHeight, bool fSegwitSeasoned)
{
if (!BIP102active(nHeight, fSegWitActive))
if (!BIP102active(nHeight, fSegwitSeasoned))
return (MAX_BLOCK_BASE_SIGOPS * 4 /* WITNESS_SCALE_FACTOR */);

return ((2 * MAX_BLOCK_BASE_SIGOPS) * 4 /* WITNESS_SCALE_FACTOR */);
Copy path View file
@@ -3059,6 +3059,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
// {0xaa, 0x21, 0xa9, 0xed}, and the following 32 bytes are SHA256^2(witness root, witness nonce). In case there are
// multiple, the last one is used.
bool fHaveWitness = false;
bool fSegwitSeasoned = false;
bool fSegWitActive = (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == THRESHOLD_ACTIVE);
if (fSegWitActive) {
int commitpos = GetWitnessCommitmentIndex(block);
@@ -3077,9 +3078,12 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
}
fHaveWitness = true;
}

const CBlockIndex* pindexForkBuffer = pindexPrev->GetAncestor(nHeight - BIP102_FORK_BUFFER);
fSegwitSeasoned = (VersionBitsState(pindexForkBuffer, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == THRESHOLD_ACTIVE);
}

if (::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) > MaxBlockBaseSize(nHeight, fSegWitActive))
if (::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) > MaxBlockBaseSize(nHeight, fSegwitSeasoned))
return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, "size limits failed");

// No witness data is allowed in blocks that don't commit to witness data, as this would otherwise leave room for spam
ProTip! Use n and p to navigate between commits in a pull request.