diff --git a/trie_by_cid/trie/iterator.go b/trie_by_cid/trie/iterator.go index 0067bc0..55e7a96 100644 --- a/trie_by_cid/trie/iterator.go +++ b/trie_by_cid/trie/iterator.go @@ -21,7 +21,6 @@ import ( "errors" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/trie" ) @@ -83,7 +82,7 @@ type nodeIterator struct { path []byte // Path to the current node err error // Failure set in case of an internal error in the iterator - resolver ethdb.KeyValueReader // Optional intermediate resolver above the disk layer + resolver trie.NodeResolver // Optional intermediate resolver above the disk layer } // errIteratorEnd is stored in nodeIterator.err when iteration is done. @@ -111,7 +110,7 @@ func newNodeIterator(trie *Trie, start []byte) NodeIterator { return it } -func (it *nodeIterator) AddResolver(resolver ethdb.KeyValueReader) { +func (it *nodeIterator) AddResolver(resolver trie.NodeResolver) { it.resolver = resolver } @@ -315,7 +314,7 @@ func (it *nodeIterator) peekSeek(seekKey []byte) (*nodeIteratorState, *int, []by func (it *nodeIterator) resolveHash(hash hashNode, path []byte) (node, error) { if it.resolver != nil { - if blob, err := it.resolver.Get(hash); err == nil && len(blob) > 0 { + if blob := it.resolver(it.trie.owner, path, common.BytesToHash(hash)); len(blob) > 0 { if resolved, err := decodeNode(hash, blob); err == nil { return resolved, nil } @@ -326,7 +325,7 @@ func (it *nodeIterator) resolveHash(hash hashNode, path []byte) (node, error) { func (it *nodeIterator) resolveBlob(hash hashNode, path []byte) ([]byte, error) { if it.resolver != nil { - if blob, err := it.resolver.Get(hash); err == nil && len(blob) > 0 { + if blob := it.resolver(it.trie.owner, path, common.BytesToHash(hash)); len(blob) > 0 { return blob, nil } } diff --git a/trie_by_cid/trie/iterator_test.go b/trie_by_cid/trie/iterator_test.go index 2666969..1078b38 100644 --- a/trie_by_cid/trie/iterator_test.go +++ b/trie_by_cid/trie/iterator_test.go @@ -114,14 +114,11 @@ func updateTrie(tr *geth_trie.Trie, vals []kvs) (kvMap, error) { } func commitTrie(t *testing.T, db *geth_trie.Database, tr *geth_trie.Trie) common.Hash { - root, nodes, err := tr.Commit(false) - if err != nil { - t.Fatalf("Failed to commit trie %v", err) - } - if err = db.Update(geth_trie.NewWithNodeSet(nodes)); err != nil { + root, nodes := tr.Commit(false) + if err := db.Update(geth_trie.NewWithNodeSet(nodes)); err != nil { t.Fatal(err) } - if err = db.Commit(root, false, nil); err != nil { + if err := db.Commit(root, false); err != nil { t.Fatal(err) } return root @@ -129,6 +126,7 @@ func commitTrie(t *testing.T, db *geth_trie.Database, tr *geth_trie.Trie) common // commit a LevelDB state trie, index to IPLD and return new trie func indexTrie(t *testing.T, edb ethdb.Database, root common.Hash) *trie.Trie { + dbConfig.Driver = postgres.PGX err := helper.IndexChain(dbConfig, geth_state.NewDatabase(edb), common.Hash{}, root) if err != nil { t.Fatal(err)