cmd/geth, eth/downloader: Updated downloading event to pass latest header

This commit is contained in:
Lucas Hendren 2019-01-05 23:15:58 -08:00
parent 965da6938a
commit f761250f23
3 changed files with 12 additions and 10 deletions

View file

@ -346,16 +346,17 @@ func startNode(ctx *cli.Context, stack *node.Node) {
}
}
var mux = stack.EventMux()
var sub = mux.Subscribe(downloader.BlockEvent{})
var sub = mux.Subscribe(downloader.DoneEvent{})
for {
select {
case headers := <-sub.Chan():
if headers == nil {
return
}
log.Info("Synchronisation completed, checking", "check", headers)
if 600 >= time.Now().Unix()-headers.Time.Unix() {
time.Sleep(exitWhenSynced)
stack.Stop()
}
default:
}
}

View file

@ -414,7 +414,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.blockchain.CurrentHeader()
d.mux.Post(DoneEvent{latest})
}
}()
if p.version < 62 {
@ -1562,9 +1563,6 @@ func (d *Downloader) processFastSyncContent(latest *types.Header) error {
if err := d.importBlockResults(afterP); err != nil {
return err
}
if 600 > time.Now().Unix()-latest.Time.Int64() {
d.mux.Post(BlockEvent{})
}
}
}

View file

@ -16,7 +16,10 @@
package downloader
type DoneEvent struct{}
type BlockEvent struct{}
import (
"github.com/ethereum/go-ethereum/core/types"
)
type DoneEvent struct{ *types.Header }
type StartEvent struct{}
type FailedEvent struct{ Err error }