@aztec/p2p 0.82.2 → 0.82.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dest/client/p2p_client.d.ts +5 -1
  2. package/dest/client/p2p_client.d.ts.map +1 -1
  3. package/dest/client/p2p_client.js +15 -4
  4. package/dest/config.d.ts.map +1 -1
  5. package/dest/config.js +1 -0
  6. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +11 -2
  7. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  8. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  9. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +40 -19
  10. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +2 -1
  11. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  12. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +14 -2
  13. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +2 -1
  14. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  15. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +8 -2
  16. package/dest/services/libp2p/libp2p_service.d.ts +2 -1
  17. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  18. package/dest/services/libp2p/libp2p_service.js +2 -1
  19. package/dest/testbench/p2p_client_testbench_worker.js +7 -2
  20. package/package.json +10 -10
  21. package/src/client/p2p_client.ts +21 -5
  22. package/src/config.ts +1 -0
  23. package/src/mem_pools/attestation_pool/attestation_pool.ts +12 -2
  24. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +40 -20
  25. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +16 -1
  26. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +12 -1
  27. package/src/services/libp2p/libp2p_service.ts +2 -1
  28. package/src/testbench/p2p_client_testbench_worker.ts +2 -1
@@ -141,6 +141,7 @@ export declare class P2PClient<T extends P2PClientType = P2PClientType.Full> ext
141
141
  private synchedBlockHashes;
142
142
  private synchedLatestBlockNumber;
143
143
  private synchedProvenBlockNumber;
144
+ private synchedLatestSlot;
144
145
  private txPool;
145
146
  private attestationPool;
146
147
  /** How many slots to keep attestations for. */
@@ -174,7 +175,8 @@ export declare class P2PClient<T extends P2PClientType = P2PClientType.Full> ext
174
175
  */
175
176
  stop(): Promise<void>;
176
177
  broadcastProposal(proposal: BlockProposal): void;
177
- getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
178
+ getAttestationsForSlot(slot: bigint, proposalId?: string): Promise<BlockAttestation[]>;
179
+ addAttestation(attestation: BlockAttestation): Promise<void>;
178
180
  registerBlockProposalHandler(handler: (block: BlockProposal) => Promise<BlockAttestation | undefined>): void;
179
181
  /**
180
182
  * Requests the transactions with the given hashes from the network.
@@ -270,6 +272,8 @@ export declare class P2PClient<T extends P2PClientType = P2PClientType.Full> ext
270
272
  * @returns Block number of latest proven L2 Block we've synced with.
271
273
  */
272
274
  getSyncedProvenBlockNum(): Promise<number>;
275
+ /** Returns latest L2 slot for which we have seen an L2 block. */
276
+ getSyncedLatestSlot(): Promise<bigint>;
273
277
  /**
274
278
  * Method to check the status the p2p client.
275
279
  * @returns Information about p2p client status: state & syncedToBlockNum.
@@ -1 +1 @@
1
- {"version":3,"file":"p2p_client.d.ts","sourceRoot":"","sources":["../../src/client/p2p_client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAsC,MAAM,iBAAiB,CAAC;AAC7F,OAAO,KAAK,EAEV,SAAS,EACT,aAAa,EACb,kBAAkB,EAClB,MAAM,EAEP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAoB,KAAK,aAAa,EA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;;OAIG;IACI,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAIrE,MAAM,IAAI,GAAG,GAAG,SAAS;IAIzB,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAInD;;;;;QAKI;IACS,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzD;;;OAGG;IACI,OAAO;IAId;;;OAGG;IACU,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvD;;;OAGG;IACU,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvD,iEAAiE;IACpD,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAInD;;;OAGG;IACU,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC;IAgB/C;;;;OAIG;YACW,wBAAwB;YAOxB,qBAAqB;IAUnC;;;;OAIG;YACW,mBAAmB;IAQjC;;;;OAIG;YACW,oBAAoB;IAiBlC;;;;OAIG;YACW,oBAAoB;IAgClC;;;OAGG;YACW,mBAAmB;YAoCnB,qBAAqB;IAenC;;;OAGG;IACH,OAAO,CAAC,eAAe;CAKxB"}
@@ -34,6 +34,7 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
34
34
  synchedBlockHashes;
35
35
  synchedLatestBlockNumber;
36
36
  synchedProvenBlockNumber;
37
+ synchedLatestSlot;
37
38
  txPool;
38
39
  attestationPool;
39
40
  /** How many slots to keep attestations for. */ keepAttestationsInPoolFor;
@@ -64,6 +65,7 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
64
65
  this.synchedBlockHashes = store.openMap('p2p_pool_block_hashes');
65
66
  this.synchedLatestBlockNumber = store.openSingleton('p2p_pool_last_l2_block');
66
67
  this.synchedProvenBlockNumber = store.openSingleton('p2p_pool_last_proven_l2_block');
68
+ this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
67
69
  this.txPool = mempools.txPool;
68
70
  this.attestationPool = mempools.attestationPool;
69
71
  }
@@ -192,7 +194,12 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
192
194
  return this.p2pService.propagate(proposal);
193
195
  }
194
196
  async getAttestationsForSlot(slot, proposalId) {
195
- return await this.attestationPool?.getAttestationsForSlot(slot, proposalId) ?? [];
197
+ return await (proposalId ? this.attestationPool?.getAttestationsForSlotAndProposal(slot, proposalId) : this.attestationPool?.getAttestationsForSlot(slot)) ?? [];
198
+ }
199
+ addAttestation(attestation) {
200
+ return this.attestationPool?.addAttestations([
201
+ attestation
202
+ ]) ?? Promise.resolve();
196
203
  }
