Skip to content

Commit

Permalink
Fixed missing wasm state timestamp and don't fetch block time for eve…
Browse files Browse the repository at this point in the history
…nts with the wrong store.
  • Loading branch information
NoahSaso committed Oct 4, 2023
1 parent 2bd0ba5 commit 38d81ed
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/db/models/WasmStateEventTransformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export class WasmStateEventTransformation extends DependendableEventModel {
''
)

// 2. Extract contract address from key.
// Dependent keys for any contract start with "*:".
// 2. Extract contract address from key. Dependent keys for any contract
// start with "*:".
const contractAddress = key.startsWith('*:') ? '' : key.split(':')[0]

key = key
Expand Down Expand Up @@ -235,8 +235,8 @@ export class WasmStateEventTransformation extends DependendableEventModel {
event.delete && !transformer.manuallyTransformDeletes
? null
: await transformer.getValue(event, async () => {
// Find most recent transformation for this contract and name before
// this block.
// Find most recent transformation for this contract and name
// before this block.

// Check evaluated transformations in case the most recent
// transformation is in the current group of events.
Expand Down
23 changes: 11 additions & 12 deletions src/scripts/export/handlers/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,14 @@ export const wasm: HandlerMaker<WasmExportData> = async ({
}

// Export state.
let stateEvents = events.flatMap((event) =>
event.type === 'state' ? event.data : []
)
let stateEvents = events
.flatMap((event) => (event.type === 'state' ? event.data : []))
.map(
(e): ParsedWasmStateEvent => ({
...e,
blockTimestamp: new Date(Number(e.blockTimeUnixMs)),
})
)
if (!stateEvents.length) {
return
}
Expand Down Expand Up @@ -319,15 +324,9 @@ export const wasm: HandlerMaker<WasmExportData> = async ({
// don't insert duplicate events. If we encounter a duplicate, we update
// the `value`, `valueJson`, and `delete` fields in case event processing
// for a block was batched separately.
const events = await WasmStateEvent.bulkCreate(
stateEvents.map((e) => ({
...e,
blockTimestamp: new Date(Number(e.blockTimeUnixMs)),
})),
{
updateOnDuplicate: ['value', 'valueJson', 'delete'],
}
)
const events = await WasmStateEvent.bulkCreate(stateEvents, {
updateOnDuplicate: ['value', 'valueJson', 'delete'],
})

return {
contracts,
Expand Down
11 changes: 11 additions & 0 deletions src/scripts/export/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ const trace = async () => {
return
}

// If trace has `store_name` that does not exist in any of the handlers,
// ignore.
if (
trace.metadata.store_name &&
!handlers.some(
({ handler }) => handler.storeName === trace.metadata.store_name
)
) {
return
}

// Fetch block time.
const blockTimeUnixMs = await getBlockTimeUnixMs(trace)
const eventWithBlockTime: TracedEventWithBlockTime = {
Expand Down

0 comments on commit 38d81ed

Please sign in to comment.