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
7 changes: 5 additions & 2 deletions yarn-project/bot/src/base_bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
FeeJuicePaymentMethod,
type SendMethodOptions,
SentTx,
TxHash,
TxReceipt,
type Wallet,
createLogger,
waitForProven,
Expand All @@ -20,7 +22,7 @@ export abstract class BaseBot {

protected constructor(public readonly pxe: PXE, public readonly wallet: Wallet, public config: BotConfig) {}

public async run() {
public async run(): Promise<TxReceipt | TxHash> {
this.attempts++;
const logCtx = { runId: Date.now() * 1000 + Math.floor(Math.random() * 1000) };
const { followChain, txMinedWaitSeconds } = this.config;
Expand All @@ -32,7 +34,7 @@ export abstract class BaseBot {

if (followChain === 'NONE') {
this.log.info(`Transaction ${txHash} sent, not waiting for it to be mined`);
return;
return txHash;
}

this.log.verbose(
Expand All @@ -50,6 +52,7 @@ export abstract class BaseBot {
`Tx #${this.attempts} ${receipt.txHash} successfully mined in block ${receipt.blockNumber} (stats: ${this.successes}/${this.attempts} success)`,
logCtx,
);
return receipt;
}

protected abstract createAndSendTx(logCtx: object): Promise<SentTx>;
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/end-to-end/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ function test_cmds {
echo "$prefix simple e2e_token_contract/transfer_to_public"
echo "$prefix simple e2e_token_contract/transfer.test"

# other
echo "$prefix simple e2e_sequencer_config"

# circuit_recorder sub-tests
echo "$prefix simple e2e_circuit_recorder"

Expand Down
6 changes: 4 additions & 2 deletions yarn-project/end-to-end/src/e2e_bot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ describe('e2e_bot', () => {

beforeAll(async () => {
const initialFundedAccounts = await getInitialTestAccounts();
({ teardown, pxe } = await setup(1, { initialFundedAccounts }));
({ teardown, pxe } = await setup(1, {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Am I loosing it, or was the only change here the formatting?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Just formatting (on save). The real change in this file is further down.

initialFundedAccounts,
}));
});

afterAll(() => teardown());
Expand Down Expand Up @@ -85,7 +87,7 @@ describe('e2e_bot', () => {

it('swaps tokens from the bot', async () => {
const balancesBefore = await bot.getBalances();
await expect(bot.run()).resolves.toBeUndefined();
await expect(bot.run()).resolves.toBeDefined();
const balancesAfter = await bot.getBalances();
expect(balancesAfter.senderPrivate.token0).toBeLessThan(balancesBefore.senderPrivate.token0);
expect(balancesAfter.senderPrivate.token1).toBeGreaterThan(balancesBefore.senderPrivate.token1);
Expand Down
113 changes: 113 additions & 0 deletions yarn-project/end-to-end/src/e2e_sequencer_config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { getInitialTestAccounts } from '@aztec/accounts/testing';
import type { PXE, TxReceipt } from '@aztec/aztec.js';
import { Bot, type BotConfig, getBotDefaultConfig } from '@aztec/bot';
import type { Logger } from '@aztec/foundation/log';
import type { SequencerClient } from '@aztec/sequencer-client';

import { jest } from '@jest/globals';
import 'jest-extended';

import { setup } from './fixtures/utils.js';

describe('e2e_sequencer_config', () => {
jest.setTimeout(20 * 60 * 1000); // 20 minutes

let teardown: () => Promise<void>;
let sequencer: SequencerClient | undefined;
let config: BotConfig;
let bot: Bot;
let pxe: PXE;
let logger: Logger;

afterEach(() => {
jest.restoreAllMocks();
});

describe('bad config', () => {
it('fails to create sequencer if maxL2BlockGas is less than manaTarget', async () => {
const manaTarget = 21e18;
await expect(
setup(1, {
manaTarget: BigInt(manaTarget),
// The max is defined as 2x the manaTarget
maxL2BlockGas: manaTarget * 3,
}),
).rejects.toThrow(/provided maxL2BlockGas of \d+ is greater than the maximum allowed by the L1 \(\d+\)/);
});
});

describe('Sequencer config', () => {
const manaTarget = 21e18;
beforeAll(async () => {
const initialFundedAccounts = await getInitialTestAccounts();
({ teardown, sequencer, pxe, logger } = await setup(1, {
maxL2BlockGas: manaTarget * 2,
manaTarget: BigInt(manaTarget),
initialFundedAccounts,
}));
config = {
...getBotDefaultConfig(),
followChain: 'PENDING',
ammTxs: false,
txMinedWaitSeconds: 12,
};
bot = await Bot.create(config, { pxe });
});

afterAll(() => teardown());

it('properly sets config', () => {
if (!sequencer) {
throw new Error('Sequencer not found');
}
expect(sequencer.maxL2BlockGas).toBe(manaTarget * 2);
});

it('respects maxL2BlockGas', async () => {
await sequencer!.updateSequencerConfig({
maxTxsPerBlock: 1,
minTxsPerBlock: 0,
});
sequencer!.flush();

// Run a tx to get the total mana used
const receipt: TxReceipt = (await bot.run()) as TxReceipt;
expect(receipt).toBeDefined();
expect(receipt.status).toBe('success');
const block = await pxe.getBlock(receipt.blockNumber!);
expect(block).toBeDefined();
const totalManaUsed = block?.header.totalManaUsed!.toBigInt();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not really a note to this pr, but there should be a way to get the mana used just for the tx from the receipt or so.

Related to this pr, could you not just use the pxe to simulate the costs such that you don't need to wait on blocks? But guess you could not use the bot as easily then.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah the bot just seemed like the easiest, since I think we would need to actually send the tx regardless to show that the sequencer rejects it.


logger.info(`Total mana used: ${totalManaUsed}`);
expect(totalManaUsed).toBeGreaterThan(0n);
bot.updateConfig({
l2GasLimit: Number(totalManaUsed),
daGasLimit: Number(totalManaUsed),
});

// Set the maxL2BlockGas to the total mana used
await sequencer!.updateSequencerConfig({
maxL2BlockGas: Number(totalManaUsed),
});

// Flush the sequencer to make sure the new config is applied to the next tx
sequencer!.flush();

// Run a tx and expect it to succeed
const receipt2: TxReceipt = (await bot.run()) as TxReceipt;
expect(receipt2).toBeDefined();
expect(receipt2.status).toBe('success');

// Set the maxL2BlockGas to the total mana used - 1
await sequencer!.updateSequencerConfig({
maxL2BlockGas: Number(totalManaUsed) - 1,
});

// Flush the sequencer to make sure the new config is applied to the next tx
sequencer!.flush();

// Try to run a tx and expect it to fail
await expect(bot.run()).rejects.toThrow(/Timeout awaiting isMined/);
});
});
});
2 changes: 1 addition & 1 deletion yarn-project/ethereum/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const DefaultL1ContractsConfig = {
slashingRoundSize: 10,
governanceProposerQuorum: 6,
governanceProposerRoundSize: 10,
manaTarget: BigInt(100e6),
manaTarget: BigInt(1e10),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How come so big a value? 😛

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Tests failed otherwise. We're apparently setting insane high gas limits on transactions and I didn't want to track them all down.

provingCostPerMana: BigInt(100),
} satisfies L1ContractsConfig;

Expand Down
14 changes: 13 additions & 1 deletion yarn-project/sequencer-client/src/client/sequencer-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ export class SequencerClient {

const ethereumSlotDuration = config.ethereumSlotDuration;

const rollupManaLimit = await rollupContract.getManaLimit();
const sequencerManaLimit = config.maxL2BlockGas ?? Number(rollupManaLimit);
if (sequencerManaLimit > Number(rollupManaLimit)) {
throw new Error(
`provided maxL2BlockGas of ${sequencerManaLimit} is greater than the maximum allowed by the L1 (${rollupManaLimit})`,
);
}

// When running in anvil, assume we can post a tx up until the very last second of an L1 slot.
// Otherwise, assume we must have broadcasted the tx before the slot started (we use a default
// maxL1TxInclusionTimeIntoSlot of zero) to get the tx into that L1 slot.
Expand Down Expand Up @@ -170,7 +178,7 @@ export class SequencerClient {
contractDataSource,
l1Constants,
deps.dateProvider,
{ ...config, maxL1TxInclusionTimeIntoSlot },
{ ...config, maxL1TxInclusionTimeIntoSlot, maxL2BlockGas: sequencerManaLimit },
telemetryClient,
);
await validatorClient?.start();
Expand Down Expand Up @@ -220,4 +228,8 @@ export class SequencerClient {
get validatorAddress(): EthAddress | undefined {
return this.sequencer.getValidatorAddress();
}

get maxL2BlockGas(): number | undefined {
return this.sequencer.maxL2BlockGas;
}
}
4 changes: 4 additions & 0 deletions yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,4 +773,8 @@ export class Sequencer {
get feeRecipient(): AztecAddress {
return this._feeRecipient;
}

get maxL2BlockGas(): number | undefined {
return this.config.maxL2BlockGas;
}
}