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:
parent
31ada7d3e3
commit
38ea6101de
@ -1510,7 +1510,12 @@ func setSmartCard(ctx *cli.Context, cfg *node.Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetDataDir(ctx *cli.Context, cfg *node.Config) {
|
func SetDataDir(ctx *cli.Context, cfg *node.Config) {
|
||||||
|
// begin PluGeth injection
|
||||||
|
pluginPath := pluginDefaultDataDir(node.DefaultDataDir())
|
||||||
switch {
|
switch {
|
||||||
|
case pluginPath != "" && cfg.DataDir == node.DefaultDataDir():
|
||||||
|
cfg.DataDir = pluginPath
|
||||||
|
// end PluGeth injection
|
||||||
case ctx.IsSet(DataDirFlag.Name):
|
case ctx.IsSet(DataDirFlag.Name):
|
||||||
cfg.DataDir = ctx.String(DataDirFlag.Name)
|
cfg.DataDir = ctx.String(DataDirFlag.Name)
|
||||||
case ctx.Bool(DeveloperFlag.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 {
|
if pluginNetworkId := pluginNetworkId(); pluginNetworkId != nil {
|
||||||
cfg.NetworkId = *pluginNetworkId
|
cfg.NetworkId = *pluginNetworkId
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.EthDiscoveryURLs == nil {
|
if cfg.EthDiscoveryURLs == nil {
|
||||||
var lightMode bool
|
var lightMode bool
|
||||||
if cfg.SyncMode == downloader.LightSync {
|
if cfg.SyncMode == downloader.LightSync {
|
||||||
lightMode = true
|
lightMode = true
|
||||||
}
|
}
|
||||||
cfg.EthDiscoveryURLs := pluginETHDiscoveryURLs(lightMode) {
|
cfg.EthDiscoveryURLs = pluginETHDiscoveryURLs(lightMode)
|
||||||
cfg.SnapDiscoveryURLs := pluginSnapDiscoveryURLs()
|
cfg.SnapDiscoveryURLs = pluginSnapDiscoveryURLs()
|
||||||
}
|
}
|
||||||
//end PluGeth injection
|
//end PluGeth injection
|
||||||
|
|
||||||
|
@ -6,9 +6,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func DefaultDataDir(pl *plugins.PluginLoader, path string) string {
|
func DefaultDataDir(pl *plugins.PluginLoader, path string) string {
|
||||||
log.Error("inside default data dir hook")
|
|
||||||
dataDirPath := ""
|
dataDirPath := ""
|
||||||
fnList := pl.Lookup("DefaultDataDir", func(item interface{}) bool {
|
fnList := pl.Lookup("SetDefaultDataDir", func(item interface{}) bool {
|
||||||
_, ok := item.(func(string) string)
|
_, ok := item.(func(string) string)
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -21,7 +20,6 @@ func DefaultDataDir(pl *plugins.PluginLoader, path string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pluginDefaultDataDir(path string) string {
|
func pluginDefaultDataDir(path string) string {
|
||||||
log.Error("inside default data dir injection")
|
|
||||||
if plugins.DefaultPluginLoader == nil {
|
if plugins.DefaultPluginLoader == nil {
|
||||||
log.Warn("Attempting DefaultDataDir, but default PluginLoader has not been initialized")
|
log.Warn("Attempting DefaultDataDir, but default PluginLoader has not been initialized")
|
||||||
return ""
|
return ""
|
||||||
@ -73,26 +71,26 @@ func pluginNetworkId() *uint64 {
|
|||||||
return PluginNetworkId(plugins.DefaultPluginLoader)
|
return PluginNetworkId(plugins.DefaultPluginLoader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PluginETHDiscoveryURLs(pl *plugins.PluginLoader) []string {
|
func PluginETHDiscoveryURLs(pl *plugins.PluginLoader, mode bool) []string {
|
||||||
var ethDiscoveryURLs []string
|
var ethDiscoveryURLs []string
|
||||||
fnList := pl.Lookup("SetETHDiscoveryURLs", func(item interface{}) bool {
|
fnList := pl.Lookup("SetETHDiscoveryURLs", func(item interface{}) bool {
|
||||||
_, ok := item.(func() []string)
|
_, ok := item.(func(bool) []string)
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
for _, fni := range fnList {
|
for _, fni := range fnList {
|
||||||
if fn, ok := fni.(func() []string); ok {
|
if fn, ok := fni.(func(bool) []string); ok {
|
||||||
ethDiscoveryURLs = fn()
|
ethDiscoveryURLs = fn(mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ethDiscoveryURLs
|
return ethDiscoveryURLs
|
||||||
}
|
}
|
||||||
|
|
||||||
func pluginETHDiscoveryURLs() []string {
|
func pluginETHDiscoveryURLs(mode bool) []string {
|
||||||
if plugins.DefaultPluginLoader == nil {
|
if plugins.DefaultPluginLoader == nil {
|
||||||
log.Warn("Attempting pluginETHDiscoveryURLs, but default PluginLoader has not been initialized")
|
log.Warn("Attempting pluginETHDiscoveryURLs, but default PluginLoader has not been initialized")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return PluginETHDiscoveryURLs(plugins.DefaultPluginLoader)
|
return PluginETHDiscoveryURLs(plugins.DefaultPluginLoader, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PluginSnapDiscoveryURLs(pl *plugins.PluginLoader) []string {
|
func PluginSnapDiscoveryURLs(pl *plugins.PluginLoader) []string {
|
||||||
|
@ -43,11 +43,44 @@ func GetAPIs(stack core.Node, backend core.Backend) []core.API {
|
|||||||
|
|
||||||
// cmd/utils/
|
// 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{}{
|
m := map[string]struct{}{
|
||||||
"SetSnapDiscoveryURLs":struct{}{},
|
"SetSnapDiscoveryURLs":struct{}{},
|
||||||
}
|
}
|
||||||
hookChan <- m
|
hookChan <- m
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// core/
|
// core/
|
||||||
@ -192,6 +225,10 @@ var plugins map[string]struct{} = map[string]struct{}{
|
|||||||
// "LiveCaptureEnter": struct{}{},
|
// "LiveCaptureEnter": struct{}{},
|
||||||
// "LiveCaptureExit": struct{}{},
|
// "LiveCaptureExit": struct{}{},
|
||||||
// "LiveTracerResult": struct{}{},
|
// "LiveTracerResult": struct{}{},
|
||||||
|
"SetDefaultDataDir":struct{}{},
|
||||||
|
"SetBootstrapNodes":struct{}{},
|
||||||
|
"SetNetworkId":struct{}{},
|
||||||
|
"SetETHDiscoveryURLs": struct{}{},
|
||||||
"SetSnapDiscoveryURLs": struct{}{},
|
"SetSnapDiscoveryURLs": struct{}{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +116,14 @@ func BlockChain() {
|
|||||||
// delete(plugins, "LiveCaptureExit")
|
// delete(plugins, "LiveCaptureExit")
|
||||||
// case f("LiveTracerResult"):
|
// case f("LiveTracerResult"):
|
||||||
// delete(plugins, "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"):
|
case f("SetSnapDiscoveryURLs"):
|
||||||
delete(plugins, "SetSnapDiscoveryURLs")
|
delete(plugins, "SetSnapDiscoveryURLs")
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
[Eth]
|
[Eth]
|
||||||
NetworkId = 6448
|
NetworkId = 6448
|
||||||
SyncMode = "snap"
|
SyncMode = "snap"
|
||||||
EthDiscoveryURLs = []
|
|
||||||
SnapDiscoveryURLs = []
|
|
||||||
NoPruning = false
|
NoPruning = false
|
||||||
NoPrefetch = false
|
NoPrefetch = false
|
||||||
TxLookupLimit = 2350000
|
TxLookupLimit = 2350000
|
||||||
|
Loading…
Reference in New Issue
Block a user