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
c57c54ce
Commit
c57c54ce
authored
Dec 09, 2016
by
Zsolt Felfoldi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth, les: defer starting LES service until ETH initial sync is finished
parent
c8130df1
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
5 deletions
+42
-5
backend.go
eth/backend.go
+2
-0
handler.go
eth/handler.go
+3
-1
sync.go
eth/sync.go
+8
-1
handler.go
les/handler.go
+2
-2
server.go
les/server.go
+27
-1
No files found.
eth/backend.go
View file @
c57c54ce
...
...
@@ -104,6 +104,7 @@ type Config struct {
type
LesServer
interface
{
Start
(
srvr
*
p2p
.
Server
)
Synced
()
Stop
()
Protocols
()
[]
p2p
.
Protocol
}
...
...
@@ -145,6 +146,7 @@ type Ethereum struct {
func
(
s
*
Ethereum
)
AddLesServer
(
ls
LesServer
)
{
s
.
lesServer
=
ls
s
.
protocolManager
.
lesServer
=
ls
}
// New creates a new Ethereum object (including the
...
...
eth/handler.go
View file @
c57c54ce
...
...
@@ -87,6 +87,8 @@ type ProtocolManager struct {
quitSync
chan
struct
{}
noMorePeers
chan
struct
{}
lesServer
LesServer
// wait group is used for graceful shutdowns during downloading
// and processing
wg
sync
.
WaitGroup
...
...
@@ -171,7 +173,7 @@ func NewProtocolManager(config *params.ChainConfig, fastSync bool, networkId int
return
blockchain
.
CurrentBlock
()
.
NumberU64
()
}
inserter
:=
func
(
blocks
types
.
Blocks
)
(
int
,
error
)
{
atomic
.
StoreUint32
(
&
manager
.
synced
,
1
)
// Mark initial sync done on any fetcher import
manager
.
setSynced
(
)
// Mark initial sync done on any fetcher import
return
manager
.
insertChain
(
blocks
)
}
manager
.
fetcher
=
fetcher
.
New
(
blockchain
.
GetBlockByHash
,
validator
,
manager
.
BroadcastBlock
,
heighter
,
inserter
,
manager
.
removePeer
)
...
...
eth/sync.go
View file @
c57c54ce
...
...
@@ -180,7 +180,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
if
err
:=
pm
.
downloader
.
Synchronise
(
peer
.
id
,
pHead
,
pTd
,
mode
);
err
!=
nil
{
return
}
atomic
.
StoreUint32
(
&
pm
.
synced
,
1
)
// Mark initial sync done
pm
.
setSynced
(
)
// Mark initial sync done
// If fast sync was enabled, and we synced up, disable it
if
atomic
.
LoadUint32
(
&
pm
.
fastSync
)
==
1
{
...
...
@@ -191,3 +191,10 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
}
}
}
// setSynced sets the synced flag and notifies the light server if present
func
(
pm
*
ProtocolManager
)
setSynced
()
{
if
atomic
.
SwapUint32
(
&
pm
.
synced
,
1
)
==
0
&&
pm
.
lesServer
!=
nil
{
pm
.
lesServer
.
Synced
()
}
}
les/handler.go
View file @
c57c54ce
...
...
@@ -267,9 +267,9 @@ func (pm *ProtocolManager) Start(srvr *p2p.Server) {
}
else
{
if
topicDisc
!=
nil
{
go
func
()
{
glog
.
V
(
logger
.
Debug
)
.
Infoln
(
"Starting registering topic"
,
string
(
lesTopic
))
glog
.
V
(
logger
.
Info
)
.
Infoln
(
"Starting registering topic"
,
string
(
lesTopic
))
topicDisc
.
RegisterTopic
(
lesTopic
,
pm
.
quitSync
)
glog
.
V
(
logger
.
Debug
)
.
Infoln
(
"Stopped registering topic"
,
string
(
lesTopic
))
glog
.
V
(
logger
.
Info
)
.
Infoln
(
"Stopped registering topic"
,
string
(
lesTopic
))
}()
}
go
func
()
{
...
...
les/server.go
View file @
c57c54ce
...
...
@@ -42,6 +42,9 @@ type LesServer struct {
fcManager
*
flowcontrol
.
ClientManager
// nil if our node is client only
fcCostStats
*
requestCostStats
defParams
*
flowcontrol
.
ServerParams
srvr
*
p2p
.
Server
synced
,
stopped
bool
lock
sync
.
Mutex
}
func
NewLesServer
(
eth
*
eth
.
Ethereum
,
config
*
eth
.
Config
)
(
*
LesServer
,
error
)
{
...
...
@@ -67,12 +70,35 @@ func (s *LesServer) Protocols() []p2p.Protocol {
return
s
.
protocolManager
.
SubProtocols
}
// Start only starts the actual service if the ETH protocol has already been synced,
// otherwise it will be started by Synced()
func
(
s
*
LesServer
)
Start
(
srvr
*
p2p
.
Server
)
{
s
.
protocolManager
.
Start
(
srvr
)
s
.
lock
.
Lock
()
defer
s
.
lock
.
Unlock
()
s
.
srvr
=
srvr
if
s
.
synced
{
s
.
protocolManager
.
Start
(
s
.
srvr
)
}
}
// Synced notifies the server that the ETH protocol has been synced and LES service can be started
func
(
s
*
LesServer
)
Synced
()
{
s
.
lock
.
Lock
()
defer
s
.
lock
.
Unlock
()
s
.
synced
=
true
if
s
.
srvr
!=
nil
&&
!
s
.
stopped
{
s
.
protocolManager
.
Start
(
s
.
srvr
)
}
}
// Stop stops the LES service
func
(
s
*
LesServer
)
Stop
()
{
s
.
lock
.
Lock
()
defer
s
.
lock
.
Unlock
()
s
.
stopped
=
true
s
.
fcCostStats
.
store
()
s
.
fcManager
.
Stop
()
go
func
()
{
...
...
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