197
204
  // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
198
205
  // ^ This pattern is not my favorite (md)
@@ -368,6 +375,9 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
368
375
  */ async getSyncedProvenBlockNum() {
369
376
  return await this.synchedProvenBlockNumber.getAsync() ?? INITIAL_L2_BLOCK_NUM - 1;
370
377
  }
378
+ /** Returns latest L2 slot for which we have seen an L2 block. */ async getSyncedLatestSlot() {
379
+ return await this.synchedLatestSlot.getAsync() ?? BigInt(0);
380
+ }
371
381
  /**
372
382
  * Method to check the status the p2p client.
373
383
  * @returns Information about p2p client status: state & syncedToBlockNum.
@@ -422,10 +432,11 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
422
432
  }
423
433
  await this.markTxsAsMinedFromBlocks(blocks.map((b)=>b.block));
424
434
  await this.addAttestationsToPool(blocks);
425
- const lastBlockNum = blocks.at(-1).block.number;
435
+ const lastBlock = blocks.at(-1).block;
426
436
  await Promise.all(blocks.map(async (block)=>this.synchedBlockHashes.set(block.block.number, (await block.block.hash()).toString())));
427
- await this.synchedLatestBlockNumber.set(lastBlockNum);
428
- this.log.verbose(`Synched to latest block ${lastBlockNum}`);
437
+ await this.synchedLatestBlockNumber.set(lastBlock.number);
438
+ await this.synchedLatestSlot.set(lastBlock.header.getSlot());
439
+ this.log.verbose(`Synched to latest block ${lastBlock.number}`);
429
440
  await this.startServiceIfSynched();
430
441
  }
431
442
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAMxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,KAAK,WAAW,EAAuB,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EAAE,KAAK,gBAAgB,EAA4B,MAAM,8BAA8B,CAAC;AAE/F;;GAEG;AACH,MAAM,WAAW,SAAU,SAAQ,gBAAgB,EAAE,WAAW;IAC9D;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,qBAAqB,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,6BAA6B,EAAE,OAAO,CAAC;IAEvC;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,cAAc,EAAE,MAAM,EAAE,CAAC;IAEzB,sEAAsE;IACtE,4BAA4B,EAAE,OAAO,CAAC;IAEtC,iGAAiG;IACjG,yBAAyB,EAAE,OAAO,CAAC;IAEnC;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IAEpB,+HAA+H;IAC/H,sBAAsB,EAAE,MAAM,CAAC;IAE/B,+CAA+C;IAC/C,yBAAyB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O,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yIAGlC,CAAC"}
package/dest/config.js CHANGED
@@ -187,6 +187,7 @@ export function getP2PDefaultConfig() {
187
187
  const bootnodeConfigKeys = [
188
188
  'p2pIp',
189
189
  'p2pPort',
190
+ 'listenAddress',
190
191
  'peerIdPrivateKey',
191
192
  'dataDirectory',
192
193
  'dataStoreMapSizeKB',
@@ -44,7 +44,16 @@ export interface AttestationPool {
44
44
  */
45
45
  deleteAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<void>;
46
46
  /**
47
- * Get Attestations for slot
47
+ * Get all Attestations for all proposals for a given slot
48
+ *
49
+ * Retrieve all of the attestations observed pertaining to a given slot
50
+ *
51
+ * @param slot - The slot to query
52
+ * @return BlockAttestations
53
+ */
54
+ getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]>;
55
+ /**
56
+ * Get Attestations for slot and given proposal
48
57
  *
49
58
  * Retrieve all of the attestations observed pertaining to a given slot
50
59
  *
@@ -52,6 +61,6 @@ export interface AttestationPool {
52
61
  * @param proposalId - The proposal to query
53
62
  * @return BlockAttestations
54
63
  */
55
- getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
64
+ getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
56
65
  }
57
66
  //# sourceMappingURL=attestation_pool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"attestation_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/attestation_pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,eAAe,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;;;OAIG;IACH,kBAAkB,CAAC,YAAY,E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,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAElE;;;;;;;;OAQG;IACH,iCAAiC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;CAClG"}
