Initial commit of ETC plugin work

This commit is contained in:
philip-morlier 2023-09-26 07:26:19 -07:00
parent 3993f2f870
commit 399cbbc8fd
4 changed files with 149 additions and 3 deletions

View File

@ -95,6 +95,12 @@ var (
Value: flags.DirectoryString(filepath.Join("<datadir>", "plugins")),
Category: flags.EthCategory,
}
// ClassicFlag = &cli.BoolFlag{
// Name: "Classic",
// Usage: "Sepolia network: pre-configured proof-of-work test network",
// Category: flags.EthCategory,
// }
//end PluGeth code injection
DataDirFlag = &flags.DirectoryFlag{
Name: "datadir",
@ -965,7 +971,12 @@ func init() {
// if none (or the empty string) is specified. If the node is starting a testnet,
// 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 pluginPath := pluginDefaultDataDir(path); pluginPath != "" {
return pluginPath
}
// end PluGeth injection
if ctx.Bool(RinkebyFlag.Name) {
return filepath.Join(path, "rinkeby")
}
@ -1018,6 +1029,11 @@ func setNodeUserIdent(ctx *cli.Context, cfg *node.Config) {
// flags, reverting to pre-configured ones if none have been specified.
func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls := params.MainnetBootnodes
// begin PluGeth injection
if pluginUrls := pluginSetBootstrapNodes(); pluginUrls != nil {
urls = pluginUrls
}
// end PluGeth injection
switch {
case ctx.IsSet(BootnodesFlag.Name):
urls = SplitAndTrim(ctx.String(BootnodesFlag.Name))
@ -1651,6 +1667,18 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
setRequiredBlocks(ctx, cfg)
setLes(ctx, cfg)
// beginPluGethInjection
if pluginNetworkId := pluginNetworkId(); pluginNetworkId != nil {
cfg.NetworkId = *pluginNetworkId
}
if pluginETHDiscoveryURLs := pluginETHDiscoveryURLs(); pluginETHDiscoveryURLs != nil {
cfg.EthDiscoveryURLs = pluginETHDiscoveryURLs
}
if pluginSnapDiscoveryURLs := pluginSnapDiscoveryURLs(); pluginSnapDiscoveryURLs != nil {
cfg.SnapDiscoveryURLs = pluginSnapDiscoveryURLs
}
//end PluGeth injection
// Cap the cache allowance and tune the garbage collector
mem, err := gopsutil.VirtualMemory()
if err == nil {

118
cmd/utils/plugin_hooks.go Normal file
View File

@ -0,0 +1,118 @@
package utils
import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/plugins"
)
func DefaultDataDir(pl *plugins.PluginLoader, path string) string {
log.Error("inside default data dir hook")
dataDirPath := ""
fnList := pl.Lookup("DefaultDataDir", func(item interface{}) bool {
_, ok := item.(func(string) string)
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func(string) string); ok {
dataDirPath = fn(path)
}
}
return dataDirPath
}
func pluginDefaultDataDir(path string) string {
log.Error("inside default data dir injection")
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting DefaultDataDir, but default PluginLoader has not been initialized")
return ""
}
return DefaultDataDir(plugins.DefaultPluginLoader, path)
}
func PluginSetBootStrapNodes(pl *plugins.PluginLoader) []string {
var urls []string
fnList := pl.Lookup("SetBootstrapNodes", func(item interface{}) bool {
_, ok := item.(func() []string)
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func() []string); ok {
urls = fn()
}
}
return urls
}
func pluginSetBootstrapNodes() []string {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting pluginSetBootStrapNodes, but default PluginLoader has not been initialized")
return nil
}
return PluginSetBootStrapNodes(plugins.DefaultPluginLoader)
}
func PluginNetworkId(pl *plugins.PluginLoader) *uint64 {
var networkId *uint64
fnList := pl.Lookup("SetNetworkId", func(item interface{}) bool {
_, ok := item.(func() *uint64)
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func() *uint64); ok {
networkId = fn()
}
}
return networkId
}
func pluginNetworkId() *uint64 {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting pluginNetworkID, but default PluginLoader has not been initialized")
return nil
}
return PluginNetworkId(plugins.DefaultPluginLoader)
}
func PluginETHDiscoveryURLs(pl *plugins.PluginLoader) []string {
var ethDiscoveryURLs []string
fnList := pl.Lookup("SetETHDiscoveryURLs", func(item interface{}) bool {
_, ok := item.(func() []string)
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func() []string); ok {
ethDiscoveryURLs = fn()
}
}
return ethDiscoveryURLs
}
func pluginETHDiscoveryURLs() []string {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting pluginETHDiscoveryURLs, but default PluginLoader has not been initialized")
return nil
}
return PluginETHDiscoveryURLs(plugins.DefaultPluginLoader)
}
func PluginSnapDiscoveryURLs(pl *plugins.PluginLoader) []string {
var snapDiscoveryURLs []string
fnList := pl.Lookup("SetSnapDiscoveryURLs", func(item interface{}) bool {
_, ok := item.(func() []string)
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func() []string); ok {
snapDiscoveryURLs = fn()
}
}
return snapDiscoveryURLs
}
func pluginSnapDiscoveryURLs() []string {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting PluginSnapDiscoveryURLs, but default PluginLoader has not been initialized")
return nil
}
return PluginSnapDiscoveryURLs(plugins.DefaultPluginLoader)
}

2
go.mod
View File

@ -38,7 +38,7 @@ require (
github.com/graph-gophers/graphql-go v1.3.0
github.com/hashicorp/go-bexpr v0.1.10
github.com/holiman/bloomfilter/v2 v2.0.3
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c
github.com/holiman/uint256 v1.2.3
github.com/huin/goupnp v1.0.3
github.com/influxdata/influxdb-client-go/v2 v2.4.0
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c

4
go.sum
View File

@ -230,8 +230,8 @@ github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c h1:DZfsyhDK1hnSS5lH8l+JggqzEleHteTYfutAiVlSUM8=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o=
github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ=
github.com/huin/goupnp v1.0.3/go.mod h1:ZxNlw5WqJj6wSsRK5+YfflQGXYfccj5VgQsMNixHM7Y=