From 956b6f7d95b6eccfc505750164386f0e2589fd47 Mon Sep 17 00:00:00 2001 From: stasatdaglabs <39559713+stasatdaglabs@users.noreply.github.com> Date: Thu, 2 Apr 2020 17:47:51 +0300 Subject: [PATCH] [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. --- database/ffldb/ldb/cursor.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/database/ffldb/ldb/cursor.go b/database/ffldb/ldb/cursor.go index 43118a8c0..d1ea0248f 100644 --- a/database/ffldb/ldb/cursor.go +++ b/database/ffldb/ldb/cursor.go @@ -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