@@ -1 +1 @@
1
- {"version":3,"file":"attestation_pool_test_suite.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/attestation_pool_test_suite.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAK7D,wBAAgB,uBAAuB,CAAC,kBAAkB,EAAE,MAAM,eAAe,QA4NhF"}
1
+ {"version":3,"file":"attestation_pool_test_suite.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/attestation_pool_test_suite.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAK7D,wBAAgB,uBAAuB,CAAC,kBAAkB,EAAE,MAAM,eAAe,QAgPhF"}
@@ -34,17 +34,38 @@ export function describeAttestationPool(getAttestationPool) {
34
34
  it('should add attestations to pool', async ()=>{
35
35
  const slotNumber = 420;
36
36
  const archive = Fr.random();
37
- const attestations = await Promise.all(signers.map((signer)=>mockAttestation(signer, slotNumber, archive)));
37
+ const attestations = await Promise.all(signers.slice(0, -1).map((signer)=>mockAttestation(signer, slotNumber, archive)));
38
38
  await ap.addAttestations(attestations);
39
39
  // Check metrics have been updated.
40
40
  expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
41
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
42
- expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
43
- compareAttestations(retreivedAttestations, attestations);
41
+ const retrievedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
42
+ expect(retrievedAttestations.length).toBe(attestations.length);
43
+ compareAttestations(retrievedAttestations, attestations);
44
+ const retrievedAttestationsForSlot = await ap.getAttestationsForSlot(BigInt(slotNumber));
45
+ expect(retrievedAttestationsForSlot.length).toBe(attestations.length);
46
+ compareAttestations(retrievedAttestationsForSlot, attestations);
47
+ // Add another one
48
+ const newAttestation = await mockAttestation(signers[NUMBER_OF_SIGNERS_PER_TEST - 1], slotNumber, archive);
49
+ await ap.addAttestations([
50
+ newAttestation
51
+ ]);
52
+ expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(1);
53
+ const retrievedAttestationsAfterAdd = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
54
+ expect(retrievedAttestationsAfterAdd.length).toBe(attestations.length + 1);
55
+ compareAttestations(retrievedAttestationsAfterAdd, [
56
+ ...attestations,
57
+ newAttestation
58
+ ]);
59
+ const retrievedAttestationsForSlotAfterAdd = await ap.getAttestationsForSlot(BigInt(slotNumber));
60
+ expect(retrievedAttestationsForSlotAfterAdd.length).toBe(attestations.length + 1);
61
+ compareAttestations(retrievedAttestationsForSlotAfterAdd, [
62
+ ...attestations,
63
+ newAttestation
64
+ ]);
44
65
  // Delete by slot
45
66
  await ap.deleteAttestationsForSlot(BigInt(slotNumber));
46
- expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
47
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
67
+ expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length + 1);
68
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
48
69
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
49
70
  });
50
71
  it('should handle duplicate proposals in a slot', async ()=>{
@@ -66,7 +87,7 @@ export function describeAttestationPool(getAttestationPool) {
66
87
  }
67
88
  // Add them to store and check we end up with only one
68
89
  await ap.addAttestations(attestations);
69
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
90
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
70
91
  expect(retreivedAttestations.length).toBe(1);
71
92
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestations[0].toBuffer());
72
93
  expect(retreivedAttestations[0].payload.txHashes).toEqual(txs);
@@ -75,7 +96,7 @@ export function describeAttestationPool(getAttestationPool) {
75
96
  await ap.addAttestations([
76
97
  attestations[0]
77
98
  ]);
78
- expect(await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString())).toHaveLength(1);
99
+ expect(await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString())).toHaveLength(1);
79
100
  });
