diff options
author | gary rong <garyrong0905@gmail.com> | 2018-08-28 15:08:16 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-08-28 15:08:16 +0800 |
commit | b69476b372a26679e5bdb33db3d508f2c955e7ff (patch) | |
tree | 47757ef2b65302f19aca96327b7a34ad73f652a5 /les/odr_requests.go | |
parent | c64d72bea207ccaca3f6aded25d8730a4b8696cd (diff) | |
download | dexon-b69476b372a26679e5bdb33db3d508f2c955e7ff.tar dexon-b69476b372a26679e5bdb33db3d508f2c955e7ff.tar.gz dexon-b69476b372a26679e5bdb33db3d508f2c955e7ff.tar.bz2 dexon-b69476b372a26679e5bdb33db3d508f2c955e7ff.tar.lz dexon-b69476b372a26679e5bdb33db3d508f2c955e7ff.tar.xz dexon-b69476b372a26679e5bdb33db3d508f2c955e7ff.tar.zst dexon-b69476b372a26679e5bdb33db3d508f2c955e7ff.zip |
all: make indexer configurable (#17188)
Diffstat (limited to 'les/odr_requests.go')
-rw-r--r-- | les/odr_requests.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/les/odr_requests.go b/les/odr_requests.go index 075fcd92c..9e9b2673f 100644 --- a/les/odr_requests.go +++ b/les/odr_requests.go @@ -365,7 +365,7 @@ func (r *ChtRequest) CanSend(peer *peer) bool { peer.lock.RLock() defer peer.lock.RUnlock() - return peer.headInfo.Number >= light.HelperTrieConfirmations && r.ChtNum <= (peer.headInfo.Number-light.HelperTrieConfirmations)/light.CHTFrequencyClient + return peer.headInfo.Number >= r.Config.ChtConfirms && r.ChtNum <= (peer.headInfo.Number-r.Config.ChtConfirms)/r.Config.ChtSize } // Request sends an ODR request to the LES network (implementation of LesOdrRequest) @@ -379,7 +379,21 @@ func (r *ChtRequest) Request(reqID uint64, peer *peer) error { Key: encNum[:], AuxReq: auxHeader, } - return peer.RequestHelperTrieProofs(reqID, r.GetCost(peer), []HelperTrieReq{req}) + switch peer.version { + case lpv1: + var reqsV1 ChtReq + if req.Type != htCanonical || req.AuxReq != auxHeader || len(req.Key) != 8 { + return fmt.Errorf("Request invalid in LES/1 mode") + } + blockNum := binary.BigEndian.Uint64(req.Key) + // convert HelperTrie request to old CHT request + reqsV1 = ChtReq{ChtNum: (req.TrieIdx + 1) * (r.Config.ChtSize / r.Config.PairChtSize), BlockNum: blockNum, FromLevel: req.FromLevel} + return peer.RequestHelperTrieProofs(reqID, r.GetCost(peer), []ChtReq{reqsV1}) + case lpv2: + return peer.RequestHelperTrieProofs(reqID, r.GetCost(peer), []HelperTrieReq{req}) + default: + panic(nil) + } } // Valid processes an ODR request reply message from the LES network @@ -484,7 +498,7 @@ func (r *BloomRequest) CanSend(peer *peer) bool { if peer.version < lpv2 { return false } - return peer.headInfo.Number >= light.HelperTrieConfirmations && r.BloomTrieNum <= (peer.headInfo.Number-light.HelperTrieConfirmations)/light.BloomTrieFrequency + return peer.headInfo.Number >= r.Config.BloomTrieConfirms && r.BloomTrieNum <= (peer.headInfo.Number-r.Config.BloomTrieConfirms)/r.Config.BloomTrieSize } // Request sends an ODR request to the LES network (implementation of LesOdrRequest) |