mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
trie/trienode: rename structs and methods in proofset/prooflist
This commit is contained in:
parent
7900aceebd
commit
dd14ff1dee
11 changed files with 35 additions and 35 deletions
|
|
@ -530,11 +530,11 @@ func (s *Suite) snapGetAccountRange(t *utesting.T, tc *accRangeTest) error {
|
|||
for i, key := range hashes {
|
||||
keys[i] = common.CopyBytes(key[:])
|
||||
}
|
||||
nodes := make(trienode.NodeList, len(proof))
|
||||
nodes := make(trienode.ProofList, len(proof))
|
||||
for i, node := range proof {
|
||||
nodes[i] = node
|
||||
}
|
||||
proofdb := nodes.ProofSet()
|
||||
proofdb := nodes.Set()
|
||||
|
||||
var end []byte
|
||||
if len(keys) > 0 {
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ func ServiceGetAccountRangeQuery(chain *core.BlockChain, req *GetAccountRangePac
|
|||
}
|
||||
}
|
||||
var proofs [][]byte
|
||||
for _, blob := range proof.NodeList() {
|
||||
for _, blob := range proof.List() {
|
||||
proofs = append(proofs, blob)
|
||||
}
|
||||
return accounts, proofs
|
||||
|
|
@ -438,7 +438,7 @@ func ServiceGetStorageRangesQuery(chain *core.BlockChain, req *GetStorageRangesP
|
|||
return nil, nil
|
||||
}
|
||||
}
|
||||
for _, blob := range proof.NodeList() {
|
||||
for _, blob := range proof.List() {
|
||||
proofs = append(proofs, blob)
|
||||
}
|
||||
// Proof terminates the reply as proofs are only added if a node
|
||||
|
|
|
|||
|
|
@ -2394,11 +2394,11 @@ func (s *Syncer) OnAccounts(peer SyncPeer, id uint64, hashes []common.Hash, acco
|
|||
for i, key := range hashes {
|
||||
keys[i] = common.CopyBytes(key[:])
|
||||
}
|
||||
nodes := make(trienode.NodeList, len(proof))
|
||||
nodes := make(trienode.ProofList, len(proof))
|
||||
for i, node := range proof {
|
||||
nodes[i] = node
|
||||
}
|
||||
proofdb := nodes.ProofSet()
|
||||
proofdb := nodes.Set()
|
||||
|
||||
var end []byte
|
||||
if len(keys) > 0 {
|
||||
|
|
@ -2639,7 +2639,7 @@ func (s *Syncer) OnStorage(peer SyncPeer, id uint64, hashes [][]common.Hash, slo
|
|||
for j, key := range hashes[i] {
|
||||
keys[j] = common.CopyBytes(key[:])
|
||||
}
|
||||
nodes := make(trienode.NodeList, 0, len(proof))
|
||||
nodes := make(trienode.ProofList, 0, len(proof))
|
||||
if i == len(hashes)-1 {
|
||||
for _, node := range proof {
|
||||
nodes = append(nodes, node)
|
||||
|
|
@ -2658,7 +2658,7 @@ func (s *Syncer) OnStorage(peer SyncPeer, id uint64, hashes [][]common.Hash, slo
|
|||
} else {
|
||||
// A proof was attached, the response is only partial, check that the
|
||||
// returned data is indeed part of the storage trie
|
||||
proofdb := nodes.ProofSet()
|
||||
proofdb := nodes.Set()
|
||||
|
||||
var end []byte
|
||||
if len(keys) > 0 {
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ func createAccountRequestResponse(t *testPeer, root common.Hash, origin common.H
|
|||
t.logger.Error("Could not prove last item", "error", err)
|
||||
}
|
||||
}
|
||||
for _, blob := range proof.NodeList() {
|
||||
for _, blob := range proof.List() {
|
||||
proofs = append(proofs, blob)
|
||||
}
|
||||
return keys, vals, proofs
|
||||
|
|
@ -367,7 +367,7 @@ func createStorageRequestResponse(t *testPeer, root common.Hash, accounts []comm
|
|||
t.logger.Error("Could not prove last item", "error", err)
|
||||
}
|
||||
}
|
||||
for _, blob := range proof.NodeList() {
|
||||
for _, blob := range proof.List() {
|
||||
proofs = append(proofs, blob)
|
||||
}
|
||||
break
|
||||
|
|
@ -426,7 +426,7 @@ func createStorageRequestResponseAlwaysProve(t *testPeer, root common.Hash, acco
|
|||
t.logger.Error("Could not prove last item", "error", err)
|
||||
}
|
||||
}
|
||||
for _, blob := range proof.NodeList() {
|
||||
for _, blob := range proof.List() {
|
||||
proofs = append(proofs, blob)
|
||||
}
|
||||
break
|
||||
|
|
@ -614,7 +614,7 @@ func testSyncBloatedProof(t *testing.T, scheme string) {
|
|||
keys = append(keys[:1], keys[2:]...)
|
||||
vals = append(vals[:1], vals[2:]...)
|
||||
}
|
||||
for _, blob := range proof.NodeList() {
|
||||
for _, blob := range proof.List() {
|
||||
proofs = append(proofs, blob)
|
||||
}
|
||||
if err := t.remote.OnAccounts(t, requestId, keys, vals, proofs); err != nil {
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ func (h *clientHandler) handleMsg(p *serverPeer) error {
|
|||
p.Log().Trace("Received les/2 proofs response")
|
||||
var resp struct {
|
||||
ReqID, BV uint64
|
||||
Data trienode.NodeList
|
||||
Data trienode.ProofList
|
||||
}
|
||||
if err := msg.Decode(&resp); err != nil {
|
||||
return errResp(ErrDecode, "msg %v: %v", msg, err)
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ func testGetProofs(t *testing.T, protocol int) {
|
|||
}
|
||||
// Send the proof request and verify the response
|
||||
sendRequest(rawPeer.app, GetProofsV2Msg, 42, proofreqs)
|
||||
if err := expectResponse(rawPeer.app, ProofsV2Msg, 42, testBufLimit, proofsV2.NodeList()); err != nil {
|
||||
if err := expectResponse(rawPeer.app, ProofsV2Msg, 42, testBufLimit, proofsV2.List()); err != nil {
|
||||
t.Errorf("proofs mismatch: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -460,7 +460,7 @@ func testGetStaleProof(t *testing.T, protocol int) {
|
|||
proofsV2 := trienode.NewProofSet()
|
||||
t, _ := trie.New(trie.StateTrieID(header.Root), server.backend.Blockchain().TrieDB())
|
||||
t.Prove(account, proofsV2)
|
||||
expected = proofsV2.NodeList()
|
||||
expected = proofsV2.List()
|
||||
}
|
||||
if err := expectResponse(rawPeer.app, ProofsV2Msg, 42, testBufLimit, expected); err != nil {
|
||||
t.Errorf("codes mismatch: %v", err)
|
||||
|
|
|
|||
|
|
@ -223,9 +223,9 @@ func (r *TrieRequest) Validate(db ethdb.Database, msg *Msg) error {
|
|||
if msg.MsgType != MsgProofsV2 {
|
||||
return errInvalidMessageType
|
||||
}
|
||||
proofs := msg.Obj.(trienode.NodeList)
|
||||
proofs := msg.Obj.(trienode.ProofList)
|
||||
// Verify the proof and store if checks out
|
||||
nodeSet := proofs.ProofSet()
|
||||
nodeSet := proofs.Set()
|
||||
reads := &readTraceDB{db: nodeSet}
|
||||
if _, err := trie.VerifyProof(r.Id.Root, r.Key, reads); err != nil {
|
||||
return fmt.Errorf("merkle proof verification failed: %v", err)
|
||||
|
|
@ -309,7 +309,7 @@ type HelperTrieReq struct {
|
|||
}
|
||||
|
||||
type HelperTrieResps struct { // describes all responses, not just a single one
|
||||
Proofs trienode.NodeList
|
||||
Proofs trienode.ProofList
|
||||
AuxData [][]byte
|
||||
}
|
||||
|
||||
|
|
@ -357,7 +357,7 @@ func (r *ChtRequest) Validate(db ethdb.Database, msg *Msg) error {
|
|||
if len(resp.AuxData) != 1 {
|
||||
return errInvalidEntryCount
|
||||
}
|
||||
nodeSet := resp.Proofs.ProofSet()
|
||||
nodeSet := resp.Proofs.Set()
|
||||
headerEnc := resp.AuxData[0]
|
||||
if len(headerEnc) == 0 {
|
||||
return errHeaderUnavailable
|
||||
|
|
@ -452,7 +452,7 @@ func (r *BloomRequest) Validate(db ethdb.Database, msg *Msg) error {
|
|||
}
|
||||
resps := msg.Obj.(HelperTrieResps)
|
||||
proofs := resps.Proofs
|
||||
nodeSet := proofs.ProofSet()
|
||||
nodeSet := proofs.Set()
|
||||
reads := &readTraceDB{db: nodeSet}
|
||||
|
||||
r.BloomBits = make([][]byte, len(r.SectionIndexList))
|
||||
|
|
|
|||
|
|
@ -900,7 +900,7 @@ func (p *clientPeer) replyReceiptsRLP(reqID uint64, receipts []rlp.RawValue) *re
|
|||
}
|
||||
|
||||
// replyProofsV2 creates a reply with a batch of merkle proofs, corresponding to the ones requested.
|
||||
func (p *clientPeer) replyProofsV2(reqID uint64, proofs trienode.NodeList) *reply {
|
||||
func (p *clientPeer) replyProofsV2(reqID uint64, proofs trienode.ProofList) *reply {
|
||||
data, _ := rlp.EncodeToBytes(proofs)
|
||||
return &reply{p.rw, ProofsV2Msg, reqID, data}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -445,7 +445,7 @@ func handleGetProofs(msg Decoder) (serveRequestFn, uint64, uint64, error) {
|
|||
break
|
||||
}
|
||||
}
|
||||
return p.replyProofsV2(r.ReqID, nodes.NodeList())
|
||||
return p.replyProofsV2(r.ReqID, nodes.List())
|
||||
}, r.ReqID, uint64(len(r.Reqs)), nil
|
||||
}
|
||||
|
||||
|
|
@ -499,7 +499,7 @@ func handleGetHelperTrieProofs(msg Decoder) (serveRequestFn, uint64, uint64, err
|
|||
break
|
||||
}
|
||||
}
|
||||
return p.replyHelperTrieProofs(r.ReqID, HelperTrieResps{Proofs: nodes.NodeList(), AuxData: auxData})
|
||||
return p.replyHelperTrieProofs(r.ReqID, HelperTrieResps{Proofs: nodes.List(), AuxData: auxData})
|
||||
}, r.ReqID, uint64(len(r.Reqs)), nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ func (set *NodeSet) Merge(owner common.Hash, nodes map[string]*Node) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// AddLeaf adds the provided leaf node into set. TODNodeSetO(rjl493456442) how can
|
||||
// AddLeaf adds the provided leaf node into set. TODO(rjl493456442) how can
|
||||
// we get rid of it?
|
||||
func (set *NodeSet) AddLeaf(parent common.Hash, blob []byte) {
|
||||
set.Leaves = append(set.Leaves, &leaf{Blob: blob, Parent: parent})
|
||||
|
|
|
|||
|
|
@ -102,12 +102,12 @@ func (db *ProofSet) DataSize() int {
|
|||
return db.dataSize
|
||||
}
|
||||
|
||||
// NodeList converts the node set to a NodeList
|
||||
func (db *ProofSet) NodeList() NodeList {
|
||||
// List converts the node set to a ProofList
|
||||
func (db *ProofSet) List() ProofList {
|
||||
db.lock.RLock()
|
||||
defer db.lock.RUnlock()
|
||||
|
||||
var values NodeList
|
||||
var values ProofList
|
||||
for _, key := range db.order {
|
||||
values = append(values, db.nodes[key])
|
||||
}
|
||||
|
|
@ -124,36 +124,36 @@ func (db *ProofSet) Store(target ethdb.KeyValueWriter) {
|
|||
}
|
||||
}
|
||||
|
||||
// NodeList stores an ordered list of trie nodes. It implements ethdb.KeyValueWriter.
|
||||
type NodeList []rlp.RawValue
|
||||
// ProofList stores an ordered list of trie nodes. It implements ethdb.KeyValueWriter.
|
||||
type ProofList []rlp.RawValue
|
||||
|
||||
// Store writes the contents of the list to the given database
|
||||
func (n NodeList) Store(db ethdb.KeyValueWriter) {
|
||||
func (n ProofList) Store(db ethdb.KeyValueWriter) {
|
||||
for _, node := range n {
|
||||
db.Put(crypto.Keccak256(node), node)
|
||||
}
|
||||
}
|
||||
|
||||
// ProofSet converts the node list to a ProofSet
|
||||
func (n NodeList) ProofSet() *ProofSet {
|
||||
// Set converts the node list to a ProofSet
|
||||
func (n ProofList) Set() *ProofSet {
|
||||
db := NewProofSet()
|
||||
n.Store(db)
|
||||
return db
|
||||
}
|
||||
|
||||
// Put stores a new node at the end of the list
|
||||
func (n *NodeList) Put(key []byte, value []byte) error {
|
||||
func (n *ProofList) Put(key []byte, value []byte) error {
|
||||
*n = append(*n, value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete panics as there's no reason to remove a node from the list.
|
||||
func (n *NodeList) Delete(key []byte) error {
|
||||
func (n *ProofList) Delete(key []byte) error {
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
// DataSize returns the aggregated data size of nodes in the list
|
||||
func (n NodeList) DataSize() int {
|
||||
func (n ProofList) DataSize() int {
|
||||
var size int
|
||||
for _, node := range n {
|
||||
size += len(node)
|
||||
Loading…
Reference in a new issue