80
101
  it('should store attestations by differing slot', async ()=>{
81
102
  const slotNumbers = [
@@ -89,7 +110,7 @@ export function describeAttestationPool(getAttestationPool) {
89
110
  for (const attestation of attestations){
90
111
  const slot = attestation.payload.header.globalVariables.slotNumber;
91
112
  const archive = attestation.archive.toString();
92
- const retreivedAttestations = await ap.getAttestationsForSlot(slot.toBigInt(), archive);
113
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(slot.toBigInt(), archive);
93
114
  expect(retreivedAttestations.length).toBe(1);
94
115
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestation.toBuffer());
95
116
  expect(retreivedAttestations[0].payload.header.globalVariables.slotNumber).toEqual(slot);
@@ -113,7 +134,7 @@ export function describeAttestationPool(getAttestationPool) {
113
134
  for (const attestation of attestations){
114
135
  const slot = attestation.payload.header.globalVariables.slotNumber;
115
136
  const proposalId = attestation.archive.toString();
116
- const retreivedAttestations = await ap.getAttestationsForSlot(slot.toBigInt(), proposalId);
137
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(slot.toBigInt(), proposalId);
117
138
  expect(retreivedAttestations.length).toBe(1);
118
139
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestation.toBuffer());
119
140
  expect(retreivedAttestations[0].payload.header.globalVariables.slotNumber).toEqual(slot);
@@ -126,12 +147,12 @@ export function describeAttestationPool(getAttestationPool) {
126
147
  const proposalId = attestations[0].archive.toString();
127
148
  await ap.addAttestations(attestations);
128
149
  expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
129
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
150
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
130
151
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
131
152
  compareAttestations(retreivedAttestations, attestations);
132
153
  await ap.deleteAttestations(attestations);
133
154
  expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
134
- const gottenAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
155
+ const gottenAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
135
156
  expect(gottenAfterDelete.length).toBe(0);
136
157
  });
137
158
  it('should blanket delete attestations per slot', async ()=>{
@@ -140,11 +161,11 @@ export function describeAttestationPool(getAttestationPool) {
140
161
  const attestations = await Promise.all(signers.map((signer)=>mockAttestation(signer, slotNumber, archive)));
141
162
  const proposalId = attestations[0].archive.toString();
142
163
  await ap.addAttestations(attestations);
143
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
164
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
144
165
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
145
166
  compareAttestations(retreivedAttestations, attestations);
146
167
  await ap.deleteAttestationsForSlot(BigInt(slotNumber));
147
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
168
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
148
169
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
149
170
  });
150
171
  it('should blanket delete attestations per slot and proposal', async ()=>{
@@ -160,14 +181,14 @@ export function describeAttestationPool(getAttestationPool) {
160
181
  await ap.addAttestations(attestations2);
161
182
  expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
162
183
  expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations2.length);
163
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
184
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
164
185
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
165
186
  compareAttestations(retreivedAttestations, attestations);
166
187
  await ap.deleteAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
167
188
  expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
168
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
189
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
169
190
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
170
- const retreivedAttestationsAfterDeleteForOtherProposal = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId2);
191
+ const retreivedAttestationsAfterDeleteForOtherProposal = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId2);
171
192
  expect(retreivedAttestationsAfterDeleteForOtherProposal.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
172
193
  compareAttestations(retreivedAttestationsAfterDeleteForOtherProposal, attestations2);
173
194
  });
@@ -185,11 +206,11 @@ export function describeAttestationPool(getAttestationPool) {
185
206
  const attestations = (await Promise.all(slotNumbers.map((slotNumber)=>createAttestationsForSlot(slotNumber)))).flat();
186
207
  const proposalId = attestations[0].archive.toString();
187
208
  await ap.addAttestations(attestations);
188
- const attestationsForSlot1 = await ap.getAttestationsForSlot(BigInt(1), proposalId);
209
+ const attestationsForSlot1 = await ap.getAttestationsForSlotAndProposal(BigInt(1), proposalId);
189
210
  expect(attestationsForSlot1.length).toBe(signers.length);
190
211
  const deleteAttestationsSpy = jest.spyOn(ap, 'deleteAttestationsForSlot');
191
212
  await ap.deleteAttestationsOlderThan(BigInt(73));
192
- const attestationsForSlot1AfterDelete = await ap.getAttestationsForSlot(BigInt(1), proposalId);
213
+ const attestationsForSlot1AfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(1), proposalId);
193
214
  expect(attestationsForSlot1AfterDelete.length).toBe(0);
194
215
  expect(deleteAttestationsSpy).toHaveBeenCalledTimes(5);
195
216
  expect(deleteAttestationsSpy).toHaveBeenCalledWith(BigInt(1));
@@ -13,7 +13,8 @@ export declare class KvAttestationPool implements AttestationPool {
13
13
  private getProposalKey;
14
14
  private getAttestationKey;
15
15
  addAttestations(attestations: BlockAttestation[]): Promise<void>;
16
- getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
16
+ getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]>;
17
+ getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
17
18
  deleteAttestationsOlderThan(oldestSlot: bigint): Promise<void>;
18
19
  deleteAttestationsForSlot(slot: bigint): Promise<void>;
19
20
  deleteAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"kv_attestation_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/kv_attestation_pool.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAGnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,qBAAa,iBAAkB,YAAW,eAAe;IAQrD,OAAO,CAAC,KAAK;IAEb,OAAO,CAAC,GAAG;IATb,OAAO,CAAC,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AAO,CAAC,gBAAgB,CAAqC;IAC7D,OAAO,CAAC,uBAAuB,CAAqC;gBAG1D,KAAK,EAAE,iBAAiB,EAChC,SAAS,GAAE,eAAsC,EACzC,GAAG,yCAAyC;IAStD,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,iBAAiB;IAIZ,eAAe,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BhE,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAYjE,iCAAiC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAsBhG,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9D,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBtD,oCAAoC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBrF,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAkBjF"}
@@ -37,13 +37,25 @@ export class KvAttestationPool {
37
37
  await this.proposalsForSlot.set(slotNumber.toString(), proposalId.toString());
38
38
  await this.attestationsForProposal.set(this.getProposalKey(slotNumber, proposalId), this.getAttestationKey(slotNumber, proposalId, address));
39
39
  this.log.verbose(`Added attestation for slot ${slotNumber.toBigInt()} from ${address}`, {
40
- signature: attestation.signature.toString()
40
+ signature: attestation.signature.toString(),
41
+ slotNumber,
42
+ address,
43
+ proposalId
41
44
  });
42
45
  }
43
46
  });
44
47
  this.metrics.recordAddedObjects(attestations.length);
45
48
  }
46
- async getAttestationsForSlot(slot, proposalId) {
49
+ async getAttestationsForSlot(slot) {
50
+ const slotFr = new Fr(slot);
51
+ const proposalIds = await toArray(this.proposalsForSlot.getValuesAsync(slotFr.toString()));
52
+ const attestations = [];
53
+ for (const proposalId of proposalIds){
54
+ attestations.push(...await this.getAttestationsForSlotAndProposal(slot, proposalId));
55
+ }
56
+ return attestations;
57
+ }
58
+ async getAttestationsForSlotAndProposal(slot, proposalId) {
47
59
  const attestationIds = await toArray(this.attestationsForProposal.getValuesAsync(this.getProposalKey(slot, proposalId)));
48
60
  const attestations = [];
49
61
  // alternatively iterate this.attestaions starting from slot-proposal-EthAddress.zero
@@ -7,7 +7,8 @@ export declare class InMemoryAttestationPool implements AttestationPool {
7
7
  private metrics;
8
8
  private attestations;
9
9
  constructor(telemetry?: TelemetryClient, log?: import("@aztec/foundation/log").Logger);
10
- getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
10
+ getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]>;
11
+ getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
11
12
  addAttestations(attestations: BlockAttestation[]): Promise<void>;
12
13
  deleteAttestationsOlderThan(oldestSlot: bigint): Promise<void>;
13
14
  deleteAttestationsForSlot(slot: bigint): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"memory_attestation_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/memory_attestation_pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAGnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,qBAAa,uBAAwB,YAAW,eAAe;;IAKE,OAAO,CAAC,GAAG;IAJ1E,OAAO,CAAC,OAAO,CAAwC;IAEvD,OAAO,CAAC,YAAY,CAAgG;gBAExG,SAAS,GAAE,eAAsC,EAAU,GAAG,yCAAuC;IAK1G,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE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AAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWtD,oCAAoC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAe/E,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBjF"}
@@ -10,7 +10,10 @@ export class InMemoryAttestationPool {
10
10
  this.attestations = new Map();
11
11
  this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL);
12
12
  }
