cmd/geth, eth/, les: switched to downloader event

This commit is contained in:
Lucas Hendren 2018-10-15 01:23:34 -04:00
parent c9daec2cbe
commit 832035636b
4 changed files with 10 additions and 10 deletions

View file

@ -34,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/console" "github.com/ethereum/go-ethereum/console"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/internal/debug" "github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/les" "github.com/ethereum/go-ethereum/les"
@ -340,18 +341,21 @@ func startNode(ctx *cli.Context, stack *node.Node) {
if err := stack.Service(&lightEthereum); err != nil { if err := stack.Service(&lightEthereum); err != nil {
utils.Fatalf("LightEthereum service not running: %v", err) utils.Fatalf("LightEthereum service not running: %v", err)
} }
<-lightEthereum.Downloader().SyncedCh var mux = stack.EventMux()
log.Info("Synchronisation completed, exitting", "countdown", exitWhenSynced) var sub = mux.Subscribe(downloader.DoneEvent{})
<-sub.Chan()
log.Info("Synchronisation completed, exitting", "countdown", downloader.DoneEvent{})
time.Sleep(exitWhenSynced) time.Sleep(exitWhenSynced)
stack.Stop() stack.Stop()
} else { } else {
var ethereum *eth.Ethereum var ethereum *eth.Ethereum
if err := stack.Service(&ethereum); err != nil { if err := stack.Service(&ethereum); err != nil {
utils.Fatalf("Ethereum service not running: %v", err) utils.Fatalf("Ethereum service not running: %v", err)
} }
<-ethereum.Downloader().SyncedCh var mux = stack.EventMux()
log.Info("Synchronisation completed, exitting", "countdown", exitWhenSynced) var sub = mux.Subscribe(downloader.DoneEvent{})
<-sub.Chan()
log.Info("Synchronisation completed, exitting", "countdown", downloader.DoneEvent{})
time.Sleep(exitWhenSynced) time.Sleep(exitWhenSynced)
stack.Stop() stack.Stop()
} }

View file

@ -124,7 +124,7 @@ type Config struct {
// specify time to exit after syncing // specify time to exit after syncing
ExitWhenSynced time.Duration ExitWhenSynced time.Duration
// Type of the EWASM interpreter ("" for detault) // Type of the EWASM interpreter ("" for detault)
EWASMInterpreter string EWASMInterpreter string
// Type of the EVM interpreter ("" for default) // Type of the EVM interpreter ("" for default)

View file

@ -128,7 +128,6 @@ type Downloader struct {
bodyWakeCh chan bool // [eth/62] Channel to signal the block body fetcher of new tasks bodyWakeCh chan bool // [eth/62] Channel to signal the block body fetcher of new tasks
receiptWakeCh chan bool // [eth/63] Channel to signal the receipt fetcher of new tasks receiptWakeCh chan bool // [eth/63] Channel to signal the receipt fetcher of new tasks
headerProcCh chan []*types.Header // [eth/62] Channel to feed the header processor new tasks headerProcCh chan []*types.Header // [eth/62] Channel to feed the header processor new tasks
SyncedCh chan bool
// for stateFetcher // for stateFetcher
stateSyncStart chan *stateSync stateSyncStart chan *stateSync
@ -227,7 +226,6 @@ func New(mode SyncMode, stateDb ethdb.Database, mux *event.TypeMux, chain BlockC
syncStatsState: stateSyncStats{ syncStatsState: stateSyncStats{
processed: rawdb.ReadFastTrieProgress(stateDb), processed: rawdb.ReadFastTrieProgress(stateDb),
}, },
SyncedCh: make(chan bool, 1),
trackStateReq: make(chan *stateReq), trackStateReq: make(chan *stateReq),
} }
go dl.qosTuner() go dl.qosTuner()
@ -320,7 +318,6 @@ func (d *Downloader) Synchronise(id string, head common.Hash, td *big.Int, mode
switch err { switch err {
case nil: case nil:
select { select {
case d.SyncedCh <- true:
default: default:
} }
case errBusy: case errBusy:

View file

@ -448,7 +448,6 @@ func (f *lightFetcher) nextRequest() (*distReq, uint64) {
p.Log().Debug("Synchronisation started") p.Log().Debug("Synchronisation started")
f.pm.synchronise(p) f.pm.synchronise(p)
f.syncDone <- p f.syncDone <- p
f.SyncedCh <- true
}() }()
return nil return nil
}, },