Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "fix lint issues"" #113

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"type": "node-terminal"
}
]
}
}
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"enabled": true,
"formatWithErrors": true,
"lineWidth": 80,
"indentSize": 4,
"indentWidth": 4,
"indentStyle": "space"
},
"javascript": {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/alto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { bundlerCommand, bundlerOptions } from "./config/options"
import { registerCommandToYargs } from "./util"
import * as sentry from "@sentry/node"
import dotenv from "dotenv"
import yargs from "yargs"
import { hideBin } from "yargs/helpers"
import * as sentry from "@sentry/node"
import { bundlerCommand, bundlerOptions } from "./config/options"
import { registerCommandToYargs } from "./util"

// Load environment variables from .env file
dotenv.config()
Expand Down
18 changes: 9 additions & 9 deletions packages/cli/src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BasicExecutor, ExecutorManager, SenderManager } from "@alto/executor"
import {
type IReputationManager,
MemoryMempool,
Monitor,
NullRepuationManager,
ReputationManager,
type IReputationManager
ReputationManager
} from "@alto/mempool"
import {
NonceQueuer,
Expand All @@ -16,24 +16,24 @@ import {
import type { IValidator } from "@alto/types"
import {
CompressionHandler,
type Logger,
createMetrics,
initDebugLogger,
initProductionLogger,
type Logger
initProductionLogger
} from "@alto/utils"
import { Registry } from "prom-client"
import {
createPublicClient,
createWalletClient,
type Chain,
type PublicClient,
type Transport
type Transport,
createPublicClient,
createWalletClient
} from "viem"
import { fromZodError } from "zod-validation-error"
import {
bundlerArgsSchema,
type IBundlerArgs,
type IBundlerArgsInput
type IBundlerArgsInput,
bundlerArgsSchema
} from "./config"
import { customTransport } from "./customTransport"

Expand Down
32 changes: 22 additions & 10 deletions packages/cli/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import { NodeSDK } from "@opentelemetry/sdk-node"
import { type Attributes, type Context, SpanKind } from "@opentelemetry/api"
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto"
import { Sampler, SamplingDecision, ParentBasedSampler } from "@opentelemetry/sdk-trace-base"
import { Context, Attributes, SpanKind } from "@opentelemetry/api"
import { SemanticAttributes } from "@opentelemetry/semantic-conventions"
import { FetchInstrumentation } from "opentelemetry-instrumentation-fetch-node"
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http"
import { FastifyInstrumentation } from "@opentelemetry/instrumentation-fastify"
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http"
import { PinoInstrumentation } from "@opentelemetry/instrumentation-pino"
import { NodeSDK } from "@opentelemetry/sdk-node"
import {
ParentBasedSampler,
type Sampler,
SamplingDecision
} from "@opentelemetry/sdk-trace-base"
import { SemanticAttributes } from "@opentelemetry/semantic-conventions"
import { FetchInstrumentation } from "opentelemetry-instrumentation-fetch-node"

class CustomSampler implements Sampler {
shouldSample(context: Context, traceId: string, spanName: string, spanKind: SpanKind, attributes: Attributes) {
shouldSample(
context: Context,
traceId: string,
spanName: string,
spanKind: SpanKind,
attributes: Attributes
) {
const ignoredRoutes = ["/metrics", "/health"]

const httpTarget = attributes[SemanticAttributes.HTTP_TARGET]

if (
spanKind === SpanKind.SERVER && httpTarget && ignoredRoutes.includes(httpTarget.toString())
spanKind === SpanKind.SERVER &&
httpTarget &&
ignoredRoutes.includes(httpTarget.toString())
) {
return { decision: SamplingDecision.NOT_RECORD }
}
Expand All @@ -35,9 +47,9 @@ const sdk = new NodeSDK({
}),
new FetchInstrumentation({}),
new FastifyInstrumentation(),
new PinoInstrumentation(),
new PinoInstrumentation()
],
sampler: new ParentBasedSampler({root: new CustomSampler()})
sampler: new ParentBasedSampler({ root: new CustomSampler() })
})

sdk.start()
38 changes: 19 additions & 19 deletions packages/executor/src/executor.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { IReputationManager } from "@alto/mempool"
import type { IReputationManager } from "@alto/mempool"
import {
Address,
BundleResult,
CompressedUserOperation,
type Address,
type BundleResult,
type CompressedUserOperation,
EntryPointAbi,
HexData32,
TransactionInfo,
UserOperation,
UserOperationWithHash,
type HexData32,
type TransactionInfo,
type UserOperation,
type UserOperationWithHash,
deriveUserOperation
} from "@alto/types"
import {
CompressionHandler,
Logger,
Metrics,
type CompressionHandler,
type Logger,
type Metrics,
getGasPrice,
getUserOperationHash,
maxBigInt,
Expand All @@ -22,22 +22,22 @@ import {
import * as sentry from "@sentry/node"
import { Mutex } from "async-mutex"
import {
Account,
Chain,
type Account,
type Chain,
FeeCapTooLowError,
InsufficientFundsError,
IntrinsicGasTooLowError,
NonceTooLowError,
PublicClient,
Transport,
WalletClient,
type PublicClient,
type Transport,
type WalletClient,
encodeFunctionData,
getContract
} from "viem"
import { SenderManager } from "./senderManager"
import type { SenderManager } from "./senderManager"
import {
CompressedFilterOpsAndEstimateGasParams,
DefaultFilterOpsAndEstimateGasParams,
type CompressedFilterOpsAndEstimateGasParams,
type DefaultFilterOpsAndEstimateGasParams,
createCompressedCalldata,
filterOpsAndEstimateGas,
flushStuckTransaction,
Expand Down
94 changes: 62 additions & 32 deletions packages/executor/src/executorManager.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import type { IReputationManager, Mempool, Monitor } from "@alto/mempool"
import {
SubmittedUserOperation,
TransactionInfo,
BundlingMode,
MempoolUserOperation,
CompressedUserOperation,
UserOperation,
type BundleResult,
type BundlingMode,
type CompressedUserOperation,
type HexData32,
type MempoolUserOperation,
type SubmittedUserOperation,
type TransactionInfo,
type UserOperation,
deriveUserOperation,
isCompressedType,
HexData32,
BundleResult
isCompressedType
} from "@alto/types"
import {
Logger,
Metrics,
transactionIncluded,
getGasPrice
type Logger,
type Metrics,
getGasPrice,
transactionIncluded
} from "@alto/utils"
import { IReputationManager, Mempool, Monitor } from "@alto/mempool"
import { IExecutor, ReplaceTransactionResult } from "./executor"
import {
import type {
Address,
Block,
Chain,
Expand All @@ -27,6 +26,7 @@ import {
Transport,
WatchBlocksReturnType
} from "viem"
import type { IExecutor, ReplaceTransactionResult } from "./executor"

function getTransactionsFromUserOperationEntries(
entries: SubmittedUserOperation[]
Expand Down Expand Up @@ -115,21 +115,36 @@ export class ExecutorManager {
}

async sendToExecutor(mempoolOps: MempoolUserOperation[]) {
const ops = mempoolOps.filter((op) => !isCompressedType(op)).map((op) => (op as UserOperation))
const compressedOps = mempoolOps.filter((op) => isCompressedType(op)).map((op) => (op as CompressedUserOperation))
const ops = mempoolOps
.filter((op) => !isCompressedType(op))
.map((op) => op as UserOperation)
const compressedOps = mempoolOps
.filter((op) => isCompressedType(op))
.map((op) => op as CompressedUserOperation)

const bundles: BundleResult[][] = []
if (ops.length > 0) {
bundles.push(await this.executor.bundle(this.entryPointAddress, ops))
bundles.push(
await this.executor.bundle(this.entryPointAddress, ops)
)
}
if (compressedOps.length > 0) {
bundles.push(await this.executor.bundleCompressed(this.entryPointAddress, compressedOps))
bundles.push(
await this.executor.bundleCompressed(
this.entryPointAddress,
compressedOps
)
)
}

for (const bundle of bundles) {
const isBundleSuccess = bundle.every((result) => result.status === "success")
const isBundleSuccess = bundle.every(
(result) => result.status === "success"
)
if (isBundleSuccess) {
this.metrics.bundlesSubmitted.labels({ status: "success" }).inc()
this.metrics.bundlesSubmitted
.labels({ status: "success" })
.inc()
} else {
this.metrics.bundlesSubmitted.labels({ status: "failed" }).inc()
}
Expand All @@ -139,8 +154,13 @@ export class ExecutorManager {

const filteredOutOps = mempoolOps.length - results.length
if (filteredOutOps > 0) {
this.logger.debug({ filteredOutOps }, "user operations filtered out")
this.metrics.userOperationsSubmitted.labels({ status: "filtered" }).inc(filteredOutOps)
this.logger.debug(
{ filteredOutOps },
"user operations filtered out"
)
this.metrics.userOperationsSubmitted
.labels({ status: "filtered" })
.inc(filteredOutOps)
}

let txHash: HexData32 | undefined = undefined
Expand All @@ -162,7 +182,9 @@ export class ExecutorManager {
)
txHash = res.transactionInfo.transactionHash
this.startWatchingBlocks(this.handleBlock.bind(this))
this.metrics.userOperationsSubmitted.labels({ status: "success" }).inc()
this.metrics.userOperationsSubmitted
.labels({ status: "success" })
.inc()
}
if (result.status === "failure") {
this.mempool.removeProcessing(result.error.userOpHash)
Expand All @@ -177,7 +199,9 @@ export class ExecutorManager {
},
"user operation rejected"
)
this.metrics.userOperationsSubmitted.labels({ status: "failed" }).inc()
this.metrics.userOperationsSubmitted
.labels({ status: "failed" })
.inc()
}
if (result.status === "resubmit") {
this.logger.info(
Expand All @@ -189,7 +213,9 @@ export class ExecutorManager {
)
this.mempool.removeProcessing(result.info.userOpHash)
this.mempool.add(result.info.userOperation)
this.metrics.userOperationsSubmitted.labels({ status: "resubmitted" }).inc()
this.metrics.userOperationsSubmitted
.labels({ status: "resubmitted" })
.inc()
}
}
return txHash
Expand Down Expand Up @@ -296,7 +322,9 @@ export class ExecutorManager {
return
}

this.metrics.userOperationsOnChain.labels({ status: status.transactionStatuses.status }).inc(opInfos.length)
this.metrics.userOperationsOnChain
.labels({ status: status.transactionStatuses.status })
.inc(opInfos.length)
if (status.transactionStatuses.status === "included") {
opInfos.map((info) => {
this.metrics.userOperationInclusionDuration.observe(
Expand Down Expand Up @@ -381,7 +409,7 @@ export class ExecutorManager {
this.publicClient.chain,
this.publicClient,
this.noEip1559Support,
this.logger,
this.logger
)
this.logger.trace(
{ gasPriceParameters },
Expand All @@ -396,9 +424,9 @@ export class ExecutorManager {
transactionInfos.map(async (txInfo) => {
if (
txInfo.transactionRequest.maxFeePerGas >=
gasPriceParameters.maxFeePerGas &&
gasPriceParameters.maxFeePerGas &&
txInfo.transactionRequest.maxPriorityFeePerGas >=
gasPriceParameters.maxPriorityFeePerGas
gasPriceParameters.maxPriorityFeePerGas
) {
return
}
Expand Down Expand Up @@ -432,7 +460,9 @@ export class ExecutorManager {
try {
replaceResult = await this.executor.replaceTransaction(txInfo)
} finally {
this.metrics.replacedTransactions.labels({ reason, status: replaceResult?.status || "failed" }).inc()
this.metrics.replacedTransactions
.labels({ reason, status: replaceResult?.status || "failed" })
.inc()
}
if (replaceResult.status === "failed") {
txInfo.userOperationInfos.map((opInfo) => {
Expand Down
Loading
Loading