mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-13 16:49:24 +00:00
[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:
parent
c1a039de3f
commit
956b6f7d95
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user