Skip to content

Commit

Permalink
fix: attestation pool (#8854)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 authored Sep 27, 2024
1 parent 77636f0 commit ffbad35
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ describe('MemoryAttestationPool', () => {
signers = Array.from({ length: NUMBER_OF_SIGNERS_PER_TEST }, generateAccount);
});

it('should add attestation to pool', async () => {
it('should add attestations to pool', async () => {
const slotNumber = 420;
const archive = Fr.random();
const attestations = await Promise.all(signers.map(signer => mockAttestation(signer, slotNumber, archive)));

const proposalId = attestations[0].p2pMessageIdentifier.toString();
const proposalId = attestations[0].p2pMessageIdentifier().toString();

await ap.addAttestations(attestations);

Expand All @@ -45,7 +45,27 @@ describe('MemoryAttestationPool', () => {

for (const attestation of attestations) {
const slot = attestation.payload.header.globalVariables.slotNumber;
const proposalId = attestation.p2pMessageIdentifier.toString();
const proposalId = attestation.p2pMessageIdentifier().toString();

const retreivedAttestations = await ap.getAttestationsForSlot(slot.toBigInt(), proposalId);
expect(retreivedAttestations.length).toBe(1);
expect(retreivedAttestations[0]).toEqual(attestation);
expect(retreivedAttestations[0].payload.header.globalVariables.slotNumber).toEqual(slot);
}
});

it('Should store attestations by differing slot and archive', async () => {
const slotNumbers = [1, 2, 3, 4];
const archives = [Fr.random(), Fr.random(), Fr.random(), Fr.random()];
const attestations = await Promise.all(
signers.map((signer, i) => mockAttestation(signer, slotNumbers[i], archives[i])),
);

await ap.addAttestations(attestations);

for (const attestation of attestations) {
const slot = attestation.payload.header.globalVariables.slotNumber;
const proposalId = attestation.p2pMessageIdentifier().toString();

const retreivedAttestations = await ap.getAttestationsForSlot(slot.toBigInt(), proposalId);
expect(retreivedAttestations.length).toBe(1);
Expand All @@ -58,7 +78,7 @@ describe('MemoryAttestationPool', () => {
const slotNumber = 420;
const archive = Fr.random();
const attestations = await Promise.all(signers.map(signer => mockAttestation(signer, slotNumber, archive)));
const proposalId = attestations[0].p2pMessageIdentifier.toString();
const proposalId = attestations[0].p2pMessageIdentifier().toString();

await ap.addAttestations(attestations);

Expand All @@ -76,7 +96,7 @@ describe('MemoryAttestationPool', () => {
const slotNumber = 420;
const archive = Fr.random();
const attestations = await Promise.all(signers.map(signer => mockAttestation(signer, slotNumber, archive)));
const proposalId = attestations[0].p2pMessageIdentifier.toString();
const proposalId = attestations[0].p2pMessageIdentifier().toString();

await ap.addAttestations(attestations);

Expand All @@ -94,7 +114,7 @@ describe('MemoryAttestationPool', () => {
const slotNumber = 420;
const archive = Fr.random();
const attestations = await Promise.all(signers.map(signer => mockAttestation(signer, slotNumber, archive)));
const proposalId = attestations[0].p2pMessageIdentifier.toString();
const proposalId = attestations[0].p2pMessageIdentifier().toString();

await ap.addAttestations(attestations);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class InMemoryAttestationPool implements AttestationPool {
// Perf: order and group by slot before insertion
const slotNumber = attestation.payload.header.globalVariables.slotNumber;

const proposalId = attestation.p2pMessageIdentifier.toString();
const proposalId = attestation.p2pMessageIdentifier().toString();
const address = attestation.getSender();

const slotAttestationMap = getSlotOrDefault(this.attestations, slotNumber.toBigInt());
Expand Down Expand Up @@ -59,7 +59,7 @@ export class InMemoryAttestationPool implements AttestationPool {
const slotNumber = attestation.payload.header.globalVariables.slotNumber;
const slotAttestationMap = this.attestations.get(slotNumber.toBigInt());
if (slotAttestationMap) {
const proposalId = attestation.p2pMessageIdentifier.toString();
const proposalId = attestation.p2pMessageIdentifier().toString();
const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
if (proposalAttestationMap) {
const address = attestation.getSender();
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/validator-client/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class ValidatorClient 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.p2pMessageIdentifier().toString();
const myAttestation = await this.validationService.attestToProposal(proposal);

const startTime = Date.now();
Expand Down

0 comments on commit ffbad35

Please sign in to comment.