-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Transaction sender bot (#7586)
Adds a new package `@aztec/bot` that sends txs at regular intervals. The bot idempotently deploys a schnorr account contract and a token contract and mints funds to its own account, and sends a tx with a configurable number of private and public transfers. Bot can be started via `aztec start --bot`, either connected to a remote pxe or using a local one, and optionally run within a node. The bot exposes an http control interface when started, so it can be managed like: ```bash curl -XPOST -d'{"method": "bot_getConfig"}' http://localhost:8090 curl -XPOST -d'{"method": "bot_update", "params": [{"txIntervalSeconds": 20}]}' http://localhost:8090 curl -XPOST -d'{"method": "bot_stop"}' http://localhost:8090 ``` A known issue is that running the bot within a non-sandbox node fails with #7537. Fixes #7562
- Loading branch information
1 parent
26408c1
commit 176fd08
Showing
36 changed files
with
766 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { type BotConfig, BotRunner, createBotRunnerRpcServer, getBotConfigFromEnv } from '@aztec/bot'; | ||
import { type PXE } from '@aztec/circuit-types'; | ||
import { type ServerList } from '@aztec/foundation/json-rpc/server'; | ||
import { type LogFn } from '@aztec/foundation/log'; | ||
|
||
import { mergeEnvVarsAndCliOptions, parseModuleOptions } from '../util.js'; | ||
|
||
export async function startBot( | ||
options: any, | ||
signalHandlers: (() => Promise<void>)[], | ||
userLog: LogFn, | ||
): Promise<ServerList> { | ||
// Services that will be started in a single multi-rpc server | ||
const services: ServerList = []; | ||
|
||
const { proverNode, archiver, sequencer, p2pBootstrap, txe, prover } = options; | ||
if (proverNode || archiver || sequencer || p2pBootstrap || txe || prover) { | ||
userLog( | ||
`Starting a bot with --prover-node, --prover, --archiver, --sequencer, --p2p-bootstrap, or --txe is not supported.`, | ||
); | ||
process.exit(1); | ||
} | ||
|
||
await addBot(options, services, signalHandlers); | ||
return services; | ||
} | ||
|
||
export async function addBot( | ||
options: any, | ||
services: ServerList, | ||
signalHandlers: (() => Promise<void>)[], | ||
deps: { pxe?: PXE } = {}, | ||
) { | ||
const envVars = getBotConfigFromEnv(); | ||
const cliOptions = parseModuleOptions(options.bot); | ||
const config = mergeEnvVarsAndCliOptions<BotConfig>(envVars, cliOptions); | ||
|
||
const botRunner = new BotRunner(config, { pxe: deps.pxe }); | ||
const botServer = createBotRunnerRpcServer(botRunner); | ||
await botRunner.start(); | ||
services.push({ bot: botServer }); | ||
signalHandlers.push(botRunner.stop); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,40 @@ | ||
import { createAztecNodeClient } from '@aztec/circuit-types'; | ||
import { type AztecNode, createAztecNodeClient } from '@aztec/circuit-types'; | ||
import { type ServerList } from '@aztec/foundation/json-rpc/server'; | ||
import { type LogFn } from '@aztec/foundation/log'; | ||
import { type PXEServiceConfig, createPXERpcServer, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; | ||
|
||
import { mergeEnvVarsAndCliOptions, parseModuleOptions } from '../util.js'; | ||
|
||
const { AZTEC_NODE_URL } = process.env; | ||
|
||
export const startPXE = async (options: any, signalHandlers: (() => Promise<void>)[], userLog: LogFn) => { | ||
// Services that will be started in a single multi-rpc server | ||
export async function startPXE(options: any, signalHandlers: (() => Promise<void>)[], userLog: LogFn) { | ||
const services: ServerList = []; | ||
// Starting a PXE with a remote node. | ||
// get env vars first | ||
const pxeConfigEnvVars = getPXEServiceConfig(); | ||
// get config from options | ||
const pxeCliOptions = parseModuleOptions(options.pxe); | ||
await addPXE(options, services, signalHandlers, userLog, {}); | ||
return services; | ||
} | ||
|
||
// Determine node url from options or env vars | ||
const nodeUrl = pxeCliOptions.nodeUrl || AZTEC_NODE_URL; | ||
// throw if no Aztec Node URL is provided | ||
if (!nodeUrl) { | ||
export async function addPXE( | ||
options: any, | ||
services: ServerList, | ||
signalHandlers: (() => Promise<void>)[], | ||
userLog: LogFn, | ||
deps: { node?: AztecNode } = {}, | ||
) { | ||
const pxeCliOptions = parseModuleOptions(options.pxe); | ||
const pxeConfig = mergeEnvVarsAndCliOptions<PXEServiceConfig>(getPXEServiceConfig(), pxeCliOptions); | ||
const nodeUrl = pxeCliOptions.nodeUrl ?? process.env.AZTEC_NODE_URL; | ||
if (!nodeUrl && !deps.node) { | ||
userLog('Aztec Node URL (nodeUrl | AZTEC_NODE_URL) option is required to start PXE without --node option'); | ||
throw new Error('Aztec Node URL (nodeUrl | AZTEC_NODE_URL) option is required to start PXE without --node option'); | ||
process.exit(1); | ||
} | ||
|
||
// merge env vars and cli options | ||
const pxeConfig = mergeEnvVarsAndCliOptions<PXEServiceConfig>(pxeConfigEnvVars, pxeCliOptions); | ||
|
||
// create a node client | ||
const node = createAztecNodeClient(nodeUrl); | ||
|
||
const node = deps.node ?? createAztecNodeClient(nodeUrl); | ||
const pxe = await createPXEService(node, pxeConfig); | ||
const pxeServer = createPXERpcServer(pxe); | ||
|
||
// Add PXE to services list | ||
services.push({ pxe: pxeServer }); | ||
|
||
// Add PXE stop function to signal handlers | ||
signalHandlers.push(pxe.stop); | ||
return services; | ||
}; | ||
|
||
return pxe; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
{ | ||
"path": "../bb-prover" | ||
}, | ||
{ | ||
"path": "../bot" | ||
}, | ||
{ | ||
"path": "../builder" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@aztec/foundation/eslint'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Transactions Bot | ||
|
||
Simple bot that connects to a PXE to send txs on a recurring basis. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"name": "@aztec/bot", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"exports": { | ||
".": "./dest/index.js" | ||
}, | ||
"inherits": [ | ||
"../package.common.json" | ||
], | ||
"scripts": { | ||
"build": "yarn clean && tsc -b", | ||
"build:dev": "tsc -b --watch", | ||
"clean": "rm -rf ./dest .tsbuildinfo", | ||
"formatting": "run -T prettier --check ./src && run -T eslint ./src", | ||
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src", | ||
"bb": "node --no-warnings ./dest/bb/index.js", | ||
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests" | ||
}, | ||
"jest": { | ||
"moduleNameMapper": { | ||
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1" | ||
}, | ||
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", | ||
"rootDir": "./src", | ||
"transform": { | ||
"^.+\\.tsx?$": [ | ||
"@swc/jest", | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"decorators": true | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"extensionsToTreatAsEsm": [ | ||
".ts" | ||
], | ||
"reporters": [ | ||
[ | ||
"default", | ||
{ | ||
"summaryThreshold": 9999 | ||
} | ||
] | ||
] | ||
}, | ||
"dependencies": { | ||
"@aztec/accounts": "workspace:^", | ||
"@aztec/aztec.js": "workspace:^", | ||
"@aztec/circuit-types": "workspace:^", | ||
"@aztec/circuits.js": "workspace:^", | ||
"@aztec/entrypoints": "workspace:^", | ||
"@aztec/foundation": "workspace:^", | ||
"@aztec/noir-contracts.js": "workspace:^", | ||
"@aztec/protocol-contracts": "workspace:^", | ||
"@aztec/types": "workspace:^", | ||
"source-map-support": "^0.5.21", | ||
"tslib": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"@jest/globals": "^29.5.0", | ||
"@types/jest": "^29.5.0", | ||
"@types/memdown": "^3.0.0", | ||
"@types/node": "^18.7.23", | ||
"@types/source-map-support": "^0.5.10", | ||
"jest": "^29.5.0", | ||
"jest-mock-extended": "^3.0.3", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.0.4" | ||
}, | ||
"files": [ | ||
"dest", | ||
"src", | ||
"!*.test.*" | ||
], | ||
"types": "./dest/index.d.ts", | ||
"engines": { | ||
"node": ">=18" | ||
} | ||
} |
Oops, something went wrong.