Skip to content

Commit

Permalink
Add new EventsDB version that does a full reindex
Browse files Browse the repository at this point in the history
  • Loading branch information
rkalis committed Nov 28, 2024
1 parent 1061d0e commit 1de2d1b
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions lib/databases/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,16 @@ class EventsDB extends Dexie {

constructor() {
super('Events');
this.version(2023_03_14).stores({
events: '[chainId+topicsKey], topics, toBlock',
});

// Add key for chainId
this.version(2023_04_10.1).stores({
events: '[chainId+topicsKey], chainId, topics, toBlock',
});

// On 2023-04-10, We moved the "-50" calculation from the backend to the frontend (for flexibility)
// We need to subtract 50 blocks from the fromBlock and toBlock for Covalent supported chains to make up for this
this.version(2023_04_10.2).upgrade((tx) => {
const affectedChains = [1666600000, 4689, 9001, 71402, 288, 592, 336]; // Covalent supported chains (2023-04-10)
tx.table<Events>('events')
.where('chainId')
.anyOf(affectedChains)
.modify((entry) => {
entry.toBlock -= 50;
});
});

// On 2024-10-25, we fixed that Permit2 events and allowances can also use alternative Permit2 contracts
// This requires a full re-index of all events
this.version(2024_10_25).upgrade((tx) => {
tx.table<Events>('events').clear();
});

// On 2024-11-28, we found a bug with the formatting of specific events, which requires a full re-index of all events.
// Because this is a full re-index, we removed previous database migrations since those are no longer relevant.
this.version(2024_11_28)
.stores({
events: '[chainId+topicsKey], chainId, topics, toBlock',
})
.upgrade((tx) => {
tx.table<Events>('events').clear();
});
}

// Note: It is always assumed that this function is called to get logs for the entire chain (i.e. from block 0 to 'latest')
Expand Down

0 comments on commit 1de2d1b

Please sign in to comment.