Skip to content

Commit 9795aca

Browse files
committed
Handle base fee calculation for transition block
1 parent bc6fe0f commit 9795aca

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

consensus/misc/eip1559/eip1559.go

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
5858
// CalcBaseFee calculates the basefee of the header.
5959
// The time belongs to the new block to check if Canyon is activted or not
6060
func CalcBaseFee(config *params.ChainConfig, parent *types.Header, time uint64) *big.Int {
61+
// If this is the cel2 transition block then we use the initial base fee
62+
// from the Cel2Config of the chain config.
63+
if config.Cel2Time != nil && *config.Cel2Time == time {
64+
return new(big.Int).SetUint64(config.Cel2Config.TransitionBlockBaseFee)
65+
}
66+
6167
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
6268
if !config.IsLondon(parent.Number) {
6369
return new(big.Int).SetUint64(params.InitialBaseFee)

params/celo_config.go

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

params/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ type ChainConfig struct {
434434

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

437+
Cel2Config *Cel2Config `json:"cel2Config,omitempty"` // Cel2 config
438+
437439
// TerminalTotalDifficulty is the amount of total difficulty reached by
438440
// the network that triggers the consensus upgrade.
439441
TerminalTotalDifficulty *big.Int `json:"terminalTotalDifficulty,omitempty"`

0 commit comments

Comments
 (0)