From 29f60675ca351bf4c2659cca85c4a126ebef3917 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Wed, 11 Sep 2024 14:10:27 -0700 Subject: [PATCH] params: additional ChainConfig hooks --- params/config.go | 6 +++--- params/hooks.libevm.go | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/params/config.go b/params/config.go index 2e5850c440dc..56d179ba827a 100644 --- a/params/config.go +++ b/params/config.go @@ -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. @@ -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 { @@ -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. diff --git a/params/hooks.libevm.go b/params/hooks.libevm.go index c44cd3f1f055..2b0b74fe86d0 100644 --- a/params/hooks.libevm.go +++ b/params/hooks.libevm.go @@ -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 @@ -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