Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spartan/aztec-bot/templates/env.configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data:
BOT_PRIVATE_TRANSFERS_PER_TX: {{ .Values.bot.privateTransfersPerTx | quote }}
BOT_PUBLIC_TRANSFERS_PER_TX: {{ .Values.bot.publicTransfersPerTx | quote }}
BOT_FOLLOW_CHAIN: {{ .Values.bot.followChain | quote }}
PXE_SYNC_CHAIN_TIP: {{ .Values.bot.pxeSyncChainTip | quote }}
BOT_NO_START: {{ .Values.bot.botNoStart | quote }}
BOT_FEE_PAYMENT_METHOD: {{ .Values.bot.feePaymentMethod | quote }}
BOT_AMM_TXS: {{ .Values.bot.ammTxs | quote }}
Expand Down
1 change: 1 addition & 0 deletions spartan/aztec-bot/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ bot:
publicTransfersPerTx: 1
# Do not wait for transactions
followChain: "NONE"
pxeSyncChainTip: "checkpointed"
botNoStart: false
feePaymentMethod: "fee_juice"
ammTxs: false
Expand Down
4 changes: 4 additions & 0 deletions spartan/scripts/deploy_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ BOT_TRANSFERS_TX_INTERVAL_SECONDS=${BOT_TRANSFERS_TX_INTERVAL_SECONDS:-60}
BOT_SWAPS_TX_INTERVAL_SECONDS=${BOT_SWAPS_TX_INTERVAL_SECONDS:-60}
BOT_TRANSFERS_FOLLOW_CHAIN=${BOT_TRANSFERS_FOLLOW_CHAIN:-NONE}
BOT_SWAPS_FOLLOW_CHAIN=${BOT_SWAPS_FOLLOW_CHAIN:-NONE}
BOT_TRANSFERS_PXE_SYNC_CHAIN_TIP=${BOT_TRANSFERS_PXE_SYNC_CHAIN_TIP:-checkpointed}
BOT_SWAPS_PXE_SYNC_CHAIN_TIP=${BOT_SWAPS_PXE_SYNC_CHAIN_TIP:-checkpointed}

RPC_INGRESS_ENABLED=${RPC_INGRESS_ENABLED:-false}
RPC_INGRESS_HOSTS=${RPC_INGRESS_HOSTS:-[]}
Expand Down Expand Up @@ -506,6 +508,8 @@ BOT_SWAPS_MNEMONIC_START_INDEX = ${BOT_SWAPS_MNEMONIC_START_INDEX}
BOT_SWAPS_REPLICAS = ${BOT_SWAPS_REPLICAS}
BOT_SWAPS_TX_INTERVAL_SECONDS = ${BOT_SWAPS_TX_INTERVAL_SECONDS}
BOT_SWAPS_FOLLOW_CHAIN = "${BOT_SWAPS_FOLLOW_CHAIN}"
BOT_TRANSFERS_PXE_SYNC_CHAIN_TIP = "${BOT_TRANSFERS_PXE_SYNC_CHAIN_TIP}"
BOT_SWAPS_PXE_SYNC_CHAIN_TIP = "${BOT_SWAPS_PXE_SYNC_CHAIN_TIP}"
BOT_TRANSFERS_L2_PRIVATE_KEY = "${BOT_TRANSFERS_L2_PRIVATE_KEY:-0xcafe01}"
BOT_SWAPS_L2_PRIVATE_KEY = "${BOT_SWAPS_L2_PRIVATE_KEY:-0xcafe02}"

