Skip to content

Commit

Permalink
Merge pull request #1 from dean65/hardfork_euler
Browse files Browse the repository at this point in the history
Force check that Euler height cannot be a multiple of 200
  • Loading branch information
gothery001 authored Mar 16, 2022
2 parents 1054f93 + e58ffe8 commit 1a27de6
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
if err := newcfg.CheckConfigForkOrder(); err != nil {
return newcfg, common.Hash{}, err
}
if err := newcfg.VerifyForkConfig(); err != nil {
return newcfg, common.Hash{}, err
}
storedcfg := rawdb.ReadChainConfig(db, stored)
if storedcfg == nil {
log.Warn("Found genesis block without chain config")
Expand Down
12 changes: 11 additions & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package params

import (
"encoding/binary"
"errors"
"fmt"
"math/big"

Expand Down Expand Up @@ -496,7 +497,7 @@ func (c *ChainConfig) String() string {
default:
engine = "unknown"
}
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, Engine: %v, Euler: %v}",
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, Euler: %v, Engine: %v}",
c.ChainID,
c.HomesteadBlock,
c.DAOForkBlock,
Expand Down Expand Up @@ -756,6 +757,15 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
return nil
}

func (c *ChainConfig) VerifyForkConfig() error {
if c.EulerBlock != nil && c.EulerBlock.Cmp(common.Big0) != 0 {
if _, mod := new(big.Int).DivMod(c.EulerBlock, big.NewInt(200), new(big.Int)); mod.Cmp(common.Big0) == 0 {
return errors.New("euler height can't be multiple of 200")
}
}
return nil
}

// isForkIncompatible returns true if a fork scheduled at s1 cannot be rescheduled to
// block s2 because head is already past the fork.
func isForkIncompatible(s1, s2, head *big.Int) bool {
Expand Down
105 changes: 105 additions & 0 deletions params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"math/big"
"reflect"
"testing"

"github.com/ethereum/go-ethereum/common"
)

func TestCheckCompatible(t *testing.T) {
Expand Down Expand Up @@ -96,3 +98,106 @@ func TestCheckCompatible(t *testing.T) {
}
}
}

func TestChainConfig_VerifyForkConfig(t *testing.T) {
type fields struct {
ChainID *big.Int
HomesteadBlock *big.Int
DAOForkBlock *big.Int
DAOForkSupport bool
EIP150Block *big.Int
EIP150Hash common.Hash
EIP155Block *big.Int
EIP158Block *big.Int
ByzantiumBlock *big.Int
ConstantinopleBlock *big.Int
PetersburgBlock *big.Int
IstanbulBlock *big.Int
MuirGlacierBlock *big.Int
BerlinBlock *big.Int
YoloV3Block *big.Int
EWASMBlock *big.Int
CatalystBlock *big.Int
RamanujanBlock *big.Int
NielsBlock *big.Int
MirrorSyncBlock *big.Int
BrunoBlock *big.Int
EulerBlock *big.Int
Ethash *EthashConfig
Clique *CliqueConfig
Parlia *ParliaConfig
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{
name: "Test VerifyForkConfig Case 1",
fields: fields{},
wantErr: false,
},
{
name: "Test VerifyForkConfig Case 2",
fields: fields{
EulerBlock: big.NewInt(0),
},
wantErr: false,
},
{
name: "Test VerifyForkConfig Case 3",
fields: fields{
EulerBlock: big.NewInt(200),
},
wantErr: true,
},
{
name: "Test VerifyForkConfig Case 4",
fields: fields{
EulerBlock: big.NewInt(19231208),
},
wantErr: false,
},
{
name: "Test VerifyForkConfig Case 5",
fields: fields{
EulerBlock: big.NewInt(1998200),
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &ChainConfig{
ChainID: tt.fields.ChainID,
HomesteadBlock: tt.fields.HomesteadBlock,
DAOForkBlock: tt.fields.DAOForkBlock,
DAOForkSupport: tt.fields.DAOForkSupport,
EIP150Block: tt.fields.EIP150Block,
EIP150Hash: tt.fields.EIP150Hash,
EIP155Block: tt.fields.EIP155Block,
EIP158Block: tt.fields.EIP158Block,
ByzantiumBlock: tt.fields.ByzantiumBlock,
ConstantinopleBlock: tt.fields.ConstantinopleBlock,
PetersburgBlock: tt.fields.PetersburgBlock,
IstanbulBlock: tt.fields.IstanbulBlock,
MuirGlacierBlock: tt.fields.MuirGlacierBlock,
BerlinBlock: tt.fields.BerlinBlock,
YoloV3Block: tt.fields.YoloV3Block,
EWASMBlock: tt.fields.EWASMBlock,
CatalystBlock: tt.fields.CatalystBlock,
RamanujanBlock: tt.fields.RamanujanBlock,
NielsBlock: tt.fields.NielsBlock,
MirrorSyncBlock: tt.fields.MirrorSyncBlock,
BrunoBlock: tt.fields.BrunoBlock,
EulerBlock: tt.fields.EulerBlock,
Ethash: tt.fields.Ethash,
Clique: tt.fields.Clique,
Parlia: tt.fields.Parlia,
}
if err := c.VerifyForkConfig(); (err != nil) != tt.wantErr {
t.Errorf("ChainConfig.VerifyForkConfig() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit 1a27de6

Please sign in to comment.