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
d87f7a1e
Commit
d87f7a1e
authored
May 17, 2016
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth: skip transaction handling during fast sync
parent
adc1b503
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
14 deletions
+23
-14
handler.go
eth/handler.go
+15
-8
sync.go
eth/sync.go
+4
-3
sync_test.go
eth/sync_test.go
+4
-3
No files found.
eth/handler.go
View file @
d87f7a1e
...
...
@@ -22,6 +22,7 @@ import (
"math"
"math/big"
"sync"
"sync/atomic"
"time"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -58,7 +59,7 @@ type blockFetcherFn func([]common.Hash) error
type
ProtocolManager
struct
{
networkId
int
fastSync
bool
fastSync
uint32
txpool
txPool
blockchain
*
core
.
BlockChain
chaindb
ethdb
.
Database
...
...
@@ -87,15 +88,9 @@ type ProtocolManager struct {
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
// with the ethereum network.
func
NewProtocolManager
(
config
*
core
.
ChainConfig
,
fastSync
bool
,
networkId
int
,
mux
*
event
.
TypeMux
,
txpool
txPool
,
pow
pow
.
PoW
,
blockchain
*
core
.
BlockChain
,
chaindb
ethdb
.
Database
)
(
*
ProtocolManager
,
error
)
{
// Figure out whether to allow fast sync or not
if
fastSync
&&
blockchain
.
CurrentBlock
()
.
NumberU64
()
>
0
{
glog
.
V
(
logger
.
Info
)
.
Infof
(
"blockchain not empty, fast sync disabled"
)
fastSync
=
false
}
// Create the protocol manager with the base fields
manager
:=
&
ProtocolManager
{
networkId
:
networkId
,
fastSync
:
fastSync
,
eventMux
:
mux
,
txpool
:
txpool
,
blockchain
:
blockchain
,
...
...
@@ -106,6 +101,14 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int,
txsyncCh
:
make
(
chan
*
txsync
),
quitSync
:
make
(
chan
struct
{}),
}
// Figure out whether to allow fast sync or not
if
fastSync
&&
blockchain
.
CurrentBlock
()
.
NumberU64
()
>
0
{
glog
.
V
(
logger
.
Info
)
.
Infof
(
"blockchain not empty, fast sync disabled"
)
fastSync
=
false
}
if
fastSync
{
manager
.
fastSync
=
uint32
(
1
)
}
// Initiate a sub-protocol for every implemented version we can handle
manager
.
SubProtocols
=
make
([]
p2p
.
Protocol
,
0
,
len
(
ProtocolVersions
))
for
i
,
version
:=
range
ProtocolVersions
{
...
...
@@ -678,7 +681,11 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
case
msg
.
Code
==
TxMsg
:
// Transactions arrived, parse all of them and deliver to the pool
// Transactions arrived, make sure we have a valid chain to handle them
if
atomic
.
LoadUint32
(
&
pm
.
fastSync
)
==
1
{
break
}
// Transactions can be processed, parse all of them and deliver to the pool
var
txs
[]
*
types
.
Transaction
if
err
:=
msg
.
Decode
(
&
txs
);
err
!=
nil
{
return
errResp
(
ErrDecode
,
"msg %v: %v"
,
msg
,
err
)
...
...
eth/sync.go
View file @
d87f7a1e
...
...
@@ -18,6 +18,7 @@ package eth
import
(
"math/rand"
"sync/atomic"
"time"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -167,18 +168,18 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
}
// Otherwise try to sync with the downloader
mode
:=
downloader
.
FullSync
if
pm
.
fastSync
{
if
atomic
.
LoadUint32
(
&
pm
.
fastSync
)
==
1
{
mode
=
downloader
.
FastSync
}
if
err
:=
pm
.
downloader
.
Synchronise
(
peer
.
id
,
peer
.
Head
(),
peer
.
Td
(),
mode
);
err
!=
nil
{
return
}
// If fast sync was enabled, and we synced up, disable it
if
pm
.
fastSync
{
if
atomic
.
LoadUint32
(
&
pm
.
fastSync
)
==
1
{
// Disable fast sync if we indeed have something in our chain
if
pm
.
blockchain
.
CurrentBlock
()
.
NumberU64
()
>
0
{
glog
.
V
(
logger
.
Info
)
.
Infof
(
"fast sync complete, auto disabling"
)
pm
.
fastSync
=
false
atomic
.
StoreUint32
(
&
pm
.
fastSync
,
0
)
}
}
}
eth/sync_test.go
View file @
d87f7a1e
...
...
@@ -17,6 +17,7 @@
package
eth
import
(
"sync/atomic"
"testing"
"time"
...
...
@@ -29,12 +30,12 @@ import (
func
TestFastSyncDisabling
(
t
*
testing
.
T
)
{
// Create a pristine protocol manager, check that fast sync is left enabled
pmEmpty
:=
newTestProtocolManagerMust
(
t
,
true
,
0
,
nil
,
nil
)
if
!
pmEmpty
.
fastSync
{
if
atomic
.
LoadUint32
(
&
pmEmpty
.
fastSync
)
==
0
{
t
.
Fatalf
(
"fast sync disabled on pristine blockchain"
)
}
// Create a full protocol manager, check that fast sync gets disabled
pmFull
:=
newTestProtocolManagerMust
(
t
,
true
,
1024
,
nil
,
nil
)
if
pmFull
.
fastSync
{
if
atomic
.
LoadUint32
(
&
pmFull
.
fastSync
)
==
1
{
t
.
Fatalf
(
"fast sync not disabled on non-empty blockchain"
)
}
// Sync up the two peers
...
...
@@ -47,7 +48,7 @@ func TestFastSyncDisabling(t *testing.T) {
pmEmpty
.
synchronise
(
pmEmpty
.
peers
.
BestPeer
())
// Check that fast sync was disabled
if
pmEmpty
.
fastSync
{
if
atomic
.
LoadUint32
(
&
pmEmpty
.
fastSync
)
==
1
{
t
.
Fatalf
(
"fast sync not disabled after successful synchronisation"
)
}
}
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