13
- getAttestationsForSlot(slot, proposalId) {
13
+ getAttestationsForSlot(slot) {
14
+ return Promise.resolve(Array.from(this.attestations.get(slot)?.values() ?? []).flatMap((proposalAttestationMap)=>Array.from(proposalAttestationMap.values())));
15
+ }
16
+ getAttestationsForSlotAndProposal(slot, proposalId) {
14
17
  const slotAttestationMap = this.attestations.get(slot);
15
18
  if (slotAttestationMap) {
16
19
  const proposalAttestationMap = slotAttestationMap.get(proposalId);
@@ -30,7 +33,10 @@ export class InMemoryAttestationPool {
30
33
  const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
31
34
  proposalAttestationMap.set(address.toString(), attestation);
32
35
  this.log.verbose(`Added attestation for slot ${slotNumber.toBigInt()} from ${address}`, {
33
- signature: attestation.signature.toString()
36
+ signature: attestation.signature.toString(),
37
+ slotNumber,
38
+ address,
39
+ proposalId
34
40
  });
35
41
  }
36
42
  // TODO: set these to pending or something ????
@@ -103,7 +103,8 @@ export declare class LibP2PService<T extends P2PClientType> extends WithTracer i
103
103
  private handleNewGossipMessage;
104
104
  private validateReceivedMessage;
105
105
  private handleGossipedTx;
106
- /**Process Attestation From Peer
106
+ /**
107
+ * Process Attestation From Peer
107
108
  * When a proposal is received from a peer, we add it to the attestation pool, so it can be accessed by other services.
108
109
  *
109
110
  * @param attestation - The attestation to process.
@@ -1 +1 @@
1
- {"version":3,"file":"libp2p_service.d.ts","sourceRoot":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;;;;;;;;OAQG;IACH,OAAO,CAAC,uBAAuB;IA2B/B;;;;;OAKG;YACW,cAAc;IA8B5B;;;;;;;;;;OAUG;YACW,wBAAwB;IAuBtC;;;;;OAKG;IAOU,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAUjG;;;;;OAKG;IAIU,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAUnF,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;YAI7B,WAAW;YAcX,UAAU;CAYzB"}
@@ -383,7 +383,8 @@ import { ReqResp } from '../reqresp/reqresp.js';
383
383
  tx
384
384
  ]);
385
385
  }
386
- /**Process Attestation From Peer
386
+ /**
387
+ * Process Attestation From Peer
387
388
  * When a proposal is received from a peer, we add it to the attestation pool, so it can be accessed by other services.
388
389
  *
389
390
  * @param attestation - The attestation to process.
@@ -35,12 +35,17 @@ function mockAttestationPool() {
35
35
  deleteAttestationsOlderThan: ()=>Promise.resolve(),
36
36
  deleteAttestationsForSlot: ()=>Promise.resolve(),
37
37
  deleteAttestationsForSlotAndProposal: ()=>Promise.resolve(),
38
- getAttestationsForSlot: ()=>Promise.resolve([])
38
+ getAttestationsForSlot: ()=>Promise.resolve([]),
39
+ getAttestationsForSlotAndProposal: ()=>Promise.resolve([])
39
40
  };
40
41
  }
41
42
  function mockEpochCache() {
42
43
  return {
43
- getCommittee: ()=>Promise.resolve([]),
44
+ getCommittee: ()=>Promise.resolve({
45
+ committee: [],
46
+ seed: 1n,
47
+ epoch: 0n
48
+ }),
44
49
  getProposerIndexEncoding: ()=>'0x',
45
50
  getEpochAndSlotNow: ()=>({
46
51
  epoch: 0n,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/p2p",
3
- "version": "0.82.2",
3
+ "version": "0.82.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -65,14 +65,14 @@
65
65
  ]
66
66
  },
67
67
  "dependencies": {
68
- "@aztec/constants": "0.82.2",
69
- "@aztec/epoch-cache": "0.82.2",
70
- "@aztec/foundation": "0.82.2",
71
- "@aztec/kv-store": "0.82.2",
72
- "@aztec/noir-protocol-circuits-types": "0.82.2",
73
- "@aztec/protocol-contracts": "0.82.2",
74
- "@aztec/stdlib": "0.82.2",
75
- "@aztec/telemetry-client": "0.82.2",
68
+ "@aztec/constants": "0.82.3",
69
+ "@aztec/epoch-cache": "0.82.3",
70
+ "@aztec/foundation": "0.82.3",
71
+ "@aztec/kv-store": "0.82.3",
72
+ "@aztec/noir-protocol-circuits-types": "0.82.3",
73
+ "@aztec/protocol-contracts": "0.82.3",
74
+ "@aztec/stdlib": "0.82.3",
75
+ "@aztec/telemetry-client": "0.82.3",
76
76
  "@chainsafe/discv5": "9.0.0",
77
77
  "@chainsafe/enr": "3.0.0",
78
78
  "@chainsafe/libp2p-gossipsub": "13.0.0",
@@ -101,7 +101,7 @@
101
101
  "xxhash-wasm": "^1.1.0"
102
102
  },
103
103
  "devDependencies": {
104
- "@aztec/archiver": "0.82.2",
104
+ "@aztec/archiver": "0.82.3",
105
105
  "@jest/globals": "^29.5.0",
106
106
  "@types/jest": "^29.5.0",
107
107
  "@types/node": "^18.14.6",
@@ -187,6 +187,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
187
187
  private synchedBlockHashes: AztecAsyncMap<number, string>;
188
188
  private synchedLatestBlockNumber: AztecAsyncSingleton<number>;
189
189
  private synchedProvenBlockNumber: AztecAsyncSingleton<number>;
190
+ private synchedLatestSlot: AztecAsyncSingleton<bigint>;
190
191
 
191
192
  private txPool: TxPool;
192
193
  private attestationPool: T extends P2PClientType.Full ? AttestationPool : undefined;
@@ -236,6 +237,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
236
237
  this.synchedBlockHashes = store.openMap('p2p_pool_block_hashes');
237
238
  this.synchedLatestBlockNumber = store.openSingleton('p2p_pool_last_l2_block');
238
239
  this.synchedProvenBlockNumber = store.openSingleton('p2p_pool_last_proven_l2_block');
240
+ this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
239
241
 
240
242
  this.txPool = mempools.txPool;
241
243
  this.attestationPool = mempools.attestationPool!;
@@ -380,8 +382,16 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
380
382
  return this.p2pService.propagate(proposal);
381
383
  }
382
384
 
383
- public async getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]> {
384
- return (await this.attestationPool?.getAttestationsForSlot(slot, proposalId)) ?? [];
385
+ public async getAttestationsForSlot(slot: bigint, proposalId?: string): Promise<BlockAttestation[]> {
386
+ return (
387
+ (await (proposalId
388
+ ? this.attestationPool?.getAttestationsForSlotAndProposal(slot, proposalId)
389
+ : this.attestationPool?.getAttestationsForSlot(slot))) ?? []
390
+ );
391
+ }
392
+
393
+ public addAttestation(attestation: BlockAttestation): Promise<void> {
394
+ return this.attestationPool?.addAttestations([attestation]) ?? Promise.resolve();
385
395
  }
386
396
 
387
397
  // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
@@ -592,6 +602,11 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
592
602
  return (await this.synchedProvenBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
593
603
  }
594
604
 
605
+ /** Returns latest L2 slot for which we have seen an L2 block. */
606
+ public async getSyncedLatestSlot(): Promise<bigint> {
607
+ return (await this.synchedLatestSlot.getAsync()) ?? BigInt(0);
608
+ }
609
+
595
610
  /**
596
611
  * Method to check the status the p2p client.
597
612
  * @returns Information about p2p client status: state & syncedToBlockNum.
@@ -659,12 +674,13 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
659
674
 
660
675
  await this.markTxsAsMinedFromBlocks(blocks.map(b => b.block));
661
676
  await this.addAttestationsToPool(blocks);
662
- const lastBlockNum = blocks.at(-1)!.block.number;
677
+ const lastBlock = blocks.at(-1)!.block;
663
678
  await Promise.all(
664
679
  blocks.map(async block => this.synchedBlockHashes.set(block.block.number, (await block.block.hash()).toString())),
665
680
  );
666
- await this.synchedLatestBlockNumber.set(lastBlockNum);
667
- this.log.verbose(`Synched to latest block ${lastBlockNum}`);
681
+ await this.synchedLatestBlockNumber.set(lastBlock.number);
682
+ await this.synchedLatestSlot.set(lastBlock.header.getSlot());
683
+ this.log.verbose(`Synched to latest block ${lastBlock.number}`);
668
684
  await this.startServiceIfSynched();
669
685
  }
670
686
 
package/src/config.ts CHANGED
@@ -371,6 +371,7 @@ export type BootnodeConfig = Pick<
371
371
  const bootnodeConfigKeys: (keyof BootnodeConfig)[] = [
372
372
  'p2pIp',
373
373
  'p2pPort',
374
+ 'listenAddress',
374
375
  'peerIdPrivateKey',
375
376
  'dataDirectory',
376
377
  'dataStoreMapSizeKB',
@@ -50,7 +50,17 @@ export interface AttestationPool {
50
50
  deleteAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<void>;
51
51
 
52
52
  /**
53
- * Get Attestations for slot
53
+ * Get all Attestations for all proposals for a given slot
54
+ *
55
+ * Retrieve all of the attestations observed pertaining to a given slot
56
+ *
57
+ * @param slot - The slot to query
58
+ * @return BlockAttestations
59
+ */
60
+ getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]>;
61
+
62
+ /**
63
+ * Get Attestations for slot and given proposal
54
64
  *
55
65
  * Retrieve all of the attestations observed pertaining to a given slot
56
66
  *
@@ -58,5 +68,5 @@ export interface AttestationPool {
58
68
  * @param proposalId - The proposal to query
59
69
  * @return BlockAttestations
60
70
  */
61
- getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
71
+ getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
62
72
  }
@@ -45,25 +45,45 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
45
45
  it('should add attestations to pool', async () => {
46
46
  const slotNumber = 420;
47
47
  const archive = Fr.random();
48
- const attestations = await Promise.all(signers.map(signer => mockAttestation(signer, slotNumber, archive)));
48
+ const attestations = await Promise.all(
49
+ signers.slice(0, -1).map(signer => mockAttestation(signer, slotNumber, archive)),
50
+ );
49
51
 
50
52
  await ap.addAttestations(attestations);
51
53
 
52
54
  // Check metrics have been updated.
53
55
  expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
54
56
 
55
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
57
+ const retrievedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
58
+ expect(retrievedAttestations.length).toBe(attestations.length);
59
+ compareAttestations(retrievedAttestations, attestations);
56
60
 
57
- expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
61
+ const retrievedAttestationsForSlot = await ap.getAttestationsForSlot(BigInt(slotNumber));
62
+ expect(retrievedAttestationsForSlot.length).toBe(attestations.length);
63
+ compareAttestations(retrievedAttestationsForSlot, attestations);
58
64
 
59
- compareAttestations(retreivedAttestations, attestations);
65
+ // Add another one
66
+ const newAttestation = await mockAttestation(signers[NUMBER_OF_SIGNERS_PER_TEST - 1], slotNumber, archive);
67
+ await ap.addAttestations([newAttestation]);
68
+ expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(1);
69
+ const retrievedAttestationsAfterAdd = await ap.getAttestationsForSlotAndProposal(
70
+ BigInt(slotNumber),
71
+ archive.toString(),
72
+ );
73
+ expect(retrievedAttestationsAfterAdd.length).toBe(attestations.length + 1);
74
+ compareAttestations(retrievedAttestationsAfterAdd, [...attestations, newAttestation]);
75
+ const retrievedAttestationsForSlotAfterAdd = await ap.getAttestationsForSlot(BigInt(slotNumber));
76
+ expect(retrievedAttestationsForSlotAfterAdd.length).toBe(attestations.length + 1);
77
+ compareAttestations(retrievedAttestationsForSlotAfterAdd, [...attestations, newAttestation]);
60
78
 
61
79
  // Delete by slot
62
80
  await ap.deleteAttestationsForSlot(BigInt(slotNumber));
81
+ expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length + 1);
63
82
 
64
- expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
65
-
66
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
83
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(
84
+ BigInt(slotNumber),
85
+ archive.toString(),
86
+ );
67
87
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
68
88
  });
