From e5efdebfdfc35b93beb095f4b9f714555a013e2b Mon Sep 17 00:00:00 2001 From: pacamara Date: Thu, 14 Dec 2017 12:32:32 +0000 Subject: [PATCH] les: add GetCheckpoint to LES--tidy comments, rename fn --- les/odr_requests.go | 6 +----- les/peer.go | 2 +- les/sync.go | 10 +++++----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/les/odr_requests.go b/les/odr_requests.go index 0c79485a26..08ef2a80b4 100644 --- a/les/odr_requests.go +++ b/les/odr_requests.go @@ -545,9 +545,7 @@ func (r *BloomRequest) Validate(db ethdb.Database, msg *Msg) error { return nil } -/////////////////////////////////////////////////////////////////////////////////////////// -// status.im request 320 - +// For status.im request 320 type CheckpointReq struct { SectionIdx uint64 } @@ -598,8 +596,6 @@ func (r *CheckpointRequest) Validate(db ethdb.Database, msg *Msg) error { return nil } -/////////////////////////////////////////////////////////////////////////////////////////////// - // 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. type readTraceDB struct { diff --git a/les/peer.go b/les/peer.go index 8ab90dc12b..a4fc683055 100644 --- a/les/peer.go +++ b/les/peer.go @@ -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 { p.Log().Debug("Fetching checkpoint", "req", req, "p.version", p.version, "lpv1", lpv1) switch p.version { diff --git a/les/sync.go b/les/sync.go index d2d114965d..248c91dc97 100644 --- a/les/sync.go +++ b/les/sync.go @@ -81,19 +81,19 @@ func (pm *ProtocolManager) synchronise(peer *peer) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() - updateChtFromPeer(pm, peer, ctx) + updateCheckpointFromPeer(pm, peer, ctx) pm.blockchain.(*light.LightChain).SyncCht(ctx) 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. -func updateChtFromPeer(pm *ProtocolManager, peer *peer, ctx context.Context) { - log.Info("Downloading latest CHT root from peer", "peer.headBlockInfo", peer.headBlockInfo()) +// Status.im issue 320: Use GetCheckpoint to download the latest checkpoint from a peer. +func updateCheckpointFromPeer(pm *ProtocolManager, peer *peer, ctx context.Context) { + log.Info("Downloading latest checkpoint from peer", "peer.headBlockInfo", peer.headBlockInfo()) // Formula from lightchain.go:SyncCht: num := cht.Number*ChtFrequency – 1 var hbl = peer.headBlockInfo() var peerHeadBlockNum = hbl.Number - log.Debug("UpdateChtFromPeer", "peerHeadBlockNum", peerHeadBlockNum) + log.Debug("updateCheckpointFromPeer", "peerHeadBlockNum", peerHeadBlockNum) var sectionIdx uint64 = ((peerHeadBlockNum + 1) / light.ChtFrequency) - 1 log.Debug("Retrieving checkpoint with: ", "sectionIdx", sectionIdx)