From e844a5b5b951063ca8b8e5488ec8d0ca37bfac35 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:17:36 +0000 Subject: [PATCH 1/2] fix: e2e-p2p attestation timeout --- yarn-project/validator-client/src/validator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/validator-client/src/validator.ts b/yarn-project/validator-client/src/validator.ts index 6fa24f39b9a..d364f9565fe 100644 --- a/yarn-project/validator-client/src/validator.ts +++ b/yarn-project/validator-client/src/validator.ts @@ -146,7 +146,7 @@ export class ValidatorClient extends WithTracer implements Validator { const slot = proposal.payload.header.globalVariables.slotNumber.toBigInt(); this.log.info(`Waiting for ${numberOfRequiredAttestations} attestations for slot: ${slot}`); - const proposalId = proposal.p2pMessageIdentifier().toString(); + const proposalId = proposal.archive.toString(); const myAttestation = await this.validationService.attestToProposal(proposal); const startTime = Date.now(); From 0ba0386bd339e8227ac15bb422e4924807cd8e4c Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:26:24 +0000 Subject: [PATCH 2/2] add test --- .../src/p2p/block_attestation.test.ts | 2 +- .../src/p2p/block_proposal.test.ts | 2 +- yarn-project/circuit-types/src/p2p/mocks.ts | 31 +++++++++++----- .../validator-client/src/validator.test.ts | 35 ++++++++++++++++++- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/yarn-project/circuit-types/src/p2p/block_attestation.test.ts b/yarn-project/circuit-types/src/p2p/block_attestation.test.ts index 908e4551c17..fc32fa7a704 100644 --- a/yarn-project/circuit-types/src/p2p/block_attestation.test.ts +++ b/yarn-project/circuit-types/src/p2p/block_attestation.test.ts @@ -21,7 +21,7 @@ describe('Block Attestation serialization / deserialization', () => { it('Should serialize / deserialize + recover sender', () => { const account = Secp256k1Signer.random(); - const attestation = makeBlockAttestation(account); + const attestation = makeBlockAttestation({ signer: account }); const serialized = attestation.toBuffer(); const deserialized = BlockAttestation.fromBuffer(serialized); diff --git a/yarn-project/circuit-types/src/p2p/block_proposal.test.ts b/yarn-project/circuit-types/src/p2p/block_proposal.test.ts index 4be10936fec..f1ea41ece79 100644 --- a/yarn-project/circuit-types/src/p2p/block_proposal.test.ts +++ b/yarn-project/circuit-types/src/p2p/block_proposal.test.ts @@ -21,7 +21,7 @@ describe('Block Proposal serialization / deserialization', () => { it('Should serialize / deserialize + recover sender', () => { const account = Secp256k1Signer.random(); - const proposal = makeBlockProposal(account); + const proposal = makeBlockProposal({ signer: account }); const serialized = proposal.toBuffer(); const deserialized = BlockProposal.fromBuffer(serialized); diff --git a/yarn-project/circuit-types/src/p2p/mocks.ts b/yarn-project/circuit-types/src/p2p/mocks.ts index efe104f6697..0286c4207ed 100644 --- a/yarn-project/circuit-types/src/p2p/mocks.ts +++ b/yarn-project/circuit-types/src/p2p/mocks.ts @@ -1,3 +1,4 @@ +import { type Header } from '@aztec/circuits.js'; import { makeHeader } from '@aztec/circuits.js/testing'; import { Secp256k1Signer } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; @@ -8,11 +9,25 @@ import { BlockProposal } from './block_proposal.js'; import { ConsensusPayload } from './consensus_payload.js'; import { getHashedSignaturePayloadEthSignedMessage } from './signature_utils.js'; -const makeAndSignConsensusPayload = (signer = Secp256k1Signer.random()) => { +export interface MakeConsensusPayloadOptions { + signer?: Secp256k1Signer; + header?: Header; + archive?: Fr; + txHashes?: TxHash[]; +} + +const makeAndSignConsensusPayload = (options?: MakeConsensusPayloadOptions) => { + const { + signer = Secp256k1Signer.random(), + header = makeHeader(1), + archive = Fr.random(), + txHashes = [0, 1, 2, 3, 4, 5].map(() => TxHash.random()), + } = options ?? {}; + const payload = ConsensusPayload.fromFields({ - header: makeHeader(1), - archive: Fr.random(), - txHashes: [0, 1, 2, 3, 4, 5].map(() => TxHash.random()), + header, + archive, + txHashes, }); const hash = getHashedSignaturePayloadEthSignedMessage(payload); @@ -21,13 +36,13 @@ const makeAndSignConsensusPayload = (signer = Secp256k1Signer.random()) => { return { payload, signature }; }; -export const makeBlockProposal = (signer = Secp256k1Signer.random()): BlockProposal => { - const { payload, signature } = makeAndSignConsensusPayload(signer); +export const makeBlockProposal = (options?: MakeConsensusPayloadOptions): BlockProposal => { + const { payload, signature } = makeAndSignConsensusPayload(options); return new BlockProposal(payload, signature); }; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8028) -export const makeBlockAttestation = (signer?: Secp256k1Signer): BlockAttestation => { - const { payload, signature } = makeAndSignConsensusPayload(signer); +export const makeBlockAttestation = (options?: MakeConsensusPayloadOptions): BlockAttestation => { + const { payload, signature } = makeAndSignConsensusPayload(options); return new BlockAttestation(payload, signature); }; diff --git a/yarn-project/validator-client/src/validator.test.ts b/yarn-project/validator-client/src/validator.test.ts index 8edc491ce0e..ac4ca372d48 100644 --- a/yarn-project/validator-client/src/validator.test.ts +++ b/yarn-project/validator-client/src/validator.test.ts @@ -3,6 +3,7 @@ */ import { TxHash } from '@aztec/circuit-types'; import { makeHeader } from '@aztec/circuits.js/testing'; +import { Secp256k1Signer } from '@aztec/foundation/crypto'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { type P2P } from '@aztec/p2p'; @@ -12,7 +13,7 @@ import { describe, expect, it } from '@jest/globals'; import { type MockProxy, mock } from 'jest-mock-extended'; import { type PrivateKeyAccount, generatePrivateKey, privateKeyToAccount } from 'viem/accounts'; -import { makeBlockProposal } from '../../circuit-types/src/p2p/mocks.js'; +import { makeBlockAttestation, makeBlockProposal } from '../../circuit-types/src/p2p/mocks.js'; import { type ValidatorClientConfig } from './config.js'; import { AttestationTimeoutError, @@ -81,4 +82,36 @@ describe('ValidationService', () => { TransactionsNotAvailableError, ); }); + + it('Should collect attestations for a proposal', async () => { + const signer = Secp256k1Signer.random(); + const attestor1 = Secp256k1Signer.random(); + const attestor2 = Secp256k1Signer.random(); + + const archive = Fr.random(); + const txHashes = [0, 1, 2, 3, 4, 5].map(() => TxHash.random()); + + const proposal = makeBlockProposal({ signer, archive, txHashes }); + + // Mock the attestations to be returned + const expectedAttestations = [ + makeBlockAttestation({ signer: attestor1, archive, txHashes }), + makeBlockAttestation({ signer: attestor2, archive, txHashes }), + ]; + p2pClient.getAttestationsForSlot.mockImplementation((slot, proposalId) => { + if ( + slot === proposal.payload.header.globalVariables.slotNumber.toBigInt() && + proposalId === proposal.archive.toString() + ) { + return Promise.resolve(expectedAttestations); + } + return Promise.resolve([]); + }); + + // Perform the query + const numberOfRequiredAttestations = 3; + const attestations = await validatorClient.collectAttestations(proposal, numberOfRequiredAttestations); + + expect(attestations).toHaveLength(numberOfRequiredAttestations); + }); });