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
44147d05
Commit
44147d05
authored
Jun 09, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth: fix data race accessing peer.recentHash
parent
05cae69d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
12 deletions
+32
-12
handler.go
eth/handler.go
+3
-3
peer.go
eth/peer.go
+25
-6
sync.go
eth/sync.go
+4
-3
No files found.
eth/handler.go
View file @
44147d05
...
@@ -157,7 +157,7 @@ func (pm *ProtocolManager) handle(p *peer) error {
...
@@ -157,7 +157,7 @@ func (pm *ProtocolManager) handle(p *peer) error {
}
}
defer
pm
.
removePeer
(
p
.
id
)
defer
pm
.
removePeer
(
p
.
id
)
if
err
:=
pm
.
downloader
.
RegisterPeer
(
p
.
id
,
p
.
recentHash
,
p
.
requestHashes
,
p
.
requestBlocks
);
err
!=
nil
{
if
err
:=
pm
.
downloader
.
RegisterPeer
(
p
.
id
,
p
.
Head
()
,
p
.
requestHashes
,
p
.
requestBlocks
);
err
!=
nil
{
return
err
return
err
}
}
// propagate existing transactions. new transactions appearing
// propagate existing transactions. new transactions appearing
...
@@ -303,7 +303,7 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
...
@@ -303,7 +303,7 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
// Mark the hashes as present at the remote node
// Mark the hashes as present at the remote node
for
_
,
hash
:=
range
hashes
{
for
_
,
hash
:=
range
hashes
{
p
.
blockHashes
.
Add
(
hash
)
p
.
blockHashes
.
Add
(
hash
)
p
.
recentHash
=
hash
p
.
SetHead
(
hash
)
}
}
// Schedule all the unknown hashes for retrieval
// Schedule all the unknown hashes for retrieval
unknown
:=
make
([]
common
.
Hash
,
0
,
len
(
hashes
))
unknown
:=
make
([]
common
.
Hash
,
0
,
len
(
hashes
))
...
@@ -354,7 +354,7 @@ func (pm *ProtocolManager) importBlock(p *peer, block *types.Block, td *big.Int)
...
@@ -354,7 +354,7 @@ func (pm *ProtocolManager) importBlock(p *peer, block *types.Block, td *big.Int)
// Mark the block as present at the remote node (don't duplicate already held data)
// Mark the block as present at the remote node (don't duplicate already held data)
p
.
blockHashes
.
Add
(
hash
)
p
.
blockHashes
.
Add
(
hash
)
p
.
recentHash
=
hash
p
.
SetHead
(
hash
)
if
td
!=
nil
{
if
td
!=
nil
{
p
.
td
=
td
p
.
td
=
td
}
}
...
...
eth/peer.go
View file @
44147d05
...
@@ -40,9 +40,11 @@ type peer struct {
...
@@ -40,9 +40,11 @@ type peer struct {
protv
,
netid
int
protv
,
netid
int
recentHash
common
.
Hash
id
string
id
string
td
*
big
.
Int
td
*
big
.
Int
head
common
.
Hash
headLock
sync
.
RWMutex
genesis
,
ourHash
common
.
Hash
genesis
,
ourHash
common
.
Hash
ourTd
*
big
.
Int
ourTd
*
big
.
Int
...
@@ -51,14 +53,14 @@ type peer struct {
...
@@ -51,14 +53,14 @@ type peer struct {
blockHashes
*
set
.
Set
blockHashes
*
set
.
Set
}
}
func
newPeer
(
protv
,
netid
int
,
genesis
,
recentHash
common
.
Hash
,
td
*
big
.
Int
,
p
*
p2p
.
Peer
,
rw
p2p
.
MsgReadWriter
)
*
peer
{
func
newPeer
(
protv
,
netid
int
,
genesis
,
head
common
.
Hash
,
td
*
big
.
Int
,
p
*
p2p
.
Peer
,
rw
p2p
.
MsgReadWriter
)
*
peer
{
id
:=
p
.
ID
()
id
:=
p
.
ID
()
return
&
peer
{
return
&
peer
{
Peer
:
p
,
Peer
:
p
,
rw
:
rw
,
rw
:
rw
,
genesis
:
genesis
,
genesis
:
genesis
,
ourHash
:
recentHash
,
ourHash
:
head
,
ourTd
:
td
,
ourTd
:
td
,
protv
:
protv
,
protv
:
protv
,
netid
:
netid
,
netid
:
netid
,
...
@@ -68,6 +70,23 @@ func newPeer(protv, netid int, genesis, recentHash common.Hash, td *big.Int, p *
...
@@ -68,6 +70,23 @@ func newPeer(protv, netid int, genesis, recentHash common.Hash, td *big.Int, p *
}
}
}
}
// Head retrieves a copy of the current head (most recent) hash of the peer.
func
(
p
*
peer
)
Head
()
(
hash
common
.
Hash
)
{
p
.
headLock
.
RLock
()
defer
p
.
headLock
.
RUnlock
()
copy
(
hash
[
:
],
p
.
head
[
:
])
return
hash
}
// SetHead updates the head (most recent) hash of the peer.
func
(
p
*
peer
)
SetHead
(
hash
common
.
Hash
)
{
p
.
headLock
.
Lock
()
defer
p
.
headLock
.
Unlock
()
copy
(
p
.
head
[
:
],
hash
[
:
])
}
// sendTransactions sends transactions to the peer and includes the hashes
// sendTransactions sends transactions to the peer and includes the hashes
// in it's tx hash set for future reference. The tx hash will allow the
// in it's tx hash set for future reference. The tx hash will allow the
// manager to check whether the peer has already received this particular
// manager to check whether the peer has already received this particular
...
@@ -160,7 +179,7 @@ func (p *peer) handleStatus() error {
...
@@ -160,7 +179,7 @@ func (p *peer) handleStatus() error {
// Set the total difficulty of the peer
// Set the total difficulty of the peer
p
.
td
=
status
.
TD
p
.
td
=
status
.
TD
// set the best hash of the peer
// set the best hash of the peer
p
.
recentHash
=
status
.
CurrentBlock
p
.
head
=
status
.
CurrentBlock
return
<-
errc
return
<-
errc
}
}
...
...
eth/sync.go
View file @
44147d05
...
@@ -214,14 +214,15 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
...
@@ -214,14 +214,15 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
// FIXME if we have the hash in our chain and the TD of the peer is
// FIXME if we have the hash in our chain and the TD of the peer is
// much higher than ours, something is wrong with us or the peer.
// much higher than ours, something is wrong with us or the peer.
// Check if the hash is on our own chain
// Check if the hash is on our own chain
if
pm
.
chainman
.
HasBlock
(
peer
.
recentHash
)
{
head
:=
peer
.
Head
()
if
pm
.
chainman
.
HasBlock
(
head
)
{
glog
.
V
(
logger
.
Debug
)
.
Infoln
(
"Synchronisation canceled: head already known"
)
glog
.
V
(
logger
.
Debug
)
.
Infoln
(
"Synchronisation canceled: head already known"
)
return
return
}
}
// Get the hashes from the peer (synchronously)
// Get the hashes from the peer (synchronously)
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Attempting synchronisation: %v, 0x%x"
,
peer
.
id
,
peer
.
recentHash
)
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Attempting synchronisation: %v, 0x%x"
,
peer
.
id
,
head
)
err
:=
pm
.
downloader
.
Synchronise
(
peer
.
id
,
peer
.
recentHash
)
err
:=
pm
.
downloader
.
Synchronise
(
peer
.
id
,
head
)
switch
err
{
switch
err
{
case
nil
:
case
nil
:
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Synchronisation completed"
)
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Synchronisation completed"
)
...
...
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