Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

[WIP]: Fix/sync stuck near head #606

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
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
606 changes: 309 additions & 297 deletions core/blockchain.go

Large diffs are not rendered by default.

714 changes: 377 additions & 337 deletions eth/downloader/downloader.go

Large diffs are not rendered by default.

1,382 changes: 540 additions & 842 deletions eth/downloader/downloader_test.go

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions eth/downloader/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"time"

"github.com/ethereumproject/go-ethereum/common"
"github.com/ethereumproject/go-ethereum/event"
)

const (
Expand Down Expand Up @@ -345,8 +346,10 @@ func (p *peer) String() string {
// peerSet represents the collection of active peer participating in the chain
// download procedure.
type peerSet struct {
peers map[string]*peer
lock sync.RWMutex
peers map[string]*peer
newPeerFeed event.Feed
peerDropFeed event.Feed
lock sync.RWMutex
}

// newPeerSet creates a new peer set top track the active download sources.
Expand All @@ -356,6 +359,16 @@ func newPeerSet() *peerSet {
}
}

// SubscribeNewPeers subscribes to peer arrival events.
func (ps *peerSet) SubscribeNewPeers(ch chan<- *peer) event.Subscription {
return ps.newPeerFeed.Subscribe(ch)
}

// SubscribePeerDrops subscribes to peer departure events.
func (ps *peerSet) SubscribePeerDrops(ch chan<- *peer) event.Subscription {
return ps.peerDropFeed.Subscribe(ch)
}

// Reset iterates over the current peer set, and resets each of the known peers
// to prepare for a next batch of block retrieval.
func (ps *peerSet) Reset() {
Expand Down Expand Up @@ -542,10 +555,10 @@ func (ps *peerSet) idlePeers(minProtocol, maxProtocol int, idleCheck func(*peer)
return idle, total
}

// medianRTT returns the median RTT of te peerset, considering only the tuning
// medianRTT returns the median RTT of the peerset, considering only the tuning
// peers if there are more peers available.
func (ps *peerSet) medianRTT() time.Duration {
// Gather all the currnetly measured round trip times
// Gather all the currently measured round trip times
ps.lock.RLock()
defer ps.lock.RUnlock()

Expand Down
Loading