Merge pull request #111 from openrelayxyz/feature/network-etc-miner

Feature/network etc miner
This commit is contained in:
Austin Roberts 2024-03-04 13:42:48 -06:00 committed by GitHub
commit ba3343ad12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 58 additions and 14 deletions

View File

@ -1440,7 +1440,6 @@ func SetDataDir(ctx *cli.Context, cfg *node.Config) {
pluginPath := pluginDefaultDataDir(node.DefaultDataDir()) pluginPath := pluginDefaultDataDir(node.DefaultDataDir())
switch { switch {
case pluginPath != "" && ctx.String(DataDirFlag.Name) == node.DefaultDataDir(): case pluginPath != "" && ctx.String(DataDirFlag.Name) == node.DefaultDataDir():
log.Error("Inside datdir injection number two")
cfg.DataDir = pluginPath cfg.DataDir = pluginPath
// end PluGeth injection // end PluGeth injection
case ctx.IsSet(DataDirFlag.Name): case ctx.IsSet(DataDirFlag.Name):

View File

@ -60,6 +60,11 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
table = &cancunInstructionSet table = &cancunInstructionSet
case evm.chainRules.IsShanghai: case evm.chainRules.IsShanghai:
table = &shanghaiInstructionSet table = &shanghaiInstructionSet
// begin PluGeth injection
if !evm.chainRules.IsMerge {
table[RANDOM] = frontierInstructionSet[DIFFICULTY]
}
// end PluGeth injection
case evm.chainRules.IsMerge: case evm.chainRules.IsMerge:
table = &mergeInstructionSet table = &mergeInstructionSet
case evm.chainRules.IsLondon: case evm.chainRules.IsLondon:
@ -72,10 +77,12 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
table = &constantinopleInstructionSet table = &constantinopleInstructionSet
case evm.chainRules.IsByzantium: case evm.chainRules.IsByzantium:
table = &byzantiumInstructionSet table = &byzantiumInstructionSet
// begin PluGeth injection // begin PluGeth injection
case evm.chainRules.IsEIP160: case evm.chainRules.IsEIP160:
// end PluGeth injection
table = &spuriousDragonInstructionSet table = &spuriousDragonInstructionSet
// end PluGeth injection
case evm.chainRules.IsEIP150: case evm.chainRules.IsEIP150:
table = &tangerineWhistleInstructionSet table = &tangerineWhistleInstructionSet
case evm.chainRules.IsHomestead: case evm.chainRules.IsHomestead:

View File

@ -977,9 +977,12 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
header.MixDigest = genParams.random header.MixDigest = genParams.random
} }
// Set baseFee and GasLimit if we are on an EIP-1559 chain // Set baseFee and GasLimit if we are on an EIP-1559 chain
if w.chainConfig.IsLondon(header.Number) {
// begin PluGeth injection
if w.chainConfig.Is1559(header.Number) {
header.BaseFee = eip1559.CalcBaseFee(w.chainConfig, parent) header.BaseFee = eip1559.CalcBaseFee(w.chainConfig, parent)
if !w.chainConfig.IsLondon(parent.Number) { if !w.chainConfig.Is1559(parent.Number) {
// end PluGeth injection
parentGasLimit := parent.GasLimit * w.chainConfig.ElasticityMultiplier() parentGasLimit := parent.GasLimit * w.chainConfig.ElasticityMultiplier()
header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil) header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil)
} }

View File

@ -558,10 +558,14 @@ func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *bi
return parentTotalDiff.Cmp(c.TerminalTotalDifficulty) < 0 && totalDiff.Cmp(c.TerminalTotalDifficulty) >= 0 return parentTotalDiff.Cmp(c.TerminalTotalDifficulty) < 0 && totalDiff.Cmp(c.TerminalTotalDifficulty) >= 0
} }
// begin Plugeth injection -- the following code is being commented to enable network plugins to initiate the shanghai fork
// IsShanghai returns whether time is either equal to the Shanghai fork time or greater. // IsShanghai returns whether time is either equal to the Shanghai fork time or greater.
func (c *ChainConfig) IsShanghai(num *big.Int, time uint64) bool { // func (c *ChainConfig) IsShanghai(num *big.Int, time uint64) bool {
return c.IsLondon(num) && isTimestampForked(c.ShanghaiTime, time) // return c.IsLondon(num) && isTimestampForked(c.ShanghaiTime, time)
} // }
// end PluGeth injection
// IsCancun returns whether num is either equal to the Cancun fork time or greater. // IsCancun returns whether num is either equal to the Cancun fork time or greater.
func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool { func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool {
@ -929,7 +933,11 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
IsBerlin: c.IsBerlin(num), IsBerlin: c.IsBerlin(num),
IsLondon: c.IsLondon(num), IsLondon: c.IsLondon(num),
IsMerge: isMerge, IsMerge: isMerge,
IsShanghai: isMerge && c.IsShanghai(num, timestamp), // IsShanghai: isMerge && c.IsShanghai(num, timestamp),
// the above is being commented and replaced with the plugeth code below to hotwire the chainrules to allow shanghai without the merge
// begin PluGeth injection
IsShanghai: c.IsShanghai(num, timestamp),
// end PluGeth injection
IsCancun: isMerge && c.IsCancun(num, timestamp), IsCancun: isMerge && c.IsCancun(num, timestamp),
IsPrague: isMerge && c.IsPrague(num, timestamp), IsPrague: isMerge && c.IsPrague(num, timestamp),
IsVerkle: isMerge && c.IsVerkle(num, timestamp), IsVerkle: isMerge && c.IsVerkle(num, timestamp),

View File

@ -39,3 +39,16 @@ func (c *ChainConfig) IsEIP160(num *big.Int) bool {
} }
return c.IsEIP158(num) return c.IsEIP158(num)
} }
// IsShanghai is modified here to return whether num is either equal to the Shanghai fork block or greater, if the chain supports Shanghai
// the foundation implementation has been commented out
func (c *ChainConfig) IsShanghai(num *big.Int, time uint64) bool {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting isPluginShanghai, but default PluginLoader has not been initialized")
return c.IsLondon(num) && isTimestampForked(c.ShanghaiTime, time)
}
if active, ok := PluginEIPCheck(plugins.DefaultPluginLoader, "IsShanghai", num); ok {
return active
}
return c.IsLondon(num) && isTimestampForked(c.ShanghaiTime, time)
}

