Skip to content

Commit eaf3e65

Browse files
spalladinoclaude
andcommitted
refactor(p2p): remove AttestationPool interface, rename KvAttestationPool to AttestationPool
- Merge KvAttestationPool class into attestation_pool.ts and rename to AttestationPool - Move TryAddResult type definition to the class file - Delete kv_attestation_pool.ts and kv_attestation_pool.test.ts files - Add AttestationPoolApi type alias for typing mocks and test implementations - Update all imports across the codebase to use the renamed class - Update MemPools and P2PClientDeps types to use AttestationPoolApi for flexibility - Rename test file from kv_attestation_pool.test.ts to attestation_pool.test.ts Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 518c836 commit eaf3e65

File tree

14 files changed

+454
-460
lines changed

14 files changed

+454
-460
lines changed

yarn-project/p2p/src/client/factory.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-clien
1313

1414
import { P2PClient } from '../client/p2p_client.js';
1515
import type { P2PConfig } from '../config.js';
16-
import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
17-
import { KvAttestationPool } from '../mem_pools/attestation_pool/kv_attestation_pool.js';
16+
import { AttestationPool, type AttestationPoolApi } from '../mem_pools/attestation_pool/attestation_pool.js';
1817
import type { MemPools } from '../mem_pools/interface.js';
1918
import { AztecKVTxPool, type TxPool } from '../mem_pools/tx_pool/index.js';
2019
import { DummyP2PService } from '../services/dummy_service.js';
@@ -26,7 +25,7 @@ import { configureP2PClientAddresses, createLibP2PPeerIdFromPrivateKey, getPeerI
2625
export type P2PClientDeps<T extends P2PClientType> = {
2726
txPool?: TxPool;
2827
store?: AztecAsyncKVStore;
29-
attestationPool?: AttestationPool;
28+
attestationPool?: AttestationPoolApi;
3029
logger?: Logger;
3130
txCollectionNodeSources?: TxSource[];
3231
p2pServiceFactory?: (...args: Parameters<(typeof LibP2PService)['new']>) => Promise<LibP2PService<T>>;
@@ -76,7 +75,7 @@ export async function createP2PClient<T extends P2PClientType>(
7675
maxPendingTxCount: config.maxPendingTxCount,
7776
archivedTxLimit: config.archivedTxLimit,
7877
}),
79-
attestationPool: deps.attestationPool ?? new KvAttestationPool(attestationStore, telemetry),
78+
attestationPool: deps.attestationPool ?? new AttestationPool(attestationStore, telemetry),
8079
};
8180

