Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node: refactor package node #21105

Merged
merged 160 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
3b2c927
created a new package node_2 where i am experimenting w/ interfaces a…
renaynay Apr 15, 2020
d44ac53
httpHandler -> httpServer
renaynay Apr 20, 2020
ec0c791
saving progress, working on ethstats impl
renaynay Apr 23, 2020
7f36098
committing progress, eth.ethereum + les.lightethereum impl backend
renaynay Apr 23, 2020
bc838a2
not working yet, but committing progress
renaynay Apr 23, 2020
a607196
fixed some registration for services
renaynay Apr 23, 2020
c842bf8
semi-functional impl
renaynay Apr 27, 2020
8dbba60
fixed dev mode start-up, should be working fine now
renaynay Apr 27, 2020
2b67abf
registerrpc and regiterprotocols
renaynay Apr 28, 2020
bf8a05b
fixed RegisterLifecycle to be generic
renaynay Apr 28, 2020
fc7bff8
reverted capitalization of endpoint -- accident
renaynay Apr 28, 2020
ca32adf
removed TODO
renaynay Apr 28, 2020
8290243
remove unnecessary constructor types
renaynay Apr 28, 2020
95bc256
fixes http/ws servers not being able to be started on given host/port
renaynay Apr 29, 2020
0ba43ec
registerHTTP but not w the signature felix suggested
renaynay May 3, 2020
4985505
enable rpc/ws
renaynay May 4, 2020
62ec847
changed RegisterHTTP and cleaned up some code, now gql can start on s…
renaynay May 4, 2020
104ca9c
some clean up
renaynay May 4, 2020
6e53f68
changed console http startup
renaynay May 4, 2020
deb1a8c
allow ws to be enabled on same port as http from console
renaynay May 4, 2020
06a8de8
added todos
renaynay May 7, 2020
4dd45c9
first steps implementing new design
renaynay May 12, 2020
c4f1d63
functional geth
renaynay May 12, 2020
e15007e
registering all apis
renaynay May 12, 2020
3993923
added todo
renaynay May 13, 2020
0a3f9a2
removed todo
renaynay May 13, 2020
2888ca4
Register http (#16)
renaynay May 15, 2020
1f1bc0d
remove unnecessary RegisterHTTP method
renaynay May 19, 2020
ae58c94
added docs, removed err return from register lifecycle
renaynay May 19, 2020
7acc43f
HTTPServer implements Lifecycle and can be started by the lifecycle l…
renaynay May 19, 2020
35460fd
removed unnecessary ListenerAddr
renaynay May 19, 2020
ccadac3
stopServer removes stopped server from list of httpservers on node an…
renaynay May 19, 2020
e3f2bd1
starting to remove use of node.Service throughout codebase
renaynay May 19, 2020
1f5f52e
WIP, trying to remove node.Service from tests
renaynay May 19, 2020
5866e01
fixes node tests (#18)
renaynay May 25, 2020
1badd5d
http server array now a map (#19)
renaynay May 25, 2020
fbc9a64
removed unnecessary change to pass host, port instead of endpoint
renaynay May 25, 2020
60ced1c
added some more tests for http servers
renaynay May 25, 2020
53a2c8f
moved some gql-specific tests to gql package
renaynay May 26, 2020
331d0a6
removed todo
renaynay May 26, 2020
45eecce
whisper tests working
renaynay Jun 3, 2020
a380ff6
create a standalone whisper service for wnode purposes
renaynay Jun 3, 2020
076a9a5
p2p/simulations uses `node.Lifecycle` instead of `node.Service` (#21)
renaynay Jun 4, 2020
3eb4fc8
fixed mailserver tests
renaynay Jun 5, 2020
6e41e41
les tests passing
renaynay Jun 5, 2020
2df58f7
changes after rebasing on master, likely bc of serverpool pr
renaynay Jun 5, 2020
fd6623e
fixed p2p testing package
renaynay Jun 5, 2020
ebde331
removing unnecessary methods and fixing todos
renaynay Jun 8, 2020
06bf009
removing more unnecessary methods
renaynay Jun 8, 2020
4ce4c40
instead of passing both les and eth explicitly, fetch backend from node
renaynay Jun 8, 2020
cc3daf6
typo
renaynay Jun 8, 2020
3f132b5
fetch backend from service context rather than node since node isnt s…
renaynay Jun 8, 2020
306f390
fixing some broken tests
renaynay Jun 8, 2020
fddc6bd
linted
renaynay Jun 8, 2020
6c91bb4
not passing backends to startnode
renaynay Jun 9, 2020
5d67845
fixing docs
renaynay Jun 9, 2020
b8c5dc4
fixed dao_test
renaynay Jun 16, 2020
885a7d4
lint
renaynay Jun 16, 2020
abbe6f8
fixed current tests, but need to add more
renaynay Jun 16, 2020
ae92dee
new test to check for proper creation of http servers on node
renaynay Jun 16, 2020
f2fcf69
added more test coverage, removed some useless code
renaynay Jun 17, 2020
204514c
minor changes, removing spaces, cleaninng up
renaynay Jun 17, 2020
41a25c3
some changes to graphql and other misc
renaynay Jun 18, 2020
666db04
linted
renaynay Jun 19, 2020
828646c
no need to pass gen state to makefullnode
renaynay Jun 19, 2020
3443202
missing register apis and protocols
renaynay Jun 22, 2020
9ed169e
register http before starting
renaynay Jun 22, 2020
fb8e5b0
added some documentation
renaynay Jun 22, 2020
e897df9
minor fixes
renaynay Jun 22, 2020
cfae6ed
Changes requested from PR review (#23)
renaynay Jun 29, 2020
d49a5be
attempt at fixing http test (#24)
renaynay Jun 30, 2020
52896ae
fixed broken http test, waiting whether it passes on all builds
renaynay Jun 30, 2020
dce4780
use int32 instead of bool when checking whether to handle requests (#25)
renaynay Jul 2, 2020
0e7b866
make sure to register all APIs when registering services apis on node
renaynay Jul 3, 2020
a5204a4
store int32
renaynay Jul 6, 2020
71d9590
remove P2PServer method from les, unnecessary
renaynay Jul 6, 2020
7661eb8
refactor http servers + graphql (#26)
renaynay Jul 7, 2020
d96b280
removed some TODOs
renaynay Jul 7, 2020
ff002b1
init leth handler
renaynay Jul 9, 2020
bafc12a
register protocols and apis of les on eth backend
renaynay Jul 9, 2020
975061c
node: make Node.Attach work before Node.Start
fjl Jul 10, 2020
8a568a4
all: excise SetContractBackend
fjl Jul 10, 2020
e930d38
revert blackbox test for ethclient
renaynay Jul 10, 2020
54b8389
les: fix setOracle for chains without checkpoint
fjl Jul 10, 2020
212bb78
les --> lifecycle decoupled from ethbackend (#29)
renaynay Jul 10, 2020
1844d22
remove Fatalf from node, should panic instead
renaynay Jul 10, 2020
a24c7b8
eth: remove AddLesServer
fjl Jul 10, 2020
aaee36b
cmd/utils: remove duplicate protocol/API registration
fjl Jul 10, 2020
ebc7061
remove newgqlhandler from rpcstack
renaynay Jul 10, 2020
5d2e755
node: stop lifecycles in reverse order
fjl Jul 10, 2020
1b50b55
node: simplify RegisterLifecycle
fjl Jul 10, 2020
489bb05
donnt check ls
renaynay Jul 10, 2020
b2931b6
Explicit type check for backend (#27)
renaynay Jul 10, 2020
e7602e3
go mod tidy
renaynay Jul 10, 2020
9ee9bbe
linted
renaynay Jul 13, 2020
b26ea83
changes requested by gary
renaynay Jul 15, 2020
dd06152
node: unexport CreateHTTPServer
fjl Jul 13, 2020
57ffd7c
graphql: don't check for HTTP server creation
fjl Jul 13, 2020
c8b01c4
node: unexport ExistingHTTPServer
fjl Jul 13, 2020
783ad61
node: add new lifecycle docs
fjl Jul 21, 2020
af82314
node: fix comment on Start
fjl Jul 21, 2020
33ffe5b
node: move datadir cleanup from Stop to Close
fjl Jul 21, 2020
767e3b1
node: simplify stop channel
fjl Jul 21, 2020
ce38ec6
node: remove Stop
fjl Jul 21, 2020
cd46fce
all: Node.Stop -> Node.Close
fjl Jul 21, 2020
d2c2474
mobile: add TODO for restart
fjl Jul 21, 2020
4fdd72b
node: add more runstate checks
fjl Jul 21, 2020
068fe78
node: ensure Register* can only be used in initializing state
fjl Jul 21, 2020
81ecb44
removed unnecessary use of fmt.Sprintf
renaynay Jul 21, 2020
0ea3bb4
revert accidental q
renaynay Jul 21, 2020
f3f1178
fixed ethstats backend interface
renaynay Jul 21, 2020
3c0fb99
node: whitespace changes
fjl Jul 21, 2020
7801fad
p2p/simulations/adapters: use Node.Attach where possible
fjl Jul 21, 2020
d4e2173
node: avoid setting server to nil
fjl Jul 21, 2020
dab27f6
node: use simple lock
fjl Jul 21, 2020
b8d7587
node: more cosmetic fixes
fjl Jul 21, 2020
b6c60cf
node: track open databases
fjl Jul 21, 2020
4ae4172
core/rawdb: make Freezer.Close idempotent
fjl Jul 21, 2020
8400a5d
node: avoid auto-closing DB if service closes it first
fjl Jul 21, 2020
fa88f30
p2p/simulations/adapters: delete snapshotService
fjl Jul 21, 2020
4da9ef7
p2p: delete Server.Running
fjl Jul 21, 2020
e1f4668
cmd/geth, cmd/utils: gofmt -w -s
fjl Jul 22, 2020
a30d401
p2p/simulations/examples: remove unused APIs callback
fjl Jul 22, 2020
5a3cf7a
p2p/testing: delete unused package
fjl Jul 22, 2020
e6cd0e3
node: unexport RegisterHTTPServer
fjl Jul 22, 2020
aba0667
node: clean up instrumented service tests
fjl Jul 22, 2020
a23b650
node: add test for database auto-closing
fjl Jul 22, 2020
0a5312a
node: WIP TestNodeOpenDatabaseFromLifecycle
fjl Jul 22, 2020
39dbf65
node: move Start up
fjl Jul 22, 2020
6a16cbe
node: simplify Start/Stop concurrency handling
fjl Jul 22, 2020
cc9fddd
node: unexport built-in API handler objects
fjl Jul 22, 2020
390e8a3
node: move RegisterApisFromWhitelist
fjl Jul 22, 2020
908268d
miner: fix test scripts
fjl Jul 22, 2020
891b286
miner: simplify test scripts
fjl Jul 22, 2020
c70d5e6
miner: simplify test scripts even more
fjl Jul 22, 2020
45f162c
node: remove atomic operations on n.state
fjl Jul 23, 2020
4a6faff
node: WIP rewrite HTTP server setup
fjl Jul 24, 2020
a1a4454
descriptive logging
renaynay Jul 27, 2020
2d81929
removed ws log
renaynay Jul 27, 2020
c985bd4
node: add test for StartRPC API
fjl Jul 27, 2020
f2dbf7e
node: fix test
fjl Jul 27, 2020
47315c0
node: delete redundant websocket enabling test
fjl Jul 27, 2020
9a1131c
node: fix all the HTTP server API tests
fjl Jul 27, 2020
6d544c6
node: improve comments
fjl Jul 27, 2020
d7c1258
node: fix starting RPC after it failed to listen
fjl Jul 27, 2020
b8b1046
changed node tests
renaynay Jul 27, 2020
8580962
rpcstack tests
renaynay Jul 27, 2020
68cc90c
linted and new tests
renaynay Jul 28, 2020
917135f
reshuffling some funcs in rpcstack
renaynay Jul 28, 2020
3664dd5
node: move disableWS down as well
fjl Aug 3, 2020
de11bb1
node: improve comments
fjl Aug 3, 2020
98cf053
go.mod: revert dependency updates
fjl Aug 3, 2020
b265e2c
eth: fix compile issue in backend.go
fjl Aug 3, 2020
1c639bd
node: fix IPC API registration
fjl Aug 3, 2020
e11bc43
graphql: fix test
fjl Aug 3, 2020
f1b1b33
node: remove blank line
fjl Aug 3, 2020
3001cf5
node: sort+dedup logged HTTP handlers
fjl Aug 3, 2020
4d42e9f
node: fix lint issue
fjl Aug 3, 2020
2b5bd5e
node: rename RegisterPath -> RegisterHandler
fjl Aug 3, 2020
74e2aa9
node: explain RegisterHandler 'name' parameter in docs
fjl Aug 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,20 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*discv5.Node, network u
if err != nil {
return nil, err
}

// Assemble the Ethereum light client protocol
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
cfg := eth.DefaultConfig
cfg.SyncMode = downloader.LightSync
cfg.NetworkId = network
cfg.Genesis = genesis
return les.New(ctx, &cfg)
}); err != nil {
return nil, err
cfg := eth.DefaultConfig
cfg.SyncMode = downloader.LightSync
cfg.NetworkId = network
cfg.Genesis = genesis
lesBackend, err := les.New(stack, &cfg)
if err != nil {
return nil, fmt.Errorf("Failed to register the Ethereum service: %w", err)
}

// Assemble the ethstats monitoring and reporting service'
if stats != "" {
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
var serv *les.LightEthereum
ctx.Service(&serv)
return ethstats.New(stats, nil, serv)
}); err != nil {
if err := ethstats.New(stack, lesBackend.ApiBackend, lesBackend.Engine(), stats); err != nil {
return nil, err
}
}
Expand All @@ -268,7 +265,7 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*discv5.Node, network u
// Attach to the client and retrieve and interesting metadatas
api, err := stack.Attach()
if err != nil {
stack.Stop()
stack.Close()
return nil, err
}
client := ethclient.NewClient(api)
Expand Down
15 changes: 8 additions & 7 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ func initGenesis(ctx *cli.Context) error {
if err := json.NewDecoder(file).Decode(genesis); err != nil {
utils.Fatalf("invalid genesis file: %v", err)
}

// Open an initialise both full and light databases
stack := makeFullNode(ctx)
stack, _ := makeConfigNode(ctx)
defer stack.Close()

for _, name := range []string{"chaindata", "lightchaindata"} {
Expand Down Expand Up @@ -277,7 +278,7 @@ func importChain(ctx *cli.Context) error {
utils.SetupMetrics(ctx)
// Start system runtime metrics collection
go metrics.CollectProcessMetrics(3 * time.Second)
stack := makeFullNode(ctx)
stack, _ := makeFullNode(ctx)
defer stack.Close()

chain, db := utils.MakeChain(ctx, stack, false)
Expand Down Expand Up @@ -371,7 +372,7 @@ func exportChain(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.")
}
stack := makeFullNode(ctx)
stack, _ := makeFullNode(ctx)
defer stack.Close()

chain, _ := utils.MakeChain(ctx, stack, true)
Expand Down Expand Up @@ -406,7 +407,7 @@ func importPreimages(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.")
}
stack := makeFullNode(ctx)
stack, _ := makeFullNode(ctx)
defer stack.Close()

db := utils.MakeChainDatabase(ctx, stack)
Expand All @@ -424,7 +425,7 @@ func exportPreimages(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.")
}
stack := makeFullNode(ctx)
stack, _ := makeFullNode(ctx)
defer stack.Close()

db := utils.MakeChainDatabase(ctx, stack)
Expand All @@ -446,7 +447,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, _ := makeFullNode(ctx)
defer stack.Close()

chain, chainDb := utils.MakeChain(ctx, stack, false)
Expand Down Expand Up @@ -554,7 +555,7 @@ func confirmAndRemoveDB(database string, kind string) {
}

func dump(ctx *cli.Context) error {
stack := makeFullNode(ctx)
stack, _ := makeFullNode(ctx)
defer stack.Close()

chain, chainDb := utils.MakeChain(ctx, stack, true)
Expand Down
12 changes: 7 additions & 5 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
Expand Down Expand Up @@ -144,9 +145,10 @@ func enableWhisper(ctx *cli.Context) bool {
return false
}

func makeFullNode(ctx *cli.Context) *node.Node {
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
stack, cfg := makeConfigNode(ctx)
utils.RegisterEthService(stack, &cfg.Eth)

backend := utils.RegisterEthService(stack, &cfg.Eth)

// Whisper must be explicitly enabled by specifying at least 1 whisper flag or in dev mode
shhEnabled := enableWhisper(ctx)
Expand All @@ -165,13 +167,13 @@ func makeFullNode(ctx *cli.Context) *node.Node {
}
// Configure GraphQL if requested
if ctx.GlobalIsSet(utils.GraphQLEnabledFlag.Name) {
utils.RegisterGraphQLService(stack, cfg.Node.GraphQLEndpoint(), cfg.Node.GraphQLCors, cfg.Node.GraphQLVirtualHosts, cfg.Node.HTTPTimeouts)
utils.RegisterGraphQLService(stack, backend, cfg.Node)
}
// Add the Ethereum Stats daemon if requested.
if cfg.Ethstats.URL != "" {
utils.RegisterEthStatsService(stack, cfg.Ethstats.URL)
utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL)
}
return stack
return stack, backend
}

// dumpConfig is the dumpconfig command.
Expand Down
16 changes: 8 additions & 8 deletions cmd/geth/consolecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/JavaScript-Cons
func localConsole(ctx *cli.Context) error {
// Create and start the node based on the CLI flags
prepare(ctx)
node := makeFullNode(ctx)
startNode(ctx, node)
defer node.Close()
stack, backend := makeFullNode(ctx)
startNode(ctx, stack, backend)
defer stack.Close()

// Attach to the newly started node and start the JavaScript console
client, err := node.Attach()
client, err := stack.Attach()
if err != nil {
utils.Fatalf("Failed to attach to the inproc geth: %v", err)
}
Expand Down Expand Up @@ -190,12 +190,12 @@ 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)
startNode(ctx, node)
defer node.Close()
stack, backend := makeFullNode(ctx)
startNode(ctx, stack, backend)
defer stack.Close()

// Attach to the newly started node and start the JavaScript console
client, err := node.Attach()
client, err := stack.Attach()
if err != nil {
utils.Fatalf("Failed to attach to the inproc geth: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/geth/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
} else {
// Force chain initialization
args := []string{"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--ipcdisable", "--datadir", datadir}
geth := runGeth(t, append(args, []string{"--exec", "2+2", "console"}...)...)
geth.WaitExit()
runGeth(t, append(args, []string{"--exec", "2+2", "console"}...)...).WaitExit()
}
// Retrieve the DAO config flag from the database
path := filepath.Join(datadir, "geth", "chaindata")
Expand Down
49 changes: 15 additions & 34 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node"
Expand Down Expand Up @@ -171,8 +171,6 @@ var (
utils.LegacyRPCCORSDomainFlag,
utils.LegacyRPCVirtualHostsFlag,
utils.GraphQLEnabledFlag,
utils.GraphQLListenAddrFlag,
utils.GraphQLPortFlag,
utils.GraphQLCORSDomainFlag,
utils.GraphQLVirtualHostsFlag,
utils.HTTPApiFlag,
Expand Down Expand Up @@ -350,18 +348,20 @@ func geth(ctx *cli.Context) error {
if args := ctx.Args(); len(args) > 0 {
return fmt.Errorf("invalid command: %q", args[0])
}

prepare(ctx)
node := makeFullNode(ctx)
defer node.Close()
startNode(ctx, node)
node.Wait()
stack, backend := makeFullNode(ctx)
defer stack.Close()

startNode(ctx, stack, backend)
stack.Wait()
return nil
}

// startNode boots up the system node and all registered protocols, after which
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
// miner.
func startNode(ctx *cli.Context, stack *node.Node) {
func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend) {
debug.Memsize.Add("node", stack)

// Start up the node itself
Expand All @@ -381,25 +381,6 @@ func startNode(ctx *cli.Context, stack *node.Node) {
}
ethClient := ethclient.NewClient(rpcClient)

// Set contract backend for ethereum service if local node
// is serving LES requests.
if ctx.GlobalInt(utils.LegacyLightServFlag.Name) > 0 || ctx.GlobalInt(utils.LightServeFlag.Name) > 0 {
var ethService *eth.Ethereum
if err := stack.Service(&ethService); err != nil {
utils.Fatalf("Failed to retrieve ethereum service: %v", err)
}
ethService.SetContractBackend(ethClient)
}
// Set contract backend for les service if local node is
// running as a light client.
if ctx.GlobalString(utils.SyncModeFlag.Name) == "light" {
var lesService *les.LightEthereum
if err := stack.Service(&lesService); err != nil {
utils.Fatalf("Failed to retrieve light ethereum service: %v", err)
}
lesService.SetContractBackend(ethClient)
}

go func() {
// Open any wallets already attached
for _, wallet := range stack.AccountManager().Wallets() {
Expand Down Expand Up @@ -451,7 +432,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
if timestamp := time.Unix(int64(done.Latest.Time), 0); time.Since(timestamp) < 10*time.Minute {
log.Info("Synchronisation completed", "latestnum", done.Latest.Number, "latesthash", done.Latest.Hash(),
"age", common.PrettyAge(timestamp))
stack.Stop()
stack.Close()
}
}
}()
Expand All @@ -463,24 +444,24 @@ func startNode(ctx *cli.Context, stack *node.Node) {
if ctx.GlobalString(utils.SyncModeFlag.Name) == "light" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think everything in this block is code that only works for full nodes.
We should create an auxiliary function for setting up *eth.Ethereum specifically
and then put a type assertion for *eth.Ethereum here.

utils.Fatalf("Light clients do not support mining")
}
var ethereum *eth.Ethereum
if err := stack.Service(&ethereum); err != nil {
ethBackend, ok := backend.(*eth.EthAPIBackend)
if !ok {
utils.Fatalf("Ethereum service not running: %v", err)
}

// Set the gas price to the limits from the CLI and start mining
gasprice := utils.GlobalBig(ctx, utils.MinerGasPriceFlag.Name)
if ctx.GlobalIsSet(utils.LegacyMinerGasPriceFlag.Name) && !ctx.GlobalIsSet(utils.MinerGasPriceFlag.Name) {
gasprice = utils.GlobalBig(ctx, utils.LegacyMinerGasPriceFlag.Name)
}
ethereum.TxPool().SetGasPrice(gasprice)

ethBackend.TxPool().SetGasPrice(gasprice)
// start mining
threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name)
if ctx.GlobalIsSet(utils.LegacyMinerThreadsFlag.Name) && !ctx.GlobalIsSet(utils.MinerThreadsFlag.Name) {
threads = ctx.GlobalInt(utils.LegacyMinerThreadsFlag.Name)
log.Warn("The flag --minerthreads is deprecated and will be removed in the future, please use --miner.threads")
}

if err := ethereum.StartMining(threads); err != nil {
if err := ethBackend.StartMining(threads); err != nil {
utils.Fatalf("Failed to start mining: %v", err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.WSApiFlag,
utils.WSAllowedOriginsFlag,
utils.GraphQLEnabledFlag,
utils.GraphQLListenAddrFlag,
utils.GraphQLPortFlag,
utils.GraphQLCORSDomainFlag,
utils.GraphQLVirtualHostsFlag,
utils.RPCGlobalGasCap,
Expand Down Expand Up @@ -231,6 +229,8 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.LegacyWSApiFlag,
utils.LegacyGpoBlocksFlag,
utils.LegacyGpoPercentileFlag,
utils.LegacyGraphQLListenAddrFlag,
utils.LegacyGraphQLPortFlag,
}, debug.DeprecatedFlags...),
},
{
Expand Down
2 changes: 1 addition & 1 deletion cmd/p2psim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func createNode(ctx *cli.Context) error {
config.PrivateKey = privKey
}
if services := ctx.String("services"); services != "" {
config.Services = strings.Split(services, ",")
config.Lifecycles = strings.Split(services, ",")
}
node, err := client.CreateNode(config)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func StartNode(stack *node.Node) {
defer signal.Stop(sigc)
<-sigc
log.Info("Got interrupt, shutting down...")
go stack.Stop()
go stack.Close()
for i := 10; i > 0; i-- {
<-sigc
if i > 1 {
Expand Down
Loading