good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
f8670771
Commit
f8670771
authored
Jun 9, 2015
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
eth: fix data race accessing peer.td
parent
44147d05
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
eth/handler.go
+2
-2
2 additions, 2 deletions
eth/handler.go
eth/peer.go
+30
-11
30 additions, 11 deletions
eth/peer.go
eth/sync.go
+1
-1
1 addition, 1 deletion
eth/sync.go
with
33 additions
and
14 deletions
eth/handler.go
+
2
−
2
View file @
f8670771
...
@@ -356,7 +356,7 @@ func (pm *ProtocolManager) importBlock(p *peer, block *types.Block, td *big.Int)
...
@@ -356,7 +356,7 @@ func (pm *ProtocolManager) importBlock(p *peer, block *types.Block, td *big.Int)
p
.
blockHashes
.
Add
(
hash
)
p
.
blockHashes
.
Add
(
hash
)
p
.
SetHead
(
hash
)
p
.
SetHead
(
hash
)
if
td
!=
nil
{
if
td
!=
nil
{
p
.
td
=
td
p
.
SetTd
(
td
)
}
}
// Log the block's arrival
// Log the block's arrival
_
,
chainHead
,
_
:=
pm
.
chainman
.
Status
()
_
,
chainHead
,
_
:=
pm
.
chainman
.
Status
()
...
@@ -369,7 +369,7 @@ func (pm *ProtocolManager) importBlock(p *peer, block *types.Block, td *big.Int)
...
@@ -369,7 +369,7 @@ func (pm *ProtocolManager) importBlock(p *peer, block *types.Block, td *big.Int)
})
})
// If the block's already known or its difficulty is lower than ours, drop
// If the block's already known or its difficulty is lower than ours, drop
if
pm
.
chainman
.
HasBlock
(
hash
)
{
if
pm
.
chainman
.
HasBlock
(
hash
)
{
p
.
td
=
pm
.
chainman
.
GetBlock
(
hash
)
.
Td
// update the peer's TD to the real value
p
.
SetTd
(
pm
.
chainman
.
GetBlock
(
hash
)
.
Td
)
// update the peer's TD to the real value
return
nil
return
nil
}
}
if
td
!=
nil
&&
pm
.
chainman
.
Td
()
.
Cmp
(
td
)
>
0
&&
new
(
big
.
Int
)
.
Add
(
block
.
Number
(),
big
.
NewInt
(
7
))
.
Cmp
(
pm
.
chainman
.
CurrentBlock
()
.
Number
())
<
0
{
if
td
!=
nil
&&
pm
.
chainman
.
Td
()
.
Cmp
(
td
)
>
0
&&
new
(
big
.
Int
)
.
Add
(
block
.
Number
(),
big
.
NewInt
(
7
))
.
Cmp
(
pm
.
chainman
.
CurrentBlock
()
.
Number
())
<
0
{
...
...
This diff is collapsed.
Click to expand it.
eth/peer.go
+
30
−
11
View file @
f8670771
...
@@ -41,10 +41,10 @@ type peer struct {
...
@@ -41,10 +41,10 @@ type peer struct {
protv
,
netid
int
protv
,
netid
int
id
string
id
string
td
*
big
.
Int
head
common
.
Hash
head
common
.
Hash
headLock
sync
.
RWMutex
td
*
big
.
Int
lock
sync
.
RWMutex
genesis
,
ourHash
common
.
Hash
genesis
,
ourHash
common
.
Hash
ourTd
*
big
.
Int
ourTd
*
big
.
Int
...
@@ -72,8 +72,8 @@ func newPeer(protv, netid int, genesis, head common.Hash, td *big.Int, p *p2p.Pe
...
@@ -72,8 +72,8 @@ func newPeer(protv, netid int, genesis, head common.Hash, td *big.Int, p *p2p.Pe
// Head retrieves a copy of the current head (most recent) hash of the peer.
// Head retrieves a copy of the current head (most recent) hash of the peer.
func
(
p
*
peer
)
Head
()
(
hash
common
.
Hash
)
{
func
(
p
*
peer
)
Head
()
(
hash
common
.
Hash
)
{
p
.
headL
ock
.
RLock
()
p
.
l
ock
.
RLock
()
defer
p
.
headL
ock
.
RUnlock
()
defer
p
.
l
ock
.
RUnlock
()
copy
(
hash
[
:
],
p
.
head
[
:
])
copy
(
hash
[
:
],
p
.
head
[
:
])
return
hash
return
hash
...
@@ -81,12 +81,28 @@ func (p *peer) Head() (hash common.Hash) {
...
@@ -81,12 +81,28 @@ func (p *peer) Head() (hash common.Hash) {
// SetHead updates the head (most recent) hash of the peer.
// SetHead updates the head (most recent) hash of the peer.
func
(
p
*
peer
)
SetHead
(
hash
common
.
Hash
)
{
func
(
p
*
peer
)
SetHead
(
hash
common
.
Hash
)
{
p
.
headL
ock
.
Lock
()
p
.
l
ock
.
Lock
()
defer
p
.
headL
ock
.
Unlock
()
defer
p
.
l
ock
.
Unlock
()
copy
(
p
.
head
[
:
],
hash
[
:
])
copy
(
p
.
head
[
:
],
hash
[
:
])
}
}
// Td retrieves the current total difficulty of a peer.
func
(
p
*
peer
)
Td
()
*
big
.
Int
{
p
.
lock
.
RLock
()
defer
p
.
lock
.
RUnlock
()
return
new
(
big
.
Int
)
.
Set
(
p
.
td
)
}
// SetTd updates the current total difficulty of a peer.
func
(
p
*
peer
)
SetTd
(
td
*
big
.
Int
)
{
p
.
lock
.
Lock
()
defer
p
.
lock
.
Unlock
()
p
.
td
.
Set
(
td
)
}
// 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
...
@@ -275,11 +291,14 @@ func (ps *peerSet) BestPeer() *peer {
...
@@ -275,11 +291,14 @@ func (ps *peerSet) BestPeer() *peer {
ps
.
lock
.
RLock
()
ps
.
lock
.
RLock
()
defer
ps
.
lock
.
RUnlock
()
defer
ps
.
lock
.
RUnlock
()
var
best
*
peer
var
(
bestPeer
*
peer
bestTd
*
big
.
Int
)
for
_
,
p
:=
range
ps
.
peers
{
for
_
,
p
:=
range
ps
.
peers
{
if
best
==
nil
||
p
.
td
.
Cmp
(
best
.
t
d
)
>
0
{
if
td
:=
p
.
Td
();
bestPeer
==
nil
||
td
.
Cmp
(
best
T
d
)
>
0
{
best
=
p
best
Peer
,
bestTd
=
p
,
td
}
}
}
}
return
best
return
best
Peer
}
}
This diff is collapsed.
Click to expand it.
eth/sync.go
+
1
−
1
View file @
f8670771
...
@@ -208,7 +208,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
...
@@ -208,7 +208,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
return
return
}
}
// Make sure the peer's TD is higher than our own. If not drop.
// Make sure the peer's TD is higher than our own. If not drop.
if
peer
.
td
.
Cmp
(
pm
.
chainman
.
Td
())
<=
0
{
if
peer
.
Td
()
.
Cmp
(
pm
.
chainman
.
Td
())
<=
0
{
return
return
}
}
// 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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment