Skip to content

Commit

Permalink
Merge pull request #269 from pimlicolabs/fix/included-timestamp
Browse files Browse the repository at this point in the history
fix timestamp for includedOnChain event
  • Loading branch information
mouseless0x authored Jul 16, 2024
2 parents ef2fe58 + db796bf commit 994e556
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
5 changes: 3 additions & 2 deletions src/executor/executorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export class ExecutorManager {
this.eventManager.emitIncludedOnChain(
userOperationHash,
status.hash,
Number(status.transactionStatuses.blockTimeStamp) * 1000
status.transactionStatuses.blockNumber as bigint
)
this.monitor.setUserOperationStatus(userOperationHash, {
status: "included",
Expand Down Expand Up @@ -457,7 +457,8 @@ export class ExecutorManager {
})
this.eventManager.emitFailedOnChain(
userOperationHash,
status.hash
status.hash,
status.transactionStatuses.blockNumber as bigint
)
this.logger.info(
{
Expand Down
32 changes: 24 additions & 8 deletions src/handlers/eventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,37 @@ export class EventManager {
}

// emits when the userOperation was mined onchain but failed
async emitFailedOnChain(userOperationHash: Hex, transactionHash: Hex) {
async emitFailedOnChain(
userOperationHash: Hex,
transactionHash: Hex,
blockNumber: bigint
) {
await this.emitEvent({
userOperationHash,
event: {
eventType: "failed_onchain",
transactionHash
transactionHash,
data: {
blockNumber: Number(blockNumber)
}
}
})
}

// emits when the userOperation has been included onchain but bundled by a frontrunner
async emitFrontranOnChain(userOperationHash: Hex, transactionHash: Hex) {
async emitFrontranOnChain(
userOperationHash: Hex,
transactionHash: Hex,
blockNumber: bigint
) {
await this.emitEvent({
userOperationHash,
event: {
eventType: "frontran_onchain",
transactionHash
transactionHash,
data: {
blockNumber: Number(blockNumber)
}
}
})
}
Expand All @@ -55,15 +69,17 @@ export class EventManager {
async emitIncludedOnChain(
userOperationHash: Hex,
transactionHash: Hex,
timestamp: number
blockNumber: bigint
) {
await this.emitEvent({
userOperationHash,
event: {
eventType: "included_onchain",
transactionHash
},
timestamp
transactionHash,
data: {
blockNumber: Number(blockNumber)
}
}
})
}

Expand Down
15 changes: 12 additions & 3 deletions src/types/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,15 +825,24 @@ const OpEventType = z.union([
}),
z.object({
eventType: z.literal("included_onchain"),
transactionHash: hexData32Schema
transactionHash: hexData32Schema,
data: z.object({
blockNumber: z.number()
})
}),
z.object({
eventType: z.literal("frontran_onchain"),
transactionHash: hexData32Schema
transactionHash: hexData32Schema,
data: z.object({
blockNumber: z.number()
})
}),
z.object({
eventType: z.literal("failed_onchain"),
transactionHash: hexData32Schema
transactionHash: hexData32Schema,
data: z.object({
blockNumber: z.number()
})
})
])

Expand Down
15 changes: 6 additions & 9 deletions src/utils/userop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,11 @@ export const transactionIncluded = async (
[userOperationHash: HexData32]: {
accountDeployed: boolean
}
blockTimeStamp: bigint
blockNumber: bigint | undefined
}> => {
try {
const rcp = await publicClient.getTransactionReceipt({ hash: txHash })
const block = await publicClient.getBlock({
blockHash: rcp.blockHash
})
const blockTimeStamp = block.timestamp
const blockNumber = rcp.blockNumber

if (rcp.status === "success") {
// find if any logs are UserOperationEvent or AccountDeployed
Expand Down Expand Up @@ -283,23 +280,23 @@ export const transactionIncluded = async (
if (success) {
return {
status: "included",
blockTimeStamp,
blockNumber,
...r
}
}
return {
status: "reverted",
blockTimeStamp
blockNumber
}
}
return {
status: "failed",
blockTimeStamp
blockNumber
}
} catch (_e) {
return {
status: "not_found",
blockTimeStamp: 0n
blockNumber: undefined
}
}
}
Expand Down

0 comments on commit 994e556

Please sign in to comment.