Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Jan 26, 2025
1 parent e571611 commit c51dfe2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 99 deletions.
49 changes: 16 additions & 33 deletions src/executor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import type { Logger, Metrics } from "@alto/utils"
import {
getUserOperationHash,
isVersion06,
maxBigInt,
parseViemError,
scaleBigIntByPercent,
Expand Down Expand Up @@ -118,14 +117,11 @@ export class Executor {
async replaceTransaction(
transactionInfo: TransactionInfo
): Promise<ReplaceTransactionResult> {
const {
isVersion06,
entryPoint,
transactionRequest,
userOperationInfos,
executor,
transactionHash
} = transactionInfo
const { transactionRequest, executor, transactionHash, bundle } =
transactionInfo

const { userOperations, version, entryPoint } = bundle
const isVersion06 = version === "0.6"

let gasPriceParameters: GasPriceParameters
try {
Expand All @@ -148,9 +144,7 @@ export class Executor {
)
}

const opsToResubmit = userOperationInfos.map(
(optr) => optr.userOperation
)
const opsToResubmit = userOperations

const ep = getContract({
abi: isVersion06 ? EntryPointV06Abi : EntryPointV07Abi,
Expand Down Expand Up @@ -223,7 +217,7 @@ export class Executor {
isUserOpVersion06: isVersion06,
isReplacementTx: true,
ops: userOps,
entryPoint: transactionInfo.entryPoint
entryPoint: transactionInfo.bundle.entryPoint
}

try {
Expand Down Expand Up @@ -272,13 +266,10 @@ export class Executor {
...transactionInfo.previousTransactionHashes
],
lastReplaced: Date.now(),
userOperationInfos: opsToBundle.map((op) => {
return {
entryPoint,
userOperation: op,
userOperationHash: this.getOpHashes([op])[0]
}
})
bundle: {
...transactionInfo.bundle,
userOperations: opsToBundle
}
}

return {
Expand Down Expand Up @@ -693,19 +684,12 @@ export class Executor {
}
}

const userOperationInfos = opsToBundle.map((op) => {
return {
entryPoint,
userOperation: op,
userOperationHash: this.getOpHashes([op])[0],
lastReplaced: Date.now(),
firstSubmitted: Date.now()
}
})

const transactionInfo: TransactionInfo = {
entryPoint,
isVersion06: version === "0.6",
bundle: {
entryPoint,
version,
userOperations: opsToBundle
},
transactionHash: transactionHash,
previousTransactionHashes: [],
transactionRequest: {
Expand All @@ -716,7 +700,6 @@ export class Executor {
nonce: nonce
},
executor: wallet,
userOperationInfos,
lastReplaced: Date.now(),
timesPotentiallyIncluded: 0
}
Expand Down
134 changes: 71 additions & 63 deletions src/executor/executorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ export class ExecutorManager {
return txHash
}

getOpHash(userOperation: UserOperation): HexData32 {
getOpHash(userOperation: UserOperation, entryPoint: Address): HexData32 {
return getUserOperationHash(
userOperation,
this.config.entrypoints[0],
entryPoint,
this.config.publicClient.chain.id
)
}
Expand Down Expand Up @@ -256,15 +256,15 @@ export class ExecutorManager {
userOperation: op,
reason
}))
this.dropUserOperations(droppedUserOperations)
this.dropUserOperations(droppedUserOperations, entryPoint)
}

if (bundle.status === "bundle_success") {
const { userOpsBundled, rejectedUserOperations, transactionInfo } =
bundle

this.markUserOperationsAsSubmitted(userOpsBundled, transactionInfo)
this.dropUserOperations(rejectedUserOperations)
this.dropUserOperations(rejectedUserOperations, entryPoint)

return transactionInfo.transactionHash
}
Expand Down Expand Up @@ -304,10 +304,11 @@ export class ExecutorManager {
) {
const {
transactionHash: currentTransactionHash,
userOperationInfos: opInfos,
previousTransactionHashes,
isVersion06
bundle,
previousTransactionHashes
} = transactionInfo
const { userOperations, version } = bundle
const isVersion06 = version === "0.6"

const txHashesToCheck = [
currentTransactionHash,
Expand Down Expand Up @@ -337,15 +338,6 @@ export class ExecutorManager {
const finalizedTransaction = mined ?? reverted

if (!finalizedTransaction) {
for (const { userOperationHash } of opInfos) {
this.logger.trace(
{
userOperationHash,
currentTransactionHash
},
"user op still pending"
)
}
return
}

Expand All @@ -359,11 +351,14 @@ export class ExecutorManager {
if (bundlingStatus.status === "included") {
this.metrics.userOperationsOnChain
.labels({ status: bundlingStatus.status })
.inc(opInfos.length)
.inc(userOperations.length)

const { userOperationDetails } = bundlingStatus
opInfos.map((opInfo) => {
const { userOperation, userOperationHash, entryPoint } = opInfo
userOperations.map((userOperation) => {
const userOperationHash = this.getOpHash(
userOperation,
entryPoint
)
const opDetails = userOperationDetails[userOperationHash]

// TODO: keep this metric
Expand Down Expand Up @@ -418,17 +413,22 @@ export class ExecutorManager {
await this.replaceTransaction(transactionInfo, "AA95")
} else {
await Promise.all(
opInfos.map(({ userOperationHash }) => {
userOperations.map((userOperation) => {
this.checkFrontrun({
userOperationHash,
userOperationHash: this.getOpHash(
userOperation,
entryPoint
),
transactionHash,
blockNumber
})
})
)

opInfos.map(({ userOperationHash }) => {
this.mempool.removeSubmitted(userOperationHash)
userOperations.map((userOperation) => {
this.mempool.removeSubmitted(
this.getOpHash(userOperation, entryPoint)
)
})
this.senderManager.markWalletProcessed(transactionInfo.executor)
}
Expand Down Expand Up @@ -749,18 +749,20 @@ export class ExecutorManager {
}

if (replaceResult.status === "failed") {
const { transactionHash, bundle } = txInfo

this.logger.warn(
{ oldTxHash: txInfo.transactionHash, reason },
{ oldTxHash: transactionHash, reason },
"failed to replace transaction"
)

const droppedUserOperations = txInfo.userOperationInfos.map(
(opInfo) => ({
userOperation: opInfo.userOperation,
const droppedUserOperations = bundle.userOperations.map(
(userOperation) => ({
userOperation,
reason: "Failed to replace transaction"
})
)
this.dropUserOperations(droppedUserOperations)
this.dropUserOperations(droppedUserOperations, bundle.entryPoint)
this.senderManager.markWalletProcessed(txInfo.executor)
return
}
Expand All @@ -773,8 +775,10 @@ export class ExecutorManager {
txInfo.timesPotentiallyIncluded += 1

if (txInfo.timesPotentiallyIncluded >= 3) {
txInfo.userOperationInfos.map((opInfo) => {
this.mempool.removeSubmitted(opInfo.userOperationHash)
txInfo.bundle.userOperations.map((userOperation) => {
this.mempool.removeSubmitted(
this.getOpHash(userOperation, txInfo.bundle.entryPoint)
)
})
const txSender = txInfo.executor
this.senderManager.markWalletProcessed(txSender)
Expand All @@ -789,34 +793,35 @@ export class ExecutorManager {

const newTxInfo = replaceResult.transactionInfo

const missingOps = txInfo.userOperationInfos.filter(
(info) =>
!newTxInfo.userOperationInfos
.map((ni) => ni.userOperationHash)
.includes(info.userOperationHash)
)

const matchingOps = txInfo.userOperationInfos.filter((info) =>
newTxInfo.userOperationInfos
.map((ni) => ni.userOperationHash)
.includes(info.userOperationHash)
)

matchingOps.map((opInfo) => {
this.mempool.replaceSubmitted(opInfo, newTxInfo)
})

missingOps.map((opInfo) => {
this.mempool.removeSubmitted(opInfo.userOperationHash)
this.logger.warn(
{
oldTxHash: txInfo.transactionHash,
newTxHash: newTxInfo.transactionHash,
reason
},
"missing op in new tx"
)
})
// TODO: FIX THIS USING BUDNLE_RESULT SUCCESS opsBundles + opsRejected
//const missingOps = txInfo.bundle.userOperations.filter(
// (info) =>
// !newTxInfo.userOperationInfos
// .map((ni) => ni.userOperationHash)
// .includes(info.userOperationHash)
//)

//const matchingOps = txInfo.userOperationInfos.filter((info) =>
// newTxInfo.userOperationInfos
// .map((ni) => ni.userOperationHash)
// .includes(info.userOperationHash)
//)

//matchingOps.map((opInfo) => {
// this.mempool.replaceSubmitted(opInfo, newTxInfo)
//})

//missingOps.map((opInfo) => {
// this.mempool.removeSubmitted(opInfo.userOperationHash)
// this.logger.warn(
// {
// oldTxHash: txInfo.transactionHash,
// newTxHash: newTxInfo.transactionHash,
// reason
// },
// "missing op in new tx"
// )
//})

this.logger.info(
{
Expand All @@ -835,7 +840,7 @@ export class ExecutorManager {
transactionInfo: TransactionInfo
) {
userOperations.map((op) => {
const opHash = this.getOpHash(op)
const opHash = this.getOpHash(op, transactionInfo.bundle.entryPoint)

this.mempool.markSubmitted(opHash, transactionInfo)

Expand All @@ -859,20 +864,23 @@ export class ExecutorManager {
userOperations.map((op) => {
this.logger.info(
{
userOpHash: this.getOpHash(op),
userOpHash: this.getOpHash(op, entryPoint),
reason
},
"resubmitting user operation"
)
this.mempool.removeProcessing(this.getOpHash(op))
this.mempool.removeProcessing(this.getOpHash(op, entryPoint))
this.mempool.add(op, entryPoint)
this.metrics.userOperationsResubmitted.inc()
})
}

dropUserOperations(rejectedUserOperations: RejectedUserOperation[]) {
dropUserOperations(
rejectedUserOperations: RejectedUserOperation[],
entryPoint: Address
) {
rejectedUserOperations.map(({ userOperation, reason }) => {
const userOpHash = this.getOpHash(userOperation)
const userOpHash = this.getOpHash(userOperation, entryPoint)
this.mempool.removeProcessing(userOpHash)
this.eventManager.emitDropped(
userOpHash,
Expand Down
4 changes: 1 addition & 3 deletions src/types/mempool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ export interface ReferencedCodeHashes {
export type TransactionInfo = {
transactionHash: HexData32
previousTransactionHashes: HexData32[]
entryPoint: Address
isVersion06: boolean
transactionRequest: {
gas: bigint
chain: Chain
maxFeePerGas: bigint
maxPriorityFeePerGas: bigint
nonce: number
}
bundle: UserOperationBundle
executor: Account
userOperationInfos: UserOperationInfo[]
lastReplaced: number
timesPotentiallyIncluded: number
}
Expand Down

0 comments on commit c51dfe2

Please sign in to comment.