[NOD-900] Fix bad key in Seek (#687)

* [NOD-900] Fix Seek not working at expected.

* [NOD-900] Wrap error messages.

* [NOD-900] Use ldbIterator.Key instead of LevelDBCursor.Key.

* [NOD-900] Add a comment.
This commit is contained in:
stasatdaglabs 2020-04-02 17:47:51 +03:00 committed by GitHub
parent c1a039de3f
commit 956b6f7d95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,18 +53,20 @@ func (c *LevelDBCursor) Seek(key []byte) error {
return errors.New("cannot seek a closed cursor")
}
notFoundErr := errors.Wrapf(database.ErrNotFound, "key %s not "+
"found", hex.EncodeToString(key))
found := c.ldbIterator.Seek(key)
if !found {
return errors.Wrapf(database.ErrNotFound, "key %s not "+
"found", hex.EncodeToString(key))
return notFoundErr
}
currentKey, err := c.Key()
if err != nil {
return err
// Use c.ldbIterator.Key because c.Key removes the prefix from the key
currentKey := c.ldbIterator.Key()
if currentKey == nil {
return notFoundErr
}
if !bytes.Equal(currentKey, key) {
return errors.Wrapf(database.ErrNotFound, "key %s not "+
"found", hex.EncodeToString(key))
return notFoundErr
}
return nil