Skip to content

Commit 034ecc3

Browse files
authored
les: remove useless protocol defines (#22115)
This PR has two changes in the les protocol: - the auxRoot is not supported. See ethereum/devp2p#171 for more information - the empty response will be returned in GetHelperTrieProofsMsg request if the merkle proving is failed. note, for backward compatibility, the empty merkle proof as well as the request auxiliary data will still be returned in les2/3 protocol no matter the proving is successful or not. the proving failure can happen e.g. request the proving for a non-included entry in helper trie (unstable header).
1 parent c76573a commit 034ecc3

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

les/benchmark.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (b *benchmarkHelperTrie) request(peer *serverPeer, index int) error {
156156
for i := range reqs {
157157
key := make([]byte, 8)
158158
binary.BigEndian.PutUint64(key[:], uint64(rand.Int63n(int64(b.headNum))))
159-
reqs[i] = HelperTrieReq{Type: htCanonical, TrieIdx: b.sectionCount - 1, Key: key, AuxReq: auxHeader}
159+
reqs[i] = HelperTrieReq{Type: htCanonical, TrieIdx: b.sectionCount - 1, Key: key, AuxReq: htAuxHeader}
160160
}
161161
}
162162

les/handler_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func testGetCHTProofs(t *testing.T, protocol int) {
443443
Type: htCanonical,
444444
TrieIdx: 0,
445445
Key: key,
446-
AuxReq: auxHeader,
446+
AuxReq: htAuxHeader,
447447
}}
448448
// Send the proof request and verify the response
449449
sendRequest(server.peer.app, GetHelperTrieProofsMsg, 42, requestsV2)

les/odr_requests.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,9 @@ const (
295295
htCanonical = iota // Canonical hash trie
296296
htBloomBits // BloomBits trie
297297

298-
// applicable for all helper trie requests
299-
auxRoot = 1
300-
// applicable for htCanonical
301-
auxHeader = 2
298+
// helper trie auxiliary types
299+
// htAuxNone = 1 ; deprecated number, used in les2/3 previously.
300+
htAuxHeader = 2 // applicable for htCanonical, requests for relevant headers
302301
)
303302

304303
type HelperTrieReq struct {
@@ -339,7 +338,7 @@ func (r *ChtRequest) Request(reqID uint64, peer *serverPeer) error {
339338
Type: htCanonical,
340339
TrieIdx: r.ChtNum,
341340
Key: encNum[:],
342-
AuxReq: auxHeader,
341+
AuxReq: htAuxHeader,
343342
}
344343
return peer.requestHelperTrieProofs(reqID, []HelperTrieReq{req})
345344
}

les/server_handler.go

+17-15
Original file line numberDiff line numberDiff line change
@@ -741,22 +741,24 @@ func (h *serverHandler) handleMsg(p *clientPeer, wg *sync.WaitGroup) error {
741741
auxTrie, _ = trie.New(root, trie.NewDatabase(rawdb.NewTable(h.chainDb, prefix)))
742742
}
743743
}
744-
if request.AuxReq == auxRoot {
745-
var data []byte
746-
if root != (common.Hash{}) {
747-
data = root[:]
748-
}
744+
if auxTrie == nil {
745+
sendResponse(req.ReqID, 0, nil, task.servingTime)
746+
return
747+
}
748+
// TODO(rjl493456442) short circuit if the proving is failed.
749+
// The original client side code has a dirty hack to retrieve
750+
// the headers with no valid proof. Keep the compatibility for
751+
// legacy les protocol and drop this hack when the les2/3 are
752+
// not supported.
753+
err := auxTrie.Prove(request.Key, request.FromLevel, nodes)
754+
if p.version >= lpv4 && err != nil {
755+
sendResponse(req.ReqID, 0, nil, task.servingTime)
756+
return
757+
}
758+
if request.AuxReq == htAuxHeader {
759+
data := h.getAuxiliaryHeaders(request)
749760
auxData = append(auxData, data)
750761
auxBytes += len(data)
751-
} else {
752-
if auxTrie != nil {
753-
auxTrie.Prove(request.Key, request.FromLevel, nodes)
754-
}
755-
if request.AuxReq != 0 {
756-
data := h.getAuxiliaryHeaders(request)
757-
auxData = append(auxData, data)
758-
auxBytes += len(data)
759-
}
760762
}
761763
if nodes.DataSize()+auxBytes >= softResponseLimit {
762764
break
@@ -904,7 +906,7 @@ func (h *serverHandler) getHelperTrie(typ uint, index uint64) (common.Hash, stri
904906

905907
// getAuxiliaryHeaders returns requested auxiliary headers for the CHT request.
906908
func (h *serverHandler) getAuxiliaryHeaders(req HelperTrieReq) []byte {
907-
if req.Type == htCanonical && req.AuxReq == auxHeader && len(req.Key) == 8 {
909+
if req.Type == htCanonical && req.AuxReq == htAuxHeader && len(req.Key) == 8 {
908910
blockNum := binary.BigEndian.Uint64(req.Key)
909911
hash := rawdb.ReadCanonicalHash(h.chainDb, blockNum)
910912
return rawdb.ReadHeaderRLP(h.chainDb, hash, blockNum)

0 commit comments

Comments
 (0)