Skip to content

Commit 0b4f33d

Browse files
authored
feat(trie): export LoadFromProof (#2455)
1 parent 620535d commit 0b4f33d

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

lib/trie/database.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,17 @@ func (t *Trie) store(db chaindb.Batch, n Node) error {
7878
return nil
7979
}
8080

81-
// loadFromProof create a partial trie based on the proof slice, as it only contains nodes that are in the proof afaik.
82-
func (t *Trie) loadFromProof(rawProof [][]byte, rootHash []byte) error {
83-
if len(rawProof) == 0 {
81+
// LoadFromProof sets a partial trie based on the proof slice of encoded nodes.
82+
// Note this is exported because it is imported is used by:
83+
// https://github.com/ComposableFi/ibc-go/blob/6d62edaa1a3cb0768c430dab81bb195e0b0c72db/modules/light-clients/11-beefy/types/client_state.go#L78
84+
func (t *Trie) LoadFromProof(proofEncodedNodes [][]byte, rootHash []byte) error {
85+
if len(proofEncodedNodes) == 0 {
8486
return ErrEmptyProof
8587
}
8688

87-
proofHashToNode := make(map[string]Node, len(rawProof))
89+
proofHashToNode := make(map[string]Node, len(proofEncodedNodes))
8890

89-
for i, rawNode := range rawProof {
91+
for i, rawNode := range proofEncodedNodes {
9092
decodedNode, err := node.Decode(bytes.NewReader(rawNode))
9193
if err != nil {
9294
return fmt.Errorf("%w: at index %d: 0x%x",

lib/trie/proof.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func VerifyProof(proof [][]byte, root []byte, items []Pair) (bool, error) {
8484
}
8585

8686
proofTrie := NewEmptyTrie()
87-
if err := proofTrie.loadFromProof(proof, root); err != nil {
87+
if err := proofTrie.LoadFromProof(proof, root); err != nil {
8888
return false, fmt.Errorf("%w: %s", ErrLoadFromProof, err)
8989
}
9090

lib/trie/proof_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestVerifyProof_ShouldReturnTrueWithouCompareValues(t *testing.T) {
161161
require.NoError(t, err)
162162
}
163163

164-
func TestBranchNodes_SameHash_DiferentPaths_GenerateAndVerifyProof(t *testing.T) {
164+
func TestBranchNodes_SameHash_DifferentPaths_GenerateAndVerifyProof(t *testing.T) {
165165
value := []byte("somevalue")
166166
entries := []Pair{
167167
{Key: []byte("d"), Value: value},

0 commit comments

Comments
 (0)