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).
This commit is contained in:
parent
c76573a97b
commit
034ecc3210
@ -156,7 +156,7 @@ func (b *benchmarkHelperTrie) request(peer *serverPeer, index int) error {
|
|||||||
for i := range reqs {
|
for i := range reqs {
|
||||||
key := make([]byte, 8)
|
key := make([]byte, 8)
|
||||||
binary.BigEndian.PutUint64(key[:], uint64(rand.Int63n(int64(b.headNum))))
|
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}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ func testGetCHTProofs(t *testing.T, protocol int) {
|
|||||||
Type: htCanonical,
|
Type: htCanonical,
|
||||||
TrieIdx: 0,
|
TrieIdx: 0,
|
||||||
Key: key,
|
Key: key,
|
||||||
AuxReq: auxHeader,
|
AuxReq: htAuxHeader,
|
||||||
}}
|
}}
|
||||||
// Send the proof request and verify the response
|
// Send the proof request and verify the response
|
||||||
sendRequest(server.peer.app, GetHelperTrieProofsMsg, 42, requestsV2)
|
sendRequest(server.peer.app, GetHelperTrieProofsMsg, 42, requestsV2)
|
||||||
|
@ -295,10 +295,9 @@ const (
|
|||||||
htCanonical = iota // Canonical hash trie
|
htCanonical = iota // Canonical hash trie
|
||||||
htBloomBits // BloomBits trie
|
htBloomBits // BloomBits trie
|
||||||
|
|
||||||
// applicable for all helper trie requests
|
// helper trie auxiliary types
|
||||||
auxRoot = 1
|
// htAuxNone = 1 ; deprecated number, used in les2/3 previously.
|
||||||
// applicable for htCanonical
|
htAuxHeader = 2 // applicable for htCanonical, requests for relevant headers
|
||||||
auxHeader = 2
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type HelperTrieReq struct {
|
type HelperTrieReq struct {
|
||||||
@ -339,7 +338,7 @@ func (r *ChtRequest) Request(reqID uint64, peer *serverPeer) error {
|
|||||||
Type: htCanonical,
|
Type: htCanonical,
|
||||||
TrieIdx: r.ChtNum,
|
TrieIdx: r.ChtNum,
|
||||||
Key: encNum[:],
|
Key: encNum[:],
|
||||||
AuxReq: auxHeader,
|
AuxReq: htAuxHeader,
|
||||||
}
|
}
|
||||||
return peer.requestHelperTrieProofs(reqID, []HelperTrieReq{req})
|
return peer.requestHelperTrieProofs(reqID, []HelperTrieReq{req})
|
||||||
}
|
}
|
||||||
|
@ -741,23 +741,25 @@ func (h *serverHandler) handleMsg(p *clientPeer, wg *sync.WaitGroup) error {
|
|||||||
auxTrie, _ = trie.New(root, trie.NewDatabase(rawdb.NewTable(h.chainDb, prefix)))
|
auxTrie, _ = trie.New(root, trie.NewDatabase(rawdb.NewTable(h.chainDb, prefix)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if request.AuxReq == auxRoot {
|
if auxTrie == nil {
|
||||||
var data []byte
|
sendResponse(req.ReqID, 0, nil, task.servingTime)
|
||||||
if root != (common.Hash{}) {
|
return
|
||||||
data = root[:]
|
|
||||||
}
|
}
|
||||||
auxData = append(auxData, data)
|
// TODO(rjl493456442) short circuit if the proving is failed.
|
||||||
auxBytes += len(data)
|
// The original client side code has a dirty hack to retrieve
|
||||||
} else {
|
// the headers with no valid proof. Keep the compatibility for
|
||||||
if auxTrie != nil {
|
// legacy les protocol and drop this hack when the les2/3 are
|
||||||
auxTrie.Prove(request.Key, request.FromLevel, nodes)
|
// 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 != 0 {
|
if request.AuxReq == htAuxHeader {
|
||||||
data := h.getAuxiliaryHeaders(request)
|
data := h.getAuxiliaryHeaders(request)
|
||||||
auxData = append(auxData, data)
|
auxData = append(auxData, data)
|
||||||
auxBytes += len(data)
|
auxBytes += len(data)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if nodes.DataSize()+auxBytes >= softResponseLimit {
|
if nodes.DataSize()+auxBytes >= softResponseLimit {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -904,7 +906,7 @@ func (h *serverHandler) getHelperTrie(typ uint, index uint64) (common.Hash, stri
|
|||||||
|
|
||||||
// getAuxiliaryHeaders returns requested auxiliary headers for the CHT request.
|
// getAuxiliaryHeaders returns requested auxiliary headers for the CHT request.
|
||||||
func (h *serverHandler) getAuxiliaryHeaders(req HelperTrieReq) []byte {
|
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)
|
blockNum := binary.BigEndian.Uint64(req.Key)
|
||||||
hash := rawdb.ReadCanonicalHash(h.chainDb, blockNum)
|
hash := rawdb.ReadCanonicalHash(h.chainDb, blockNum)
|
||||||
return rawdb.ReadHeaderRLP(h.chainDb, hash, blockNum)
|
return rawdb.ReadHeaderRLP(h.chainDb, hash, blockNum)
|
||||||
|
Loading…
Reference in New Issue
Block a user