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
32559cca
Commit
32559cca
authored
8 years ago
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth: don't accept transactions until we sync up with the network
parent
826efc22
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
4 deletions
+13
-4
handler.go
eth/handler.go
+10
-4
protocol_test.go
eth/protocol_test.go
+1
-0
sync.go
eth/sync.go
+2
-0
No files found.
eth/handler.go
View file @
32559cca
...
...
@@ -59,7 +59,9 @@ type blockFetcherFn func([]common.Hash) error
type
ProtocolManager
struct
{
networkId
int
fastSync
uint32
fastSync
uint32
// Flag whether fast sync is enabled (gets disabled if we already have blocks)
synced
uint32
// Flag whether we're considered synchronised (enables transaction processing)
txpool
txPool
blockchain
*
core
.
BlockChain
chaindb
ethdb
.
Database
...
...
@@ -161,7 +163,11 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int,
heighter
:=
func
()
uint64
{
return
blockchain
.
CurrentBlock
()
.
NumberU64
()
}
manager
.
fetcher
=
fetcher
.
New
(
blockchain
.
GetBlock
,
validator
,
manager
.
BroadcastBlock
,
heighter
,
manager
.
insertChain
,
manager
.
removePeer
)
inserter
:=
func
(
blocks
types
.
Blocks
)
(
int
,
error
)
{
atomic
.
StoreUint32
(
&
manager
.
synced
,
1
)
// Mark initial sync done on any fetcher import
return
manager
.
insertChain
(
blocks
)
}
manager
.
fetcher
=
fetcher
.
New
(
blockchain
.
GetBlock
,
validator
,
manager
.
BroadcastBlock
,
heighter
,
inserter
,
manager
.
removePeer
)
if
blockchain
.
Genesis
()
.
Hash
()
.
Hex
()
==
defaultGenesisHash
&&
networkId
==
1
{
glog
.
V
(
logger
.
Debug
)
.
Infoln
(
"Bad Block Reporting is enabled"
)
...
...
@@ -698,8 +704,8 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
case
msg
.
Code
==
TxMsg
:
// Transactions arrived, make sure we have a valid chain to handle them
if
atomic
.
LoadUint32
(
&
pm
.
fastSync
)
==
1
{
// Transactions arrived, make sure we have a valid
and fresh
chain to handle them
if
atomic
.
LoadUint32
(
&
pm
.
synced
)
==
0
{
break
}
// Transactions can be processed, parse all of them and deliver to the pool
...
...
This diff is collapsed.
Click to expand it.
eth/protocol_test.go
View file @
32559cca
...
...
@@ -97,6 +97,7 @@ func TestRecvTransactions63(t *testing.T) { testRecvTransactions(t, 63) }
func
testRecvTransactions
(
t
*
testing
.
T
,
protocol
int
)
{
txAdded
:=
make
(
chan
[]
*
types
.
Transaction
)
pm
:=
newTestProtocolManagerMust
(
t
,
false
,
0
,
nil
,
txAdded
)
pm
.
synced
=
1
// mark synced to accept transactions
p
,
_
:=
newTestPeer
(
"peer"
,
protocol
,
pm
,
true
)
defer
pm
.
Stop
()
defer
p
.
close
()
...
...
This diff is collapsed.
Click to expand it.
eth/sync.go
View file @
32559cca
...
...
@@ -174,6 +174,8 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
if
err
:=
pm
.
downloader
.
Synchronise
(
peer
.
id
,
peer
.
Head
(),
peer
.
Td
(),
mode
);
err
!=
nil
{
return
}
atomic
.
StoreUint32
(
&
pm
.
synced
,
1
)
// Mark initial sync done
// If fast sync was enabled, and we synced up, disable it
if
atomic
.
LoadUint32
(
&
pm
.
fastSync
)
==
1
{
// Disable fast sync if we indeed have something in our chain
...
...
This diff is collapsed.
Click to expand it.
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