aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/peer.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-07-25 20:14:14 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-07-25 20:14:14 +0800
commit1dd272080dfb49a07a87c46e18d8aeaa0fd41a08 (patch)
treeec47d1ede87ac09607689277e0b90f40712556fe /eth/downloader/peer.go
parent771655e3fee585ce4bc47dfaa279557c6c1c2421 (diff)
downloadgo-tangerine-1dd272080dfb49a07a87c46e18d8aeaa0fd41a08.tar
go-tangerine-1dd272080dfb49a07a87c46e18d8aeaa0fd41a08.tar.gz
go-tangerine-1dd272080dfb49a07a87c46e18d8aeaa0fd41a08.tar.bz2
go-tangerine-1dd272080dfb49a07a87c46e18d8aeaa0fd41a08.tar.lz
go-tangerine-1dd272080dfb49a07a87c46e18d8aeaa0fd41a08.tar.xz
go-tangerine-1dd272080dfb49a07a87c46e18d8aeaa0fd41a08.tar.zst
go-tangerine-1dd272080dfb49a07a87c46e18d8aeaa0fd41a08.zip
eth, eth/downloader: better remote head tracking
Diffstat (limited to 'eth/downloader/peer.go')
-rw-r--r--eth/downloader/peer.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/eth/downloader/peer.go b/eth/downloader/peer.go
index c2b7a52d0..b0bfc66c8 100644
--- a/eth/downloader/peer.go
+++ b/eth/downloader/peer.go
@@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"math"
+ "math/big"
"sort"
"strings"
"sync"
@@ -37,6 +38,9 @@ const (
measurementImpact = 0.1 // The impact a single measurement has on a peer's final throughput value.
)
+// Head hash and total difficulty retriever for
+type currentHeadRetrievalFn func() (common.Hash, *big.Int)
+
// Block header and body fetchers belonging to eth/62 and above
type relativeHeaderFetcherFn func(common.Hash, int, int, bool) error
type absoluteHeaderFetcherFn func(uint64, int, int, bool) error
@@ -52,8 +56,7 @@ var (
// peer represents an active peer from which hashes and blocks are retrieved.
type peer struct {
- id string // Unique identifier of the peer
- head common.Hash // Hash of the peers latest known block
+ id string // Unique identifier of the peer
headerIdle int32 // Current header activity state of the peer (idle = 0, active = 1)
blockIdle int32 // Current block activity state of the peer (idle = 0, active = 1)
@@ -74,6 +77,8 @@ type peer struct {
lacking map[common.Hash]struct{} // Set of hashes not to request (didn't have previously)
+ currentHead currentHeadRetrievalFn // Method to fetch the currently known head of the peer
+
getRelHeaders relativeHeaderFetcherFn // [eth/62] Method to retrieve a batch of headers from an origin hash
getAbsHeaders absoluteHeaderFetcherFn // [eth/62] Method to retrieve a batch of headers from an absolute position
getBlockBodies blockBodyFetcherFn // [eth/62] Method to retrieve a batch of block bodies
@@ -87,14 +92,14 @@ type peer struct {
// newPeer create a new downloader peer, with specific hash and block retrieval
// mechanisms.
-func newPeer(id string, version int, head common.Hash,
+func newPeer(id string, version int, currentHead currentHeadRetrievalFn,
getRelHeaders relativeHeaderFetcherFn, getAbsHeaders absoluteHeaderFetcherFn, getBlockBodies blockBodyFetcherFn,
getReceipts receiptFetcherFn, getNodeData stateFetcherFn) *peer {
return &peer{
id: id,
- head: head,
lacking: make(map[common.Hash]struct{}),
+ currentHead: currentHead,
getRelHeaders: getRelHeaders,
getAbsHeaders: getAbsHeaders,
getBlockBodies: getBlockBodies,