69
89
 
@@ -82,7 +102,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
82
102
  // Add them to store and check we end up with only one
83
103
  await ap.addAttestations(attestations);
84
104
 
85
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString());
105
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
86
106
  expect(retreivedAttestations.length).toBe(1);
87
107
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestations[0].toBuffer());
88
108
  expect(retreivedAttestations[0].payload.txHashes).toEqual(txs);
@@ -90,7 +110,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
90
110
 
91
111
  // Try adding them on another operation and check they are still not duplicated
92
112
  await ap.addAttestations([attestations[0]]);
93
- expect(await ap.getAttestationsForSlot(BigInt(slotNumber), archive.toString())).toHaveLength(1);
113
+ expect(await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString())).toHaveLength(1);
94
114
  });
95
115
 
96
116
  it('should store attestations by differing slot', async () => {
@@ -103,7 +123,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
103
123
  const slot = attestation.payload.header.globalVariables.slotNumber;
104
124
  const archive = attestation.archive.toString();
105
125
 
106
- const retreivedAttestations = await ap.getAttestationsForSlot(slot.toBigInt(), archive);
126
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(slot.toBigInt(), archive);
107
127
  expect(retreivedAttestations.length).toBe(1);
108
128
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestation.toBuffer());
109
129
  expect(retreivedAttestations[0].payload.header.globalVariables.slotNumber).toEqual(slot);
@@ -123,7 +143,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
123
143
  const slot = attestation.payload.header.globalVariables.slotNumber;
124
144
  const proposalId = attestation.archive.toString();
125
145
 
126
- const retreivedAttestations = await ap.getAttestationsForSlot(slot.toBigInt(), proposalId);
146
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(slot.toBigInt(), proposalId);
127
147
  expect(retreivedAttestations.length).toBe(1);
128
148
  expect(retreivedAttestations[0].toBuffer()).toEqual(attestation.toBuffer());
129
149
  expect(retreivedAttestations[0].payload.header.globalVariables.slotNumber).toEqual(slot);
@@ -140,7 +160,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
140
160
 
141
161
  expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
142
162
 
143
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
163
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
144
164
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
145
165
  compareAttestations(retreivedAttestations, attestations);
146
166
 
@@ -148,7 +168,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
148
168
 
149
169
  expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
150
170
 
151
- const gottenAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
171
+ const gottenAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
152
172
  expect(gottenAfterDelete.length).toBe(0);
153
173
  });
