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

cmd,eth: 16400 Add an option to stop geth once in sync. WIP for light mode #17321

Merged
merged 35 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7ea50b7
cmd, eth: Added in the flag to step geth once sync based on input
lhendre Jul 26, 2018
52b38e0
cmd, eth: 16400 Add an option to stop geth once in sync.
lhendre Aug 6, 2018
1492a0d
cmd: 16400 Add an option to stop geth once in sync. WIP
lhendre Aug 6, 2018
3ba6900
cmd/geth/main, les/fletcher: added in light mode support
lhendre Aug 30, 2018
a4cd1ea
cmd/geth/main, les/fletcher: Cleaned Comments and code for light mode
lhendre Aug 30, 2018
6f39df9
Merge branch 'master' into master
lhendre Sep 1, 2018
0d61f89
cmd: 16400 Fixed formatting issue and cleaned code
lhendre Sep 3, 2018
136e27b
Merge branch master into master
lhendre Sep 3, 2018
6d1305b
cmd, eth, les: 16400 Fixed formatting issues
lhendre Sep 3, 2018
c22c382
cmd, eth, les: Performed gofmt to update formatting
lhendre Sep 3, 2018
87eab8a
cmd, eth, les: Fixed bugs resulting formatting
lhendre Sep 6, 2018
c9daec2
Merge branch 'master' into master
lhendre Sep 25, 2018
8320356
cmd/geth, eth/, les: switched to downloader event
lhendre Oct 15, 2018
5cec18b
eth: Fixed styling and gen_config
lhendre Oct 17, 2018
498c417
eth/: Fix nil error in config file
lhendre Oct 17, 2018
20af817
cmd/geth: Updated countdown log
lhendre Oct 17, 2018
6d43b16
les/fetcher.go: Removed depcreated channel
lhendre Oct 25, 2018
46496d6
eth/downloader.go: Removed deprecated select
lhendre Oct 25, 2018
78494d7
Merge branch 'master' into master
lhendre Nov 19, 2018
d0481a5
cmd/geth, cmd/utils: Fixed minor issues
lhendre Nov 21, 2018
cceaae3
eth: Reverted config files to proper format
lhendre Nov 27, 2018
1a808ae
eth: Fixed typo in config file
lhendre Nov 27, 2018
1008f25
cmd/geth, eth/down: Updated code to use header time stamp
lhendre Dec 20, 2018
965da69
eth/downloader: Changed the time threshold to 10 minutes
lhendre Dec 22, 2018
f761250
cmd/geth, eth/downloader: Updated downloading event to pass latest he…
lhendre Jan 6, 2019
9124434
cmd/geth: Updated main to use right timer object
lhendre Jan 7, 2019
b939822
cmd/geth: Removed unused failed event
lhendre Jan 8, 2019
eeaef14
cmd/geth: added in correct time field with type assertion
lhendre Jan 11, 2019
41ebfe2
cmd/geth, cmd/utils: Updated flag to use boolean
lhendre Jan 14, 2019
b3e6304
cmd/geth, cmd/utils, eth/downloader: Cleaned up code based on recomme…
lhendre Jan 25, 2019
8c32235
cmd/geth: Removed unneeded import
lhendre Jan 25, 2019
0b8fa15
cmd/geth, eth/downloader: fixed event field and suggested changes
lhendre Jan 25, 2019
1744e19
Merge branch 'master' into master
lhendre Jan 25, 2019
c8660fa
cmd/geth, cmd/utils: Updated flag and linting issue
lhendre Jan 26, 2019
e5f630b
Merge branch 'master' of https://github.com/lhendre/go-ethereum
lhendre Jan 26, 2019
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
30 changes: 30 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/console"
"github.com/ethereum/go-ethereum/eth"
"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/log"
Expand Down Expand Up @@ -87,6 +89,7 @@ var (
utils.ULCTrustedNodesFlag,
utils.ULCMinTrustedFractionFlag,
utils.SyncModeFlag,
utils.ExitWhenSyncedFlag,
utils.GCModeFlag,
utils.LightServFlag,
utils.LightPeersFlag,
Expand Down Expand Up @@ -339,6 +342,33 @@ func startNode(ctx *cli.Context, stack *node.Node) {
}
}
}()

// Spawn a standalone goroutine for status synchronization monitoring,
// close the node when synchronization is complete if user required.
if ctx.GlobalBool(utils.ExitWhenSyncedFlag.Name) {
go func() {
sub := stack.EventMux().Subscribe(downloader.DoneEvent{})
defer sub.Unsubscribe()
for {
select {
case event := <-sub.Chan():
if event == nil {
continue
}
done, ok := event.Data.(downloader.DoneEvent)
if !ok {
continue
}
if timestamp := time.Unix(done.Latest.Time.Int64(), 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()
}
}
}
}()
}

lhendre marked this conversation as resolved.
Show resolved Hide resolved
// Start auxiliary services if enabled
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) {
// Mining only makes sense if a full Ethereum node is running
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.TestnetFlag,
utils.RinkebyFlag,
utils.SyncModeFlag,
utils.ExitWhenSyncedFlag,
utils.GCModeFlag,
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
utils.EthStatsURLFlag,
utils.IdentityFlag,
Expand Down
5 changes: 4 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ var (
Usage: "Document Root for HTTPClient file scheme",
Value: DirectoryString{homeDir()},
}
ExitWhenSyncedFlag = cli.BoolFlag{
Name: "exitwhensynced",
Usage: "Exists syncing by given time (default 0) after block synchronisation",
}
ULCModeConfigFlag = cli.StringFlag{
Name: "ulc.config",
Usage: "Config file to use for ultra light client mode",
Expand All @@ -178,7 +182,6 @@ var (
Name: "ulc.trusted",
Usage: "List of trusted ULC servers",
}
lhendre marked this conversation as resolved.
Show resolved Hide resolved

defaultSyncMode = eth.DefaultConfig.SyncMode
SyncModeFlag = TextMarshalerFlag{
Name: "syncmode",
Expand Down
5 changes: 2 additions & 3 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.I
if err != nil {
d.mux.Post(FailedEvent{err})
} else {
d.mux.Post(DoneEvent{})
latest := d.lightchain.CurrentHeader()
d.mux.Post(DoneEvent{latest})
}
}()
if p.version < 62 {
Expand Down Expand Up @@ -1369,7 +1370,6 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
}
// Otherwise split the chunk of headers into batches and process them
gotHeaders = true

for len(headers) > 0 {
// Terminate if something failed in between processing chunks
select {
Expand Down Expand Up @@ -1432,7 +1432,6 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
headers = headers[limit:]
origin += uint64(limit)
}

// Update the highest block number we know if a higher one is found.
d.syncStatsLock.Lock()
if d.syncStatsChainHeight < origin {
Expand Down
6 changes: 5 additions & 1 deletion eth/downloader/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package downloader

type DoneEvent struct{}
import "github.com/ethereum/go-ethereum/core/types"

type DoneEvent struct {
Latest *types.Header
}
type StartEvent struct{}
type FailedEvent struct{ Err error }