Skip to content

Commit 60cd5bf

Browse files
authored
Merge pull request bnb-chain#2842 from fjl/downloader-remove-eth61
eth, eth/downloader, eth/fetcher: delete eth/61 sync code
2 parents f58ac2b + 016007b commit 60cd5bf

15 files changed

Lines changed: 119 additions & 1524 deletions

‎eth/downloader/downloader.go‎

Lines changed: 69 additions & 598 deletions
Large diffs are not rendered by default.

‎eth/downloader/downloader_test.go‎

Lines changed: 4 additions & 118 deletions
Large diffs are not rendered by default.

‎eth/downloader/metrics.go‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ import (
2323
)
2424

2525
var (
26-
hashInMeter = metrics.NewMeter("eth/downloader/hashes/in")
27-
hashReqTimer = metrics.NewTimer("eth/downloader/hashes/req")
28-
hashDropMeter = metrics.NewMeter("eth/downloader/hashes/drop")
29-
hashTimeoutMeter = metrics.NewMeter("eth/downloader/hashes/timeout")
30-
31-
blockInMeter = metrics.NewMeter("eth/downloader/blocks/in")
32-
blockReqTimer = metrics.NewTimer("eth/downloader/blocks/req")
33-
blockDropMeter = metrics.NewMeter("eth/downloader/blocks/drop")
34-
blockTimeoutMeter = metrics.NewMeter("eth/downloader/blocks/timeout")
35-
3626
headerInMeter = metrics.NewMeter("eth/downloader/headers/in")
3727
headerReqTimer = metrics.NewTimer("eth/downloader/headers/req")
3828
headerDropMeter = metrics.NewMeter("eth/downloader/headers/drop")

‎eth/downloader/peer.go‎

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ const (
3737
measurementImpact = 0.1 // The impact a single measurement has on a peer's final throughput value.
3838
)
3939

40-
// Hash and block fetchers belonging to eth/61 and below
41-
type relativeHashFetcherFn func(common.Hash) error
42-
type absoluteHashFetcherFn func(uint64, int) error
43-
type blockFetcherFn func([]common.Hash) error
44-
4540
// Block header and body fetchers belonging to eth/62 and above
4641
type relativeHeaderFetcherFn func(common.Hash, int, int, bool) error
4742
type absoluteHeaderFetcherFn func(uint64, int, int, bool) error
@@ -79,10 +74,6 @@ type peer struct {
7974

8075
lacking map[common.Hash]struct{} // Set of hashes not to request (didn't have previously)
8176

82-
getRelHashes relativeHashFetcherFn // [eth/61] Method to retrieve a batch of hashes from an origin hash
83-
getAbsHashes absoluteHashFetcherFn // [eth/61] Method to retrieve a batch of hashes from an absolute position
84-
getBlocks blockFetcherFn // [eth/61] Method to retrieve a batch of blocks
85-
8677
getRelHeaders relativeHeaderFetcherFn // [eth/62] Method to retrieve a batch of headers from an origin hash
8778
getAbsHeaders absoluteHeaderFetcherFn // [eth/62] Method to retrieve a batch of headers from an absolute position
8879
getBlockBodies blockBodyFetcherFn // [eth/62] Method to retrieve a batch of block bodies
@@ -97,18 +88,13 @@ type peer struct {
9788
// newPeer create a new downloader peer, with specific hash and block retrieval
9889
// mechanisms.
9990
func newPeer(id string, version int, head common.Hash,
100-
getRelHashes relativeHashFetcherFn, getAbsHashes absoluteHashFetcherFn, getBlocks blockFetcherFn, // eth/61 callbacks, remove when upgrading
10191
getRelHeaders relativeHeaderFetcherFn, getAbsHeaders absoluteHeaderFetcherFn, getBlockBodies blockBodyFetcherFn,
10292
getReceipts receiptFetcherFn, getNodeData stateFetcherFn) *peer {
10393
return &peer{
10494
id: id,
10595
head: head,
10696
lacking: make(map[common.Hash]struct{}),
10797

108-
getRelHashes: getRelHashes,
109-
getAbsHashes: getAbsHashes,
110-
getBlocks: getBlocks,
111-
11298
getRelHeaders: getRelHeaders,
11399
getAbsHeaders: getAbsHeaders,
114100
getBlockBodies: getBlockBodies,
@@ -138,28 +124,6 @@ func (p *peer) Reset() {
138124
p.lacking = make(map[common.Hash]struct{})
139125
}
140126

141-
// Fetch61 sends a block retrieval request to the remote peer.
142-
func (p *peer) Fetch61(request *fetchRequest) error {
143-
// Sanity check the protocol version
144-
if p.version != 61 {
145-
panic(fmt.Sprintf("block fetch [eth/61] requested on eth/%d", p.version))
146-
}
147-
// Short circuit if the peer is already fetching
148-
if !atomic.CompareAndSwapInt32(&p.blockIdle, 0, 1) {
149-
return errAlreadyFetching
150-
}
151-
p.blockStarted = time.Now()
152-
153-
// Convert the hash set to a retrievable slice
154-
hashes := make([]common.Hash, 0, len(request.Hashes))
155-
for hash, _ := range request.Hashes {
156-
hashes = append(hashes, hash)
157-
}
158-
go p.getBlocks(hashes)
159-
160-
return nil
161-
}
162-
163127
// FetchHeaders sends a header retrieval request to the remote peer.
164128
func (p *peer) FetchHeaders(from uint64, count int) error {
165129
// Sanity check the protocol version
@@ -481,20 +445,6 @@ func (ps *peerSet) AllPeers() []*peer {
481445
return list
482446
}
483447

484-
// BlockIdlePeers retrieves a flat list of all the currently idle peers within the
485-
// active peer set, ordered by their reputation.
486-
func (ps *peerSet) BlockIdlePeers() ([]*peer, int) {
487-
idle := func(p *peer) bool {
488-
return atomic.LoadInt32(&p.blockIdle) == 0
489-
}
490-
throughput := func(p *peer) float64 {
491-
p.lock.RLock()
492-
defer p.lock.RUnlock()
493-
return p.blockThroughput
494-
}
495-
return ps.idlePeers(61, 61, idle, throughput)
496-
}
497-
498448
// HeaderIdlePeers retrieves a flat list of all the currently header-idle peers
499449
// within the active peer set, ordered by their reputation.
500450
func (ps *peerSet) HeaderIdlePeers() ([]*peer, int) {

‎eth/downloader/queue.go‎

Lines changed: 2 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ var (
4545

4646
var (
4747
errNoFetchesPending = errors.New("no fetches pending")
48-
errStateSyncPending = errors.New("state trie sync already scheduled")
4948
errStaleDelivery = errors.New("stale delivery")
5049
)
5150

@@ -74,18 +73,13 @@ type queue struct {
7473
mode SyncMode // Synchronisation mode to decide on the block parts to schedule for fetching
7574
fastSyncPivot uint64 // Block number where the fast sync pivots into archive synchronisation mode
7675

77-
hashPool map[common.Hash]int // [eth/61] Pending hashes, mapping to their insertion index (priority)
78-
hashQueue *prque.Prque // [eth/61] Priority queue of the block hashes to fetch
79-
hashCounter int // [eth/61] Counter indexing the added hashes to ensure retrieval order
80-
8176
headerHead common.Hash // [eth/62] Hash of the last queued header to verify order
8277

8378
// Headers are "special", they download in batches, supported by a skeleton chain
8479
headerTaskPool map[uint64]*types.Header // [eth/62] Pending header retrieval tasks, mapping starting indexes to skeleton headers
8580
headerTaskQueue *prque.Prque // [eth/62] Priority queue of the skeleton indexes to fetch the filling headers for
8681
headerPeerMiss map[string]map[uint64]struct{} // [eth/62] Set of per-peer header batches known to be unavailable
8782
headerPendPool map[string]*fetchRequest // [eth/62] Currently pending header retrieval operations
88-
headerDonePool map[uint64]struct{} // [eth/62] Set of the completed header fetches
8983
headerResults []*types.Header // [eth/62] Result cache accumulating the completed headers
9084
headerProced int // [eth/62] Number of headers already processed from the results
9185
headerOffset uint64 // [eth/62] Number of the first header in the result cache
@@ -124,8 +118,6 @@ type queue struct {
124118
func newQueue(stateDb ethdb.Database) *queue {
125119
lock := new(sync.Mutex)
126120
return &queue{
127-
hashPool: make(map[common.Hash]int),
128-
hashQueue: prque.New(),
129121
headerPendPool: make(map[string]*fetchRequest),
130122
headerContCh: make(chan bool),
131123
blockTaskPool: make(map[common.Hash]*types.Header),
@@ -158,10 +150,6 @@ func (q *queue) Reset() {
158150
q.mode = FullSync
159151
q.fastSyncPivot = 0
160152

161-
q.hashPool = make(map[common.Hash]int)
162-
q.hashQueue.Reset()
163-
q.hashCounter = 0
164-
165153
q.headerHead = common.Hash{}
166154

167155
q.headerPendPool = make(map[string]*fetchRequest)
@@ -208,7 +196,7 @@ func (q *queue) PendingBlocks() int {
208196
q.lock.Lock()
209197
defer q.lock.Unlock()
210198

211-
return q.hashQueue.Size() + q.blockTaskQueue.Size()
199+
return q.blockTaskQueue.Size()
212200
}
213201

214202
// PendingReceipts retrieves the number of block receipts pending for retrieval.
@@ -272,7 +260,7 @@ func (q *queue) Idle() bool {
272260
q.lock.Lock()
273261
defer q.lock.Unlock()
274262

275-
queued := q.hashQueue.Size() + q.blockTaskQueue.Size() + q.receiptTaskQueue.Size() + q.stateTaskQueue.Size()
263+
queued := q.blockTaskQueue.Size() + q.receiptTaskQueue.Size() + q.stateTaskQueue.Size()
276264
pending := len(q.blockPendPool) + len(q.receiptPendPool) + len(q.statePendPool)
277265
cached := len(q.blockDonePool) + len(q.receiptDonePool)
278266

@@ -323,34 +311,6 @@ func (q *queue) ShouldThrottleReceipts() bool {
323311
return pending >= len(q.resultCache)-len(q.receiptDonePool)
324312
}
325313

326-
// Schedule61 adds a set of hashes for the download queue for scheduling, returning
327-
// the new hashes encountered.
328-
func (q *queue) Schedule61(hashes []common.Hash, fifo bool) []common.Hash {
329-
q.lock.Lock()
330-
defer q.lock.Unlock()
331-
332-
// Insert all the hashes prioritised in the arrival order
333-
inserts := make([]common.Hash, 0, len(hashes))
334-
for _, hash := range hashes {
335-
// Skip anything we already have
336-
if old, ok := q.hashPool[hash]; ok {
337-
glog.V(logger.Warn).Infof("Hash %x already scheduled at index %v", hash, old)
338-
continue
339-
}
340-
// Update the counters and insert the hash
341-
q.hashCounter = q.hashCounter + 1
342-
inserts = append(inserts, hash)
343-
344-
q.hashPool[hash] = q.hashCounter
345-
if fifo {
346-
q.hashQueue.Push(hash, -float32(q.hashCounter)) // Lowest gets schedules first
347-
} else {
348-
q.hashQueue.Push(hash, float32(q.hashCounter)) // Highest gets schedules first
349-
}
350-
}
351-
return inserts
352-
}
353-
354314
// ScheduleSkeleton adds a batch of header retrieval tasks to the queue to fill
355315
// up an already retrieved header skeleton.
356316
func (q *queue) ScheduleSkeleton(from uint64, skeleton []*types.Header) {
@@ -550,15 +510,6 @@ func (q *queue) ReserveHeaders(p *peer, count int) *fetchRequest {
550510
return request
551511
}
552512

553-
// ReserveBlocks reserves a set of block hashes for the given peer, skipping any
554-
// previously failed download.
555-
func (q *queue) ReserveBlocks(p *peer, count int) *fetchRequest {
556-
q.lock.Lock()
557-
defer q.lock.Unlock()
558-
559-
return q.reserveHashes(p, count, q.hashQueue, nil, q.blockPendPool, len(q.resultCache)-len(q.blockDonePool))
560-
}
561-
562513
// ReserveNodeData reserves a set of node data hashes for the given peer, skipping
563514
// any previously failed download.
564515
func (q *queue) ReserveNodeData(p *peer, count int) *fetchRequest {
@@ -753,11 +704,6 @@ func (q *queue) CancelHeaders(request *fetchRequest) {
753704
q.cancel(request, q.headerTaskQueue, q.headerPendPool)
754705
}
755706

756-
// CancelBlocks aborts a fetch request, returning all pending hashes to the queue.
757-
func (q *queue) CancelBlocks(request *fetchRequest) {
758-
q.cancel(request, q.hashQueue, q.blockPendPool)
759-
}
760-
761707
// CancelBodies aborts a body fetch request, returning all pending headers to the
762708
// task queue.
763709
func (q *queue) CancelBodies(request *fetchRequest) {
@@ -801,9 +747,6 @@ func (q *queue) Revoke(peerId string) {
801747
defer q.lock.Unlock()
802748

803749
if request, ok := q.blockPendPool[peerId]; ok {
804-
for hash, index := range request.Hashes {
805-
q.hashQueue.Push(hash, float32(index))
806-
}
807750
for _, header := range request.Headers {
808751
q.blockTaskQueue.Push(header, -float32(header.Number.Uint64()))
809752
}
@@ -832,15 +775,6 @@ func (q *queue) ExpireHeaders(timeout time.Duration) map[string]int {
832775
return q.expire(timeout, q.headerPendPool, q.headerTaskQueue, headerTimeoutMeter)
833776
}
834777

835-
// ExpireBlocks checks for in flight requests that exceeded a timeout allowance,
836-
// canceling them and returning the responsible peers for penalisation.
837-
func (q *queue) ExpireBlocks(timeout time.Duration) map[string]int {
838-
q.lock.Lock()
839-
defer q.lock.Unlock()
840-
841-
return q.expire(timeout, q.blockPendPool, q.hashQueue, blockTimeoutMeter)
842-
}
843-
844778
// ExpireBodies checks for in flight block body requests that exceeded a timeout
845779
// allowance, canceling them and returning the responsible peers for penalisation.
846780
func (q *queue) ExpireBodies(timeout time.Duration) map[string]int {
@@ -907,74 +841,6 @@ func (q *queue) expire(timeout time.Duration, pendPool map[string]*fetchRequest,
907841
return expiries
908842
}
909843

910-
// DeliverBlocks injects a block retrieval response into the download queue. The
911-
// method returns the number of blocks accepted from the delivery and also wakes
912-
// any threads waiting for data delivery.
913-
func (q *queue) DeliverBlocks(id string, blocks []*types.Block) (int, error) {
914-
q.lock.Lock()
915-
defer q.lock.Unlock()
916-
917-
// Short circuit if the blocks were never requested
918-
request := q.blockPendPool[id]
919-
if request == nil {
920-
return 0, errNoFetchesPending
921-
}
922-
blockReqTimer.UpdateSince(request.Time)
923-
delete(q.blockPendPool, id)
924-
925-
// If no blocks were retrieved, mark them as unavailable for the origin peer
926-
if len(blocks) == 0 {
927-
for hash, _ := range request.Hashes {
928-
request.Peer.MarkLacking(hash)
929-
}
930-
}
931-
// Iterate over the downloaded blocks and add each of them
932-
accepted, errs := 0, make([]error, 0)
933-
for _, block := range blocks {
934-
// Skip any blocks that were not requested
935-
hash := block.Hash()
936-
if _, ok := request.Hashes[hash]; !ok {
937-
errs = append(errs, fmt.Errorf("non-requested block %x", hash))
938-
continue
939-
}
940-
// Reconstruct the next result if contents match up
941-
index := int(block.Number().Int64() - int64(q.resultOffset))
942-
if index >= len(q.resultCache) || index < 0 {
943-
errs = []error{errInvalidChain}
944-
break
945-
}
946-
q.resultCache[index] = &fetchResult{
947-
Header: block.Header(),
948-
Transactions: block.Transactions(),
949-
Uncles: block.Uncles(),
950-
}
951-
q.blockDonePool[block.Hash()] = struct{}{}
952-
953-
delete(request.Hashes, hash)
954-
delete(q.hashPool, hash)
955-
accepted++
956-
}
957-
// Return all failed or missing fetches to the queue
958-
for hash, index := range request.Hashes {
959-
q.hashQueue.Push(hash, float32(index))
960-
}
961-
// Wake up WaitResults
962-
if accepted > 0 {
963-
q.active.Signal()
964-
}
965-
// If none of the blocks were good, it's a stale delivery
966-
switch {
967-
case len(errs) == 0:
968-
return accepted, nil
969-
case len(errs) == 1 && (errs[0] == errInvalidChain || errs[0] == errInvalidBlock):
970-
return accepted, errs[0]
971-
case len(errs) == len(blocks):
972-
return accepted, errStaleDelivery
973-
default:
974-
return accepted, fmt.Errorf("multiple failures: %v", errs)
975-
}
976-
}
977-
978844
// DeliverHeaders injects a header retrieval response into the header results
979845
// cache. This method either accepts all headers it received, or none of them
980846
// if they do not map correctly to the skeleton.

‎eth/downloader/types.go‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,6 @@ type dataPack interface {
7373
Stats() string
7474
}
7575

76-
// hashPack is a batch of block hashes returned by a peer (eth/61).
77-
type hashPack struct {
78-
peerId string
79-
hashes []common.Hash
80-
}
81-
82-
func (p *hashPack) PeerId() string { return p.peerId }
83-
func (p *hashPack) Items() int { return len(p.hashes) }
84-
func (p *hashPack) Stats() string { return fmt.Sprintf("%d", len(p.hashes)) }
85-
86-
// blockPack is a batch of blocks returned by a peer (eth/61).
87-
type blockPack struct {
88-
peerId string
89-
blocks []*types.Block
90-
}
91-
92-
func (p *blockPack) PeerId() string { return p.peerId }
93-
func (p *blockPack) Items() int { return len(p.blocks) }
94-
func (p *blockPack) Stats() string { return fmt.Sprintf("%d", len(p.blocks)) }
95-
9676
// headerPack is a batch of block headers returned by a peer.
9777
type headerPack struct {
9878
peerId string

0 commit comments

Comments
 (0)