Expand Down
2 changes: 2 additions & 0 deletions spartan/terraform/deploy-aztec-infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ locals {
"bot.replicaCount" = var.BOT_TRANSFERS_REPLICAS
"bot.txIntervalSeconds" = var.BOT_TRANSFERS_TX_INTERVAL_SECONDS
"bot.followChain" = var.BOT_TRANSFERS_FOLLOW_CHAIN
"bot.pxeSyncChainTip" = var.BOT_TRANSFERS_PXE_SYNC_CHAIN_TIP
"bot.botPrivateKey" = var.BOT_TRANSFERS_L2_PRIVATE_KEY
"bot.nodeUrl" = local.internal_rpc_url
"bot.mnemonic" = var.BOT_MNEMONIC
Expand All @@ -599,6 +600,7 @@ locals {
"bot.replicaCount" = var.BOT_SWAPS_REPLICAS
"bot.txIntervalSeconds" = var.BOT_SWAPS_TX_INTERVAL_SECONDS
"bot.followChain" = var.BOT_SWAPS_FOLLOW_CHAIN
"bot.pxeSyncChainTip" = var.BOT_SWAPS_PXE_SYNC_CHAIN_TIP
"bot.botPrivateKey" = var.BOT_SWAPS_L2_PRIVATE_KEY
"bot.nodeUrl" = local.internal_rpc_url
"bot.mnemonic" = var.BOT_MNEMONIC
Expand Down
12 changes: 12 additions & 0 deletions spartan/terraform/deploy-aztec-infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ variable "BOT_TRANSFERS_FOLLOW_CHAIN" {
default = "PENDING"
}

variable "BOT_TRANSFERS_PXE_SYNC_CHAIN_TIP" {
description = "Transfers bot PXE sync chain tip mode (e.g., checkpointed)"
type = string
default = "checkpointed"
}

variable "BOT_TRANSFERS_L2_PRIVATE_KEY" {
description = "Private key for the transfers bot (hex string starting with 0x)"
nullable = true
Expand Down Expand Up @@ -549,6 +555,12 @@ variable "BOT_SWAPS_FOLLOW_CHAIN" {
default = "PENDING"
}

variable "BOT_SWAPS_PXE_SYNC_CHAIN_TIP" {
description = "AMM swaps bot PXE sync chain tip mode (e.g., checkpointed)"
type = string
default = "checkpointed"
}

variable "BOT_SWAPS_L2_PRIVATE_KEY" {
description = "Private key for the AMM swaps bot (hex string starting with 0x)"
type = string
Expand Down
7 changes: 5 additions & 2 deletions yarn-project/aztec/src/cli/cmds/start_bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@aztec/telemetry-client';
import { TestWallet } from '@aztec/test-wallet/server';

import { extractRelevantOptions } from '../util.js';
import { extractRelevantOptions, stringifyConfig } from '../util.js';
import { getVersions } from '../versioning.js';

export async function startBot(
Expand All @@ -38,10 +38,11 @@ export async function startBot(
const aztecNode = createAztecNodeClient(config.nodeUrl, getVersions(), fetch);

const pxeConfig = extractRelevantOptions<PXEConfig & CliPXEOptions>(options, allPxeConfigMappings, 'pxe');
userLog(`Creating bot test wallet with config ${stringifyConfig(pxeConfig)}`);
const wallet = await TestWallet.create(aztecNode, pxeConfig);

const telemetry = await initTelemetryClient(getTelemetryClientConfig());
await addBot(options, signalHandlers, services, wallet, aztecNode, telemetry, undefined);
await addBot(options, signalHandlers, services, wallet, aztecNode, telemetry, undefined, userLog);
}

export async function addBot(
Expand All @@ -52,8 +53,10 @@ export async function addBot(
aztecNode: AztecNode,
telemetry: TelemetryClient,
aztecNodeAdmin?: AztecNodeAdmin,
userLog?: LogFn,
) {
const config = extractRelevantOptions<BotConfig>(options, botConfigMappings, 'bot');
userLog?.(`Starting bot with config ${stringifyConfig(config)}`);

const db = await (config.dataDirectory
? createStore('bot', BotStore.SCHEMA_VERSION, config)
Expand Down
7 changes: 7 additions & 0 deletions yarn-project/aztec/src/cli/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ViemClient } from '@aztec/ethereum/types';
import type { ConfigMappingsType } from '@aztec/foundation/config';
import { Fr } from '@aztec/foundation/curves/bn254';
import { EthAddress } from '@aztec/foundation/eth-address';
import { jsonStringify } from '@aztec/foundation/json-rpc';
import { type LogFn, createLogger } from '@aztec/foundation/log';
import type { SharedNodeConfig } from '@aztec/node-lib/config';
import type { ProverConfig } from '@aztec/stdlib/interfaces/server';
Expand Down Expand Up @@ -388,3 +389,9 @@ export async function setupUpdateMonitor(

checker.start();
}

export function stringifyConfig(config: object): string {
return Object.entries(config)
.map(([key, value]) => `${key}=${jsonStringify(value)}`)
.join(' ');
}
22 changes: 6 additions & 16 deletions yarn-project/bot/src/base_bot.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { AztecAddress } from '@aztec/aztec.js/addresses';
import {
BatchCall,
ContractFunctionInteraction,
type SendInteractionOptions,
waitForProven,
} from '@aztec/aztec.js/contracts';
import { BatchCall, ContractFunctionInteraction, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
import { createLogger } from '@aztec/aztec.js/log';
import { waitForTx } from '@aztec/aztec.js/node';
import { TxHash, TxReceipt } from '@aztec/aztec.js/tx';
import { TxHash, TxReceipt, TxStatus } from '@aztec/aztec.js/tx';
import { Gas } from '@aztec/stdlib/gas';
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
import type { TestWallet } from '@aztec/test-wallet/server';
Expand All @@ -29,8 +24,8 @@ export abstract class BaseBot {

public async run(): Promise<TxReceipt | TxHash> {
this.attempts++;
const logCtx = { runId: Date.now() * 1000 + Math.floor(Math.random() * 1000) };
const { followChain, txMinedWaitSeconds } = this.config;
const logCtx = { runId: Date.now() * 1000 + Math.floor(Math.random() * 1000), followChain, txMinedWaitSeconds };

this.log.verbose(`Creating tx`, logCtx);
const txHash = await this.createAndSendTx(logCtx);
Expand All @@ -40,14 +35,9 @@ export abstract class BaseBot {
return txHash;
}

this.log.verbose(
`Awaiting tx ${txHash.toString()} to be on the ${followChain} chain (timeout ${txMinedWaitSeconds}s)`,
logCtx,
);
const receipt = await waitForTx(this.node, txHash, { timeout: txMinedWaitSeconds });
if (followChain === 'PROVEN') {
await waitForProven(this.node, receipt, { provenTimeout: txMinedWaitSeconds });
}
const waitForStatus = TxStatus[followChain];
this.log.verbose(`Awaiting tx ${txHash.toString()} to be on the ${followChain} chain`, logCtx);
const receipt = await waitForTx(this.node, txHash, { timeout: txMinedWaitSeconds, waitForStatus });
this.successes++;
this.log.info(
`Tx #${this.attempts} ${receipt.txHash} successfully mined in block ${receipt.blockNumber} (stats: ${this.successes}/${this.attempts} success)`,
Expand Down
10 changes: 7 additions & 3 deletions yarn-project/bot/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { ComponentsVersions } from '@aztec/stdlib/versioning';

import { z } from 'zod';

const BotFollowChain = ['NONE', 'PENDING', 'PROVEN'] as const;
const BotFollowChain = ['NONE', 'PROPOSED', 'CHECKPOINTED', 'PROVEN'] as const;
type BotFollowChain = (typeof BotFollowChain)[number];

export enum SupportedTokenContracts {
Expand Down Expand Up @@ -213,10 +213,14 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
description: 'Which chain the bot follows',
defaultValue: 'NONE',
parseEnv(val) {
if (!(BotFollowChain as readonly string[]).includes(val.toUpperCase())) {
const upper = val.toUpperCase();
if (upper === 'PENDING') {
return 'CHECKPOINTED';
}
if (!(BotFollowChain as readonly string[]).includes(upper)) {
throw new Error(`Invalid value for BOT_FOLLOW_CHAIN: ${val}`);
}
return val as BotFollowChain;
return upper as BotFollowChain;
},
},
maxPendingTxs: {
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/end-to-end/src/e2e_bot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('e2e_bot', () => {
beforeAll(async () => {
config = {
...getBotDefaultConfig(),
followChain: 'PENDING',
followChain: 'CHECKPOINTED',
ammTxs: false,
};
bot = await Bot.create(config, wallet, aztecNode, undefined, new BotStore(await openTmpStore('bot')));
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('e2e_bot', () => {
const config: BotConfig = {
...getBotDefaultConfig(),

followChain: 'PENDING',
followChain: 'CHECKPOINTED',
ammTxs: false,

// this bot has a well defined private key and salt
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('e2e_bot', () => {
const config: BotConfig = {
...getBotDefaultConfig(),

followChain: 'PENDING',
followChain: 'CHECKPOINTED',
ammTxs: false,

// this bot has a well defined private key and salt
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('e2e_bot', () => {
beforeAll(async () => {
config = {
...getBotDefaultConfig(),
followChain: 'PENDING',
followChain: 'CHECKPOINTED',
ammTxs: true,
};
bot = await AmmBot.create(config, wallet, aztecNode, undefined, new BotStore(await openTmpStore('bot')));
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('e2e_bot', () => {
beforeAll(() => {
config = {
...getBotDefaultConfig(),
followChain: 'PENDING',
followChain: 'CHECKPOINTED',
ammTxs: false,
senderPrivateKey: new SecretValue(Fr.random()),
l1PrivateKey: new SecretValue(bufferToHex(getPrivateKeyFromIndex(8)!)),
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_sequencer_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('e2e_sequencer_config', () => {
}));
config = {
...getBotDefaultConfig(),
followChain: 'PENDING',
followChain: 'CHECKPOINTED',
ammTxs: false,
txMinedWaitSeconds: 12,
};
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/spartan/gating-passive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('a test that passively observes the network in the presence of network
logger: debugLogger,
replicas: 1,
txIntervalSeconds: 10,
followChain: 'PENDING',
followChain: 'CHECKPOINTED',
});
});

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/spartan/utils/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function installTransferBot({
logger: log,
replicas = 1,
txIntervalSeconds = 10,
followChain = 'PENDING',
followChain = 'CHECKPOINTED',
mnemonic = process.env.LABS_INFRA_MNEMONIC ?? 'test test test test test test test test test test test junk',
mnemonicStartIndex,
botPrivateKey = process.env.BOT_TRANSFERS_L2_PRIVATE_KEY ?? '0xcafe01',
Expand Down
Loading