View File

@ -243,7 +243,8 @@ func RPCSubscriptionTest() {
// params/ // params/
func Is1559(*big.Int) bool { // while this hook resides in params the injections are in consensus/misc/ (2), and core/ (2) // Is1559 is written in params/ the injections are in: consensus/misc/ (2), and core/ (2) and miner/ (1)
func Is1559(*big.Int) bool {
m := map[string]struct{}{ m := map[string]struct{}{
"Is1559":struct{}{}, "Is1559":struct{}{},
} }
@ -251,9 +252,19 @@ func Is1559(*big.Int) bool { // while this hook resides in params the injections
return true return true
} }
// the following two hooks are both testing the PluginEIPCheck() hook
func Is160(num *big.Int) bool { func Is160(num *big.Int) bool {
m := map[string]struct{}{ m := map[string]struct{}{
"PluginEIPCheck":struct{}{}, "Is160":struct{}{},
}
hookChan <- m
return true
}
func IsShanghai(num *big.Int) bool {
m := map[string]struct{}{
"IsShanghai":struct{}{},
} }
hookChan <- m hookChan <- m
return true return true
@ -300,6 +311,7 @@ var plugins map[string]struct{} = map[string]struct{}{
"ForkIDs": struct{}{}, "ForkIDs": struct{}{},
"OpCodeSelect":struct{}{}, "OpCodeSelect":struct{}{},
"Is1559":struct{}{}, "Is1559":struct{}{},
"PluginEIPCheck":struct{}{}, "Is160":struct{}{},
"IsShanghai":struct{}{},
} }

View File

@ -12,7 +12,7 @@ import (
"github.com/openrelayxyz/plugeth-utils/restricted/crypto" "github.com/openrelayxyz/plugeth-utils/restricted/crypto"
) )
var hookChan chan map[string]struct{} = make(chan map[string]struct{}, 10) var hookChan chan map[string]struct{} = make(chan map[string]struct{}, 20)
var quit chan string = make(chan string) var quit chan string = make(chan string)
func (service *engineService) CaptureShutdown(ctx context.Context) { func (service *engineService) CaptureShutdown(ctx context.Context) {
@ -136,8 +136,10 @@ func BlockChain() {
delete(plugins, "OpCodeSelect") delete(plugins, "OpCodeSelect")
case f("Is1559"): case f("Is1559"):
delete(plugins, "Is1559") delete(plugins, "Is1559")
case f("PluginEIPCheck"): case f("Is160"):
delete(plugins, "PluginEIPCheck") delete(plugins, "Is160")
case f("IsShanghai"):
delete(plugins, "IsShanghai")
} }
} }
} }