Skip to content

Commit

Permalink
Handle base fee calculation for transition block
Browse files Browse the repository at this point in the history
  • Loading branch information
piersy committed Jun 21, 2024
1 parent 2fd4979 commit 5ae796d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions consensus/misc/eip1559/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
// CalcBaseFee calculates the basefee of the header.
// The time belongs to the new block to check if Canyon is activted or not
func CalcBaseFee(config *params.ChainConfig, parent *types.Header, time uint64) *big.Int {

// If this is the cel2 transition block then we use the inital base fee

Check failure on line 62 in consensus/misc/eip1559/eip1559.go

View workflow job for this annotation

GitHub Actions / Lint

`inital` is a misspelling of `initial` (misspell)
// from the Cel2Config of the chain config.
if config.Cel2Time != nil && *config.Cel2Time == time {
return new(big.Int).SetUint64(config.Cel2Config.TransitionBlockBaseFee)
}

// If the current block is the first EIP-1559 block, return the InitialBaseFee.
if !config.IsLondon(parent.Number) {
return new(big.Int).SetUint64(params.InitialBaseFee)
Expand Down
19 changes: 19 additions & 0 deletions params/celo_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package params

// Cel2Config holds config required when running a cel2 chain.
type Cel2Config struct {
// TransitionBlockBaseFee is the base fee for the transition block in a
// migrated chain. it must be set for migrated chains during the migration
// to the value in the transition block. For non migrated chains it does
// not need to be set.This is required because we need
// eip1559.CalcBaseFee(config *params.ChainConfig, parent *types.Header,
// time uint64) to be able to return the correct base fee for the
// transition block and CalcBaseFee does not have access to the current
// header so cannot know what the base fee should be. We can't just use the
// base fee of the parent either because if we are transitioning at a
// pre-gingerbread block then it won't have a base fee, so this seems like
// the least invasive approach. Alternatively we could change the signature
// of CalcBaseFee to include the current header but that would require
// changing code in a number of places.
TransitionBlockBaseFee uint64
}
2 changes: 2 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ type ChainConfig struct {

Cel2Time *uint64 `json:"cel2Time,omitempty"` // Cel2 switch time (nil = no fork, 0 = already on optimism cel2)

Cel2Config *Cel2Config `json:"cel2Config,omitempty"` // Cel2 config

// TerminalTotalDifficulty is the amount of total difficulty reached by
// the network that triggers the consensus upgrade.
TerminalTotalDifficulty *big.Int `json:"terminalTotalDifficulty,omitempty"`
Expand Down

0 comments on commit 5ae796d

Please sign in to comment.