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
32b07e8b
Commit
32b07e8b
authored
Sep 25, 2019
by
Gary Rong
Committed by
Martin Holst Swende
Sep 25, 2019
Browse files
Options
Downloads
Patches
Plain Diff
les: fix checkpoint sync (#20120)
parent
aca39a64
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
les/checkpointoracle.go
+2
-5
2 additions, 5 deletions
les/checkpointoracle.go
les/client_handler.go
+6
-4
6 additions, 4 deletions
les/client_handler.go
les/sync.go
+9
-6
9 additions, 6 deletions
les/sync.go
les/sync_test.go
+100
-1
100 additions, 1 deletion
les/sync_test.go
with
117 additions
and
16 deletions
les/checkpointoracle.go
+
2
−
5
View file @
32b07e8b
...
...
@@ -35,11 +35,8 @@ type checkpointOracle struct {
config
*
params
.
CheckpointOracleConfig
contract
*
checkpointoracle
.
CheckpointOracle
// Whether the contract backend is set.
running
int32
running
int32
// Flag whether the contract backend is set or not
getLocal
func
(
uint64
)
params
.
TrustedCheckpoint
// Function used to retrieve local checkpoint
syncDoneHook
func
()
// Function used to notify that light syncing has completed.
}
// newCheckpointOracle returns a checkpoint registrar handler.
...
...
This diff is collapsed.
Click to expand it.
les/client_handler.go
+
6
−
4
View file @
32b07e8b
...
...
@@ -42,10 +42,12 @@ type clientHandler struct {
closeCh
chan
struct
{}
wg
sync
.
WaitGroup
// WaitGroup used to track all connected peers.
syncDone
func
()
// Test hooks when syncing is done.
}
func
newClientHandler
(
ulcServers
[]
string
,
ulcFraction
int
,
checkpoint
*
params
.
TrustedCheckpoint
,
backend
*
LightEthereum
)
*
clientHandler
{
handler
:=
&
clientHandler
{
checkpoint
:
checkpoint
,
backend
:
backend
,
closeCh
:
make
(
chan
struct
{}),
}
...
...
This diff is collapsed.
Click to expand it.
les/sync.go
+
9
−
6
View file @
32b07e8b
...
...
@@ -135,21 +135,24 @@ func (h *clientHandler) synchronise(peer *peer) {
mode
=
legacyCheckpointSync
log
.
Debug
(
"Disable checkpoint syncing"
,
"reason"
,
"checkpoint is hardcoded"
)
case
h
.
backend
.
oracle
==
nil
||
!
h
.
backend
.
oracle
.
isRunning
()
:
if
h
.
checkpoint
==
nil
{
mode
=
lightSync
// Downgrade to light sync unfortunately.
}
else
{
checkpoint
=
h
.
checkpoint
mode
=
legacyCheckpointSync
}
log
.
Debug
(
"Disable checkpoint syncing"
,
"reason"
,
"checkpoint syncing is not activated"
)
}
// Notify testing framework if syncing has completed(for testing purpose).
defer
func
()
{
if
h
.
backend
.
oracle
!=
nil
&&
h
.
backend
.
oracle
.
syncDone
Hook
!=
nil
{
h
.
backend
.
oracle
.
syncDone
Hook
()
if
h
.
syncDone
!=
nil
{
h
.
syncDone
()
}
}()
start
:=
time
.
Now
()
if
mode
==
checkpointSync
||
mode
==
legacyCheckpointSync
{
// Validate the advertised checkpoint
if
mode
==
legacyCheckpointSync
{
checkpoint
=
h
.
checkpoint
}
else
if
mode
==
checkpointSync
{
if
mode
==
checkpointSync
{
if
err
:=
h
.
validateCheckpoint
(
peer
);
err
!=
nil
{
log
.
Debug
(
"Failed to validate checkpoint"
,
"reason"
,
err
)
h
.
removePeer
(
peer
.
id
)
...
...
This diff is collapsed.
Click to expand it.
les/sync_test.go
+
100
−
1
View file @
32b07e8b
...
...
@@ -102,7 +102,7 @@ func testCheckpointSyncing(t *testing.T, protocol int, syncMode int) {
}
done
:=
make
(
chan
error
)
client
.
handler
.
backend
.
oracle
.
syncDone
Hook
=
func
()
{
client
.
handler
.
syncDone
=
func
()
{
header
:=
client
.
handler
.
backend
.
blockchain
.
CurrentHeader
()
if
header
.
Number
.
Uint64
()
==
expected
{
done
<-
nil
...
...
@@ -131,3 +131,102 @@ func testCheckpointSyncing(t *testing.T, protocol int, syncMode int) {
t
.
Error
(
"checkpoint syncing timeout"
)
}
}
func
TestMissOracleBackend
(
t
*
testing
.
T
)
{
testMissOracleBackend
(
t
,
true
)
}
func
TestMissOracleBackendNoCheckpoint
(
t
*
testing
.
T
)
{
testMissOracleBackend
(
t
,
false
)
}
func
testMissOracleBackend
(
t
*
testing
.
T
,
hasCheckpoint
bool
)
{
config
:=
light
.
TestServerIndexerConfig
waitIndexers
:=
func
(
cIndexer
,
bIndexer
,
btIndexer
*
core
.
ChainIndexer
)
{
for
{
cs
,
_
,
_
:=
cIndexer
.
Sections
()
bts
,
_
,
_
:=
btIndexer
.
Sections
()
if
cs
>=
1
&&
bts
>=
1
{
break
}
time
.
Sleep
(
10
*
time
.
Millisecond
)
}
}
// Generate 512+4 blocks (totally 1 CHT sections)
server
,
client
,
tearDown
:=
newClientServerEnv
(
t
,
int
(
config
.
ChtSize
+
config
.
ChtConfirms
),
3
,
waitIndexers
,
nil
,
0
,
false
,
false
)
defer
tearDown
()
expected
:=
config
.
ChtSize
+
config
.
ChtConfirms
s
,
_
,
head
:=
server
.
chtIndexer
.
Sections
()
cp
:=
&
params
.
TrustedCheckpoint
{
SectionIndex
:
0
,
SectionHead
:
head
,
CHTRoot
:
light
.
GetChtRoot
(
server
.
db
,
s
-
1
,
head
),
BloomRoot
:
light
.
GetBloomTrieRoot
(
server
.
db
,
s
-
1
,
head
),
}
// Register the assembled checkpoint into oracle.
header
:=
server
.
backend
.
Blockchain
()
.
CurrentHeader
()
data
:=
append
([]
byte
{
0x19
,
0x00
},
append
(
registrarAddr
.
Bytes
(),
append
([]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
cp
.
Hash
()
.
Bytes
()
...
)
...
)
...
)
sig
,
_
:=
crypto
.
Sign
(
crypto
.
Keccak256
(
data
),
signerKey
)
sig
[
64
]
+=
27
// Transform V from 0/1 to 27/28 according to the yellow paper
if
_
,
err
:=
server
.
handler
.
server
.
oracle
.
contract
.
RegisterCheckpoint
(
bind
.
NewKeyedTransactor
(
signerKey
),
cp
.
SectionIndex
,
cp
.
Hash
()
.
Bytes
(),
new
(
big
.
Int
)
.
Sub
(
header
.
Number
,
big
.
NewInt
(
1
)),
header
.
ParentHash
,
[][]
byte
{
sig
});
err
!=
nil
{
t
.
Error
(
"register checkpoint failed"
,
err
)
}
server
.
backend
.
Commit
()
// Wait for the checkpoint registration
for
{
_
,
hash
,
_
,
err
:=
server
.
handler
.
server
.
oracle
.
contract
.
Contract
()
.
GetLatestCheckpoint
(
nil
)
if
err
!=
nil
||
hash
==
[
32
]
byte
{}
{
time
.
Sleep
(
100
*
time
.
Millisecond
)
continue
}
break
}
expected
+=
1
// Explicitly set the oracle as nil. In normal use case it can happen
// that user wants to unlock something which blocks the oracle backend
// initialisation. But at the same time syncing starts.
//
// See https://github.com/ethereum/go-ethereum/issues/20097 for more detail.
//
// In this case, client should run light sync or legacy checkpoint sync
// if hardcoded checkpoint is configured.
client
.
handler
.
backend
.
oracle
=
nil
// For some private networks it can happen checkpoint syncing is enabled
// but there is no hardcoded checkpoint configured.
if
hasCheckpoint
{
client
.
handler
.
checkpoint
=
cp
client
.
handler
.
backend
.
blockchain
.
AddTrustedCheckpoint
(
cp
)
}
done
:=
make
(
chan
error
)
client
.
handler
.
syncDone
=
func
()
{
header
:=
client
.
handler
.
backend
.
blockchain
.
CurrentHeader
()
if
header
.
Number
.
Uint64
()
==
expected
{
done
<-
nil
}
else
{
done
<-
fmt
.
Errorf
(
"blockchain length mismatch, want %d, got %d"
,
expected
,
header
.
Number
)
}
}
// Create connected peer pair.
_
,
err1
,
_
,
err2
:=
newTestPeerPair
(
"peer"
,
2
,
server
.
handler
,
client
.
handler
)
select
{
case
<-
time
.
After
(
time
.
Millisecond
*
100
)
:
case
err
:=
<-
err1
:
t
.
Fatalf
(
"peer 1 handshake error: %v"
,
err
)
case
err
:=
<-
err2
:
t
.
Fatalf
(
"peer 2 handshake error: %v"
,
err
)
}
select
{
case
err
:=
<-
done
:
if
err
!=
nil
{
t
.
Error
(
"sync failed"
,
err
)
}
return
case
<-
time
.
NewTimer
(
10
*
time
.
Second
)
.
C
:
t
.
Error
(
"checkpoint syncing timeout"
)
}
}
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