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
b041aed6
Commit
b041aed6
authored
Jul 09, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1450 from karalabe/fix-propagation-td
eth: calculate the correct TD, only update if better
parents
cd6d703e
4f95e2f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
5 deletions
+17
-5
handler.go
eth/handler.go
+15
-3
peer.go
eth/peer.go
+2
-2
No files found.
eth/handler.go
View file @
b041aed6
...
@@ -19,6 +19,7 @@ package eth
...
@@ -19,6 +19,7 @@ package eth
import
(
import
(
"fmt"
"fmt"
"math"
"math"
"math/big"
"sync"
"sync"
"time"
"time"
...
@@ -412,8 +413,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
...
@@ -412,8 +413,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
pm
.
fetcher
.
Enqueue
(
p
.
id
,
request
.
Block
)
pm
.
fetcher
.
Enqueue
(
p
.
id
,
request
.
Block
)
// TODO: Schedule a sync to cover potential gaps (this needs proto update)
// TODO: Schedule a sync to cover potential gaps (this needs proto update)
p
.
SetTd
(
request
.
TD
)
if
request
.
TD
.
Cmp
(
p
.
Td
())
>
0
{
go
pm
.
synchronise
(
p
)
p
.
SetTd
(
request
.
TD
)
go
pm
.
synchronise
(
p
)
}
case
TxMsg
:
case
TxMsg
:
// Transactions arrived, parse all of them and deliver to the pool
// Transactions arrived, parse all of them and deliver to the pool
...
@@ -452,9 +455,18 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool) {
...
@@ -452,9 +455,18 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool) {
// If propagation is requested, send to a subset of the peer
// If propagation is requested, send to a subset of the peer
if
propagate
{
if
propagate
{
// Calculate the TD of the block (it's not imported yet, so block.Td is not valid)
var
td
*
big
.
Int
if
parent
:=
pm
.
chainman
.
GetBlock
(
block
.
ParentHash
());
parent
!=
nil
{
td
=
new
(
big
.
Int
)
.
Add
(
parent
.
Td
,
block
.
Difficulty
())
}
else
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"propagating dangling block #%d [%x]"
,
block
.
NumberU64
(),
hash
[
:
4
])
return
}
// Send the block to a subset of our peers
transfer
:=
peers
[
:
int
(
math
.
Sqrt
(
float64
(
len
(
peers
))))]
transfer
:=
peers
[
:
int
(
math
.
Sqrt
(
float64
(
len
(
peers
))))]
for
_
,
peer
:=
range
transfer
{
for
_
,
peer
:=
range
transfer
{
peer
.
SendNewBlock
(
block
)
peer
.
SendNewBlock
(
block
,
td
)
}
}
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"propagated block %x to %d peers in %v"
,
hash
[
:
4
],
len
(
transfer
),
time
.
Since
(
block
.
ReceivedAt
))
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"propagated block %x to %d peers in %v"
,
hash
[
:
4
],
len
(
transfer
),
time
.
Since
(
block
.
ReceivedAt
))
}
}
...
...
eth/peer.go
View file @
b041aed6
...
@@ -167,12 +167,12 @@ func (p *peer) SendNewBlockHashes(hashes []common.Hash) error {
...
@@ -167,12 +167,12 @@ func (p *peer) SendNewBlockHashes(hashes []common.Hash) error {
}
}
// SendNewBlock propagates an entire block to a remote peer.
// SendNewBlock propagates an entire block to a remote peer.
func
(
p
*
peer
)
SendNewBlock
(
block
*
types
.
Block
)
error
{
func
(
p
*
peer
)
SendNewBlock
(
block
*
types
.
Block
,
td
*
big
.
Int
)
error
{
propBlockOutPacketsMeter
.
Mark
(
1
)
propBlockOutPacketsMeter
.
Mark
(
1
)
propBlockOutTrafficMeter
.
Mark
(
block
.
Size
()
.
Int64
())
propBlockOutTrafficMeter
.
Mark
(
block
.
Size
()
.
Int64
())
p
.
knownBlocks
.
Add
(
block
.
Hash
())
p
.
knownBlocks
.
Add
(
block
.
Hash
())
return
p2p
.
Send
(
p
.
rw
,
NewBlockMsg
,
[]
interface
{}{
block
,
block
.
T
d
})
return
p2p
.
Send
(
p
.
rw
,
NewBlockMsg
,
[]
interface
{}{
block
,
t
d
})
}
}
// RequestHashes fetches a batch of hashes from a peer, starting at from, going
// RequestHashes fetches a batch of hashes from a peer, starting at from, going
...
...
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