Skip to content

Commit

Permalink
params: additional ChainConfig hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Sep 11, 2024
1 parent 36b6e91 commit 29f6067
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 3 additions & 3 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (c *ChainConfig) Description() string {
if c.VerkleTime != nil {
banner += fmt.Sprintf(" - Verkle: @%-10v\n", *c.VerkleTime)
}
return banner
return banner + c.Hooks().Description()
}

// IsHomestead returns whether num is either equal to the homestead block or greater.
Expand Down Expand Up @@ -671,7 +671,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
lastFork = cur
}
}
return nil
return c.Hooks().CheckConfigForkOrder()
}

func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int, headTimestamp uint64) *ConfigCompatError {
Expand Down Expand Up @@ -742,7 +742,7 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
if isForkTimestampIncompatible(c.VerkleTime, newcfg.VerkleTime, headTimestamp) {
return newTimestampCompatError("Verkle fork timestamp", c.VerkleTime, newcfg.VerkleTime)
}
return nil
return c.Hooks().CheckCompatible(newcfg, headNumber, headTimestamp)
}

// BaseFeeChangeDenominator bounds the amount the base fee can change between blocks.
Expand Down
20 changes: 19 additions & 1 deletion params/hooks.libevm.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package params

import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/libevm"
)

// ChainConfigHooks are required for all types registered as [Extras] for
// [ChainConfig] payloads.
type ChainConfigHooks interface{}
type ChainConfigHooks interface {
CheckCompatible(newcfg *ChainConfig, headNumber *big.Int, headTimestamp uint64) *ConfigCompatError
CheckConfigForkOrder() error
Description() string
}

// TODO(arr4n): given the choice of whether a hook should be defined on a
// ChainConfig or on the Rules, what are the guiding principles? A ChainConfig
Expand Down Expand Up @@ -66,6 +72,18 @@ var _ interface {
RulesHooks
} = NOOPHooks{}

func (NOOPHooks) CheckCompatible(_ *ChainConfig, _ *big.Int, _ uint64) *ConfigCompatError {
return nil
}

func (NOOPHooks) CheckConfigForkOrder() error {
return nil
}

func (NOOPHooks) Description() string {
return ""
}

// CanExecuteTransaction allows all (otherwise valid) transactions.
func (NOOPHooks) CanExecuteTransaction(_ common.Address, _ *common.Address, _ libevm.StateReader) error {
return nil
Expand Down

0 comments on commit 29f6067

Please sign in to comment.