Skip to content

les: remove useless protocol defines #22115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion les/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (b *benchmarkHelperTrie) request(peer *serverPeer, index int) error {
for i := range reqs {
key := make([]byte, 8)
binary.BigEndian.PutUint64(key[:], uint64(rand.Int63n(int64(b.headNum))))
reqs[i] = HelperTrieReq{Type: htCanonical, TrieIdx: b.sectionCount - 1, Key: key, AuxReq: auxHeader}
reqs[i] = HelperTrieReq{Type: htCanonical, TrieIdx: b.sectionCount - 1, Key: key, AuxReq: htAuxHeader}
}
}

Expand Down
2 changes: 1 addition & 1 deletion les/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func testGetCHTProofs(t *testing.T, protocol int) {
Type: htCanonical,
TrieIdx: 0,
Key: key,
AuxReq: auxHeader,
AuxReq: htAuxHeader,
}}
// Send the proof request and verify the response
sendRequest(server.peer.app, GetHelperTrieProofsMsg, 42, requestsV2)
Expand Down
9 changes: 4 additions & 5 deletions les/odr_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,9 @@ const (
htCanonical = iota // Canonical hash trie
htBloomBits // BloomBits trie

// applicable for all helper trie requests
auxRoot = 1
// applicable for htCanonical
auxHeader = 2
// helper trie auxiliary types
htAuxNone = 1 // deprecated number, used in les2/3 previously.
htAuxHeader = 2 // applicable for htCanonical, requests for relevant headers
)

type HelperTrieReq struct {
Expand Down Expand Up @@ -339,7 +338,7 @@ func (r *ChtRequest) Request(reqID uint64, peer *serverPeer) error {
Type: htCanonical,
TrieIdx: r.ChtNum,
Key: encNum[:],
AuxReq: auxHeader,
AuxReq: htAuxHeader,
}
return peer.requestHelperTrieProofs(reqID, []HelperTrieReq{req})
}
Expand Down
32 changes: 17 additions & 15 deletions les/server_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,22 +741,24 @@ func (h *serverHandler) handleMsg(p *clientPeer, wg *sync.WaitGroup) error {
auxTrie, _ = trie.New(root, trie.NewDatabase(rawdb.NewTable(h.chainDb, prefix)))
}
}
if request.AuxReq == auxRoot {
var data []byte
if root != (common.Hash{}) {
data = root[:]
}
if auxTrie == nil {
sendResponse(req.ReqID, 0, nil, task.servingTime)
return
}
// TODO(rjl493456442) short circuit if the proving is failed.
// The original client side code has a dirty hack to retrieve
// the headers with no valid proof. Keep the compatibility for
// legacy les protocol and drop this hack when the les2/3 are
// not supported.
err := auxTrie.Prove(request.Key, request.FromLevel, nodes)
if p.version >= lpv4 && err != nil {
sendResponse(req.ReqID, 0, nil, task.servingTime)
return
}
if request.AuxReq == htAuxHeader {
data := h.getAuxiliaryHeaders(request)
auxData = append(auxData, data)
auxBytes += len(data)
} else {
if auxTrie != nil {
auxTrie.Prove(request.Key, request.FromLevel, nodes)
}
if request.AuxReq != 0 {
data := h.getAuxiliaryHeaders(request)
auxData = append(auxData, data)
auxBytes += len(data)
}
}
if nodes.DataSize()+auxBytes >= softResponseLimit {
break
Expand Down Expand Up @@ -904,7 +906,7 @@ func (h *serverHandler) getHelperTrie(typ uint, index uint64) (common.Hash, stri

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