Skip to content

Commit

Permalink
chore: address minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Aug 30, 2024
1 parent 72240f2 commit ad57586
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
41 changes: 34 additions & 7 deletions yarn-project/end-to-end/src/e2e_p2p_network.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import { getSchnorrAccount } from '@aztec/accounts/schnorr';
import { type AztecNodeConfig, type AztecNodeService } from '@aztec/aztec-node';
import { CompleteAddress, type DebugLogger, Fr, GrumpkinScalar, type SentTx, TxStatus, sleep } from '@aztec/aztec.js';
import {
CompleteAddress,
type DebugLogger,
type DeployL1Contracts,
EthCheatCodes,
Fr,
GrumpkinScalar,
type SentTx,
TxStatus,
sleep,
} from '@aztec/aztec.js';
import { EthAddress } from '@aztec/circuits.js';
import { RollupAbi } from '@aztec/l1-artifacts';
import { type BootstrapNode } from '@aztec/p2p';
import { type PXEService, createPXEService, getPXEServiceConfig as getRpcConfig } from '@aztec/pxe';

import { jest } from '@jest/globals';
import fs from 'fs';
import { getContract } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';

import {
Expand All @@ -32,6 +44,7 @@ describe('e2e_p2p_network', () => {
let teardown: () => Promise<void>;
let bootstrapNode: BootstrapNode;
let bootstrapNodeEnr: string;
let deployL1ContractsValues: DeployL1Contracts;

beforeEach(async () => {
// If we want to test with interval mining, we can use the local host and start `anvil --block-time 12`
Expand All @@ -47,18 +60,32 @@ describe('e2e_p2p_network', () => {

const initialValidators = [EthAddress.fromString(account.address)];

for (let i = 0; i < NUM_NODES; i++) {
const account = privateKeyToAccount(`0x${getPrivateKeyFromIndex(i + 1)!.toString('hex')}`);
initialValidators.push(EthAddress.fromString(account.address));
}

({ teardown, config, logger } = await setup(0, { initialValidators, ...options }));
({ teardown, config, logger, deployL1ContractsValues } = await setup(0, { initialValidators, ...options }));

bootstrapNode = await createBootstrapNode(BOOT_NODE_UDP_PORT);
bootstrapNodeEnr = bootstrapNode.getENR().encodeTxt();

config.minTxsPerBlock = NUM_TXS_PER_BLOCK;
config.maxTxsPerBlock = NUM_TXS_PER_BLOCK;

const rollup = getContract({
address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
abi: RollupAbi,
client: deployL1ContractsValues.walletClient,
});

for (let i = 0; i < NUM_NODES; i++) {
const account = privateKeyToAccount(`0x${getPrivateKeyFromIndex(i + 1)!.toString('hex')}`);
await rollup.write.addValidator([account.address]);
}

//@note Now we jump ahead to the next epoch such that the validator committee is picked
// INTERVAL MINING: If we are using anvil interval mining this will NOT progress the time!
// Which means that the validator set will still be empty! So anyone can propose.
const slotsInEpoch = await rollup.read.EPOCH_DURATION();
const timestamp = await rollup.read.getTimestampForSlot([slotsInEpoch]);
const cheatCodes = new EthCheatCodes(config.l1RpcUrl);
await cheatCodes.warp(Number(timestamp));
});

afterEach(() => teardown());
Expand Down
13 changes: 2 additions & 11 deletions yarn-project/sequencer-client/src/publisher/l1-publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,11 @@ describe('L1Publisher', () => {

it('does not retry if simulating a publish and propose tx fails', async () => {
rollupContractRead.archive.mockResolvedValue(l2Block.header.lastArchive.root.toString() as `0x${string}`);
rollupContractSimulate.propose.mockRejectedValueOnce(new Error());
rollupContractRead.validateHeader.mockRejectedValueOnce(new Error('Test error'));

if (L1Publisher.SKIP_SIMULATION) {
rollupContractRead.validateHeader.mockRejectedValueOnce(new Error('Test error'));
}

const result = await publisher.processL2Block(l2Block);
await expect(publisher.processL2Block(l2Block)).rejects.toThrow();

expect(result).toEqual(false);
if (!L1Publisher.SKIP_SIMULATION) {
expect(rollupContractSimulate.propose).toHaveBeenCalledTimes(1);
}
expect(rollupContractRead.validateHeader).toHaveBeenCalledTimes(1);

expect(rollupContractWrite.propose).toHaveBeenCalledTimes(0);
});

Expand Down
6 changes: 4 additions & 2 deletions yarn-project/validator-client/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ export class ValidatorClient implements Validator {

this.log.info(`Waiting for ${numberOfRequiredAttestations} attestations for slot: ${slot}`);

let attestations: BlockAttestation[] = [await this.attestToProposal(proposal)];
const myAttestation = await this.attestToProposal(proposal);

let attestations: BlockAttestation[] = [];
while (attestations.length < numberOfRequiredAttestations) {
attestations = await this.p2pClient.getAttestationsForSlot(slot);
attestations = [myAttestation, ...(await this.p2pClient.getAttestationsForSlot(slot))];

if (attestations.length < numberOfRequiredAttestations) {
this.log.verbose(`Waiting ${this.attestationPoolingIntervalMs}ms for more attestations...`);
Expand Down

0 comments on commit ad57586

Please sign in to comment.