diff --git a/cmd/geth/main.go b/cmd/geth/main.go index b3d39ef8a1..cdc8e31118 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -32,8 +32,8 @@ import ( "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/console" - "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/downloader" + "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/internal/debug" "github.com/ethereum/go-ethereum/les" @@ -346,11 +346,19 @@ func startNode(ctx *cli.Context, stack *node.Node) { } } var mux = stack.EventMux() - var sub = mux.Subscribe(downloader.DoneEvent{}) - <-sub.Chan() - log.Info("Synchronisation completed, exitting", "countdown", exitWhenSynced) - time.Sleep(exitWhenSynced) - stack.Stop() + var sub = mux.Subscribe(downloader.BlockEvent{}) + for { + select { + case headers := <-sub.Chan(): + if headers == nil { + return + } + log.Info("Synchronisation completed, checking", "check", headers) + time.Sleep(exitWhenSynced) + stack.Stop() + default: + } + } }() } diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index f81a5cbac2..925339d831 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -1347,7 +1347,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 { @@ -1410,7 +1409,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 { @@ -1564,6 +1562,9 @@ func (d *Downloader) processFastSyncContent(latest *types.Header) error { if err := d.importBlockResults(afterP); err != nil { return err } + if 4400000 > time.Now().Unix()-latest.Time.Int64() { + d.mux.Post(BlockEvent{}) + } } } diff --git a/eth/downloader/events.go b/eth/downloader/events.go index 64905b8f2a..a70d21f50f 100644 --- a/eth/downloader/events.go +++ b/eth/downloader/events.go @@ -17,5 +17,6 @@ package downloader type DoneEvent struct{} +type BlockEvent struct{} type StartEvent struct{} type FailedEvent struct{ Err error }