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 24facc0 commit 25daacd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 63 deletions.
10 changes: 5 additions & 5 deletions src/cli/setupServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,13 @@ const getEventManager = ({
const getExecutor = ({
mempool,
config,
senderManager,
reputationManager,
metrics,
gasPriceManager,
eventManager
}: {
mempool: MemoryMempool
config: AltoConfig
senderManager: SenderManager
reputationManager: InterfaceReputationManager
metrics: Metrics
gasPriceManager: GasPriceManager
Expand All @@ -114,7 +112,6 @@ const getExecutor = ({
return new Executor({
mempool,
config,
senderManager,
reputationManager,
metrics,
gasPriceManager,
Expand All @@ -127,6 +124,7 @@ const getExecutorManager = ({
executor,
mempool,
monitor,
senderManager,
reputationManager,
metrics,
gasPriceManager,
Expand All @@ -137,6 +135,7 @@ const getExecutorManager = ({
mempool: MemoryMempool
monitor: Monitor
reputationManager: InterfaceReputationManager
senderManager: SenderManager
metrics: Metrics
gasPriceManager: GasPriceManager
eventManager: EventManager
Expand All @@ -146,6 +145,7 @@ const getExecutorManager = ({
executor,
mempool,
monitor,
senderManager,
reputationManager,
metrics,
gasPriceManager,
Expand Down Expand Up @@ -275,7 +275,6 @@ export const setupServer = async ({
const executor = getExecutor({
mempool,
config,
senderManager,
reputationManager,
metrics,
gasPriceManager,
Expand All @@ -287,6 +286,7 @@ export const setupServer = async ({
executor,
mempool,
monitor,
senderManager,
reputationManager,
metrics,
gasPriceManager,
Expand Down Expand Up @@ -314,7 +314,7 @@ export const setupServer = async ({
})

if (config.flushStuckTransactionsDuringStartup) {
executor.flushStuckTransactions()
senderManager.flushOnStartUp()
}

const rootLogger = config.getLogger(
Expand Down
55 changes: 2 additions & 53 deletions src/executor/executor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { SenderManager } from "@alto/executor"
import type { EventManager, GasPriceManager } from "@alto/handlers"
import type { InterfaceReputationManager, MemoryMempool } from "@alto/mempool"
import {
Expand Down Expand Up @@ -37,11 +36,7 @@ import {
BaseError,
NonceTooHighError
} from "viem"
import {
flushStuckTransaction,
isTransactionUnderpricedError,
getAuthorizationList
} from "./utils"
import { isTransactionUnderpricedError, getAuthorizationList } from "./utils"
import type { SendTransactionErrorType } from "viem"
import type { AltoConfig } from "../createConfig"
import type { SendTransactionOptions } from "./types"
Expand Down Expand Up @@ -76,7 +71,6 @@ export type ReplaceTransactionResult =
export class Executor {
// private unWatch: WatchBlocksReturnType | undefined
config: AltoConfig
senderManager: SenderManager
logger: Logger
metrics: Metrics
reputationManager: InterfaceReputationManager
Expand All @@ -88,23 +82,20 @@ export class Executor {
constructor({
config,
mempool,
senderManager,
reputationManager,
metrics,
gasPriceManager,
eventManager
}: {
config: AltoConfig
mempool: MemoryMempool
senderManager: SenderManager
reputationManager: InterfaceReputationManager
metrics: Metrics
gasPriceManager: GasPriceManager
eventManager: EventManager
}) {
this.config = config
this.mempool = mempool
this.senderManager = senderManager
this.reputationManager = reputationManager
this.logger = config.getLogger(
{ module: "executor" },
Expand All @@ -123,13 +114,6 @@ export class Executor {
throw new Error("Method not implemented.")
}

markWalletProcessed(executor: Account) {
if (!this.senderManager.availableWallets.includes(executor)) {
this.senderManager.pushWallet(executor)
}
return Promise.resolve()
}

async replaceTransaction(
transactionInfo: TransactionInfo
): Promise<ReplaceTransactionResult> {
Expand Down Expand Up @@ -351,38 +335,6 @@ export class Executor {
})
}

async flushStuckTransactions(): Promise<void> {
const allWallets = new Set(this.senderManager.wallets)

const utilityWallet = this.senderManager.utilityAccount
if (utilityWallet) {
allWallets.add(utilityWallet)
}

const wallets = Array.from(allWallets)

const gasPrice = await this.gasPriceManager.tryGetNetworkGasPrice()

const promises = wallets.map((wallet) => {
try {
flushStuckTransaction(
this.config.publicClient,
this.config.walletClient,
wallet,
gasPrice.maxFeePerGas * 5n,
this.logger
)
} catch (e) {
this.logger.error(
{ error: e },
"error flushing stuck transaction"
)
}
})

await Promise.all(promises)
}

async sendHandleOpsTransaction({
txParam,
opts
Expand Down Expand Up @@ -567,11 +519,10 @@ export class Executor {
}

async bundle(
wallet: Account,
entryPoint: Address,
ops: UserOperation[]
): Promise<BundleResult> {
const wallet = await this.senderManager.getWallet()

// Find bundle EntryPoint version.
const firstOpVersion = isVersion06(ops[0])
const allSameVersion = ops.every(
Expand Down Expand Up @@ -613,7 +564,6 @@ export class Executor {
{ error: err },
"Failed to get parameters for bundling"
)
this.markWalletProcessed(wallet)
return {
status: "bundle_resubmit",
reason: "Failed to get parameters for bundling",
Expand Down Expand Up @@ -654,7 +604,6 @@ export class Executor {
return {
status: "bundle_failure",
reason: "INTERNAL FAILURE",
// TODO: we want to log the failure reason
userOpsBundled: ops
}
}
Expand Down
24 changes: 19 additions & 5 deletions src/executor/executorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import {
TransactionReceiptNotFoundError,
type WatchBlocksReturnType,
getAbiItem,
Hex
Hex,
Account
} from "viem"
import type { Executor, ReplaceTransactionResult } from "./executor"
import type { AltoConfig } from "../createConfig"
import { SenderManager } from "./senderManager"

function getTransactionsFromUserOperationEntries(
entries: SubmittedUserOperation[]
Expand All @@ -53,6 +55,7 @@ const SCALE_FACTOR = 10 // Interval increases by 5ms per task per minute
const RPM_WINDOW = 60000 // 1 minute window in ms

export class ExecutorManager {
private senderManager: SenderManager
private config: AltoConfig
private executor: Executor
private mempool: MemoryMempool
Expand All @@ -75,7 +78,8 @@ export class ExecutorManager {
reputationManager,
metrics,
gasPriceManager,
eventManager
eventManager,
senderManager
}: {
config: AltoConfig
executor: Executor
Expand All @@ -85,6 +89,7 @@ export class ExecutorManager {
metrics: Metrics
gasPriceManager: GasPriceManager
eventManager: EventManager
senderManager: SenderManager
}) {
this.config = config
this.reputationManager = reputationManager
Expand All @@ -100,6 +105,7 @@ export class ExecutorManager {
this.metrics = metrics
this.gasPriceManager = gasPriceManager
this.eventManager = eventManager
this.senderManager = senderManager

this.bundlingMode = this.config.bundleMode

Expand Down Expand Up @@ -223,13 +229,21 @@ export class ExecutorManager {
entryPoint: Address,
userOps: UserOperation[]
): Promise<Hex[]> {
const bundles: BundleResult[] = []
if (userOps.length === 0) {
return []
}

const bundles: { wallet: Account; bundle: BundleResult }[] = []
if (userOps.length > 0) {
bundles.push(await this.executor.bundle(entryPoint, userOps))
const wallet = await this.senderManager.getWallet()
bundles.push({
wallet,
bundle: await this.executor.bundle(wallet, entryPoint, userOps)
})
}

let txHashes: Hex[] = []
for (const bundle of bundles) {
for (const { wallet, bundle } of bundles) {
switch (bundle.status) {
case "bundle_success":
this.metrics.bundlesSubmitted
Expand Down
40 changes: 40 additions & 0 deletions src/executor/senderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getContract
} from "viem"
import type { AltoConfig } from "../createConfig"
import { flushStuckTransaction } from "./utils"

const waitForTransactionReceipt = async (
publicClient: PublicClient,
Expand Down Expand Up @@ -261,4 +262,43 @@ export class SenderManager {
this.metrics.walletsAvailable.set(this.availableWallets.length)
return
}

public markWalletProcessed(executor: Account) {
if (!this.availableWallets.includes(executor)) {
this.pushWallet(executor)
}
return Promise.resolve()
}

async flushOnStartUp(): Promise<void> {
const allWallets = new Set(this.wallets)

const utilityWallet = this.utilityAccount
if (utilityWallet) {
allWallets.add(utilityWallet)
}

const wallets = Array.from(allWallets)

const gasPrice = await this.gasPriceManager.tryGetNetworkGasPrice()

const promises = wallets.map((wallet) => {
try {
flushStuckTransaction(
this.config.publicClient,
this.config.walletClient,
wallet,
gasPrice.maxFeePerGas * 5n,
this.logger
)
} catch (e) {
this.logger.error(
{ error: e },
"error flushing stuck transaction"
)
}
})

await Promise.all(promises)
}
}

0 comments on commit 25daacd

Please sign in to comment.