154
174
 
@@ -160,13 +180,13 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
160
180
 
161
181
  await ap.addAttestations(attestations);
162
182
 
163
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
183
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
164
184
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
165
185
  compareAttestations(retreivedAttestations, attestations);
166
186
 
167
187
  await ap.deleteAttestationsForSlot(BigInt(slotNumber));
168
188
 
169
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
189
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
170
190
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
171
191
  });
172
192
 
@@ -187,7 +207,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
187
207
  expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations.length);
188
208
  expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations2.length);
189
209
 
190
- const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
210
+ const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
191
211
  expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
192
212
  compareAttestations(retreivedAttestations, attestations);
193
213
 
@@ -195,10 +215,10 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
195
215
 
196
216
  expect(metricsMock.recordRemovedObjects).toHaveBeenCalledWith(attestations.length);
197
217
 
198
- const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
218
+ const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
199
219
  expect(retreivedAttestationsAfterDelete.length).toBe(0);
200
220
 
201
- const retreivedAttestationsAfterDeleteForOtherProposal = await ap.getAttestationsForSlot(
221
+ const retreivedAttestationsAfterDeleteForOtherProposal = await ap.getAttestationsForSlotAndProposal(
202
222
  BigInt(slotNumber),
203
223
  proposalId2,
204
224
  );
@@ -215,14 +235,14 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
215
235
 
216
236
  await ap.addAttestations(attestations);
217
237
 
218
- const attestationsForSlot1 = await ap.getAttestationsForSlot(BigInt(1), proposalId);
238
+ const attestationsForSlot1 = await ap.getAttestationsForSlotAndProposal(BigInt(1), proposalId);
219
239
  expect(attestationsForSlot1.length).toBe(signers.length);
220
240
 
221
241
  const deleteAttestationsSpy = jest.spyOn(ap, 'deleteAttestationsForSlot');
222
242
 
223
243
  await ap.deleteAttestationsOlderThan(BigInt(73));
224
244
 
225
- const attestationsForSlot1AfterDelete = await ap.getAttestationsForSlot(BigInt(1), proposalId);
245
+ const attestationsForSlot1AfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(1), proposalId);
226
246
  expect(attestationsForSlot1AfterDelete.length).toBe(0);
