Skip to content

Commit

Permalink
Set tx get max attempts lower
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Dec 17, 2024
1 parent d46a763 commit a54e78a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
35 changes: 20 additions & 15 deletions yarn-project/end-to-end/src/e2e_epochs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ describe('e2e_epochs', () => {
let l1BlockNumber: number;
let handle: NodeJS.Timeout;

const EPOCH_DURATION = 4;
const L1_BLOCK_TIME = 8;
const L2_SLOT_DURATION_IN_L1_BLOCKS = 2;
const EPOCH_DURATION_IN_L2_SLOTS = 4;
const L2_SLOT_DURATION_IN_L1_SLOTS = 2;
const L1_BLOCK_TIME_IN_S = 8;

beforeAll(async () => {
// Set up system without any account nor protocol contracts
Expand All @@ -35,14 +35,16 @@ describe('e2e_epochs', () => {
assumeProvenThrough: undefined,
skipProtocolContracts: true,
salt: 1,
aztecEpochDuration: EPOCH_DURATION,
aztecSlotDuration: L1_BLOCK_TIME * L2_SLOT_DURATION_IN_L1_BLOCKS,
ethereumSlotDuration: L1_BLOCK_TIME,
aztecEpochProofClaimWindowInL2Slots: EPOCH_DURATION / 2,
aztecEpochDuration: EPOCH_DURATION_IN_L2_SLOTS,
aztecSlotDuration: L1_BLOCK_TIME_IN_S * L2_SLOT_DURATION_IN_L1_SLOTS,
ethereumSlotDuration: L1_BLOCK_TIME_IN_S,
aztecEpochProofClaimWindowInL2Slots: EPOCH_DURATION_IN_L2_SLOTS / 2,
minTxsPerBlock: 0,
realProofs: false,
startProverNode: true,
txPropagationMaxQueryAttempts: 60,
// This must be enough so that the tx from the prover is delayed properly,
// but not so much to hang the sequencer and timeout the teardown
txPropagationMaxQueryAttempts: 12,
});

logger = context.logger;
Expand Down Expand Up @@ -88,8 +90,8 @@ describe('e2e_epochs', () => {

// Constants used for time calculation
constants = {
epochDuration: EPOCH_DURATION,
slotDuration: L1_BLOCK_TIME * L2_SLOT_DURATION_IN_L1_BLOCKS,
epochDuration: EPOCH_DURATION_IN_L2_SLOTS,
slotDuration: L1_BLOCK_TIME_IN_S * L2_SLOT_DURATION_IN_L1_SLOTS,
l1GenesisBlock: await rollup.getL1StartBlock(),
l1GenesisTime: await rollup.getL1GenesisTime(),
};
Expand All @@ -106,7 +108,7 @@ describe('e2e_epochs', () => {
const waitUntilEpochStarts = async (epoch: number) => {
const [start] = getTimestampRangeForEpoch(BigInt(epoch), constants);
logger.info(`Waiting until L1 timestamp ${start} is reached as the start of epoch ${epoch}`);
await waitUntilL1Timestamp(l1Client, start - BigInt(L1_BLOCK_TIME));
await waitUntilL1Timestamp(l1Client, start - BigInt(L1_BLOCK_TIME_IN_S));
return start;
};

Expand All @@ -125,12 +127,14 @@ describe('e2e_epochs', () => {
proverDelayer.pauseNextTxUntilTimestamp(epoch2Start);
logger.info(`Delayed prover tx until epoch 2 starts at ${epoch2Start}`);

// Wait until the last block of epoch 1 is published and then hold off the sequencer
await waitUntilL2BlockNumber(blockNumberAtEndOfEpoch0 + EPOCH_DURATION);
sequencerDelayer.pauseNextTxUntilTimestamp(epoch2Start + BigInt(L1_BLOCK_TIME));
// Wait until the last block of epoch 1 is published and then hold off the sequencer.
// Note that the tx below will block the sequencer until it times out
// the txPropagationMaxQueryAttempts until #10824 is fixed.
await waitUntilL2BlockNumber(blockNumberAtEndOfEpoch0 + EPOCH_DURATION_IN_L2_SLOTS);
sequencerDelayer.pauseNextTxUntilTimestamp(epoch2Start + BigInt(L1_BLOCK_TIME_IN_S));

// Next sequencer to publish a block should trigger a rollback to block 1
await waitUntilL1Timestamp(l1Client, epoch2Start + BigInt(L1_BLOCK_TIME));
await waitUntilL1Timestamp(l1Client, epoch2Start + BigInt(L1_BLOCK_TIME_IN_S));
expect(await rollup.getBlockNumber()).toEqual(1n);
expect(await rollup.getSlotNumber()).toEqual(8n);

Expand All @@ -143,5 +147,6 @@ describe('e2e_epochs', () => {
const lastL2BlockTxReceipt = await l1Client.getTransactionReceipt({ hash: lastL2BlockTxHash! });
expect(lastL2BlockTxReceipt.status).toEqual('success');
expect(lastL2BlockTxReceipt.blockNumber).toBeGreaterThan(lastProverTxReceipt!.blockNumber);
logger.info(`Test succeeded`);
});
});
19 changes: 15 additions & 4 deletions yarn-project/ethereum/src/test/tx_delayer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { omit } from '@aztec/foundation/collection';
import { type Logger, createLogger } from '@aztec/foundation/log';
import { retryUntil } from '@aztec/foundation/retry';

Expand All @@ -8,6 +9,7 @@ import {
type PublicClient,
type WalletClient,
keccak256,
parseTransaction,
publicActions,
walletActions,
} from 'viem';
Expand Down Expand Up @@ -116,16 +118,25 @@ export function withDelayer<T extends WalletClient>(
// Compute the tx hash manually so we emulate sendRawTransaction response
const { serializedTransaction } = args[0];
const txHash = keccak256(serializedTransaction);
logger.info(`Delaying tx ${txHash} until ${inspect(waitUntil)}`);
logger.info(`Delaying tx ${txHash} until ${inspect(waitUntil)}`, {
argsLen: args.length,
...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
});

// Do not await here so we can return the tx hash immediately as if it had been sent on the spot.
// Instead, delay it so it lands on the desired block number or timestamp, assuming anvil will
// mine it immediately.
void wait
.then(async () => {
const txHash = await client.sendRawTransaction(...args);
logger.info(`Sent previously delayed tx ${txHash} to land on ${inspect(waitUntil)}`);
delayer.txs.push(txHash);
const clientTxHash = await client.sendRawTransaction(...args);
if (clientTxHash !== txHash) {
logger.error(`Tx hash returned by the client does not match computed one`, {
clientTxHash,
computedTxHash: txHash,
});
}
logger.info(`Sent previously delayed tx ${clientTxHash} to land on ${inspect(waitUntil)}`);
delayer.txs.push(clientTxHash);
})
.catch(err => logger.error(`Error sending tx after delay`, err));

Expand Down

0 comments on commit a54e78a

Please sign in to comment.