Skip to content

Commit

Permalink
Merge pull request ethereum#11 from MariusVanDerWijden/withdrawals-ti…
Browse files Browse the repository at this point in the history
…mestamp-fix

core: set withdrawals hash in genesis, fix tests, add withdrawalRoot
  • Loading branch information
lightclient authored Nov 8, 2022
2 parents 23a4378 + 3a18a47 commit 102fb32
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ func (g *Genesis) ToBlock() *types.Block {
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
}
}
if g.Config != nil && g.Config.IsShanghai(big.NewInt(int64(g.Timestamp))) {
head.WithdrawalsHash = &types.EmptyRootHash
}
return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil))
}

Expand Down
2 changes: 1 addition & 1 deletion eth/catalyst/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ func TestSimultaneousNewBlock(t *testing.T) {
// includes zero withdrawals and the second includes two.
func TestWithdrawals(t *testing.T) {
genesis, blocks := generateMergeChain(10, true)
genesis.Config.ShanghaiBlock = big.NewInt(11)
genesis.Config.ShanghaiTime = big.NewInt(11)
genesis.Config.TerminalTotalDifficulty.Sub(genesis.Config.TerminalTotalDifficulty, blocks[0].Difficulty())

n, ethservice := startEthService(t, genesis, blocks)
Expand Down
2 changes: 1 addition & 1 deletion eth/fetcher/block_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func init() {
ArrowGlacierBlock: big.NewInt(0),
GrayGlacierBlock: big.NewInt(0),
MergeNetsplitBlock: big.NewInt(0),
ShanghaiBlock: big.NewInt(0),
ShanghaiTime: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true,
Ethash: new(params.EthashConfig),
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int,
ArrowGlacierBlock: big.NewInt(0),
GrayGlacierBlock: big.NewInt(0),
MergeNetsplitBlock: big.NewInt(0),
ShanghaiBlock: big.NewInt(0),
ShanghaiTime: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true,
Ethash: new(params.EthashConfig),
Expand Down
4 changes: 4 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,10 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} {
result["baseFeePerGas"] = (*hexutil.Big)(head.BaseFee)
}

if head.WithdrawalsHash != nil {
result["withdrawalsRoot"] = head.WithdrawalsHash
}

return result
}

Expand Down
2 changes: 1 addition & 1 deletion tests/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ var Forks = map[string]*params.ChainConfig{
ArrowGlacierBlock: big.NewInt(0),
MergeNetsplitBlock: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
ShanghaiBlock: big.NewInt(0),
ShanghaiTime: big.NewInt(0),
},
}

Expand Down

0 comments on commit 102fb32

Please sign in to comment.