Skip to content
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

[wip]: trie: stacktrie initialization from proof #28231

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions cmd/devp2p/internal/ethtest/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions eth/protocols/snap/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions eth/protocols/snap/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions eth/protocols/snap/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion les/client_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions les/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions les/odr_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion les/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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}
}
Expand Down
4 changes: 2 additions & 2 deletions les/server_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions light/odr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion light/odr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion light/postprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion light/nodeset.go → trie/nodeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading