Config plugin hooks and injections with test coverage.

All config hooks have been written with the exception of writing the genesis.
This commit is contained in:
philip-morlier 2023-09-28 21:19:54 -07:00
parent 31ada7d3e3
commit 38ea6101de
5 changed files with 62 additions and 15 deletions

View File

@ -1510,7 +1510,12 @@ func setSmartCard(ctx *cli.Context, cfg *node.Config) {
}
func SetDataDir(ctx *cli.Context, cfg *node.Config) {
// begin PluGeth injection
pluginPath := pluginDefaultDataDir(node.DefaultDataDir())
switch {
case pluginPath != "" && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = pluginPath
// end PluGeth injection
case ctx.IsSet(DataDirFlag.Name):
cfg.DataDir = ctx.String(DataDirFlag.Name)
case ctx.Bool(DeveloperFlag.Name):
@ -1693,13 +1698,14 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if pluginNetworkId := pluginNetworkId(); pluginNetworkId != nil {
cfg.NetworkId = *pluginNetworkId
}
if cfg.EthDiscoveryURLs == nil {
var lightMode bool
if cfg.SyncMode == downloader.LightSync {
lightMode = true
}
cfg.EthDiscoveryURLs := pluginETHDiscoveryURLs(lightMode) {
cfg.SnapDiscoveryURLs := pluginSnapDiscoveryURLs()
cfg.EthDiscoveryURLs = pluginETHDiscoveryURLs(lightMode)
cfg.SnapDiscoveryURLs = pluginSnapDiscoveryURLs()
}
//end PluGeth injection

View File

@ -6,9 +6,8 @@ import (
)
func DefaultDataDir(pl *plugins.PluginLoader, path string) string {
log.Error("inside default data dir hook")
dataDirPath := ""
fnList := pl.Lookup("DefaultDataDir", func(item interface{}) bool {
fnList := pl.Lookup("SetDefaultDataDir", func(item interface{}) bool {
_, ok := item.(func(string) string)
return ok
})
@ -21,7 +20,6 @@ func DefaultDataDir(pl *plugins.PluginLoader, path string) string {
}
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 ""
@ -73,26 +71,26 @@ func pluginNetworkId() *uint64 {
return PluginNetworkId(plugins.DefaultPluginLoader)
}
func PluginETHDiscoveryURLs(pl *plugins.PluginLoader) []string {
func PluginETHDiscoveryURLs(pl *plugins.PluginLoader, mode bool) []string {
var ethDiscoveryURLs []string
fnList := pl.Lookup("SetETHDiscoveryURLs", func(item interface{}) bool {
_, ok := item.(func() []string)
_, ok := item.(func(bool) []string)
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func() []string); ok {
ethDiscoveryURLs = fn()
if fn, ok := fni.(func(bool) []string); ok {
ethDiscoveryURLs = fn(mode)
}
}
return ethDiscoveryURLs
}
func pluginETHDiscoveryURLs() []string {
func pluginETHDiscoveryURLs(mode bool) []string {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting pluginETHDiscoveryURLs, but default PluginLoader has not been initialized")
return nil
}
return PluginETHDiscoveryURLs(plugins.DefaultPluginLoader)
return PluginETHDiscoveryURLs(plugins.DefaultPluginLoader, mode)
}
func PluginSnapDiscoveryURLs(pl *plugins.PluginLoader) []string {

View File

@ -43,11 +43,44 @@ func GetAPIs(stack core.Node, backend core.Backend) []core.API {
// cmd/utils/
func SetSnapDiscoveryURLs() {
func SetDefaultDataDir(arg string) string {
m := map[string]struct{}{
"SetDefaultDataDir":struct{}{},
}
hookChan <- m
return "test"
}
func SetBootstrapNodes() []string {
m := map[string]struct{}{
"SetBootstrapNodes":struct{}{},
}
hookChan <- m
return nil
}
func SetNetworkId() *uint64 {
m := map[string]struct{}{
"SetNetworkId":struct{}{},
}
hookChan <- m
return nil
}
func SetETHDiscoveryURLs(arg bool) []string {
m := map[string]struct{}{
"SetETHDiscoveryURLs":struct{}{},
}
hookChan <- m
return nil
}
func SetSnapDiscoveryURLs() []string {
m := map[string]struct{}{
"SetSnapDiscoveryURLs":struct{}{},
}
hookChan <- m
return nil
}
// core/
@ -192,6 +225,10 @@ var plugins map[string]struct{} = map[string]struct{}{
// "LiveCaptureEnter": struct{}{},
// "LiveCaptureExit": struct{}{},
// "LiveTracerResult": struct{}{},
"SetDefaultDataDir":struct{}{},
"SetBootstrapNodes":struct{}{},
"SetNetworkId":struct{}{},
"SetETHDiscoveryURLs": struct{}{},
"SetSnapDiscoveryURLs": struct{}{},
}

View File

@ -116,8 +116,16 @@ func BlockChain() {
// delete(plugins, "LiveCaptureExit")
// case f("LiveTracerResult"):
// delete(plugins, "LiveTracerResult")
case f("SetDefaultDataDir"):
delete(plugins, "SetDefaultDataDir")
case f("SetBootstrapNodes"):
delete(plugins, "SetBootstrapNodes")
case f("SetNetworkId"):
delete(plugins, "SetNetworkId")
case f("SetETHDiscoveryURLs"):
delete(plugins, "SetETHDiscoveryURLs")
case f("SetSnapDiscoveryURLs"):
delete(plugins, "SetSnapDiscoveryURLs")
delete(plugins, "SetSnapDiscoveryURLs")
}
}
}

View File

@ -1,8 +1,6 @@
[Eth]
NetworkId = 6448
SyncMode = "snap"
EthDiscoveryURLs = []
SnapDiscoveryURLs = []
NoPruning = false
NoPrefetch = false
TxLookupLimit = 2350000