Skip to content

Commit

Permalink
all: rebase on uint64 timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Jan 25, 2023
1 parent 3481ebc commit b43da37
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func Transition(ctx *cli.Context) error {
return NewError(ErrorConfig, errors.New("EIP-1559 config but missing 'currentBaseFee' in env section"))
}
}
if chainConfig.IsShanghai(big.NewInt(int64(prestate.Env.Number))) && prestate.Env.Withdrawals == nil {
if chainConfig.IsShanghai(prestate.Env.Number) && prestate.Env.Withdrawals == nil {
return NewError(ErrorConfig, errors.New("Shanghai config but missing 'withdrawals' in env section"))
}
isMerged := chainConfig.TerminalTotalDifficulty != nil && chainConfig.TerminalTotalDifficulty.BitLen() == 0
Expand Down
4 changes: 2 additions & 2 deletions consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa
return err
}
// Verify existence / non-existence of withdrawalsHash.
shanghai := chain.Config().IsShanghai(new(big.Int).SetUint64(header.Time))
shanghai := chain.Config().IsShanghai(header.Time)
if shanghai && header.WithdrawalsHash == nil {
return fmt.Errorf("missing withdrawalsHash")
}
Expand Down Expand Up @@ -335,7 +335,7 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types.
return
}
// If withdrawals have been activated, process each one.
if chain.Config().IsShanghai(new(big.Int).SetUint64(header.Time)) {
if chain.Config().IsShanghai(header.Time) {
for _, w := range withdrawals {
// Amount is in gwei, turn into wei
amount := new(big.Int).Mul(new(big.Int).SetUint64(w.Amount), big.NewInt(params.GWei))
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
if header.GasLimit > params.MaxGasLimit {
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, params.MaxGasLimit)
}
if chain.Config().IsShanghai(new(big.Int).SetUint64(header.Time)) {
if chain.Config().IsShanghai(header.Time) {
return fmt.Errorf("clique does not support shanghai fork")
}
// If all checks passed, validate any special fields for hard forks
Expand Down
2 changes: 1 addition & 1 deletion consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa
if diff := new(big.Int).Sub(header.Number, parent.Number); diff.Cmp(big.NewInt(1)) != 0 {
return consensus.ErrInvalidNumber
}
if chain.Config().IsShanghai(new(big.Int).SetUint64(header.Time)) {
if chain.Config().IsShanghai(header.Time) {
return fmt.Errorf("ethash does not support shanghai fork")
}
// Verify the engine specific seal securing the block
Expand Down
2 changes: 1 addition & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
}
if b.engine != nil {
// Finalize and seal the block
shanghai := config.IsShanghai(new(big.Int).SetUint64(b.header.Time))
shanghai := config.IsShanghai(b.header.Time)
if shanghai && b.withdrawals == nil {
// need to make empty list to denote non-nil, but empty withdrawals to calc withdrawals hash
b.withdrawals = make([]*types.Withdrawal, 0)
Expand Down
2 changes: 1 addition & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ 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))) {
if g.Config != nil && g.Config.IsShanghai(g.Timestamp) {
head.WithdrawalsHash = &types.EmptyRootHash
}
return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil))
Expand Down
2 changes: 1 addition & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
allLogs = append(allLogs, receipt.Logs...)
}
// Fail if Shanghai not enabled and len(withdrawals) is non-zero.
if !p.config.IsShanghai(new(big.Int).SetUint64(block.Time())) && block.Withdrawals() != nil {
if !p.config.IsShanghai(block.Time()) && block.Withdrawals() != nil {
return nil, nil, 0, fmt.Errorf("non-nil withdrawal before shanghai")
}
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
Expand Down
3 changes: 2 additions & 1 deletion eth/catalyst/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,8 @@ func TestSimultaneousNewBlock(t *testing.T) {
func TestWithdrawals(t *testing.T) {
genesis, blocks := generateMergeChain(10, true)
// Set shanghai time to last block + 5 seconds (first post-merge block)
genesis.Config.ShanghaiTime = big.NewInt(int64(blocks[len(blocks)-1].Time()) + 5)
time := blocks[len(blocks)-1].Time() + 5
genesis.Config.ShanghaiTime = &time

n, ethservice := startEthService(t, genesis, blocks)
ethservice.Merger().ReachTTD()
Expand Down
4 changes: 3 additions & 1 deletion eth/protocols/eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ var (
testAddr = crypto.PubkeyToAddress(testKey.PublicKey)
)

func u64(val uint64) *uint64 { return &val }

// testBackend is a mock implementation of the live Ethereum message handler. Its
// purpose is to allow testing the request/reply workflows and wire serialization
// in the `eth` protocol without actually doing any data processing.
Expand Down Expand Up @@ -90,7 +92,7 @@ func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int,
ArrowGlacierBlock: big.NewInt(0),
GrayGlacierBlock: big.NewInt(0),
MergeNetsplitBlock: big.NewInt(0),
ShanghaiTime: big.NewInt(0),
ShanghaiTime: u64(0),
TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true,
Ethash: new(params.EthashConfig),
Expand Down

0 comments on commit b43da37

Please sign in to comment.