From 659fbccd2fa8a40713f9133db891c9c8d5598ecc Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Fri, 16 Aug 2024 13:34:40 -0300 Subject: [PATCH 1/7] feat: Add max pending txs to bot Adds a config to txs bot so it does not send more txs if there are more than N pending txs. Adds a requirement for an AZTEC_NODE_URL to be passed into the bot runner. --- .../aztec-node/src/aztec-node/server.ts | 4 ++++ yarn-project/aztec/src/cli/cmds/start_bot.ts | 6 +++--- yarn-project/aztec/src/cli/cmds/start_node.ts | 2 +- yarn-project/bot/src/config.ts | 14 +++++++++++++ yarn-project/bot/src/runner.ts | 21 +++++++++++++++---- .../src/interfaces/aztec-node.ts | 6 ++++++ yarn-project/foundation/src/config/env_var.ts | 1 + 7 files changed, 46 insertions(+), 8 deletions(-) diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 9d2dfd36cb99..3b951bc580c1 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -385,6 +385,10 @@ export class AztecNodeService implements AztecNode { return Promise.resolve(this.p2pClient!.getTxs('pending')); } + public getPendingTxCount() { + return Promise.resolve(this.p2pClient!.getTxs('pending').length); + } + /** * Method to retrieve a single tx from the mempool or unfinalised chain. * @param txHash - The transaction hash to return. diff --git a/yarn-project/aztec/src/cli/cmds/start_bot.ts b/yarn-project/aztec/src/cli/cmds/start_bot.ts index 0888b9dbf638..4d45dd4e0db0 100644 --- a/yarn-project/aztec/src/cli/cmds/start_bot.ts +++ b/yarn-project/aztec/src/cli/cmds/start_bot.ts @@ -1,5 +1,5 @@ import { type BotConfig, BotRunner, botConfigMappings, createBotRunnerRpcServer } from '@aztec/bot'; -import { type PXE } from '@aztec/circuit-types'; +import { type AztecNode, type PXE } from '@aztec/circuit-types'; import { type ServerList } from '@aztec/foundation/json-rpc/server'; import { type LogFn } from '@aztec/foundation/log'; @@ -35,11 +35,11 @@ export function addBot( options: any, services: ServerList, signalHandlers: (() => Promise)[], - deps: { pxe?: PXE } = {}, + deps: { pxe?: PXE; node?: AztecNode } = {}, ) { const config = extractRelevantOptions(options, botConfigMappings); - const botRunner = new BotRunner(config, { pxe: deps.pxe }); + const botRunner = new BotRunner(config, deps); const botServer = createBotRunnerRpcServer(botRunner); if (!config.noStart) { void botRunner.start(); // Do not block since bot setup takes time diff --git a/yarn-project/aztec/src/cli/cmds/start_node.ts b/yarn-project/aztec/src/cli/cmds/start_node.ts index d1e2f1121da7..9748e4f57e13 100644 --- a/yarn-project/aztec/src/cli/cmds/start_node.ts +++ b/yarn-project/aztec/src/cli/cmds/start_node.ts @@ -113,7 +113,7 @@ export const startNode = async ( // Add a txs bot if requested if (options.bot) { const { addBot } = await import('./start_bot.js'); - await addBot(options, services, signalHandlers, { pxe }); + await addBot(options, services, signalHandlers, { pxe, node }); } return services; diff --git a/yarn-project/bot/src/config.ts b/yarn-project/bot/src/config.ts index 4512902f7c15..08c9cc2939e5 100644 --- a/yarn-project/bot/src/config.ts +++ b/yarn-project/bot/src/config.ts @@ -11,6 +11,8 @@ const botFollowChain = ['NONE', 'PENDING', 'PROVEN'] as const; type BotFollowChain = (typeof botFollowChain)[number]; export type BotConfig = { + /** The URL to the Aztec node to check for tx pool status. */ + nodeUrl: string | undefined; /** URL to the PXE for sending txs, or undefined if an in-proc PXE is used. */ pxeUrl: string | undefined; /** Signing private key for the sender account. */ @@ -31,10 +33,17 @@ export type BotConfig = { noStart: boolean; /** How long to wait for a tx to be mined before reporting an error. */ txMinedWaitSeconds: number; + /** Whether to wait for txs to be proven, to be mined, or no wait at all. */ followChain: BotFollowChain; + /** Do not send a tx if the node's tx pool already has this many pending txs. */ + maxPendingTxs: number; }; export const botConfigMappings: ConfigMappingsType = { + nodeUrl: { + env: 'AZTEC_NODE_URL', + description: 'The URL to the Aztec node to check for tx pool status.', + }, pxeUrl: { env: 'BOT_PXE_URL', description: 'URL to the PXE for sending txs, or undefined if an in-proc PXE is used.', @@ -99,6 +108,11 @@ export const botConfigMappings: ConfigMappingsType = { return val as BotFollowChain; }, }, + maxPendingTxs: { + env: 'BOT_MAX_PENDING_TXS', + description: "Do not send a tx if the node's tx pool already has this many pending txs.", + ...numberConfigHelper(128), + }, }; export function getBotConfigFromEnv(): BotConfig { diff --git a/yarn-project/bot/src/runner.ts b/yarn-project/bot/src/runner.ts index 3a5206c7f99c..6159c7c605d4 100644 --- a/yarn-project/bot/src/runner.ts +++ b/yarn-project/bot/src/runner.ts @@ -1,4 +1,4 @@ -import { type PXE, createDebugLogger } from '@aztec/aztec.js'; +import { type AztecNode, type PXE, createAztecNodeClient, createDebugLogger } from '@aztec/aztec.js'; import { RunningPromise } from '@aztec/foundation/running-promise'; import { Bot } from './bot.js'; @@ -8,11 +8,16 @@ export class BotRunner { private log = createDebugLogger('aztec:bot'); private bot?: Promise; private pxe?: PXE; + private node: AztecNode; private runningPromise: RunningPromise; - public constructor(private config: BotConfig, dependencies: { pxe?: PXE } = {}) { + public constructor(private config: BotConfig, dependencies: { pxe?: PXE; node?: AztecNode }) { this.pxe = dependencies.pxe; - this.runningPromise = new RunningPromise(() => this.#safeRun(), config.txIntervalSeconds * 1000); + if (!dependencies.node && !config.nodeUrl) { + throw new Error(`Missing node URL in config or dependencies`); + } + this.node = dependencies.node ?? createAztecNodeClient(config.nodeUrl!); + this.runningPromise = new RunningPromise(() => this.#work(), config.txIntervalSeconds * 1000); } /** Initializes the bot if needed. Blocks until the bot setup is finished. */ @@ -112,7 +117,15 @@ export class BotRunner { } } - async #safeRun() { + async #work() { + if (this.config.maxPendingTxs > 0) { + const pendingTxs = await this.node.getPendingTxs(); + if (pendingTxs.length >= this.config.maxPendingTxs) { + this.log.verbose(`Not sending bot tx since node has ${pendingTxs.length} pending txs`); + return; + } + } + try { await this.run(); } catch (err) { diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index 73fd5f61f8ac..fc712a7339fb 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -283,6 +283,12 @@ export interface AztecNode { */ getPendingTxs(): Promise; + /** + * Retrieves the number of pending txs + * @returns The number of pending txs. + */ + getPendingTxCount(): Promise; + /** * Method to retrieve a single pending tx. * @param txHash - The transaction hash to return. diff --git a/yarn-project/foundation/src/config/env_var.ts b/yarn-project/foundation/src/config/env_var.ts index 438571ed225b..cf78a19e91be 100644 --- a/yarn-project/foundation/src/config/env_var.ts +++ b/yarn-project/foundation/src/config/env_var.ts @@ -89,6 +89,7 @@ export type EnvVar = | 'BOT_NO_START' | 'BOT_TX_MINED_WAIT_SECONDS' | 'BOT_NO_WAIT_FOR_TRANSFERS' + | 'BOT_MAX_PENDING_TXS' | 'PXE_BLOCK_POLLING_INTERVAL_MS' | 'PXE_L2_STARTING_BLOCK' | 'PXE_DATA_DIRECTORY' From ebde8b6495f9c82d1472a0407c936bfb75433d2d Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 19 Aug 2024 10:41:11 +0000 Subject: [PATCH 2/7] Bot flush setup transactions --- yarn-project/aztec/terraform/bot/main.tf | 3 ++- yarn-project/aztec/terraform/bot/variables.tf | 4 +++ yarn-project/bot/src/config.ts | 7 ++++++ yarn-project/bot/src/factory.ts | 25 +++++++++++++++---- yarn-project/foundation/src/config/env_var.ts | 1 + 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/yarn-project/aztec/terraform/bot/main.tf b/yarn-project/aztec/terraform/bot/main.tf index 03a1c4a58cf2..da7a6104b3c4 100644 --- a/yarn-project/aztec/terraform/bot/main.tf +++ b/yarn-project/aztec/terraform/bot/main.tf @@ -170,7 +170,8 @@ resource "aws_ecs_task_definition" "aztec-bot" { { name = "BOT_FOLLOW_CHAIN", value = var.BOT_FOLLOW_CHAIN }, { name = "AZTEC_NODE_URL", value = "http://${var.DEPLOY_TAG}-aztec-node-1.local/${var.DEPLOY_TAG}/aztec-node-1/${var.API_KEY}" }, { name = "PXE_PROVER_ENABLED", value = tostring(var.PROVING_ENABLED) }, - { name = "NETWORK", value = var.DEPLOY_TAG } + { name = "NETWORK", value = var.DEPLOY_TAG }, + { name = "BOT_FLUSH_SETUP_TRANSACTIONS", value = var.BOT_FLUSH_SETUP_TRANSACTIONS } ] logConfiguration = { logDriver = "awslogs" diff --git a/yarn-project/aztec/terraform/bot/variables.tf b/yarn-project/aztec/terraform/bot/variables.tf index ecf275a84d22..6213d4300ae7 100644 --- a/yarn-project/aztec/terraform/bot/variables.tf +++ b/yarn-project/aztec/terraform/bot/variables.tf @@ -56,3 +56,7 @@ variable "BOT_COUNT" { type = string default = "1" } + +variable "BOT_FLUSH_SETUP_TRANSACTIONS" { + type = bool +} diff --git a/yarn-project/bot/src/config.ts b/yarn-project/bot/src/config.ts index 08c9cc2939e5..d2753d3b57f7 100644 --- a/yarn-project/bot/src/config.ts +++ b/yarn-project/bot/src/config.ts @@ -37,6 +37,8 @@ export type BotConfig = { followChain: BotFollowChain; /** Do not send a tx if the node's tx pool already has this many pending txs. */ maxPendingTxs: number; + /** Whether to flush after sending each 'setup' transaction */ + flushSetupTransactions: boolean; }; export const botConfigMappings: ConfigMappingsType = { @@ -113,6 +115,11 @@ export const botConfigMappings: ConfigMappingsType = { description: "Do not send a tx if the node's tx pool already has this many pending txs.", ...numberConfigHelper(128), }, + flushSetupTransactions: { + env: 'BOT_FLUSH_SETUP_TRANSACTIONS', + description: 'Make a request for the sequencer to build a block after each setup transaction.', + ...booleanConfigHelper(false), + }, }; export function getBotConfigFromEnv(): BotConfig { diff --git a/yarn-project/bot/src/factory.ts b/yarn-project/bot/src/factory.ts index b1e2e56613b0..30d560e841f4 100644 --- a/yarn-project/bot/src/factory.ts +++ b/yarn-project/bot/src/factory.ts @@ -1,6 +1,6 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr'; import { type AccountWallet, BatchCall, createDebugLogger, createPXEClient } from '@aztec/aztec.js'; -import { type FunctionCall, type PXE } from '@aztec/circuit-types'; +import { type AztecNode, type FunctionCall, type PXE } from '@aztec/circuit-types'; import { Fr, deriveSigningKey } from '@aztec/circuits.js'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; @@ -12,9 +12,11 @@ const MIN_BALANCE = 1e3; export class BotFactory { private pxe: PXE; + private node?: AztecNode; private log = createDebugLogger('aztec:bot'); - constructor(private readonly config: BotConfig, dependencies: { pxe?: PXE } = {}) { + constructor(private readonly config: BotConfig, dependencies: { pxe?: PXE; node?: AztecNode } = {}) { + this.node = dependencies.node; if (!dependencies.pxe && !config.pxeUrl) { throw new Error(`Either a PXE client or a PXE URL must be provided`); } @@ -54,7 +56,12 @@ export class BotFactory { return account.register(); } else { this.log.info(`Initializing account at ${account.getAddress().toString()}`); - return account.waitSetup({ timeout: this.config.txMinedWaitSeconds }); + const sentTx = account.deploy(); + if (this.config.flushSetupTransactions && this.node) { + await this.node.flush(); + } + await sentTx.wait({ timeout: this.config.txMinedWaitSeconds }); + return account.getWallet(); } } @@ -80,7 +87,11 @@ export class BotFactory { return deploy.register(); } else { this.log.info(`Deploying token contract at ${address.toString()}`); - return deploy.send(deployOpts).deployed({ timeout: this.config.txMinedWaitSeconds }); + const sentTx = deploy.send(deployOpts); + if (this.config.flushSetupTransactions && this.node) { + await this.node.flush(); + } + return sentTx.deployed({ timeout: this.config.txMinedWaitSeconds }); } } @@ -104,6 +115,10 @@ export class BotFactory { this.log.info(`Skipping minting as ${sender.toString()} has enough tokens`); return; } - await new BatchCall(token.wallet, calls).send().wait({ timeout: this.config.txMinedWaitSeconds }); + const sentTx = new BatchCall(token.wallet, calls).send(); + if (this.config.flushSetupTransactions && this.node) { + await this.node.flush(); + } + await sentTx.wait({ timeout: this.config.txMinedWaitSeconds }); } } diff --git a/yarn-project/foundation/src/config/env_var.ts b/yarn-project/foundation/src/config/env_var.ts index cf78a19e91be..874ed934b4d5 100644 --- a/yarn-project/foundation/src/config/env_var.ts +++ b/yarn-project/foundation/src/config/env_var.ts @@ -98,6 +98,7 @@ export type EnvVar = | 'BB_SKIP_CLEANUP' | 'PXE_PROVER_ENABLED' | 'BOT_FOLLOW_CHAIN' + | 'BOT_FLUSH_SETUP_TRANSACTIONS' | 'VALIDATOR_PRIVATE_KEY' | 'VALIDATOR_DISABLED' | 'PROVER_NODE_DISABLE_AUTOMATIC_PROVING' From 90bbc2cb45b120dcce3e51318aec59f253a517f5 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 19 Aug 2024 10:49:42 +0000 Subject: [PATCH 3/7] More bot config --- .github/workflows/devnet-deploys.yml | 18 ++++++++++++++++++ yarn-project/aztec/terraform/bot/main.tf | 3 ++- yarn-project/aztec/terraform/bot/variables.tf | 8 +++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/devnet-deploys.yml b/.github/workflows/devnet-deploys.yml index 4003544e30b3..2fba470b9f9f 100644 --- a/.github/workflows/devnet-deploys.yml +++ b/.github/workflows/devnet-deploys.yml @@ -78,6 +78,8 @@ env: TF_VAR_BOT_FOLLOW_CHAIN: "PROVEN" TF_VAR_BOT_TX_INTERVAL_SECONDS: 180 TF_VAR_BOT_COUNT: 1 + TF_VAR_BOT_FLUSH_SETUP_TRANSACTIONS: false + TF_VAR_BOT_MAX_PENDING_TXS: 1 # PXE TF_VAR_PXE_LB_RULE_PRIORITY: 4000 @@ -110,6 +112,9 @@ jobs: faucet_lb_priority: ${{ steps.set_network_vars.outputs.faucet_lb_priority }} bot_no_wait: ${{ steps.set_network_vars.outputs.bot_no_wait }} max_txs_per_block: ${{ steps.set_network_vars.outputs.max_txs_per_block }} + min_txs_per_block: ${{ steps.set_network_vars.outputs.min_txs_per_block }} + bot_flush_setup_txs: ${{ steps.set_network_vars.outputs.bot_flush_setup_txs }} + bot_max_pending_txs: ${{ steps.set_network_vars.outputs.bot_max_pending_txs }} steps: - name: Set network vars shell: bash @@ -132,7 +137,10 @@ jobs: echo "prover_node_lb_priority_range_start=6100" >> $GITHUB_OUTPUT echo "faucet_lb_priority=601" >> $GITHUB_OUTPUT echo "bot_no_wait=false" >> $GITHUB_OUTPUT + echo "min_txs_per_block=1" >> $GITHUB_OUTPUT echo "max_txs_per_block=64" >> $GITHUB_OUTPUT + echo "bot_flush_setup_txs=false" >> $GITHUB_OUTPUT + echo "bot_max_pending_txs=1" >> $GITHUB_OUTPUT elif [ "$BRANCH_NAME" = "provernet" ] then echo "deploy_tag=provernet" >> $GITHUB_OUTPUT @@ -149,7 +157,10 @@ jobs: echo "prover_node_lb_priority_range_start=6200" >> $GITHUB_OUTPUT echo "faucet_lb_priority=602" >> $GITHUB_OUTPUT echo "bot_no_wait=true" >> $GITHUB_OUTPUT + echo "min_txs_per_block=4" >> $GITHUB_OUTPUT echo "max_txs_per_block=4" >> $GITHUB_OUTPUT + echo "bot_flush_setup_txs=true" >> $GITHUB_OUTPUT + echo "bot_max_pending_txs=20" >> $GITHUB_OUTPUT elif [ "$BRANCH_NAME" = "alphanet" ] then echo "deploy_tag=alphanet" >> $GITHUB_OUTPUT @@ -166,7 +177,10 @@ jobs: echo "prover_node_lb_priority_range_start=6000" >> $GITHUB_OUTPUT echo "faucet_lb_priority=600" >> $GITHUB_OUTPUT echo "bot_no_wait=false" >> $GITHUB_OUTPUT + echo "min_txs_per_block=1" >> $GITHUB_OUTPUT echo "max_txs_per_block=64" >> $GITHUB_OUTPUT + echo "bot_flush_setup_txs=false" >> $GITHUB_OUTPUT + echo "bot_max_pending_txs=1" >> $GITHUB_OUTPUT else echo "Unrecognized Branch!!" exit 1 @@ -363,6 +377,7 @@ jobs: TF_VAR_PXE_LB_RULE_PRIORITY: ${{ needs.set-network.outputs.pxe_lb_priority_range_start }} TF_VAR_PROVER_NODE_LB_RULE_PRIORITY: ${{ needs.set-network.outputs.prover_node_lb_priority_range_start }} TF_VAR_BOT_NO_WAIT_FOR_TRANSFERS: ${{ needs.set-network.outputs.bot_no_wait }} + TF_VAR_SEQ_MIN_TX_PER_BLOCK: 1 TF_VAR_SEQ_MAX_TX_PER_BLOCK: ${{ needs.set-network.outputs.max_txs_per_block }} steps: - uses: actions/checkout@v4 @@ -566,6 +581,9 @@ jobs: TF_VAR_PXE_LB_RULE_PRIORITY: ${{ needs.set-network.outputs.pxe_lb_priority_range_start }} TF_VAR_PROVER_NODE_LB_RULE_PRIORITY: ${{ needs.set-network.outputs.prover_node_lb_priority_range_start }} TF_VAR_BOT_NO_WAIT_FOR_TRANSFERS: ${{ needs.set-network.outputs.bot_no_wait }} + TF_VAR_BOT_FLUSH_SETUP_TRANSACTIONS: ${{ needs.set-network.outputs.bot_flush_setup_txs }} + TF_VAR_BOT_MAX_PENDING_TXS: ${{ needs.set-network.outputs.bot_max_pending_txs }} + TF_VAR_SEQ_MIN_TX_PER_BLOCK: ${{ needs.set-network.outputs.min_txs_per_block }} TF_VAR_SEQ_MAX_TX_PER_BLOCK: ${{ needs.set-network.outputs.max_txs_per_block }} TF_VAR_PROVING_ENABLED: true TF_VAR_BOT_NO_START: false diff --git a/yarn-project/aztec/terraform/bot/main.tf b/yarn-project/aztec/terraform/bot/main.tf index da7a6104b3c4..28452d94d71c 100644 --- a/yarn-project/aztec/terraform/bot/main.tf +++ b/yarn-project/aztec/terraform/bot/main.tf @@ -171,7 +171,8 @@ resource "aws_ecs_task_definition" "aztec-bot" { { name = "AZTEC_NODE_URL", value = "http://${var.DEPLOY_TAG}-aztec-node-1.local/${var.DEPLOY_TAG}/aztec-node-1/${var.API_KEY}" }, { name = "PXE_PROVER_ENABLED", value = tostring(var.PROVING_ENABLED) }, { name = "NETWORK", value = var.DEPLOY_TAG }, - { name = "BOT_FLUSH_SETUP_TRANSACTIONS", value = var.BOT_FLUSH_SETUP_TRANSACTIONS } + { name = "BOT_FLUSH_SETUP_TRANSACTIONS", value = tostring(var.BOT_FLUSH_SETUP_TRANSACTIONS) }, + { name = "BOT_MAX_PENDING_TXS", value = tostring(var.BOT_MAX_PENDING_TXS) } ] logConfiguration = { logDriver = "awslogs" diff --git a/yarn-project/aztec/terraform/bot/variables.tf b/yarn-project/aztec/terraform/bot/variables.tf index 6213d4300ae7..4d3d78100f4b 100644 --- a/yarn-project/aztec/terraform/bot/variables.tf +++ b/yarn-project/aztec/terraform/bot/variables.tf @@ -58,5 +58,11 @@ variable "BOT_COUNT" { } variable "BOT_FLUSH_SETUP_TRANSACTIONS" { - type = bool + type = bool + default = false +} + +variable "BOT_MAX_PENDING_TXS" { + type = number + default = 1 } From 2bd7982f013b6ca9b7cc6cab30e8c9ba43d1403a Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 19 Aug 2024 10:55:59 +0000 Subject: [PATCH 4/7] Fixes --- yarn-project/bot/src/bot.ts | 4 ++-- yarn-project/bot/src/runner.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn-project/bot/src/bot.ts b/yarn-project/bot/src/bot.ts index acba73ddfcec..9d154f449828 100644 --- a/yarn-project/bot/src/bot.ts +++ b/yarn-project/bot/src/bot.ts @@ -7,7 +7,7 @@ import { type Wallet, createDebugLogger, } from '@aztec/aztec.js'; -import { type FunctionCall, type PXE } from '@aztec/circuit-types'; +import { type AztecNode, type FunctionCall, type PXE } from '@aztec/circuit-types'; import { GasSettings } from '@aztec/circuits.js'; import { times } from '@aztec/foundation/collection'; import { type TokenContract } from '@aztec/noir-contracts.js'; @@ -28,7 +28,7 @@ export class Bot { public readonly config: BotConfig, ) {} - static async create(config: BotConfig, dependencies: { pxe?: PXE } = {}): Promise { + static async create(config: BotConfig, dependencies: { pxe?: PXE; node?: AztecNode } = {}): Promise { const { wallet, token, recipient } = await new BotFactory(config, dependencies).setup(); return new Bot(wallet, token, recipient, config); } diff --git a/yarn-project/bot/src/runner.ts b/yarn-project/bot/src/runner.ts index 6159c7c605d4..7810a76837f3 100644 --- a/yarn-project/bot/src/runner.ts +++ b/yarn-project/bot/src/runner.ts @@ -109,7 +109,7 @@ export class BotRunner { async #createBot() { try { - this.bot = Bot.create(this.config, { pxe: this.pxe }); + this.bot = Bot.create(this.config, { pxe: this.pxe, node: this.node }); await this.bot; } catch (err) { this.log.error(`Error setting up bot: ${err}`); From b724ef39ee24f4f23e3e15cdf55f2cbc2a45043e Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 19 Aug 2024 11:01:08 +0000 Subject: [PATCH 5/7] More logging --- yarn-project/bot/src/factory.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/yarn-project/bot/src/factory.ts b/yarn-project/bot/src/factory.ts index 30d560e841f4..a131f1e41bae 100644 --- a/yarn-project/bot/src/factory.ts +++ b/yarn-project/bot/src/factory.ts @@ -58,8 +58,10 @@ export class BotFactory { this.log.info(`Initializing account at ${account.getAddress().toString()}`); const sentTx = account.deploy(); if (this.config.flushSetupTransactions && this.node) { + this.log.verbose('Flushing transactions'); await this.node.flush(); } + this.log.verbose('Waiting for account deployment to settle'); await sentTx.wait({ timeout: this.config.txMinedWaitSeconds }); return account.getWallet(); } @@ -89,8 +91,10 @@ export class BotFactory { this.log.info(`Deploying token contract at ${address.toString()}`); const sentTx = deploy.send(deployOpts); if (this.config.flushSetupTransactions && this.node) { + this.log.verbose('Flushing transactions'); await this.node.flush(); } + this.log.verbose('Waiting for token setup to settle'); return sentTx.deployed({ timeout: this.config.txMinedWaitSeconds }); } } @@ -117,8 +121,10 @@ export class BotFactory { } const sentTx = new BatchCall(token.wallet, calls).send(); if (this.config.flushSetupTransactions && this.node) { + this.log.verbose('Flushing transactions'); await this.node.flush(); } + this.log.verbose('Waiting for token mint to settle'); await sentTx.wait({ timeout: this.config.txMinedWaitSeconds }); } } From d5b97b7b5d3065a2629dbac5a28eef626d420db1 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 19 Aug 2024 11:08:52 +0000 Subject: [PATCH 6/7] Fix --- yarn-project/bot/src/factory.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn-project/bot/src/factory.ts b/yarn-project/bot/src/factory.ts index a131f1e41bae..6200774c651f 100644 --- a/yarn-project/bot/src/factory.ts +++ b/yarn-project/bot/src/factory.ts @@ -59,7 +59,7 @@ export class BotFactory { const sentTx = account.deploy(); if (this.config.flushSetupTransactions && this.node) { this.log.verbose('Flushing transactions'); - await this.node.flush(); + await this.node.flushTxs(); } this.log.verbose('Waiting for account deployment to settle'); await sentTx.wait({ timeout: this.config.txMinedWaitSeconds }); @@ -92,7 +92,7 @@ export class BotFactory { const sentTx = deploy.send(deployOpts); if (this.config.flushSetupTransactions && this.node) { this.log.verbose('Flushing transactions'); - await this.node.flush(); + await this.node.flushTxs(); } this.log.verbose('Waiting for token setup to settle'); return sentTx.deployed({ timeout: this.config.txMinedWaitSeconds }); @@ -122,7 +122,7 @@ export class BotFactory { const sentTx = new BatchCall(token.wallet, calls).send(); if (this.config.flushSetupTransactions && this.node) { this.log.verbose('Flushing transactions'); - await this.node.flush(); + await this.node.flushTxs(); } this.log.verbose('Waiting for token mint to settle'); await sentTx.wait({ timeout: this.config.txMinedWaitSeconds }); From 5743e6ded8f48f77de9d7eb57e26fea5a9a71bcd Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 19 Aug 2024 13:22:04 +0000 Subject: [PATCH 7/7] Throw is invalid config --- yarn-project/bot/src/factory.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/yarn-project/bot/src/factory.ts b/yarn-project/bot/src/factory.ts index 6200774c651f..f4af49d1f1d7 100644 --- a/yarn-project/bot/src/factory.ts +++ b/yarn-project/bot/src/factory.ts @@ -16,7 +16,9 @@ export class BotFactory { private log = createDebugLogger('aztec:bot'); constructor(private readonly config: BotConfig, dependencies: { pxe?: PXE; node?: AztecNode } = {}) { - this.node = dependencies.node; + if (config.flushSetupTransactions && !dependencies.node) { + throw new Error(`Either a node client or node url must be provided if transaction flushing is requested`); + } if (!dependencies.pxe && !config.pxeUrl) { throw new Error(`Either a PXE client or a PXE URL must be provided`); } @@ -28,6 +30,7 @@ export class BotFactory { } this.log.info(`Using remote PXE at ${config.pxeUrl!}`); this.pxe = createPXEClient(config.pxeUrl!); + this.node = dependencies.node; } /** @@ -57,9 +60,9 @@ export class BotFactory { } else { this.log.info(`Initializing account at ${account.getAddress().toString()}`); const sentTx = account.deploy(); - if (this.config.flushSetupTransactions && this.node) { + if (this.config.flushSetupTransactions) { this.log.verbose('Flushing transactions'); - await this.node.flushTxs(); + await this.node!.flushTxs(); } this.log.verbose('Waiting for account deployment to settle'); await sentTx.wait({ timeout: this.config.txMinedWaitSeconds }); @@ -90,9 +93,9 @@ export class BotFactory { } else { this.log.info(`Deploying token contract at ${address.toString()}`); const sentTx = deploy.send(deployOpts); - if (this.config.flushSetupTransactions && this.node) { + if (this.config.flushSetupTransactions) { this.log.verbose('Flushing transactions'); - await this.node.flushTxs(); + await this.node!.flushTxs(); } this.log.verbose('Waiting for token setup to settle'); return sentTx.deployed({ timeout: this.config.txMinedWaitSeconds }); @@ -120,9 +123,9 @@ export class BotFactory { return; } const sentTx = new BatchCall(token.wallet, calls).send(); - if (this.config.flushSetupTransactions && this.node) { + if (this.config.flushSetupTransactions) { this.log.verbose('Flushing transactions'); - await this.node.flushTxs(); + await this.node!.flushTxs(); } this.log.verbose('Waiting for token mint to settle'); await sentTx.wait({ timeout: this.config.txMinedWaitSeconds });