8281
const p2pService = await createP2PService<T>(

yarn-project/p2p/src/client/p2p_client.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import { type MockProxy, mock } from 'jest-mock-extended';
2525

2626
import type { P2PConfig } from '../config.js';
2727
import type { P2PService } from '../index.js';
28-
import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
29-
import { createTestAttestationPool } from '../mem_pools/attestation_pool/kv_attestation_pool.js';
28+
import { type AttestationPool, createTestAttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
3029
import type { MemPools } from '../mem_pools/interface.js';
3130
import { AztecKVTxPool } from '../mem_pools/tx_pool/aztec_kv_tx_pool.js';
3231
import type { TxPool } from '../mem_pools/tx_pool/index.js';

yarn-project/p2p/src/client/p2p_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import type { PeerId } from '@libp2p/interface';
2929
import type { ENR } from '@nethermindeth/enr';
3030

3131
import { type P2PConfig, getP2PDefaultConfig } from '../config.js';
32-
import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
32+
import type { AttestationPoolApi } from '../mem_pools/attestation_pool/attestation_pool.js';
3333
import type { MemPools } from '../mem_pools/interface.js';
3434
import type { TxPool } from '../mem_pools/tx_pool/index.js';
3535
import type { AuthRequest, StatusMessage } from '../services/index.js';
@@ -70,7 +70,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
7070
private synchedLatestSlot: AztecAsyncSingleton<bigint>;
7171

7272
private txPool: TxPool;
73-
private attestationPool: AttestationPool;
73+
private attestationPool: AttestationPoolApi;
7474

7575
private config: P2PConfig;
7676

yarn-project/p2p/src/mem_pools/attestation_pool/kv_attestation_pool.test.ts renamed to yarn-project/p2p/src/mem_pools/attestation_pool/attestation_pool.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,34 @@ import type { AztecAsyncKVStore } from '@aztec/kv-store';
55
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
66
import { makeBlockHeader, makeBlockProposal } from '@aztec/stdlib/testing';
77

8+
import { ATTESTATION_CAP_BUFFER, AttestationPool } from './attestation_pool.js';
89
import { describeAttestationPool } from './attestation_pool_test_suite.js';
9-
import { ATTESTATION_CAP_BUFFER, KvAttestationPool } from './kv_attestation_pool.js';
1010
import { mockCheckpointAttestation } from './mocks.js';
1111

12-
describe('KV Attestation Pool', () => {
13-
let kvAttestationPool: KvAttestationPool;
12+
describe('Attestation Pool', () => {
13+
let attestationPool: AttestationPool;
1414
let store: AztecAsyncKVStore;
1515

1616
beforeEach(async () => {
1717
store = await openTmpStore('test');
18-
kvAttestationPool = new KvAttestationPool(store);
18+
attestationPool = new AttestationPool(store);
1919
});
2020

2121
afterEach(() => store.close());
2222

23-
describeAttestationPool(() => kvAttestationPool);
23+
describeAttestationPool(() => attestationPool);
2424

2525
describe('BlockProposal behavior', () => {
2626
it('should allow adding block proposals up to position cap', async () => {
2727
const slotNumber = 100;
2828
const header = makeBlockHeader(1, { slotNumber: SlotNumber(slotNumber) });
2929

30-
// Add 1 proposal and re-add it (duplicate) should return alreadyExists
30+
// Add 1 proposal and re-add it (duplicate) -> should return alreadyExists
3131
const p0 = await makeBlockProposal({ blockHeader: header, archiveRoot: Fr.random() });
32-
const result0 = await kvAttestationPool.tryAddBlockProposal(p0);
32+
const result0 = await attestationPool.tryAddBlockProposal(p0);
3333
expect(result0.added).toBe(true);
3434

35-
const result0Dup = await kvAttestationPool.tryAddBlockProposal(p0);
35+
const result0Dup = await attestationPool.tryAddBlockProposal(p0);
3636
expect(result0Dup.added).toBe(false);
3737
expect(result0Dup.alreadyExists).toBe(true);
3838
});
@@ -54,20 +54,20 @@ describe('KV Attestation Pool', () => {
5454

5555
// Add each attestation using tryAddCheckpointAttestation
5656
for (let i = 0; i < attestations.length; i++) {
57-
const result = await kvAttestationPool.tryAddCheckpointAttestation(attestations[i], committeeSize);
57+
const result = await attestationPool.tryAddCheckpointAttestation(attestations[i], committeeSize);
5858
expect(result.added).toBe(true);
5959
expect(result.totalForPosition).toBe(i + 1);
6060
}
6161

6262
// A new attestation from a new signer should not be added (cap reached)
6363
const extra = mockCheckpointAttestation(Secp256k1Signer.random(), slotNumber, archive);
64-
const extraResult = await kvAttestationPool.tryAddCheckpointAttestation(extra, committeeSize);
64+
const extraResult = await attestationPool.tryAddCheckpointAttestation(extra, committeeSize);
6565
expect(extraResult.added).toBe(false);
6666
expect(extraResult.alreadyExists).toBe(false);
6767
expect(extraResult.totalForPosition).toBe(limit);
6868

6969
// Re-adding an existing attestation should return alreadyExists
70-
const existingResult = await kvAttestationPool.tryAddCheckpointAttestation(attestations[0], committeeSize);
70+
const existingResult = await attestationPool.tryAddCheckpointAttestation(attestations[0], committeeSize);
7171
expect(existingResult.added).toBe(false);
7272
expect(existingResult.alreadyExists).toBe(true);
7373
});

0 commit comments

Comments
 (0)