227
247
 
228
248
  expect(deleteAttestationsSpy).toHaveBeenCalledTimes(5);
@@ -60,6 +60,9 @@ export class KvAttestationPool implements AttestationPool {
60
60
 
61
61
  this.log.verbose(`Added attestation for slot ${slotNumber.toBigInt()} from ${address}`, {
62
62
  signature: attestation.signature.toString(),
63
+ slotNumber,
64
+ address,
65
+ proposalId,
63
66
  });
64
67
  }
65
68
  });
@@ -67,7 +70,19 @@ export class KvAttestationPool implements AttestationPool {
67
70
  this.metrics.recordAddedObjects(attestations.length);
68
71
  }
69
72
 
70
- public async getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]> {
73
+ public async getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]> {
74
+ const slotFr = new Fr(slot);
75
+ const proposalIds = await toArray(this.proposalsForSlot.getValuesAsync(slotFr.toString()));
76
+ const attestations: BlockAttestation[] = [];
77
+
78
+ for (const proposalId of proposalIds) {
79
+ attestations.push(...(await this.getAttestationsForSlotAndProposal(slot, proposalId)));
80
+ }
81
+
82
+ return attestations;
83
+ }
84
+
85
+ public async getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]> {
71
86
  const attestationIds = await toArray(
72
87
  this.attestationsForProposal.getValuesAsync(this.getProposalKey(slot, proposalId)),
73
88
  );
@@ -15,7 +15,15 @@ export class InMemoryAttestationPool implements AttestationPool {
15
15
  this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL);
16
16
  }
17
17
 
18
- public getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]> {
18
+ public getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]> {
19
+ return Promise.resolve(
20
+ Array.from(this.attestations.get(slot)?.values() ?? []).flatMap(proposalAttestationMap =>
21
+ Array.from(proposalAttestationMap.values()),
22
+ ),
23
+ );
24
+ }
25
+
26
+ public getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]> {
19
27
  const slotAttestationMap = this.attestations.get(slot);
20
28
  if (slotAttestationMap) {
21
29
  const proposalAttestationMap = slotAttestationMap.get(proposalId);
@@ -40,6 +48,9 @@ export class InMemoryAttestationPool implements AttestationPool {
40
48
 
41
49
  this.log.verbose(`Added attestation for slot ${slotNumber.toBigInt()} from ${address}`, {
42
50
  signature: attestation.signature.toString(),
51
+ slotNumber,
52
+ address,
53
+ proposalId,
43
54
  });
44
55
  }
45
56
 
@@ -521,7 +521,8 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
521
521
  await this.mempools.txPool.addTxs([tx]);
522
522
  }
523
523
 
524
- /**Process Attestation From Peer
524
+ /**
525
+ * Process Attestation From Peer
525
526
  * When a proposal is received from a peer, we add it to the attestation pool, so it can be accessed by other services.
526
527
  *
527
528
  * @param attestation - The attestation to process.
@@ -48,12 +48,13 @@ function mockAttestationPool(): AttestationPool {
48
48
  deleteAttestationsForSlot: () => Promise.resolve(),
49
49
  deleteAttestationsForSlotAndProposal: () => Promise.resolve(),
50
50
  getAttestationsForSlot: () => Promise.resolve([]),
51
+ getAttestationsForSlotAndProposal: () => Promise.resolve([]),
51
52
  };
52
53
  }
53
54
 
54
55
  function mockEpochCache(): EpochCacheInterface {
55
56
  return {
56
- getCommittee: () => Promise.resolve([] as EthAddress[]),
57
+ getCommittee: () => Promise.resolve({ committee: [], seed: 1n, epoch: 0n }),
57
58
  getProposerIndexEncoding: () => '0x' as `0x${string}`,
58
59
  getEpochAndSlotNow: () => ({ epoch: 0n, slot: 0n, ts: 0n }),
59
60
  computeProposerIndex: () => 0n,