Clean-up les service code

This commit is contained in:
Frank Szendzielarz 2019-05-28 14:51:26 +02:00
parent 2388e425f2
commit a7eaf583eb
4 changed files with 25 additions and 11 deletions

View file

@ -205,7 +205,7 @@ func initGenesis(ctx *cli.Context) error {
utils.Fatalf("invalid genesis file: %v", err)
}
// Open an initialise both full and light databases
stack := makeFullNode(ctx)
stack := makeNode(ctx)
defer stack.Close()
for _, name := range []string{"chaindata", "lightchaindata"} {
@ -227,7 +227,7 @@ func importChain(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.")
}
stack := makeFullNode(ctx)
stack := makeNode(ctx)
defer stack.Close()
chain, db := utils.MakeChain(ctx, stack)
@ -317,7 +317,7 @@ func exportChain(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.")
}
stack := makeFullNode(ctx)
stack := makeNode(ctx)
defer stack.Close()
chain, _ := utils.MakeChain(ctx, stack)
@ -352,7 +352,7 @@ func importPreimages(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.")
}
stack := makeFullNode(ctx)
stack := makeNode(ctx)
defer stack.Close()
db := utils.MakeChainDatabase(ctx, stack)
@ -370,7 +370,7 @@ func exportPreimages(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.")
}
stack := makeFullNode(ctx)
stack := makeNode(ctx)
defer stack.Close()
db := utils.MakeChainDatabase(ctx, stack)
@ -392,7 +392,7 @@ func copyDb(ctx *cli.Context) error {
utils.Fatalf("Source ancient chain directory path argument missing")
}
// Initialize a new chain for the running node to sync into
stack := makeFullNode(ctx)
stack := makeNode(ctx)
defer stack.Close()
chain, chainDb := utils.MakeChain(ctx, stack)
@ -500,7 +500,7 @@ func confirmAndRemoveDB(database string, kind string) {
}
func dump(ctx *cli.Context) error {
stack := makeFullNode(ctx)
stack := makeNode(ctx)
defer stack.Close()
chain, chainDb := utils.MakeChain(ctx, stack)

View file

@ -152,16 +152,30 @@ func enableWhisper(ctx *cli.Context) bool {
return false
}
func makeFullNode(ctx *cli.Context) *node.Node {
//makeNode initialises a node with various services so that the node and its services can be later started
func makeNode(ctx *cli.Context) *node.Node {
stack, cfg := makeConfigNode(ctx)
if ctx.GlobalIsSet(utils.ConstantinopleOverrideFlag.Name) {
cfg.Eth.ConstantinopleOverride = new(big.Int).SetUint64(ctx.GlobalUint64(utils.ConstantinopleOverrideFlag.Name))
}
//register a Service that handles the Les client if the config permits
utils.RegisterLesClientService(stack, &cfg.Eth)
//register a Service that handles the Eth capability if the config permits
utils.RegisterEthService(stack, &cfg.Eth)
//register a Service that handles the Les client if the config permits
//(the Les Server service registration depends on the Eth service being
//registered prior)
utils.RegisterLesServerService(stack, &cfg.Eth)
if ctx.GlobalBool(utils.DashboardEnabledFlag.Name) {
utils.RegisterDashboardService(stack, &cfg.Dashboard, gitCommit)
}
// Whisper must be explicitly enabled by specifying at least 1 whisper flag or in dev mode
shhEnabled := enableWhisper(ctx)
shhAutoEnabled := !ctx.GlobalIsSet(utils.WhisperEnabledFlag.Name) && ctx.GlobalIsSet(utils.DeveloperFlag.Name)

View file

@ -77,7 +77,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/JavaScript-Cons
// same time.
func localConsole(ctx *cli.Context) error {
// Create and start the node based on the CLI flags
node := makeFullNode(ctx)
node := makeNode(ctx)
startNode(ctx, node)
defer node.Close()
@ -178,7 +178,7 @@ func dialRPC(endpoint string) (*rpc.Client, error) {
// everything down.
func ephemeralConsole(ctx *cli.Context) error {
// Create and start the node based on the CLI flags
node := makeFullNode(ctx)
node := makeNode(ctx)
startNode(ctx, node)
defer node.Close()

View file

@ -297,7 +297,7 @@ func geth(ctx *cli.Context) error {
if args := ctx.Args(); len(args) > 0 {
return fmt.Errorf("invalid command: %q", args[0])
}
node := makeFullNode(ctx)
node := makeNode(ctx)
defer node.Close()
startNode(ctx, node)
node.Wait()