Skip to content

Commit

Permalink
Try replicating non-inclusion proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
Manav-Aggarwal committed Oct 27, 2022
1 parent 2931b84 commit 4b0cf54
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
2 changes: 2 additions & 0 deletions deepsubtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ func (dst *DeepSubTree) recursiveSet(node *Node, key []byte, value []byte) (
return nil, false, err
}
orphans := dst.prepareOrphansSlice()
node.persisted = false
newNode, err := dst.balance(node, &orphans)
node.persisted = true
if err != nil {
return nil, false, err
}
Expand Down
52 changes: 26 additions & 26 deletions deepsubtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestDeepSubtreeWWithAddsAndDeletes(t *testing.T) {
fmt.Println("PRINT TREE END")

subsetKeys := [][]byte{
[]byte("b"),
[]byte("a"), []byte("b"),
}
rootHash := tree.root.hash
mutableTree, err := NewMutableTree(db.NewMemDB(), 100, false)
Expand All @@ -164,31 +164,31 @@ func TestDeepSubtreeWWithAddsAndDeletes(t *testing.T) {
// Add exclusion proof for `c`
keyToAdd := []byte("c")
valueToAdd := []byte{3}
nonInclusionProof, err := tree.GetNonMembershipProof(keyToAdd)
require.NoError(err)
nonExist := nonInclusionProof.GetNonexist()
leftNonExist := nonExist.Left
if leftNonExist != nil {
leftKey := leftNonExist.Key
if has, _ := dst.Has(leftKey); !has {
err = dst.AddPath(tree.ImmutableTree, leftKey)
require.NoError(err)
dst.BuildTree(rootHash)
require.NoError(err)
}
// TODO: Add sibling node to dst
}
rightNonExist := nonExist.Right
if rightNonExist != nil {
rightKey := rightNonExist.Key
if has, _ := dst.Has(rightKey); !has {
err = dst.AddPath(tree.ImmutableTree, rightKey)
require.NoError(err)
dst.BuildTree(rootHash)
require.NoError(err)
}
// TODO: Add sibling node to dst
}
// nonInclusionProof, err := tree.GetNonMembershipProof(keyToAdd)
// require.NoError(err)
// nonExist := nonInclusionProof.GetNonexist()
// leftNonExist := nonExist.Left
// if leftNonExist != nil {
// leftKey := leftNonExist.Key
// if has, _ := dst.Has(leftKey); !has {
// err = dst.AddPath(tree.ImmutableTree, leftKey)
// require.NoError(err)
// dst.BuildTree(rootHash)
// require.NoError(err)
// }
// // TODO: Add sibling node to dst
// }
// rightNonExist := nonExist.Right
// if rightNonExist != nil {
// rightKey := rightNonExist.Key
// if has, _ := dst.Has(rightKey); !has {
// err = dst.AddPath(tree.ImmutableTree, rightKey)
// require.NoError(err)
// dst.BuildTree(rootHash)
// require.NoError(err)
// }
// // TODO: Add sibling node to dst
// }

dst.SaveVersion()

Expand Down

0 comments on commit 4b0cf54

Please sign in to comment.