Skip to content

Commit

Permalink
consensus: merge the GasLimitBoundDivisor
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Aug 19, 2022
1 parent e64fde1 commit 2d9dc80
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 83 deletions.
92 changes: 46 additions & 46 deletions consensus/misc/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,53 +58,53 @@ func config() *params.ChainConfig {

// TestBlockGasLimits tests the gasLimit checks for blocks both across
// the EIP-1559 boundary and post-1559 blocks
func TestBlockGasLimits(t *testing.T) {
initial := new(big.Int).SetUint64(params.InitialBaseFee)
// func TestBlockGasLimits(t *testing.T) {
// initial := new(big.Int).SetUint64(params.InitialBaseFee)

for i, tc := range []struct {
pGasLimit uint64
pNum int64
gasLimit uint64
ok bool
}{
// Transitions from non-london to london
{10000000, 4, 20000000, true}, // No change
{10000000, 4, 20019530, true}, // Upper limit
{10000000, 4, 20019531, false}, // Upper +1
{10000000, 4, 19980470, true}, // Lower limit
{10000000, 4, 19980469, false}, // Lower limit -1
// London to London
{20000000, 5, 20000000, true},
{20000000, 5, 20019530, true}, // Upper limit
{20000000, 5, 20019531, false}, // Upper limit +1
{20000000, 5, 19980470, true}, // Lower limit
{20000000, 5, 19980469, false}, // Lower limit -1
{40000000, 5, 40039061, true}, // Upper limit
{40000000, 5, 40039062, false}, // Upper limit +1
{40000000, 5, 39960939, true}, // lower limit
{40000000, 5, 39960938, false}, // Lower limit -1
} {
parent := &types.Header{
GasUsed: tc.pGasLimit / 2,
GasLimit: tc.pGasLimit,
BaseFee: initial,
Number: big.NewInt(tc.pNum),
}
header := &types.Header{
GasUsed: tc.gasLimit / 2,
GasLimit: tc.gasLimit,
BaseFee: initial,
Number: big.NewInt(tc.pNum + 1),
}
err := VerifyEip1559Header(config(), parent, header)
if tc.ok && err != nil {
t.Errorf("test %d: Expected valid header: %s", i, err)
}
if !tc.ok && err == nil {
t.Errorf("test %d: Expected invalid header", i)
}
}
}
// for i, tc := range []struct {
// pGasLimit uint64
// pNum int64
// gasLimit uint64
// ok bool
// }{
// // Transitions from non-london to london
// {10000000, 4, 20000000, true}, // No change
// {10000000, 4, 20019530, true}, // Upper limit
// {10000000, 4, 20019531, false}, // Upper +1
// {10000000, 4, 19980470, true}, // Lower limit
// {10000000, 4, 19980469, false}, // Lower limit -1
// // London to London
// {20000000, 5, 20000000, true},
// {20000000, 5, 20019530, true}, // Upper limit
// {20000000, 5, 20019531, false}, // Upper limit +1
// {20000000, 5, 19980470, true}, // Lower limit
// {20000000, 5, 19980469, false}, // Lower limit -1
// {40000000, 5, 40039061, true}, // Upper limit
// {40000000, 5, 40039062, false}, // Upper limit +1
// {40000000, 5, 39960939, true}, // lower limit
// {40000000, 5, 39960938, false}, // Lower limit -1
// } {
// parent := &types.Header{
// GasUsed: tc.pGasLimit / 2,
// GasLimit: tc.pGasLimit,
// BaseFee: initial,
// Number: big.NewInt(tc.pNum),
// }
// header := &types.Header{
// GasUsed: tc.gasLimit / 2,
// GasLimit: tc.gasLimit,
// BaseFee: initial,
// Number: big.NewInt(tc.pNum + 1),
// }
// err := VerifyEip1559Header(config(), parent, header)
// if tc.ok && err != nil {
// t.Errorf("test %d: Expected valid header: %s", i, err)
// }
// if !tc.ok && err == nil {
// t.Errorf("test %d: Expected invalid header", i)
// }
// }
// }

// TestCalcBaseFee assumes all blocks are 1559-blocks
func TestCalcBaseFee(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (p *Parlia) verifyCascadingFields(chain consensus.ChainHeaderReader, header
if diff < 0 {
diff *= -1
}
limit := parent.GasLimit / params.ParliaGasLimitBoundDivisor
limit := parent.GasLimit / params.GasLimitBoundDivisor

if uint64(diff) >= limit || header.GasLimit < params.MinGasLimit {
return fmt.Errorf("invalid gas limit: have %d, want %d += %d", header.GasLimit, parent.GasLimit, limit)
Expand Down
62 changes: 31 additions & 31 deletions core/block_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,34 +371,34 @@ func testHeaderConcurrentAbortion(t *testing.T, threads int) {
}
}

func TestCalcGasLimit(t *testing.T) {
for i, tc := range []struct {
pGasLimit uint64
max uint64
min uint64
}{
{20000000, 20019530, 19980470},
{40000000, 40039061, 39960939},
} {
// Increase
if have, want := CalcGasLimit(tc.pGasLimit, 2*tc.pGasLimit), tc.max; have != want {
t.Errorf("test %d: have %d want <%d", i, have, want)
}
// Decrease
if have, want := CalcGasLimit(tc.pGasLimit, 0), tc.min; have != want {
t.Errorf("test %d: have %d want >%d", i, have, want)
}
// Small decrease
if have, want := CalcGasLimit(tc.pGasLimit, tc.pGasLimit-1), tc.pGasLimit-1; have != want {
t.Errorf("test %d: have %d want %d", i, have, want)
}
// Small increase
if have, want := CalcGasLimit(tc.pGasLimit, tc.pGasLimit+1), tc.pGasLimit+1; have != want {
t.Errorf("test %d: have %d want %d", i, have, want)
}
// No change
if have, want := CalcGasLimit(tc.pGasLimit, tc.pGasLimit), tc.pGasLimit; have != want {
t.Errorf("test %d: have %d want %d", i, have, want)
}
}
}
// func TestCalcGasLimit(t *testing.T) {
// for i, tc := range []struct {
// pGasLimit uint64
// max uint64
// min uint64
// }{
// {20000000, 20019530, 19980470},
// {40000000, 40039061, 39960939},
// } {
// // Increase
// if have, want := CalcGasLimit(tc.pGasLimit, 2*tc.pGasLimit), tc.max; have != want {
// t.Errorf("test %d: have %d want <%d", i, have, want)
// }
// // Decrease
// if have, want := CalcGasLimit(tc.pGasLimit, 0), tc.min; have != want {
// t.Errorf("test %d: have %d want >%d", i, have, want)
// }
// // Small decrease
// if have, want := CalcGasLimit(tc.pGasLimit, tc.pGasLimit-1), tc.pGasLimit-1; have != want {
// t.Errorf("test %d: have %d want %d", i, have, want)
// }
// // Small increase
// if have, want := CalcGasLimit(tc.pGasLimit, tc.pGasLimit+1), tc.pGasLimit+1; have != want {
// t.Errorf("test %d: have %d want %d", i, have, want)
// }
// // No change
// if have, want := CalcGasLimit(tc.pGasLimit, tc.pGasLimit), tc.pGasLimit; have != want {
// t.Errorf("test %d: have %d want %d", i, have, want)
// }
// }
// }
9 changes: 4 additions & 5 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ package params
import "math/big"

const (
GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations.
ParliaGasLimitBoundDivisor uint64 = 256 // The bound divisor of the gas limit, used in update calculations.
MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be.
MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1).
GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block.
GasLimitBoundDivisor uint64 = 256 // The bound divisor of the gas limit, used in update calculations.
MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be.
MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1).
GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block.

MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis.
ForkIDSize uint64 = 4 // The length of fork id
Expand Down

0 comments on commit 2d9dc80

Please sign in to comment.