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

v2 bundler api #107

Merged
merged 8 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"
}
]
}
}
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.0.0/schema.json",
"files": {
"ignore": [
"node_modules",
Expand Down Expand Up @@ -33,7 +34,7 @@
"enabled": true,
"formatWithErrors": true,
"lineWidth": 80,
"indentSize": 4,
"indentWidth": 4,
"indentStyle": "space"
},
"javascript": {
Expand Down
13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
"dev": "node --inspect packages/cli/lib/alto.js run",
"test": "pnpm -r --workspace-concurrency 1 test --verbose=true",
"test:spec": "./test/spec-tests/run-spec-tests.sh",
"lint": "rome check ./",
"lint:fix": "rome check ./ --apply",
"lint": "biome check .",
"lint:fix": "pnpm run lint --apply",
"format": "biome format . --write"
},
"devDependencies": {
"biome": "^0.3.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove

"@biomejs/biome": "^1.5.1",
"@swc/core": "^1.3.102",
"@types/mocha": "^10.0.6",
Expand All @@ -32,11 +33,5 @@
"engines": {
"node": ">=18.0.0"
},
"workspaces": [
"packages/*",
"test/e2e/*"
],
"dependencies": {
"biome": "^0.3.3"
}
"workspaces": ["packages/*", "test/e2e/*"]
}
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
1 change: 1 addition & 0 deletions packages/cli/src/config/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const bundlerArgsSchema = z.object({

tenderlyEnabled: z.boolean().optional(),
minimumGasPricePercent: z.number().int().min(0),
apiVersion: z.enum(["v1", "v2"]),
noEip1559Support: z.boolean(),
noEthCallOverrideSupport: z.boolean(),
balanceOverrideEnabled: z.boolean(),
Expand Down
20 changes: 13 additions & 7 deletions packages/cli/src/config/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,37 +114,37 @@ export const bundlerOptions: CliCommandOptions<IBundlerArgsInput> = {
publicClientLogLevel: {
description: "Log level for the publicClient module",
type: "string",
require: false,
require: false
},
walletClientLogLevel: {
description: "Log level for the walletClient module",
type: "string",
require: false,
require: false
},
rpcLogLevel: {
description: "Log level for the rpc module",
type: "string",
require: false,
require: false
},
mempoolLogLevel: {
description: "Log level for the mempool module",
type: "string",
require: false,
require: false
},
executorLogLevel: {
description: "Log level for the executor module",
type: "string",
require: false,
require: false
},
reputationManagerLogLevel: {
description: "Log level for the executor module",
type: "string",
require: false,
require: false
},
nonceQueuerLogLevel: {
description: "Log level for the executor module",
type: "string",
require: false,
require: false
},
environment: {
description: "Environment",
Expand All @@ -171,6 +171,12 @@ export const bundlerOptions: CliCommandOptions<IBundlerArgsInput> = {
require: true,
default: 0
},
apiVersion: {
description: "API version of the bundler",
type: "string",
require: false,
default: "v1"
},
noEip1559Support: {
description: "Rpc url does not support EIP1559",
type: "boolean",
Expand Down
106 changes: 83 additions & 23 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 Expand Up @@ -77,12 +77,22 @@ export const bundlerHandler = async (
} else {
logger = initProductionLogger(parsedArgs.logLevel)
}
const rootLogger = logger.child({ module: "root" }, { level: parsedArgs.logLevel })
const rootLogger = logger.child(
{ module: "root" },
{ level: parsedArgs.logLevel }
)

const getChainId = async () => {
const client = createPublicClient({
transport: customTransport(args.rpcUrl, {
logger: logger.child({ module: "public_client" }, { level: parsedArgs.publicClientLogLevel || parsedArgs.logLevel })
logger: logger.child(
{ module: "public_client" },
{
level:
parsedArgs.publicClientLogLevel ||
parsedArgs.logLevel
}
)
})
})
return await client.getChainId()
Expand All @@ -106,7 +116,13 @@ export const bundlerHandler = async (

const client = createPublicClient({
transport: customTransport(args.rpcUrl, {
logger: logger.child({ module: "public_client" }, { level: parsedArgs.publicClientLogLevel || parsedArgs.logLevel })
logger: logger.child(
{ module: "public_client" },
{
level:
parsedArgs.publicClientLogLevel || parsedArgs.logLevel
}
)
}),
chain
})
Expand All @@ -119,17 +135,27 @@ export const bundlerHandler = async (

const walletClient = createWalletClient({
transport: customTransport(parsedArgs.executionRpcUrl ?? args.rpcUrl, {
logger: logger.child({ module: "wallet_client" }, { level: parsedArgs.walletClientLogLevel || parsedArgs.logLevel })
logger: logger.child(
{ module: "wallet_client" },
{
level:
parsedArgs.walletClientLogLevel || parsedArgs.logLevel
}
)
}),
chain
})

const senderManager = new SenderManager(
parsedArgs.signerPrivateKeys,
parsedArgs.utilityPrivateKey,
logger.child({ module: "executor" }, { level: parsedArgs.executorLogLevel || parsedArgs.logLevel }),
logger.child(
{ module: "executor" },
{ level: parsedArgs.executorLogLevel || parsedArgs.logLevel }
),
metrics,
parsedArgs.noEip1559Support,
parsedArgs.apiVersion,
parsedArgs.maxSigners
)

Expand All @@ -142,16 +168,27 @@ export const bundlerHandler = async (
parsedArgs.entryPoint,
BigInt(parsedArgs.minStake),
BigInt(parsedArgs.minUnstakeDelay),
logger.child({ module: "reputation_manager" }, { level: parsedArgs.reputationManagerLogLevel || parsedArgs.logLevel })
logger.child(
{ module: "reputation_manager" },
{
level:
parsedArgs.reputationManagerLogLevel ||
parsedArgs.logLevel
}
)
)

validator = new SafeValidator(
client,
senderManager,
parsedArgs.entryPoint,
logger.child({ module: "rpc" }, { level: parsedArgs.rpcLogLevel || parsedArgs.logLevel }),
logger.child(
{ module: "rpc" },
{ level: parsedArgs.rpcLogLevel || parsedArgs.logLevel }
),
metrics,
parsedArgs.utilityPrivateKey,
parsedArgs.apiVersion,
parsedArgs.tenderlyEnabled,
parsedArgs.balanceOverrideEnabled
)
Expand All @@ -160,9 +197,13 @@ export const bundlerHandler = async (
validator = new UnsafeValidator(
client,
parsedArgs.entryPoint,
logger.child({ module: "rpc" }, { level: parsedArgs.rpcLogLevel || parsedArgs.logLevel }),
logger.child(
{ module: "rpc" },
{ level: parsedArgs.rpcLogLevel || parsedArgs.logLevel }
),
metrics,
parsedArgs.utilityPrivateKey,
parsedArgs.apiVersion,
parsedArgs.tenderlyEnabled,
parsedArgs.balanceOverrideEnabled
)
Expand Down Expand Up @@ -190,7 +231,10 @@ export const bundlerHandler = async (
client,
parsedArgs.entryPoint,
parsedArgs.safeMode,
logger.child({ module: "mempool" }, { level: parsedArgs.mempoolLogLevel || parsedArgs.logLevel }),
logger.child(
{ module: "mempool" },
{ level: parsedArgs.mempoolLogLevel || parsedArgs.logLevel }
),
metrics
)

Expand All @@ -214,7 +258,10 @@ export const bundlerHandler = async (
senderManager,
reputationManager,
parsedArgs.entryPoint,
logger.child({ module: "executor" }, { level: parsedArgs.executorLogLevel || parsedArgs.logLevel }),
logger.child(
{ module: "executor" },
{ level: parsedArgs.executorLogLevel || parsedArgs.logLevel }
),
metrics,
compressionHandler,
!parsedArgs.tenderlyEnabled,
Expand All @@ -231,7 +278,10 @@ export const bundlerHandler = async (
client,
parsedArgs.entryPoint,
parsedArgs.pollingInterval,
logger.child({ module: "executor" }, { level: parsedArgs.executorLogLevel || parsedArgs.logLevel }),
logger.child(
{ module: "executor" },
{ level: parsedArgs.executorLogLevel || parsedArgs.logLevel }
),
metrics,
parsedArgs.bundleMode,
parsedArgs.bundlerFrequency,
Expand All @@ -242,7 +292,10 @@ export const bundlerHandler = async (
mempool,
client,
parsedArgs.entryPoint,
logger.child({ module: "nonce_queuer" }, { level: parsedArgs.nonceQueuerLogLevel || parsedArgs.logLevel }),
logger.child(
{ module: "nonce_queuer" },
{ level: parsedArgs.nonceQueuerLogLevel || parsedArgs.logLevel }
)
)

const rpcEndpoint = new RpcHandler(
Expand All @@ -257,9 +310,13 @@ export const bundlerHandler = async (
reputationManager,
parsedArgs.tenderlyEnabled ?? false,
parsedArgs.minimumGasPricePercent,
parsedArgs.apiVersion,
parsedArgs.noEthCallOverrideSupport,
parsedArgs.rpcMaxBlockRange,
logger.child({ module: "rpc" }, { level: parsedArgs.rpcLogLevel || parsedArgs.logLevel }),
logger.child(
{ module: "rpc" },
{ level: parsedArgs.rpcLogLevel || parsedArgs.logLevel }
),
metrics,
parsedArgs.environment,
compressionHandler,
Expand All @@ -279,7 +336,10 @@ export const bundlerHandler = async (
rpcEndpoint,
parsedArgs.port,
parsedArgs.requestTimeout,
logger.child({ module: "rpc" }, { level: parsedArgs.rpcLogLevel || parsedArgs.logLevel }),
logger.child(
{ module: "rpc" },
{ level: parsedArgs.rpcLogLevel || parsedArgs.logLevel }
),
registry,
metrics
)
Expand Down
Loading
Loading