From 453a096378df57b0280be9aa52697da434e1a457 Mon Sep 17 00:00:00 2001 From: PhilWindle <60546371+PhilWindle@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:15:54 +0100 Subject: [PATCH] chore: Configuration for bot on various networks (#8063) This PR introduces more configuration to the bot to enable the flushing of setup transactions. It also configures the networks as follows - Alphanet - Don't flush setup transactions - Max pending txs == 1 - Sequencer min txs per block = 1 Devnet - Don't flush setup transactions - Max pending txs == 1 - Sequencer min txs per block = 1 Provernet - Do flush setup transactions - Max pending txs == 20 - Sequencer min txs per block = 4 The aim is to ensure that Alphanet and Devnet continue to advance the chain if there are no other txs available. Provernet builds blocks of 4 txs and aims to keep the pool around 20 txs deep. --------- Co-authored-by: Santiago Palladino --- .github/workflows/devnet-deploys.yml | 18 ++++++++++ yarn-project/aztec/terraform/bot/main.tf | 4 ++- yarn-project/aztec/terraform/bot/variables.tf | 10 ++++++ yarn-project/bot/src/bot.ts | 4 +-- yarn-project/bot/src/config.ts | 7 ++++ yarn-project/bot/src/factory.ts | 34 ++++++++++++++++--- yarn-project/bot/src/runner.ts | 2 +- yarn-project/foundation/src/config/env_var.ts | 1 + 8 files changed, 71 insertions(+), 9 deletions(-) diff --git a/.github/workflows/devnet-deploys.yml b/.github/workflows/devnet-deploys.yml index 4003544e30b..2fba470b9f9 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 03a1c4a58cf..28452d94d71 100644 --- a/yarn-project/aztec/terraform/bot/main.tf +++ b/yarn-project/aztec/terraform/bot/main.tf @@ -170,7 +170,9 @@ 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 = 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 ecf275a84d2..4d3d78100f4 100644 --- a/yarn-project/aztec/terraform/bot/variables.tf +++ b/yarn-project/aztec/terraform/bot/variables.tf @@ -56,3 +56,13 @@ variable "BOT_COUNT" { type = string default = "1" } + +variable "BOT_FLUSH_SETUP_TRANSACTIONS" { + type = bool + default = false +} + +variable "BOT_MAX_PENDING_TXS" { + type = number + default = 1 +} diff --git a/yarn-project/bot/src/bot.ts b/yarn-project/bot/src/bot.ts index acba73ddfce..9d154f44982 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/config.ts b/yarn-project/bot/src/config.ts index 08c9cc2939e..d2753d3b57f 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 b1e2e56613b..f4af49d1f1d 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,13 @@ 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 } = {}) { + 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`); } @@ -26,6 +30,7 @@ export class BotFactory { } this.log.info(`Using remote PXE at ${config.pxeUrl!}`); this.pxe = createPXEClient(config.pxeUrl!); + this.node = dependencies.node; } /** @@ -54,7 +59,14 @@ 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.log.verbose('Flushing transactions'); + await this.node!.flushTxs(); + } + this.log.verbose('Waiting for account deployment to settle'); + await sentTx.wait({ timeout: this.config.txMinedWaitSeconds }); + return account.getWallet(); } } @@ -80,7 +92,13 @@ 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.log.verbose('Flushing transactions'); + await this.node!.flushTxs(); + } + this.log.verbose('Waiting for token setup to settle'); + return sentTx.deployed({ timeout: this.config.txMinedWaitSeconds }); } } @@ -104,6 +122,12 @@ 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.log.verbose('Flushing transactions'); + await this.node!.flushTxs(); + } + this.log.verbose('Waiting for token mint to settle'); + await sentTx.wait({ timeout: this.config.txMinedWaitSeconds }); } } diff --git a/yarn-project/bot/src/runner.ts b/yarn-project/bot/src/runner.ts index 6159c7c605d..7810a76837f 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}`); diff --git a/yarn-project/foundation/src/config/env_var.ts b/yarn-project/foundation/src/config/env_var.ts index cf78a19e91b..874ed934b4d 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'