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