@@ -2938,10 +2938,7 @@ bool IsWitnessSeasoned(const CBlockIndex* pindexPrev, const Consensus::Params& p
2938
2938
2939
2939
const int nHeight = pindexPrev->nHeight + 1 ;
2940
2940
2941
- if (nHeight < (int )BIP102_FORK_BUFFER)
2942
- return false ;
2943
-
2944
- const CBlockIndex* pindexForkBuffer = pindexPrev->GetAncestor (nHeight - BIP102_FORK_BUFFER);
2941
+ const CBlockIndex* pindexForkBuffer = pindexPrev->GetAncestor (nHeight - params.BIP102HeightDelta );
2945
2942
2946
2943
return (VersionBitsState (pindexForkBuffer, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == THRESHOLD_ACTIVE);
2947
2944
}
@@ -3069,6 +3066,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
3069
3066
// multiple, the last one is used.
3070
3067
bool fHaveWitness = false ;
3071
3068
bool fSegwitSeasoned = false ;
3069
+ bool fBIP102FirstBlock = false ;
3072
3070
bool fSegWitActive = (VersionBitsState (pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == THRESHOLD_ACTIVE);
3073
3071
if (fSegWitActive ) {
3074
3072
int commitpos = GetWitnessCommitmentIndex (block);
@@ -3088,12 +3086,28 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
3088
3086
fHaveWitness = true ;
3089
3087
}
3090
3088
3091
- fSegwitSeasoned = IsWitnessSeasoned (pindexPrev, consensusParams);
3089
+ // Look back to test SegWit activation period
3090
+ const CBlockIndex* pindexForkBuffer = pindexPrev ? pindexPrev->GetAncestor (nHeight - consensusParams.BIP102HeightDelta ) : NULL ;
3091
+ fSegwitSeasoned = (VersionBitsState (pindexForkBuffer, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == THRESHOLD_ACTIVE);
3092
+
3093
+ // Look back one more block, to detect edge
3094
+ if (fSegwitSeasoned ) {
3095
+ assert (pindexForkBuffer);
3096
+ const CBlockIndex* pindexLastSeason = pindexForkBuffer->pprev ;
3097
+ fBIP102FirstBlock = (VersionBitsState (pindexLastSeason, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) != THRESHOLD_ACTIVE);
3098
+ }
3092
3099
}
3093
3100
3101
+ // Max block base size limit
3094
3102
if (::GetSerializeSize (block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) > MaxBlockBaseSize (fSegwitSeasoned ))
3095
3103
return state.DoS (100 , false , REJECT_INVALID, " bad-blk-length" , false , " size limits failed" );
3096
3104
3105
+ // First block at fork must be large
3106
+ if (fBIP102FirstBlock ) {
3107
+ if (::GetSerializeSize (block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) <= MAX_LEGACY_BLOCK_SIZE)
3108
+ return state.DoS (100 , false , REJECT_INVALID, " bad-blk-length-toosmall" , false , " size limits failed" );
3109
+ }
3110
+
3097
3111
// No witness data is allowed in blocks that don't commit to witness data, as this would otherwise leave room for spam
3098
3112
if (!fHaveWitness ) {
3099
3113
for (size_t i = 0 ; i < block.vtx .size (); i++) {
0 commit comments