mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
parent
3fad5e1ab4
commit
2eed6c057b
5 changed files with 89 additions and 4 deletions
|
|
@ -235,7 +235,7 @@ func (x *XDPoS_v1) verifyCascadingFields(chain consensus.ChainReader, header *ty
|
||||||
return utils.ErrInvalidTimestamp
|
return utils.ErrInvalidTimestamp
|
||||||
}
|
}
|
||||||
// Verify the header's EIP-1559 attributes.
|
// Verify the header's EIP-1559 attributes.
|
||||||
if err := eip1559.VerifyEip1559Header(chain.Config(), header); err != nil {
|
if err := eip1559.VerifyEip1559Header(chain.Config(), parent, header); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ func (x *XDPoS_v2) verifyHeader(chain consensus.ChainReader, header *types.Heade
|
||||||
return utils.ErrInvalidUncleHash
|
return utils.ErrInvalidUncleHash
|
||||||
}
|
}
|
||||||
// Verify the header's EIP-1559 attributes.
|
// Verify the header's EIP-1559 attributes.
|
||||||
if err := eip1559.VerifyEip1559Header(chain.Config(), header); err != nil {
|
if err := eip1559.VerifyEip1559Header(chain.Config(), parent, header); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if header.Difficulty.Cmp(big.NewInt(1)) != 0 {
|
if header.Difficulty.Cmp(big.NewInt(1)) != 0 {
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Verify the header's EIP-1559 attributes.
|
// Verify the header's EIP-1559 attributes.
|
||||||
if err := eip1559.VerifyEip1559Header(chain.Config(), header); err != nil {
|
if err := eip1559.VerifyEip1559Header(chain.Config(), parent, header); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import (
|
||||||
// VerifyEip1559Header verifies some header attributes which were changed in EIP-1559,
|
// VerifyEip1559Header verifies some header attributes which were changed in EIP-1559,
|
||||||
// - gas limit check
|
// - gas limit check
|
||||||
// - basefee check
|
// - basefee check
|
||||||
func VerifyEip1559Header(config *params.ChainConfig, header *types.Header) error {
|
func VerifyEip1559Header(config *params.ChainConfig, parent, header *types.Header) error {
|
||||||
if !config.IsEIP1559(header.Number) {
|
if !config.IsEIP1559(header.Number) {
|
||||||
if header.BaseFee != nil {
|
if header.BaseFee != nil {
|
||||||
return fmt.Errorf("invalid baseFee: have %s, want <nil>",
|
return fmt.Errorf("invalid baseFee: have %s, want <nil>",
|
||||||
|
|
@ -42,6 +42,10 @@ func VerifyEip1559Header(config *params.ChainConfig, header *types.Header) error
|
||||||
if header.BaseFee == nil {
|
if header.BaseFee == nil {
|
||||||
return errors.New("header is missing baseFee")
|
return errors.New("header is missing baseFee")
|
||||||
}
|
}
|
||||||
|
// Verify the parent header is not malformed
|
||||||
|
if parent != nil && config.IsEIP1559(parent.Number) && parent.BaseFee == nil {
|
||||||
|
return errors.New("parent header is missing baseFee")
|
||||||
|
}
|
||||||
|
|
||||||
// Verify the baseFee is correct based on the current header.
|
// Verify the baseFee is correct based on the current header.
|
||||||
expectedBaseFee := CalcBaseFee(config, header)
|
expectedBaseFee := CalcBaseFee(config, header)
|
||||||
|
|
|
||||||
81
consensus/misc/eip1559/eip1559_test.go
Normal file
81
consensus/misc/eip1559/eip1559_test.go
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
// Copyright 2021 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package eip1559
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/big"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
|
)
|
||||||
|
|
||||||
|
func testConfigEip1559() *params.ChainConfig {
|
||||||
|
config := *params.TestChainConfig
|
||||||
|
config.Eip1559Block = big.NewInt(1)
|
||||||
|
return &config
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVerifyEip1559HeaderParentBaseFee(t *testing.T) {
|
||||||
|
config := testConfigEip1559()
|
||||||
|
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
parent *types.Header
|
||||||
|
headerNum int64
|
||||||
|
wantOk bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "eip1559 parent missing basefee",
|
||||||
|
parent: &types.Header{
|
||||||
|
Number: big.NewInt(1),
|
||||||
|
},
|
||||||
|
headerNum: 2,
|
||||||
|
wantOk: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "eip1559 parent with basefee",
|
||||||
|
parent: &types.Header{
|
||||||
|
Number: big.NewInt(1),
|
||||||
|
BaseFee: new(big.Int).Set(common.BaseFee),
|
||||||
|
},
|
||||||
|
headerNum: 2,
|
||||||
|
wantOk: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pre-eip1559 parent ignores basefee",
|
||||||
|
parent: &types.Header{
|
||||||
|
Number: big.NewInt(0),
|
||||||
|
},
|
||||||
|
headerNum: 1,
|
||||||
|
wantOk: true,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
header := &types.Header{
|
||||||
|
Number: big.NewInt(tc.headerNum),
|
||||||
|
BaseFee: new(big.Int).Set(common.BaseFee),
|
||||||
|
}
|
||||||
|
err := VerifyEip1559Header(config, tc.parent, header)
|
||||||
|
if tc.wantOk && err != nil {
|
||||||
|
t.Fatalf("%s: expected no error, got %v", tc.name, err)
|
||||||
|
}
|
||||||
|
if !tc.wantOk && err == nil {
|
||||||
|
t.Fatalf("%s: expected error, got nil", tc.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue