Skip to content

Commit

Permalink
fix: events: fix event decoding
Browse files Browse the repository at this point in the history
Events were already decoded on insertion. All we need to do is pad keys
to 32 bytes.
  • Loading branch information
Stebalien committed Feb 15, 2023
1 parent 392f1b8 commit ec9cc64
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions chain/events/filter/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,18 +486,14 @@ 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))
}
// If the key isn't 32 bytes, pad it.
if _, ok := topics[key]; ok && len(before) < 32 {
// if this is a topic, leftpad to 32 bytes
pvalue := make([]byte, 32)
copy(pvalue[32-len(after):], after)
after = pvalue
}
if _, err := update.Exec(after, before); err != nil {
return xerrors.Errorf("failed to scan from query: %w", err)
copy(pvalue[32-len(before):], before)
if _, err := update.Exec(pvalue, before); err != nil {
return xerrors.Errorf("failed to scan from query: %w", err)
}
}

if i++; i%500 == 0 {
Expand Down

0 comments on commit ec9cc64

Please sign in to comment.