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

chore: Configuration for bot on various networks #8063

Merged
merged 12 commits into from
Aug 19, 2024
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> {
Copy link
Member

Choose a reason for hiding this comment

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

don't see the new node arg being used anywhere?

Copy link
Collaborator Author

@PhilWindle PhilWindle Aug 19, 2024

Choose a reason for hiding this comment

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

It's just passed through, into the BotFactory constructor.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right it's part of the dependencies obj, got it 👍

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
31 changes: 26 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,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`);
}
Expand Down Expand Up @@ -54,7 +56,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.node) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd throw if flush is true but node is not set

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 +89,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.node) {
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 +119,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.node) {
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
Loading