Skip to content
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

Shanghai upgrade for Ethereum nodes (genesis config) #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apis/ethereum/v1alpha1/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ type Genesis struct {
// MixHash is hash combined with nonce to prove effort spent to create block
MixHash Hash `json:"mixHash,omitempty"`

// ExtraData is arbitrary data to include in block
ExtraData string `json:"extraData,omitempty"`

// ParentHash is the hash value of the previous block
ParentHash Hash `json:"parentHash,omitempty"`

// Ethash PoW engine configuration
Ethash *Ethash `json:"ethash,omitempty"`

Expand Down Expand Up @@ -133,6 +139,15 @@ type Forks struct {

// ArrowGlacier fork
ArrowGlacier uint `json:"arrowGlacier,omitempty"`

// MergeFor fork
MergeFor uint `json:"mergeFor,omitempty"`

// TerminalTotalDifficulty fork
TerminalTotalDifficulty uint `json:"terminalTotalDifficulty,omitempty"`

// ShanghaiTime timestamp-based fork
ShanghaiTime uint `json:"shanghaiTime,omitempty"`
}

// Account is Ethereum account
Expand Down
35 changes: 20 additions & 15 deletions clients/ethereum/besu_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ func (b *BesuClient) Genesis() (content string, err error) {
node := b.node
genesis := node.Spec.Genesis
mixHash := genesis.MixHash
parentHash := genesis.ParentHash
nonce := genesis.Nonce
extraData := "0x00"
extraData := genesis.ExtraData
difficulty := genesis.Difficulty
result := map[string]interface{}{}

Expand Down Expand Up @@ -190,20 +191,23 @@ func (b *BesuClient) Genesis() (content string, err error) {
}

config := map[string]interface{}{
"chainId": genesis.ChainID,
"homesteadBlock": genesis.Forks.Homestead,
"eip150Block": genesis.Forks.EIP150,
"eip155Block": genesis.Forks.EIP155,
"eip158Block": genesis.Forks.EIP158,
"byzantiumBlock": genesis.Forks.Byzantium,
"constantinopleBlock": genesis.Forks.Constantinople,
"petersburgBlock": genesis.Forks.Petersburg,
"istanbulBlock": genesis.Forks.Istanbul,
"muirGlacierBlock": genesis.Forks.MuirGlacier,
"berlinBlock": genesis.Forks.Berlin,
"londonBlock": genesis.Forks.London,
"arrowGlacierBlock": genesis.Forks.ArrowGlacier,
engine: consensusConfig,
"chainId": genesis.ChainID,
"homesteadBlock": genesis.Forks.Homestead,
"eip150Block": genesis.Forks.EIP150,
"eip155Block": genesis.Forks.EIP155,
"eip158Block": genesis.Forks.EIP158,
"byzantiumBlock": genesis.Forks.Byzantium,
"constantinopleBlock": genesis.Forks.Constantinople,
"petersburgBlock": genesis.Forks.Petersburg,
"istanbulBlock": genesis.Forks.Istanbul,
"muirGlacierBlock": genesis.Forks.MuirGlacier,
"berlinBlock": genesis.Forks.Berlin,
"londonBlock": genesis.Forks.London,
"arrowGlacierBlock": genesis.Forks.ArrowGlacier,
"mergeForBlock": genesis.Forks.MergeFor,
"terminalTotalDifficulty": genesis.Forks.TerminalTotalDifficulty,
"shanghaiTime": genesis.Forks.ShanghaiTime,
engine: consensusConfig,
}

if genesis.Forks.DAO != nil {
Expand All @@ -223,6 +227,7 @@ func (b *BesuClient) Genesis() (content string, err error) {
result["gasLimit"] = genesis.GasLimit
result["difficulty"] = difficulty
result["coinbase"] = genesis.Coinbase
result["parentHash"] = parentHash
result["mixHash"] = mixHash
result["extraData"] = extraData

Expand Down
35 changes: 20 additions & 15 deletions clients/ethereum/geth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ func (g *GethClient) Genesis() (content string, err error) {
node := g.node
genesis := node.Spec.Genesis
mixHash := genesis.MixHash
parentHash := genesis.ParentHash
nonce := genesis.Nonce
extraData := "0x00"
extraData := genesis.ExtraData
difficulty := genesis.Difficulty
result := map[string]interface{}{}

Expand All @@ -208,20 +209,23 @@ func (g *GethClient) Genesis() (content string, err error) {
}

config := map[string]interface{}{
"chainId": genesis.ChainID,
"homesteadBlock": genesis.Forks.Homestead,
"eip150Block": genesis.Forks.EIP150,
"eip155Block": genesis.Forks.EIP155,
"eip158Block": genesis.Forks.EIP158,
"byzantiumBlock": genesis.Forks.Byzantium,
"constantinopleBlock": genesis.Forks.Constantinople,
"petersburgBlock": genesis.Forks.Petersburg,
"istanbulBlock": genesis.Forks.Istanbul,
"muirGlacierBlock": genesis.Forks.MuirGlacier,
"berlinBlock": genesis.Forks.Berlin,
"londonBlock": genesis.Forks.London,
"arrowGlacierBlock": genesis.Forks.ArrowGlacier,
engine: consensusConfig,
"chainId": genesis.ChainID,
"homesteadBlock": genesis.Forks.Homestead,
"eip150Block": genesis.Forks.EIP150,
"eip155Block": genesis.Forks.EIP155,
"eip158Block": genesis.Forks.EIP158,
"byzantiumBlock": genesis.Forks.Byzantium,
"constantinopleBlock": genesis.Forks.Constantinople,
"petersburgBlock": genesis.Forks.Petersburg,
"istanbulBlock": genesis.Forks.Istanbul,
"muirGlacierBlock": genesis.Forks.MuirGlacier,
"berlinBlock": genesis.Forks.Berlin,
"londonBlock": genesis.Forks.London,
"arrowGlacierBlock": genesis.Forks.ArrowGlacier,
"mergeForBlock": genesis.Forks.MergeFor,
"terminalTotalDifficulty": genesis.Forks.TerminalTotalDifficulty,
"shanghaiTime": genesis.Forks.ShanghaiTime,
engine: consensusConfig,
}

if genesis.Forks.DAO != nil {
Expand All @@ -237,6 +241,7 @@ func (g *GethClient) Genesis() (content string, err error) {
result["difficulty"] = difficulty
result["coinbase"] = genesis.Coinbase
result["mixHash"] = mixHash
result["parentHash"] = parentHash
result["extraData"] = extraData

alloc := genesisAccounts(false, genesis.Forks)
Expand Down
13 changes: 11 additions & 2 deletions clients/ethereum/parity_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (p *ParityGenesis) NormalizeNonce(data string) string {
// Genesis returns genesis config parameter
func (p *ParityGenesis) Genesis(node *ethereumv1alpha1.Node) (content string, err error) {
genesis := node.Spec.Genesis
extraData := "0x00"
extraData := genesis.ExtraData
var engineConfig map[string]interface{}

// clique PoA settings
Expand Down Expand Up @@ -51,6 +51,9 @@ func (p *ParityGenesis) Genesis(node *ethereumv1alpha1.Node) (content string, er
berlinBlock := hex(genesis.Forks.Berlin)
londonBlock := hex(genesis.Forks.London)
arrowGlacierBlock := hex(genesis.Forks.ArrowGlacier)
mergeForBlock := hex(genesis.Forks.MergeFor)
terminalTotalDifficulty := hex(genesis.Forks.TerminalTotalDifficulty)
shanghaiTime := hex(genesis.Forks.ShanghaiTime)

// ethash PoW settings
if genesis.Ethash != nil {
Expand Down Expand Up @@ -92,7 +95,7 @@ func (p *ParityGenesis) Genesis(node *ethereumv1alpha1.Node) (content string, er
"mixHash": genesis.MixHash,
},
},
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": genesis.ParentHash,
"timestamp": genesis.Timestamp,
"gasLimit": genesis.GasLimit,
"difficulty": genesis.Difficulty,
Expand Down Expand Up @@ -153,6 +156,12 @@ func (p *ParityGenesis) Genesis(node *ethereumv1alpha1.Node) (content string, er
"eip1559BaseFeeMaxChangeDenominator": "0x8",
"eip1559ElasticityMultiplier": "0x2",
"eip1559BaseFeeInitialValue": "0x3B9ACA00",
"mergeForkIdTransition": mergeForBlock,
"eip3651TransitionTimestamp": shanghaiTime,
"eip3855TransitionTimestamp": shanghaiTime,
"eip3860TransitionTimestamp": shanghaiTime,
"eip4895TransitionTimestamp": shanghaiTime,
"terminalTotalDifficulty": terminalTotalDifficulty,
}

alloc := genesisAccounts(true, genesis.Forks)
Expand Down
16 changes: 16 additions & 0 deletions config/crd/bases/ethereum.kotal.io_nodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ spec:
in private PoW networks
type: integer
type: object
extraData:
description: ExtraData is arbitrary data to include in block
type: string
forks:
description: Forks is supported forks (network upgrade) and corresponding
block number
Expand Down Expand Up @@ -191,12 +194,21 @@ spec:
london:
description: London fork
type: integer
mergeFor:
description: MergeFor fork
type: integer
muirglacier:
description: MuirGlacier fork
type: integer
petersburg:
description: Petersburg fork
type: integer
shanghaiTime:
description: ShanghaiTime timestamp-based fork
type: integer
terminalTotalDifficulty:
description: TerminalTotalDifficulty fork
type: integer
type: object
gasLimit:
description: GastLimit is the total gas limit for all transactions
Expand Down Expand Up @@ -252,6 +264,10 @@ spec:
description: Nonce is random number used in block computation
pattern: ^0[xX][0-9a-fA-F]+$
type: string
parentHash:
description: ParentHash is the hash value of the previous block
pattern: ^0[xX][0-9a-fA-F]{64}$
type: string
timestamp:
description: Timestamp is block creation date
pattern: ^0[xX][0-9a-fA-F]+$
Expand Down