Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client/db/bolt: ignore notes with bad IDs #2144

Merged
merged 1 commit into from Feb 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion client/db/bolt/db.go
Expand Up @@ -1835,7 +1835,7 @@ func (db *BoltDB) AckNotification(id []byte) error {
// NotificationsN reads out the N most recent notifications.
func (db *BoltDB) NotificationsN(n int) ([]*dexdb.Notification, error) {
notes := make([]*dexdb.Notification, 0, n)
return notes, db.notesView(func(master *bbolt.Bucket) error {
return notes, db.notesUpdate(func(master *bbolt.Bucket) error {
trios := newestBuckets([]*bbolt.Bucket{master}, n, stampKey, nil)
for _, trio := range trios {
note, err := dexdb.DecodeNotification(getCopy(trio.b, noteKey))
Expand All @@ -1844,6 +1844,17 @@ func (db *BoltDB) NotificationsN(n int) ([]*dexdb.Notification, error) {
}
note.Ack = bEqual(trio.b.Get(ackKey), byteTrue)
note.Id = note.ID()
if !bytes.Equal(note.Id, trio.k) {
// This notification was initially stored when the serialization
// and thus note ID did not include the TopicID. Ignore it, and
// flag it acknowledged so we don't have to hear about it again.
if !note.Ack {
db.log.Tracef("Ignoring stored note with bad key: %x != %x \"%s\"",
[]byte(note.Id), trio.k, note.String())
_ = trio.b.Put(ackKey, byteTrue)
}
continue
}
notes = append(notes, note)
}
return nil
Expand Down