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
5cb1b414
Commit
5cb1b414
authored
Apr 02, 2015
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proper locking to prevent "parent unknown" INVALID blocks due to race in peer head info update
parent
dd1791c9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
5 deletions
+4
-5
peers.go
blockpool/peers.go
+4
-5
No files found.
blockpool/peers.go
View file @
5cb1b414
...
...
@@ -133,13 +133,10 @@ func (self *peer) addError(code int, format string, params ...interface{}) {
self
.
addToBlacklist
(
self
.
id
)
}
// caller must hold peer lock
func
(
self
*
peer
)
setChainInfo
(
td
*
big
.
Int
,
c
common
.
Hash
)
{
self
.
lock
.
Lock
()
defer
self
.
lock
.
Unlock
()
self
.
td
=
td
self
.
currentBlockHash
=
c
self
.
currentBlock
=
nil
self
.
parentHash
=
common
.
Hash
{}
self
.
headSection
=
nil
...
...
@@ -171,7 +168,7 @@ func (self *peers) requestBlocks(attempts int, hashes []common.Hash) {
defer
self
.
lock
.
RUnlock
()
peerCount
:=
len
(
self
.
peers
)
// on first attempt use the best peer
if
attempts
==
0
{
if
attempts
==
0
&&
self
.
best
!=
nil
{
plog
.
DebugDetailf
(
"request %v missing blocks from best peer <%s>"
,
len
(
hashes
),
self
.
best
.
id
)
self
.
best
.
requestBlocks
(
hashes
)
return
...
...
@@ -224,6 +221,7 @@ func (self *peers) addPeer(
if
found
{
// when called on an already connected peer, it means a newBlockMsg is received
// peer head info is updated
p
.
lock
.
Lock
()
if
p
.
currentBlockHash
!=
currentBlockHash
{
previousBlockHash
=
p
.
currentBlockHash
plog
.
Debugf
(
"addPeer: Update peer <%s> with td %v and current block %s (was %v)"
,
id
,
td
,
hex
(
currentBlockHash
),
hex
(
previousBlockHash
))
...
...
@@ -233,6 +231,7 @@ func (self *peers) addPeer(
self
.
status
.
values
.
NewBlocks
++
self
.
status
.
lock
.
Unlock
()
}
p
.
lock
.
Unlock
()
}
else
{
p
=
self
.
newPeer
(
td
,
currentBlockHash
,
id
,
requestBlockHashes
,
requestBlocks
,
peerError
)
...
...
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