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
25 changes: 24 additions & 1 deletion yarn-project/aztec.js/src/api/ethereum/cheat_codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,31 @@ export class RollupCheatCodes {
/** Directly calls the L1 gas fee oracle. */
public async updateL1GasFeeOracle() {
await this.asOwner(async (account, rollup) => {
await rollup.write.updateL1GasFeeOracle({ account, chain: this.client.chain });
const hash = await rollup.write.updateL1GasFeeOracle({ account, chain: this.client.chain });
await this.client.waitForTransactionReceipt({ hash });
this.logger.warn(`Updated L1 gas fee oracle`);
});
}

/**
* Bumps proving cost per mana.
* @param bumper - Callback to calculate the new proving cost per mana based on current value.
*/
public async bumpProvingCostPerMana(bumper: (before: bigint) => bigint) {
const currentCost = await this.rollup.read.getProvingCostPerManaInEth();
const newCost = bumper(currentCost);
await this.setProvingCostPerMana(newCost);
}

/**
* Directly updates proving cost per mana.
* @param ethValue - The new proving cost per mana in ETH
*/
public async setProvingCostPerMana(ethValue: bigint) {
await this.asOwner(async (account, rollup) => {
const hash = await rollup.write.setProvingCostPerMana([ethValue], { account, chain: this.client.chain });
await this.client.waitForTransactionReceipt({ hash });
this.logger.warn(`Updated proving cost per mana to ${ethValue}`);
});
}
}
1 change: 1 addition & 0 deletions yarn-project/end-to-end/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function test_cmds {
echo "$prefix simple e2e_fees/dapp_subscription"
echo "$prefix simple e2e_fees/failures"
echo "$prefix simple e2e_fees/fee_juice_payments"
echo "$prefix simple e2e_fees/fee_settings"
echo "$prefix simple e2e_fees/gas_estimation"
echo "$prefix simple e2e_fees/private_payments"
echo "$prefix simple e2e_fees/public_payments"
Expand Down
38 changes: 18 additions & 20 deletions yarn-project/end-to-end/src/e2e_fees/fee_settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type AztecNode,
type CheatCodes,
FeeJuicePaymentMethod,
retryUntil,
} from '@aztec/aztec.js';
import { Fr } from '@aztec/foundation/fields';
import { TestContract } from '@aztec/noir-contracts.js/Test';
Expand Down Expand Up @@ -41,23 +42,21 @@ describe('e2e_fees fee settings', () => {
describe('setting max fee per gas', () => {
const bumpL2Fees = async () => {
const before = await aztecNode.getCurrentBaseFees();
t.logger.info(`Initial L2 base fees are ${inspect(before)}`, { baseFees: before });

// Bumps L1 base fee, updates the L1 fee oracle, and advances slots to update L2 base fees.
// Do we need all these advance and upgrade calls? Probably not, but these calls are blazing fast,
// so it's not big deal if we're throwing some unnecessary calls. We just want higher L2 base fees.
t.logger.info(`Bumping L1 base fee per gas`);
await cheatCodes.rollup.updateL1GasFeeOracle();
await cheatCodes.eth.setNextBlockBaseFeePerGas(1e11);
await cheatCodes.eth.mine();
await cheatCodes.rollup.advanceSlots(6);
await cheatCodes.rollup.updateL1GasFeeOracle();
await cheatCodes.rollup.advanceSlots(6);
await cheatCodes.rollup.updateL1GasFeeOracle();

const after = await aztecNode.getCurrentBaseFees();
t.logger.info(`L2 base fees after L1 gas spike are ${inspect(after)}`, { baseFees: after });
expect(after.feePerL2Gas.toBigInt()).toBeGreaterThan(before.feePerL2Gas.toBigInt());
t.logger.info(`Initial L2 base fees are ${inspect(before)}`, { baseFees: before.toInspect() });
await cheatCodes.rollup.bumpProvingCostPerMana(current => (current * 120n) / 100n);
await retryUntil(
async () => {
const after = await aztecNode.getCurrentBaseFees();
t.logger.info(`L2 base fees are now ${inspect(after)}`, {
baseFeesBefore: before.toInspect(),
baseFeesAfter: after.toInspect(),
});
return after.feePerL2Gas.toBigInt() > before.feePerL2Gas.toBigInt();
},
'L2 base fee increase',
5,
1,
);
};

const sendTx = async (baseFeePadding: number | undefined) => {
Expand All @@ -66,12 +65,11 @@ describe('e2e_fees fee settings', () => {
.emit_nullifier_public(Fr.random())
.prove({ fee: { gasSettings, paymentMethod, baseFeePadding } });
const { maxFeesPerGas } = tx.data.constants.txContext.gasSettings;
t.logger.info(`Tx with hash ${tx.getTxHash()} ready with max fees ${inspect(maxFeesPerGas)}`);
t.logger.info(`Tx with hash ${await tx.getTxHash()} ready with max fees ${inspect(maxFeesPerGas)}`);
return tx;
};

// TODO(#12258): This test is currently broken on master. Fix it.
it.skip('handles base fee spikes with default padding', async () => {
it('handles base fee spikes with default padding', async () => {
// Prepare two txs using the current L2 base fees: one with no padding and one with default padding
const txWithNoPadding = await sendTx(0);
const txWithDefaultPadding = await sendTx(undefined);
Expand Down
11 changes: 7 additions & 4 deletions yarn-project/sequencer-client/src/tx_validator/gas_validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class GasTxValidator implements TxValidator<Tx> {
this.#gasFees = gasFees;
}

validateTx(tx: Tx): Promise<TxValidationResult> {
if (this.#shouldSkip(tx)) {
async validateTx(tx: Tx): Promise<TxValidationResult> {
if (await this.#shouldSkip(tx)) {
return Promise.resolve({ result: 'skipped', reason: ['Insufficient fee per gas'] });
}
return this.#validateTxFee(tx);
Expand All @@ -37,7 +37,7 @@ export class GasTxValidator implements TxValidator<Tx> {
* Note that circuits check max fees even if fee payer is unset, so we
* keep this validation even if the tx does not pay fees.
*/
#shouldSkip(tx: Tx): boolean {
async #shouldSkip(tx: Tx): Promise<boolean> {
const gasSettings = tx.data.constants.txContext.gasSettings;

// Skip the tx if its max fees are not enough for the current block's gas fees.
Expand All @@ -47,7 +47,10 @@ export class GasTxValidator implements TxValidator<Tx> {
maxFeesPerGas.feePerL2Gas.lt(this.#gasFees.feePerL2Gas);

if (notEnoughMaxFees) {
this.#log.warn(`Skipping transaction ${tx.getTxHash()} due to insufficient fee per gas`);
this.#log.warn(`Skipping transaction ${await tx.getTxHash()} due to insufficient fee per gas`, {
txMaxFeesPerGas: maxFeesPerGas.toInspect(),
currentGasFees: this.#gasFees.toInspect(),
});
}
return notEnoughMaxFees;
}
Expand Down
9 changes: 8 additions & 1 deletion yarn-project/stdlib/src/gas/gas_fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ export class GasFees {
return serializeToFields(this.feePerDaGas, this.feePerL2Gas);
}

toInspect() {
return {
feePerDaGas: this.feePerDaGas.toNumberUnsafe(),
feePerL2Gas: this.feePerL2Gas.toNumberUnsafe(),
};
}

[inspect.custom]() {
return `GasFees { feePerDaGas=${this.feePerDaGas} feePerL2Gas=${this.feePerL2Gas} }`;
return `GasFees { feePerDaGas=${this.feePerDaGas.toBigInt()} feePerL2Gas=${this.feePerL2Gas.toBigInt()} }`;
}
}
Loading