From d9de580d7445a1f2714c21919513443e761b4b11 Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Mon, 16 Oct 2023 15:33:22 -0700 Subject: [PATCH] Added IsEIP1559() hook Modifications to genesis injection and datadir injections --- cmd/utils/flags.go | 5 ++++- consensus/misc/eip1559/eip1559.go | 8 ++++++-- params/plugin_hooks.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 params/plugin_hooks.go diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 8e990844c..ee7e6794a 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -990,7 +990,7 @@ func init() { // then a subdirectory of the specified datadir will be used. func MakeDataDir(ctx *cli.Context) string { // begin PluGeth injection - if path := ctx.String(DataDirFlag.Name); path != "" { + if path := ctx.String(DataDirFlag.Name); path == "" { if pluginPath := pluginDefaultDataDir(path); pluginPath != "" { return pluginPath } @@ -1935,7 +1935,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { //begin plugeth injection if genesis := pluginGenesisBlock(); genesis != nil { + chaindb := MakeChainDatabase(ctx, stack, false) cfg.Genesis = genesis + rawdb.WriteChainConfig(chaindb, genesis.ToBlock().Hash(), genesis.Config) + chaindb.Close() } //end plugeth injection diff --git a/consensus/misc/eip1559/eip1559.go b/consensus/misc/eip1559/eip1559.go index 84b82c4c4..9b581fef4 100644 --- a/consensus/misc/eip1559/eip1559.go +++ b/consensus/misc/eip1559/eip1559.go @@ -34,7 +34,9 @@ import ( func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Header) error { // Verify that the gas limit remains within allowed bounds parentGasLimit := parent.GasLimit - if !config.IsLondon(parent.Number) { + // begin PluGeth injection + if !config.Is1559(parent.Number) { + // end PluGeth injection parentGasLimit = parent.GasLimit * config.ElasticityMultiplier() } if err := misc.VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil { @@ -56,7 +58,9 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade // CalcBaseFee calculates the basefee of the header. func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { // If the current block is the first EIP-1559 block, return the InitialBaseFee. - if !config.IsLondon(parent.Number) { + // begin PluGeth injection + if !config.Is1559(parent.Number) { + // end PluGeth injection return new(big.Int).SetUint64(params.InitialBaseFee) } diff --git a/params/plugin_hooks.go b/params/plugin_hooks.go new file mode 100644 index 000000000..b6b4705ab --- /dev/null +++ b/params/plugin_hooks.go @@ -0,0 +1,29 @@ +package params + +import ( + "math/big" + + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/plugins" +) + +// IsLondon returns whether num is either equal to the London fork block or greater. +func (c *ChainConfig) Is1559(num *big.Int) bool { + if plugins.DefaultPluginLoader == nil { + log.Warn("Attempting is1559, but default PluginLoader has not been initialized") + return c.IsLondon(num) + } + if active, ok := PluginIs1559(plugins.DefaultPluginLoader, num); ok { + return active + } + return c.IsLondon(num) +} + + +func PluginIs1559(pl *plugins.PluginLoader, num *big.Int) (bool, bool) { + fn, ok := plugins.LookupOne[func(*big.Int) bool](pl, "Is1559") + if !ok { + return false, false + } + return fn(num), ok +}