arnaucube
arnaucube/arboPublic Self-hosted repository
Small update on errors of UpdateWithTx, GenProofWithTx, ImportDump
arnaucube root@arnaucube.com
Tue, 24 Aug 2021 14:51:16 +0200
commit

5b1a40f7f40e83512231dca9e43074bee3821a38

parent

5f6c35e4354c3a48640b39f9e2bc3d63d2f07939

1 files changed, 12 insertions(+), 3 deletions(-)

jump to
M tree.go → tree.go

@@ -66,6 +66,9 @@ ErrMaxVirtualLevel = fmt.Errorf("max virtual level reached")

// ErrSnapshotNotEditable indicates when the tree is a snapshot, thus // can not be modified ErrSnapshotNotEditable = fmt.Errorf("snapshot tree can not be edited") + // ErrTreeNotEmpty indicates when the tree was expected to be empty and + // it is not + ErrTreeNotEmpty = fmt.Errorf("tree is not empty") ) // Tree defines the struct that implements the MerkleTree functionalities

@@ -578,7 +581,7 @@ return err

} oldKey, _ := ReadLeafValue(valueAtBottom) if !bytes.Equal(oldKey, k) { - return fmt.Errorf("key %s does not exist", hex.EncodeToString(k)) + return ErrKeyNotFound } leafKey, leafValue, err := t.newLeafValue(k, v)

@@ -640,7 +643,7 @@

leafK, leafV := ReadLeafValue(value) if !bytes.Equal(k, leafK) { // key not in tree, proof of non-existence - return leafK, leafV, s, false, err + return leafK, leafV, s, false, nil } return leafK, leafV, s, true, nil

@@ -993,9 +996,15 @@ func (t *Tree) ImportDump(b []byte) error {

if !t.editable() { return ErrSnapshotNotEditable } + root, err := t.Root() + if err != nil { + return err + } + if !bytes.Equal(root, t.emptyHash) { + return ErrTreeNotEmpty + } r := bytes.NewReader(b) - var err error var keys, values [][]byte for { l := make([]byte, 2)