Skip to content

Commit

Permalink
chore: Configuration for bot on various networks (#8063)
Browse files Browse the repository at this point in the history
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 <santiago@aztecprotocol.com>
  • Loading branch information
PhilWindle and spalladino authored Aug 19, 2024
1 parent 617a69c commit 453a096
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 9 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/devnet-deploys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/aztec/terraform/bot/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions yarn-project/aztec/terraform/bot/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions yarn-project/bot/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -28,7 +28,7 @@ export class Bot {
public readonly config: BotConfig,
) {}

static async create(config: BotConfig, dependencies: { pxe?: PXE } = {}): Promise<Bot> {
static async create(config: BotConfig, dependencies: { pxe?: PXE; node?: AztecNode } = {}): Promise<Bot> {
const { wallet, token, recipient } = await new BotFactory(config, dependencies).setup();
return new Bot(wallet, token, recipient, config);
}
Expand Down
7 changes: 7 additions & 0 deletions yarn-project/bot/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BotConfig> = {
Expand Down Expand Up @@ -113,6 +115,11 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
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 {
Expand Down
34 changes: 29 additions & 5 deletions yarn-project/bot/src/factory.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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`);
}
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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 });
}
}

Expand All @@ -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 });
}
}
2 changes: 1 addition & 1 deletion yarn-project/bot/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
1 change: 1 addition & 0 deletions yarn-project/foundation/src/config/env_var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 453a096

Please sign in to comment.