Skip to content

Commit

Permalink
fix: events: handle pre-decoded events in migration (#10275)
Browse files Browse the repository at this point in the history
* fix: events: handle decoded events in database

We merged #10085 without a
migration, so the event database will contain both cbor and non-cbor
values. We need to handle that.

* fix: imports
  • Loading branch information
Stebalien authored Feb 15, 2023
1 parent 392f1b8 commit 017f328
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions chain/events/filter/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"database/sql"
"encoding/hex"
"errors"
"fmt"
"sort"
Expand Down Expand Up @@ -486,11 +485,15 @@ func (ei *EventIndex) RunMigration(from, to int) error {
if err := rows.Scan(&key, &before); err != nil {
return xerrors.Errorf("failed to scan from query: %w", err)
}
after, err := cbg.ReadByteArray(bytes.NewReader(before), 4<<20)
if err != nil {
return xerrors.Errorf("failed to decode cbor: %w; value: %s", err, hex.EncodeToString(before))
reader := bytes.NewReader(before)
after, err := cbg.ReadByteArray(reader, 4<<20)
if err != nil || reader.Len() > 0 {
// Before Jan 23 we decoded events before putting them into the database. So
// we're just going to assume that that's what's happening here, log an
// error, and continue.
after = before
}
if _, ok := topics[key]; ok && len(before) < 32 {
if _, ok := topics[key]; ok && len(after) < 32 {
// if this is a topic, leftpad to 32 bytes
pvalue := make([]byte, 32)
copy(pvalue[32-len(after):], after)
Expand Down

0 comments on commit 017f328

Please sign in to comment.