Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions store/prefix/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ func (pi *prefixIterator) Key() (key []byte) {
}

key = pi.iter.Key()
key = stripPrefix(key, pi.prefix)
key, ok := bytes.CutPrefix(key, pi.prefix)
if !ok {
panic("should not happen")

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

return
}
Expand Down Expand Up @@ -192,15 +195,6 @@ func (pi *prefixIterator) Error() error {
return nil
}

// stripPrefix is copied from github.com/cometbft/cometbft/libs/db/prefix_db.go
func stripPrefix(key, prefix []byte) []byte {
if len(key) < len(prefix) || !bytes.Equal(key[:len(prefix)], prefix) {
panic("should not happen")
}

return key[len(prefix):]
}

// cpIncr wraps the bytes in types.PrefixEndBytes
func cpIncr(bz []byte) []byte {
return types.PrefixEndBytes(bz)
Expand Down