mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
all: move NodeSet from light to trie
This commit is contained in:
parent
08326794e8
commit
7cea9d4026
13 changed files with 27 additions and 27 deletions
|
|
@ -27,7 +27,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/eth/protocols/snap"
|
||||
"github.com/ethereum/go-ethereum/internal/utesting"
|
||||
"github.com/ethereum/go-ethereum/light"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
"golang.org/x/crypto/sha3"
|
||||
)
|
||||
|
|
@ -530,7 +529,7 @@ func (s *Suite) snapGetAccountRange(t *utesting.T, tc *accRangeTest) error {
|
|||
for i, key := range hashes {
|
||||
keys[i] = common.CopyBytes(key[:])
|
||||
}
|
||||
nodes := make(light.NodeList, len(proof))
|
||||
nodes := make(trie.NodeList, len(proof))
|
||||
for i, node := range proof {
|
||||
nodes[i] = node
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/light"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
|
|
@ -321,7 +320,7 @@ func ServiceGetAccountRangeQuery(chain *core.BlockChain, req *GetAccountRangePac
|
|||
it.Release()
|
||||
|
||||
// Generate the Merkle proofs for the first and last account
|
||||
proof := light.NewNodeSet()
|
||||
proof := trie.NewNodeSet()
|
||||
if err := tr.Prove(req.Origin[:], proof); err != nil {
|
||||
log.Warn("Failed to prove account range", "origin", req.Origin, "err", err)
|
||||
return nil, nil
|
||||
|
|
@ -427,7 +426,7 @@ func ServiceGetStorageRangesQuery(chain *core.BlockChain, req *GetStorageRangesP
|
|||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
proof := light.NewNodeSet()
|
||||
proof := trie.NewNodeSet()
|
||||
if err := stTrie.Prove(origin[:], proof); err != nil {
|
||||
log.Warn("Failed to prove storage range", "origin", req.Origin, "err", err)
|
||||
return nil, nil
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/light"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/p2p/msgrate"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
|
|
@ -2394,7 +2393,7 @@ func (s *Syncer) OnAccounts(peer SyncPeer, id uint64, hashes []common.Hash, acco
|
|||
for i, key := range hashes {
|
||||
keys[i] = common.CopyBytes(key[:])
|
||||
}
|
||||
nodes := make(light.NodeList, len(proof))
|
||||
nodes := make(trie.NodeList, len(proof))
|
||||
for i, node := range proof {
|
||||
nodes[i] = node
|
||||
}
|
||||
|
|
@ -2639,7 +2638,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(light.NodeList, 0, len(proof))
|
||||
nodes := make(trie.NodeList, 0, len(proof))
|
||||
if i == len(hashes)-1 {
|
||||
for _, node := range proof {
|
||||
nodes = append(nodes, node)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/light"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
|
|
@ -273,7 +272,7 @@ func createAccountRequestResponse(t *testPeer, root common.Hash, origin common.H
|
|||
// Unless we send the entire trie, we need to supply proofs
|
||||
// Actually, we need to supply proofs either way! This seems to be an implementation
|
||||
// quirk in go-ethereum
|
||||
proof := light.NewNodeSet()
|
||||
proof := trie.NewNodeSet()
|
||||
if err := t.accountTrie.Prove(origin[:], proof); err != nil {
|
||||
t.logger.Error("Could not prove inexistence of origin", "origin", origin, "error", err)
|
||||
}
|
||||
|
|
@ -353,7 +352,7 @@ func createStorageRequestResponse(t *testPeer, root common.Hash, accounts []comm
|
|||
if originHash != (common.Hash{}) || (abort && len(keys) > 0) {
|
||||
// If we're aborting, we need to prove the first and last item
|
||||
// This terminates the response (and thus the loop)
|
||||
proof := light.NewNodeSet()
|
||||
proof := trie.NewNodeSet()
|
||||
stTrie := t.storageTries[account]
|
||||
|
||||
// Here's a potential gotcha: when constructing the proof, we cannot
|
||||
|
|
@ -411,7 +410,7 @@ func createStorageRequestResponseAlwaysProve(t *testPeer, root common.Hash, acco
|
|||
if exit {
|
||||
// If we're aborting, we need to prove the first and last item
|
||||
// This terminates the response (and thus the loop)
|
||||
proof := light.NewNodeSet()
|
||||
proof := trie.NewNodeSet()
|
||||
stTrie := t.storageTries[account]
|
||||
|
||||
// Here's a potential gotcha: when constructing the proof, we cannot
|
||||
|
|
@ -599,9 +598,10 @@ func testSyncBloatedProof(t *testing.T, scheme string) {
|
|||
vals = append(vals, entry.v)
|
||||
}
|
||||
// The proofs
|
||||
proof := light.NewNodeSet()
|
||||
proof := trie.NewNodeSet()
|
||||
if err := t.accountTrie.Prove(origin[:], proof); err != nil {
|
||||
t.logger.Error("Could not prove origin", "origin", origin, "error", err)
|
||||
t.logger.Error("Could not prove origin", "origin", origin, "error", err)
|
||||
}
|
||||
// The bloat: add proof of every single element
|
||||
for _, entry := range t.accountValues {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/light"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
)
|
||||
|
||||
// clientHandler is responsible for receiving and processing all incoming server
|
||||
|
|
@ -236,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 light.NodeList
|
||||
Data trie.NodeList
|
||||
}
|
||||
if err := msg.Decode(&resp); err != nil {
|
||||
return errResp(ErrDecode, "msg %v: %v", msg, err)
|
||||
|
|
|
|||
|
|
@ -401,7 +401,7 @@ func testGetProofs(t *testing.T, protocol int) {
|
|||
bc := server.handler.blockchain
|
||||
|
||||
var proofreqs []ProofReq
|
||||
proofsV2 := light.NewNodeSet()
|
||||
proofsV2 := trie.NewNodeSet()
|
||||
|
||||
accounts := []common.Address{bankAddr, userAddr1, userAddr2, signerAddr, {}}
|
||||
for i := uint64(0); i <= bc.CurrentBlock().Number.Uint64(); i++ {
|
||||
|
|
@ -456,7 +456,7 @@ func testGetStaleProof(t *testing.T, protocol int) {
|
|||
|
||||
var expected []rlp.RawValue
|
||||
if wantOK {
|
||||
proofsV2 := light.NewNodeSet()
|
||||
proofsV2 := trie.NewNodeSet()
|
||||
t, _ := trie.New(trie.StateTrieID(header.Root), server.backend.Blockchain().TrieDB())
|
||||
t.Prove(account, proofsV2)
|
||||
expected = proofsV2.NodeList()
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ func (r *TrieRequest) Validate(db ethdb.Database, msg *Msg) error {
|
|||
if msg.MsgType != MsgProofsV2 {
|
||||
return errInvalidMessageType
|
||||
}
|
||||
proofs := msg.Obj.(light.NodeList)
|
||||
proofs := msg.Obj.(trie.NodeList)
|
||||
// Verify the proof and store if checks out
|
||||
nodeSet := proofs.NodeSet()
|
||||
reads := &readTraceDB{db: nodeSet}
|
||||
|
|
@ -308,7 +308,7 @@ type HelperTrieReq struct {
|
|||
}
|
||||
|
||||
type HelperTrieResps struct { // describes all responses, not just a single one
|
||||
Proofs light.NodeList
|
||||
Proofs trie.NodeList
|
||||
AuxData [][]byte
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -899,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 light.NodeList) *reply {
|
||||
func (p *clientPeer) replyProofsV2(reqID uint64, proofs trie.NodeList) *reply {
|
||||
data, _ := rlp.EncodeToBytes(proofs)
|
||||
return &reply{p.rw, ProofsV2Msg, reqID, data}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ func handleGetProofs(msg Decoder) (serveRequestFn, uint64, uint64, error) {
|
|||
err error
|
||||
)
|
||||
bc := backend.BlockChain()
|
||||
nodes := light.NewNodeSet()
|
||||
nodes := trie.NewNodeSet()
|
||||
|
||||
for i, request := range r.Reqs {
|
||||
if i != 0 && !waitOrStop() {
|
||||
|
|
@ -463,7 +463,7 @@ func handleGetHelperTrieProofs(msg Decoder) (serveRequestFn, uint64, uint64, err
|
|||
auxData [][]byte
|
||||
)
|
||||
bc := backend.BlockChain()
|
||||
nodes := light.NewNodeSet()
|
||||
nodes := trie.NewNodeSet()
|
||||
for i, request := range r.Reqs {
|
||||
if i != 0 && !waitOrStop() {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/txpool"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
)
|
||||
|
||||
// NoOdr is the default context passed to an ODR capable function when the ODR
|
||||
|
|
@ -90,7 +91,7 @@ func StorageTrieID(state *TrieID, address common.Address, root common.Hash) *Tri
|
|||
type TrieRequest struct {
|
||||
Id *TrieID
|
||||
Key []byte
|
||||
Proof *NodeSet
|
||||
Proof *trie.NodeSet
|
||||
}
|
||||
|
||||
// StoreResult stores the retrieved data in local database
|
||||
|
|
@ -143,7 +144,7 @@ type ChtRequest struct {
|
|||
ChtRoot common.Hash
|
||||
Header *types.Header
|
||||
Td *big.Int
|
||||
Proof *NodeSet
|
||||
Proof *trie.NodeSet
|
||||
}
|
||||
|
||||
// StoreResult stores the retrieved data in local database
|
||||
|
|
@ -163,7 +164,7 @@ type BloomRequest struct {
|
|||
SectionIndexList []uint64
|
||||
BloomTrieRoot common.Hash
|
||||
BloomBits [][]byte
|
||||
Proofs *NodeSet
|
||||
Proofs *trie.NodeSet
|
||||
}
|
||||
|
||||
// StoreResult stores the retrieved data in local database
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ func (odr *testOdr) Retrieve(ctx context.Context, req OdrRequest) error {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
nodes := NewNodeSet()
|
||||
nodes := trie.NewNodeSet()
|
||||
t.Prove(req.Key, nodes)
|
||||
req.Proof = nodes
|
||||
case *CodeRequest:
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ func NewBloomTrieIndexer(db ethdb.Database, odr OdrBackend, parentSize, size uin
|
|||
func (b *BloomTrieIndexerBackend) fetchMissingNodes(ctx context.Context, section uint64, root common.Hash) error {
|
||||
indexCh := make(chan uint, types.BloomBitLength)
|
||||
type res struct {
|
||||
nodes *NodeSet
|
||||
nodes *trie.NodeSet
|
||||
err error
|
||||
}
|
||||
resCh := make(chan res, types.BloomBitLength)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package light
|
||||
package trie
|
||||
|
||||
import (
|
||||
"errors"
|
||||
Loading…
Reference in a new issue