Added IsEIP1559() hook

Modifications to genesis injection and datadir injections
This commit is contained in:
philip-morlier 2023-10-16 15:33:22 -07:00
parent cb62de132c
commit d9de580d74
3 changed files with 39 additions and 3 deletions

View File

@ -990,7 +990,7 @@ func init() {
// then a subdirectory of the specified datadir will be used. // then a subdirectory of the specified datadir will be used.
func MakeDataDir(ctx *cli.Context) string { func MakeDataDir(ctx *cli.Context) string {
// begin PluGeth injection // begin PluGeth injection
if path := ctx.String(DataDirFlag.Name); path != "" { if path := ctx.String(DataDirFlag.Name); path == "" {
if pluginPath := pluginDefaultDataDir(path); pluginPath != "" { if pluginPath := pluginDefaultDataDir(path); pluginPath != "" {
return pluginPath return pluginPath
} }
@ -1935,7 +1935,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
//begin plugeth injection //begin plugeth injection
if genesis := pluginGenesisBlock(); genesis != nil { if genesis := pluginGenesisBlock(); genesis != nil {
chaindb := MakeChainDatabase(ctx, stack, false)
cfg.Genesis = genesis cfg.Genesis = genesis
rawdb.WriteChainConfig(chaindb, genesis.ToBlock().Hash(), genesis.Config)
chaindb.Close()
} }
//end plugeth injection //end plugeth injection

View File

@ -34,7 +34,9 @@ import (
func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Header) error { func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Header) error {
// Verify that the gas limit remains within allowed bounds // Verify that the gas limit remains within allowed bounds
parentGasLimit := parent.GasLimit parentGasLimit := parent.GasLimit
if !config.IsLondon(parent.Number) { // begin PluGeth injection
if !config.Is1559(parent.Number) {
// end PluGeth injection
parentGasLimit = parent.GasLimit * config.ElasticityMultiplier() parentGasLimit = parent.GasLimit * config.ElasticityMultiplier()
} }
if err := misc.VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil { 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. // CalcBaseFee calculates the basefee of the header.
func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
// If the current block is the first EIP-1559 block, return the InitialBaseFee. // 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) return new(big.Int).SetUint64(params.InitialBaseFee)
} }

29
params/plugin_hooks.go Normal file
View File

@ -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
}