Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
0a63c3e3
Unverified
Commit
0a63c3e3
authored
Feb 24, 2017
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: port over old logs from glog to log15
parent
5c8fe28b
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
137 additions
and
125 deletions
+137
-125
downloader.go
eth/downloader/downloader.go
+107
-96
modes.go
eth/downloader/modes.go
+8
-0
peer.go
eth/downloader/peer.go
+11
-18
queue.go
eth/downloader/queue.go
+11
-11
No files found.
eth/downloader/downloader.go
View file @
0a63c3e3
This diff is collapsed.
Click to expand it.
eth/downloader/modes.go
View file @
0a63c3e3
...
...
@@ -24,3 +24,11 @@ const (
FastSync
// Quickly download the headers, full sync only at the chain head
LightSync
// Download only the headers and terminate afterwards
)
// syncModeLabels contains a mapping of sync modes to textual label used by the
// logging system.
var
syncModeLabels
=
map
[
SyncMode
]
string
{
FullSync
:
"full"
,
FastSync
:
"fast"
,
LightSync
:
"light"
,
}
eth/downloader/peer.go
View file @
0a63c3e3
...
...
@@ -25,12 +25,12 @@ import (
"math"
"math/big"
"sort"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)
const
(
...
...
@@ -86,7 +86,8 @@ type peer struct {
getReceipts
receiptFetcherFn
// [eth/63] Method to retrieve a batch of block transaction receipts
getNodeData
stateFetcherFn
// [eth/63] Method to retrieve a batch of state trie data
version
int
// Eth protocol version number to switch strategies
version
int
// Eth protocol version number to switch strategies
logger
log
.
Logger
// Contextual logger to add extra infos to peer logs
lock
sync
.
RWMutex
}
...
...
@@ -94,7 +95,8 @@ type peer struct {
// mechanisms.
func
newPeer
(
id
string
,
version
int
,
currentHead
currentHeadRetrievalFn
,
getRelHeaders
relativeHeaderFetcherFn
,
getAbsHeaders
absoluteHeaderFetcherFn
,
getBlockBodies
blockBodyFetcherFn
,
getReceipts
receiptFetcherFn
,
getNodeData
stateFetcherFn
)
*
peer
{
getReceipts
receiptFetcherFn
,
getNodeData
stateFetcherFn
,
logger
log
.
Logger
)
*
peer
{
return
&
peer
{
id
:
id
,
lacking
:
make
(
map
[
common
.
Hash
]
struct
{}),
...
...
@@ -108,6 +110,7 @@ func newPeer(id string, version int, currentHead currentHeadRetrievalFn,
getNodeData
:
getNodeData
,
version
:
version
,
logger
:
logger
,
}
}
...
...
@@ -268,6 +271,11 @@ func (p *peer) setIdle(started time.Time, delivered int, throughput *float64, id
*
throughput
=
(
1
-
measurementImpact
)
*
(
*
throughput
)
+
measurementImpact
*
measured
p
.
rtt
=
time
.
Duration
((
1
-
measurementImpact
)
*
float64
(
p
.
rtt
)
+
measurementImpact
*
float64
(
elapsed
))
p
.
logger
.
Trace
(
"Peer throughput measurements updated"
,
"hps"
,
p
.
headerThroughput
,
"bps"
,
p
.
blockThroughput
,
"rps"
,
p
.
receiptThroughput
,
"sps"
,
p
.
stateThroughput
,
"miss"
,
len
(
p
.
lacking
),
"rtt"
,
p
.
rtt
)
}
// HeaderCapacity retrieves the peers header download allowance based on its
...
...
@@ -332,21 +340,6 @@ func (p *peer) Lacks(hash common.Hash) bool {
return
ok
}
// String implements fmt.Stringer.
func
(
p
*
peer
)
String
()
string
{
p
.
lock
.
RLock
()
defer
p
.
lock
.
RUnlock
()
return
fmt
.
Sprintf
(
"Peer %s [%s]"
,
p
.
id
,
strings
.
Join
([]
string
{
fmt
.
Sprintf
(
"hs %3.2f/s"
,
p
.
headerThroughput
),
fmt
.
Sprintf
(
"bs %3.2f/s"
,
p
.
blockThroughput
),
fmt
.
Sprintf
(
"rs %3.2f/s"
,
p
.
receiptThroughput
),
fmt
.
Sprintf
(
"ss %3.2f/s"
,
p
.
stateThroughput
),
fmt
.
Sprintf
(
"miss %4d"
,
len
(
p
.
lacking
)),
fmt
.
Sprintf
(
"rtt %v"
,
p
.
rtt
),
},
", "
))
}
// peerSet represents the collection of active peer participating in the chain
// download procedure.
type
peerSet
struct
{
...
...
eth/downloader/queue.go
View file @
0a63c3e3
...
...
@@ -364,20 +364,20 @@ func (q *queue) Schedule(headers []*types.Header, from uint64) []*types.Header {
// Make sure chain order is honoured and preserved throughout
hash
:=
header
.
Hash
()
if
header
.
Number
==
nil
||
header
.
Number
.
Uint64
()
!=
from
{
log
.
Warn
(
fmt
.
Sprintf
(
"Header #%v [%x…] broke chain ordering, expected %d"
,
header
.
Number
,
hash
[
:
4
],
from
)
)
log
.
Warn
(
"Header broke chain ordering"
,
"number"
,
header
.
Number
,
"hash"
,
hash
.
Hex
()[
2
:
10
],
"expected"
,
from
)
break
}
if
q
.
headerHead
!=
(
common
.
Hash
{})
&&
q
.
headerHead
!=
header
.
ParentHash
{
log
.
Warn
(
fmt
.
Sprintf
(
"Header #%v [%x…] broke chain ancestry"
,
header
.
Number
,
hash
[
:
4
])
)
log
.
Warn
(
"Header broke chain ancestry"
,
"number"
,
header
.
Number
,
"hash"
,
hash
.
Hex
()[
2
:
10
]
)
break
}
// Make sure no duplicate requests are executed
if
_
,
ok
:=
q
.
blockTaskPool
[
hash
];
ok
{
log
.
Warn
(
fmt
.
Sprintf
(
"Header #%d [%x…] already scheduled for block fetch"
,
header
.
Number
.
Uint64
(),
hash
[
:
4
])
)
log
.
Warn
(
"Header already scheduled for block fetch"
,
"number"
,
header
.
Number
,
"hash"
,
hash
.
Hex
()[
2
:
10
]
)
continue
}
if
_
,
ok
:=
q
.
receiptTaskPool
[
hash
];
ok
{
log
.
Warn
(
fmt
.
Sprintf
(
"Header #%d [%x…] already scheduled for receipt fetch"
,
header
.
Number
.
Uint64
(),
hash
[
:
4
])
)
log
.
Warn
(
"Header already scheduled for receipt fetch"
,
"number"
,
header
.
Number
,
"hash"
,
hash
.
Hex
()[
2
:
10
]
)
continue
}
// Queue the header for content retrieval
...
...
@@ -391,7 +391,7 @@ func (q *queue) Schedule(headers []*types.Header, from uint64) []*types.Header {
}
if
q
.
mode
==
FastSync
&&
header
.
Number
.
Uint64
()
==
q
.
fastSyncPivot
{
// Pivoting point of the fast sync, switch the state retrieval to this
log
.
Debug
(
fmt
.
Sprintf
(
"Switching state downloads to %d [%x…]"
,
header
.
Number
.
Uint64
(),
header
.
Hash
()
.
Bytes
()[
:
4
])
)
log
.
Debug
(
"Switching state downloads to new block"
,
"number"
,
header
.
Number
,
"hash"
,
hash
.
Hex
()[
2
:
10
]
)
q
.
stateTaskIndex
=
0
q
.
stateTaskPool
=
make
(
map
[
common
.
Hash
]
int
)
...
...
@@ -872,10 +872,10 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh
accepted
:=
len
(
headers
)
==
MaxHeaderFetch
if
accepted
{
if
headers
[
0
]
.
Number
.
Uint64
()
!=
request
.
From
{
log
.
Trace
(
fmt
.
Sprintf
(
"Peer %s: first header #%v [%x…] broke chain ordering, expected %d"
,
id
,
headers
[
0
]
.
Number
,
headers
[
0
]
.
Hash
()
.
Bytes
()[
:
4
],
request
.
From
)
)
log
.
Trace
(
"First header broke chain ordering"
,
"peer"
,
id
,
"number"
,
headers
[
0
]
.
Number
,
"hash"
,
headers
[
0
]
.
Hash
()
.
Hex
()[
2
:
10
],
request
.
From
)
accepted
=
false
}
else
if
headers
[
len
(
headers
)
-
1
]
.
Hash
()
!=
target
{
log
.
Trace
(
fmt
.
Sprintf
(
"Peer %s: last header #%v [%x…] broke skeleton structure, expected %x"
,
id
,
headers
[
len
(
headers
)
-
1
]
.
Number
,
headers
[
len
(
headers
)
-
1
]
.
Hash
()
.
Bytes
()[
:
4
],
target
[
:
4
])
)
log
.
Trace
(
"Last header broke skeleton structure "
,
"peer"
,
id
,
"number"
,
headers
[
len
(
headers
)
-
1
]
.
Number
,
"hash"
,
headers
[
len
(
headers
)
-
1
]
.
Hash
()
.
Hex
()[
2
:
10
],
"expected"
,
target
.
Hex
()[
2
:
10
]
)
accepted
=
false
}
}
...
...
@@ -883,12 +883,12 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh
for
i
,
header
:=
range
headers
[
1
:
]
{
hash
:=
header
.
Hash
()
if
want
:=
request
.
From
+
1
+
uint64
(
i
);
header
.
Number
.
Uint64
()
!=
want
{
log
.
Warn
(
fmt
.
Sprintf
(
"Peer %s: header #%v [%x…] broke chain ordering, expected %d"
,
id
,
header
.
Number
,
hash
[
:
4
],
want
)
)
log
.
Warn
(
"Header broke chain ordering"
,
"peer"
,
id
,
"number"
,
header
.
Number
,
"hash"
,
hash
.
Hex
()[
2
:
10
],
"expected"
,
want
)
accepted
=
false
break
}
if
headers
[
i
]
.
Hash
()
!=
header
.
ParentHash
{
log
.
Warn
(
fmt
.
Sprintf
(
"Peer %s: header #%v [%x…] broke chain ancestry"
,
id
,
header
.
Number
,
hash
[
:
4
])
)
log
.
Warn
(
"Header broke chain ancestry"
,
"peer"
,
id
,
"number"
,
header
.
Number
,
"hash"
,
hash
.
Hex
()[
2
:
10
]
)
accepted
=
false
break
}
...
...
@@ -896,7 +896,7 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh
}
// If the batch of headers wasn't accepted, mark as unavailable
if
!
accepted
{
log
.
Trace
(
fmt
.
Sprintf
(
"Peer %s: skeleton filling from header #%d not accepted"
,
id
,
request
.
From
)
)
log
.
Trace
(
"Skeleton filling not accepted"
,
"peer"
,
id
,
"from"
,
request
.
From
)
miss
:=
q
.
headerPeerMiss
[
id
]
if
miss
==
nil
{
...
...
@@ -923,7 +923,7 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh
select
{
case
headerProcCh
<-
process
:
log
.
Trace
(
fmt
.
Sprintf
(
"%s: pre-scheduled %d headers from #%v"
,
id
,
len
(
process
),
process
[
0
]
.
Number
)
)
log
.
Trace
(
"Pre-scheduled new headers"
,
"peer"
,
id
,
"count"
,
len
(
process
),
"from"
,
process
[
0
]
.
Number
)
q
.
headerProced
+=
len
(
process
)
default
:
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment