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
ebbd8b07
Commit
ebbd8b07
authored
May 11, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: revert to demotion, use harsher penalty
parent
685862d2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
8 deletions
+19
-8
downloader.go
eth/downloader/downloader.go
+9
-3
peer.go
eth/downloader/peer.go
+10
-5
No files found.
eth/downloader/downloader.go
View file @
ebbd8b07
...
@@ -335,7 +335,7 @@ out:
...
@@ -335,7 +335,7 @@ out:
// Deliver the received chunk of blocks, but drop the peer if invalid
// Deliver the received chunk of blocks, but drop the peer if invalid
if
err
:=
d
.
queue
.
Deliver
(
blockPack
.
peerId
,
blockPack
.
blocks
);
err
!=
nil
{
if
err
:=
d
.
queue
.
Deliver
(
blockPack
.
peerId
,
blockPack
.
blocks
);
err
!=
nil
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Failed delivery for peer %s: %v
\n
"
,
blockPack
.
peerId
,
err
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Failed delivery for peer %s: %v
\n
"
,
blockPack
.
peerId
,
err
)
d
.
peers
.
Unregister
(
blockPack
.
peerId
)
peer
.
Demote
(
)
break
break
}
}
if
glog
.
V
(
logger
.
Debug
)
{
if
glog
.
V
(
logger
.
Debug
)
{
...
@@ -358,7 +358,9 @@ out:
...
@@ -358,7 +358,9 @@ out:
// 1) Time for them to respond;
// 1) Time for them to respond;
// 2) Measure their speed;
// 2) Measure their speed;
// 3) Amount and availability.
// 3) Amount and availability.
d
.
peers
.
Unregister
(
pid
)
if
peer
:=
d
.
peers
.
Peer
(
pid
);
peer
!=
nil
{
peer
.
Demote
()
}
}
}
// After removing bad peers make sure we actually have sufficient peer left to keep downloading
// After removing bad peers make sure we actually have sufficient peer left to keep downloading
if
d
.
peers
.
Peers
()
==
0
{
if
d
.
peers
.
Peers
()
==
0
{
...
@@ -372,9 +374,13 @@ out:
...
@@ -372,9 +374,13 @@ out:
if
d
.
queue
.
Throttle
()
{
if
d
.
queue
.
Throttle
()
{
continue
continue
}
}
// Send a download request to all idle peers
// Send a download request to all idle peers
, until throttled
idlePeers
:=
d
.
peers
.
IdlePeers
()
idlePeers
:=
d
.
peers
.
IdlePeers
()
for
_
,
peer
:=
range
idlePeers
{
for
_
,
peer
:=
range
idlePeers
{
// Short circuit if throttling activated since above
if
d
.
queue
.
Throttle
()
{
break
}
// Get a possible chunk. If nil is returned no chunk
// Get a possible chunk. If nil is returned no chunk
// could be returned due to no hashes available.
// could be returned due to no hashes available.
request
:=
d
.
queue
.
Reserve
(
peer
,
maxBlockFetch
)
request
:=
d
.
queue
.
Reserve
(
peer
,
maxBlockFetch
)
...
...
eth/downloader/peer.go
View file @
ebbd8b07
...
@@ -86,10 +86,8 @@ func (p *peer) Demote() {
...
@@ -86,10 +86,8 @@ func (p *peer) Demote() {
for
{
for
{
// Calculate the new reputation value
// Calculate the new reputation value
prev
:=
atomic
.
LoadInt32
(
&
p
.
rep
)
prev
:=
atomic
.
LoadInt32
(
&
p
.
rep
)
next
:=
prev
-
2
next
:=
prev
/
2
if
next
<
0
{
next
=
0
}
// Try to update the old value
// Try to update the old value
if
atomic
.
CompareAndSwapInt32
(
&
p
.
rep
,
prev
,
next
)
{
if
atomic
.
CompareAndSwapInt32
(
&
p
.
rep
,
prev
,
next
)
{
return
return
...
@@ -177,7 +175,7 @@ func (ps *peerSet) AllPeers() []*peer {
...
@@ -177,7 +175,7 @@ func (ps *peerSet) AllPeers() []*peer {
}
}
// IdlePeers retrieves a flat list of all the currently idle peers within the
// IdlePeers retrieves a flat list of all the currently idle peers within the
// active peer set.
// active peer set
, ordered by their reputation
.
func
(
ps
*
peerSet
)
IdlePeers
()
[]
*
peer
{
func
(
ps
*
peerSet
)
IdlePeers
()
[]
*
peer
{
ps
.
lock
.
RLock
()
ps
.
lock
.
RLock
()
defer
ps
.
lock
.
RUnlock
()
defer
ps
.
lock
.
RUnlock
()
...
@@ -188,5 +186,12 @@ func (ps *peerSet) IdlePeers() []*peer {
...
@@ -188,5 +186,12 @@ func (ps *peerSet) IdlePeers() []*peer {
list
=
append
(
list
,
p
)
list
=
append
(
list
,
p
)
}
}
}
}
for
i
:=
0
;
i
<
len
(
list
);
i
++
{
for
j
:=
i
+
1
;
j
<
len
(
list
);
j
++
{
if
atomic
.
LoadInt32
(
&
list
[
i
]
.
rep
)
<
atomic
.
LoadInt32
(
&
list
[
j
]
.
rep
)
{
list
[
i
],
list
[
j
]
=
list
[
j
],
list
[
i
]
}
}
}
return
list
return
list
}
}
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