mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
les: add GetCheckpoint to LES--tidy comments, rename fn
This commit is contained in:
parent
aab305de87
commit
e5efdebfdf
3 changed files with 7 additions and 11 deletions
|
|
@ -545,9 +545,7 @@ func (r *BloomRequest) Validate(db ethdb.Database, msg *Msg) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
// For status.im request 320
|
||||||
// status.im request 320
|
|
||||||
|
|
||||||
type CheckpointReq struct {
|
type CheckpointReq struct {
|
||||||
SectionIdx uint64
|
SectionIdx uint64
|
||||||
}
|
}
|
||||||
|
|
@ -598,8 +596,6 @@ func (r *CheckpointRequest) Validate(db ethdb.Database, msg *Msg) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// readTraceDB stores the keys of database reads. We use this to check that received node
|
// readTraceDB stores the keys of database reads. We use this to check that received node
|
||||||
// sets contain only the trie nodes necessary to make proofs pass.
|
// sets contain only the trie nodes necessary to make proofs pass.
|
||||||
type readTraceDB struct {
|
type readTraceDB struct {
|
||||||
|
|
|
||||||
|
|
@ -325,7 +325,7 @@ func (p *peer) SendTxs(reqID, cost uint64, txs types.Transactions) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequestCheckpoint a checkpoint at the specified section index from a remote node.
|
// RequestCheckpoint requests a checkpoint at the specified section index from a remote node.
|
||||||
func (p *peer) RequestCheckpoint(reqID, cost uint64, req CheckpointReq) error {
|
func (p *peer) RequestCheckpoint(reqID, cost uint64, req CheckpointReq) error {
|
||||||
p.Log().Debug("Fetching checkpoint", "req", req, "p.version", p.version, "lpv1", lpv1)
|
p.Log().Debug("Fetching checkpoint", "req", req, "p.version", p.version, "lpv1", lpv1)
|
||||||
switch p.version {
|
switch p.version {
|
||||||
|
|
|
||||||
10
les/sync.go
10
les/sync.go
|
|
@ -81,19 +81,19 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
updateChtFromPeer(pm, peer, ctx)
|
updateCheckpointFromPeer(pm, peer, ctx)
|
||||||
pm.blockchain.(*light.LightChain).SyncCht(ctx)
|
pm.blockchain.(*light.LightChain).SyncCht(ctx)
|
||||||
pm.downloader.Synchronise(peer.id, peer.Head(), peer.Td(), downloader.LightSync)
|
pm.downloader.Synchronise(peer.id, peer.Head(), peer.Td(), downloader.LightSync)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status.im issue 320: Use GetHeaderProofs to download the latest CHT from a peer.
|
// Status.im issue 320: Use GetCheckpoint to download the latest checkpoint from a peer.
|
||||||
func updateChtFromPeer(pm *ProtocolManager, peer *peer, ctx context.Context) {
|
func updateCheckpointFromPeer(pm *ProtocolManager, peer *peer, ctx context.Context) {
|
||||||
log.Info("Downloading latest CHT root from peer", "peer.headBlockInfo", peer.headBlockInfo())
|
log.Info("Downloading latest checkpoint from peer", "peer.headBlockInfo", peer.headBlockInfo())
|
||||||
|
|
||||||
// Formula from lightchain.go:SyncCht: num := cht.Number*ChtFrequency – 1
|
// Formula from lightchain.go:SyncCht: num := cht.Number*ChtFrequency – 1
|
||||||
var hbl = peer.headBlockInfo()
|
var hbl = peer.headBlockInfo()
|
||||||
var peerHeadBlockNum = hbl.Number
|
var peerHeadBlockNum = hbl.Number
|
||||||
log.Debug("UpdateChtFromPeer", "peerHeadBlockNum", peerHeadBlockNum)
|
log.Debug("updateCheckpointFromPeer", "peerHeadBlockNum", peerHeadBlockNum)
|
||||||
|
|
||||||
var sectionIdx uint64 = ((peerHeadBlockNum + 1) / light.ChtFrequency) - 1
|
var sectionIdx uint64 = ((peerHeadBlockNum + 1) / light.ChtFrequency) - 1
|
||||||
log.Debug("Retrieving checkpoint with: ", "sectionIdx", sectionIdx)
|
log.Debug("Retrieving checkpoint with: ", "sectionIdx", sectionIdx)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue