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
5e7db8f5
Commit
5e7db8f5
authored
Jun 29, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1353 from karalabe/fix-double-fetch
eth/fetcher: don't double filter/fetch the same block
parents
a0191910
a7d22658
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
fetcher.go
eth/fetcher/fetcher.go
+17
-5
No files found.
eth/fetcher/fetcher.go
View file @
5e7db8f5
...
...
@@ -7,6 +7,8 @@ import (
"math/rand"
"time"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/logger"
...
...
@@ -104,6 +106,7 @@ type Fetcher struct {
broadcastMeter
metrics
.
Meter
// Counter for metering the inbound propagations
broadcastTimer
metrics
.
Timer
// Counter and timer for metering the block forwarding
discardMeter
metrics
.
Meter
// Counter for metering the discarded blocks
futureMeter
metrics
.
Meter
// Counter for metering future blocks
}
// New creates a block fetcher to retrieve blocks based on hash announcements.
...
...
@@ -131,6 +134,7 @@ func New(getBlock blockRetrievalFn, validateBlock blockValidatorFn, broadcastBlo
broadcastMeter
:
metrics
.
GetOrRegisterMeter
(
"eth/sync/RemoteBroadcasts"
,
metrics
.
DefaultRegistry
),
broadcastTimer
:
metrics
.
GetOrRegisterTimer
(
"eth/sync/LocalBroadcasts"
,
metrics
.
DefaultRegistry
),
discardMeter
:
metrics
.
GetOrRegisterMeter
(
"eth/sync/DiscardedBlocks"
,
metrics
.
DefaultRegistry
),
futureMeter
:
metrics
.
GetOrRegisterMeter
(
"eth/sync/FutureBlocks"
,
metrics
.
DefaultRegistry
),
}
}
...
...
@@ -323,7 +327,7 @@ func (f *Fetcher) loop() {
hash
:=
block
.
Hash
()
// Filter explicitly requested blocks from hash announcements
if
_
,
ok
:=
f
.
fetching
[
hash
];
ok
{
if
f
.
fetching
[
hash
]
!=
nil
&&
f
.
queued
[
hash
]
==
nil
{
// Discard if already imported by other means
if
f
.
getBlock
(
hash
)
==
nil
{
explicit
=
append
(
explicit
,
block
)
...
...
@@ -416,14 +420,22 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
return
}
// Quickly validate the header and propagate the block if it passes
if
err
:=
f
.
validateBlock
(
block
,
parent
);
err
!=
nil
{
switch
err
:=
f
.
validateBlock
(
block
,
parent
);
err
{
case
nil
:
// All ok, quickly propagate to our peers
f
.
broadcastTimer
.
UpdateSince
(
block
.
ReceivedAt
)
go
f
.
broadcastBlock
(
block
,
true
)
case
core
.
BlockFutureErr
:
f
.
futureMeter
.
Mark
(
1
)
// Weird future block, don't fail, but neither propagate
default
:
// Something went very wrong, drop the peer
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Peer %s: block #%d [%x] verification failed: %v"
,
peer
,
block
.
NumberU64
(),
hash
[
:
4
],
err
)
f
.
dropPeer
(
peer
)
return
}
f
.
broadcastTimer
.
UpdateSince
(
block
.
ReceivedAt
)
go
f
.
broadcastBlock
(
block
,
true
)
// Run the actual import and log any issues
if
_
,
err
:=
f
.
insertChain
(
types
.
Blocks
{
block
});
err
!=
nil
{
glog
.
V
(
logger
.
Warn
)
.
Infof
(
"Peer %s: block #%d [%x] import failed: %v"
,
peer
,
block
.
NumberU64
(),
hash
[
:
4
],
err
)
...
...
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