From 3eb6fcca1b7505a2d308623b3e7e658fc00d06e3 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Mon, 7 Oct 2024 22:53:48 +0000 Subject: [PATCH 1/7] feat: store received epoch quotes --- yarn-project/p2p/src/client/index.ts | 1 + yarn-project/p2p/src/service/libp2p_service.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/yarn-project/p2p/src/client/index.ts b/yarn-project/p2p/src/client/index.ts index aaafccba9f1..237bc151801 100644 --- a/yarn-project/p2p/src/client/index.ts +++ b/yarn-project/p2p/src/client/index.ts @@ -53,6 +53,7 @@ export const createP2PClient = async ( peerId, txPool, attestationsPool, + epochProofQuotePool, l2BlockSource, proofVerifier, worldStateSynchronizer, diff --git a/yarn-project/p2p/src/service/libp2p_service.ts b/yarn-project/p2p/src/service/libp2p_service.ts index 755439b5f2e..97ff650dfce 100644 --- a/yarn-project/p2p/src/service/libp2p_service.ts +++ b/yarn-project/p2p/src/service/libp2p_service.ts @@ -2,6 +2,7 @@ import { BlockAttestation, BlockProposal, type ClientProtocolCircuitVerifier, + EpochProofQuote, type Gossipable, type L2BlockSource, MerkleTreeId, @@ -57,6 +58,7 @@ import { } from './reqresp/interface.js'; import { ReqResp } from './reqresp/reqresp.js'; import type { P2PService, PeerDiscoveryService } from './service.js'; +import { EpochProofQuotePool } from '../epoch_proof_quote_pool/epoch_proof_quote_pool.js'; /** * Create a libp2p peer ID from the private key if provided, otherwise creates a new random ID. @@ -98,6 +100,7 @@ export class LibP2PService implements P2PService { private peerDiscoveryService: PeerDiscoveryService, private txPool: TxPool, private attestationPool: AttestationPool, + private epochProofQuotePool: EpochProofQuotePool, private l2BlockSource: L2BlockSource, private proofVerifier: ClientProtocolCircuitVerifier, private worldStateSynchronizer: WorldStateSynchronizer, @@ -202,6 +205,7 @@ export class LibP2PService implements P2PService { peerId: PeerId, txPool: TxPool, attestationPool: AttestationPool, + epochProofQuotePool: EpochProofQuotePool, l2BlockSource: L2BlockSource, proofVerifier: ClientProtocolCircuitVerifier, worldStateSynchronizer: WorldStateSynchronizer, @@ -291,6 +295,7 @@ export class LibP2PService implements P2PService { peerDiscoveryService, txPool, attestationPool, + epochProofQuotePool, l2BlockSource, proofVerifier, worldStateSynchronizer, @@ -372,6 +377,10 @@ export class LibP2PService implements P2PService { const block = BlockProposal.fromBuffer(Buffer.from(message.data)); await this.processBlockFromPeer(block); } + if (message.topic == EpochProofQuote.p2pTopic) { + const epochProofQuote = EpochProofQuote.fromBuffer(Buffer.from(message.data)); + this.processEpochProofQuoteFromPeer(epochProofQuote); + } return; } @@ -404,6 +413,11 @@ export class LibP2PService implements P2PService { } } + private processEpochProofQuoteFromPeer(epochProofQuote: EpochProofQuote): void { + this.logger.verbose(`Received epoch proof quote ${epochProofQuote.p2pMessageIdentifier()} from external peer.`); + this.epochProofQuotePool.addQuote(epochProofQuote); + } + /** * Propagates provided message to peers. * @param message - The message to propagate. From 2f3a3c0e3ee376698a1d7ab284d0d1b6404b57d3 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Mon, 7 Oct 2024 22:56:04 +0000 Subject: [PATCH 2/7] fmt --- yarn-project/p2p/src/service/libp2p_service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/p2p/src/service/libp2p_service.ts b/yarn-project/p2p/src/service/libp2p_service.ts index 97ff650dfce..b432f6eb49e 100644 --- a/yarn-project/p2p/src/service/libp2p_service.ts +++ b/yarn-project/p2p/src/service/libp2p_service.ts @@ -34,6 +34,7 @@ import { createLibp2p } from 'libp2p'; import { type AttestationPool } from '../attestation_pool/attestation_pool.js'; import { type P2PConfig } from '../config.js'; +import { type EpochProofQuotePool } from '../epoch_proof_quote_pool/epoch_proof_quote_pool.js'; import { type TxPool } from '../tx_pool/index.js'; import { DataTxValidator, @@ -58,7 +59,6 @@ import { } from './reqresp/interface.js'; import { ReqResp } from './reqresp/reqresp.js'; import type { P2PService, PeerDiscoveryService } from './service.js'; -import { EpochProofQuotePool } from '../epoch_proof_quote_pool/epoch_proof_quote_pool.js'; /** * Create a libp2p peer ID from the private key if provided, otherwise creates a new random ID. From d9deaffd9fa93d0b19b7e33bdb880670fc2321c4 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:02:34 +0000 Subject: [PATCH 3/7] chore: refactor pools --- yarn-project/p2p/src/client/index.ts | 10 +++++----- yarn-project/p2p/src/client/p2p_client.test.ts | 4 ++-- yarn-project/p2p/src/client/p2p_client.ts | 6 +++--- yarn-project/p2p/src/index.ts | 6 +++--- .../attestation_pool/attestation_pool.ts | 0 .../src/{ => mem_pools}/attestation_pool/index.ts | 0 .../attestation_pool/memory_attestation_pool.test.ts | 0 .../attestation_pool/memory_attestation_pool.ts | 0 .../src/{ => mem_pools}/attestation_pool/mocks.ts | 0 .../epoch_proof_quote_pool/epoch_proof_quote_pool.ts | 0 .../{ => mem_pools}/epoch_proof_quote_pool/index.ts | 0 .../memory_epoch_proof_quote_pool.test.ts | 0 .../memory_epoch_proof_quote_pool.ts | 0 .../epoch_proof_quote_pool/test_utils.ts | 0 yarn-project/p2p/src/mem_pools/index.ts | 4 ++++ yarn-project/p2p/src/mem_pools/interface.ts | 12 ++++++++++++ .../{ => mem_pools}/tx_pool/aztec_kv_tx_pool.test.ts | 0 .../src/{ => mem_pools}/tx_pool/aztec_kv_tx_pool.ts | 0 .../p2p/src/{ => mem_pools}/tx_pool/index.ts | 0 .../src/{ => mem_pools}/tx_pool/instrumentation.ts | 0 .../{ => mem_pools}/tx_pool/memory_tx_pool.test.ts | 0 .../src/{ => mem_pools}/tx_pool/memory_tx_pool.ts | 0 .../p2p/src/{ => mem_pools}/tx_pool/tx_pool.ts | 0 .../{ => mem_pools}/tx_pool/tx_pool_test_suite.ts | 0 yarn-project/p2p/src/service/libp2p_service.ts | 6 +++--- .../service/reqresp/p2p_client.integration.test.ts | 6 +++--- 26 files changed, 35 insertions(+), 19 deletions(-) rename yarn-project/p2p/src/{ => mem_pools}/attestation_pool/attestation_pool.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/attestation_pool/index.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/attestation_pool/memory_attestation_pool.test.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/attestation_pool/memory_attestation_pool.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/attestation_pool/mocks.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/epoch_proof_quote_pool/epoch_proof_quote_pool.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/epoch_proof_quote_pool/index.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.test.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/epoch_proof_quote_pool/test_utils.ts (100%) create mode 100644 yarn-project/p2p/src/mem_pools/index.ts create mode 100644 yarn-project/p2p/src/mem_pools/interface.ts rename yarn-project/p2p/src/{ => mem_pools}/tx_pool/aztec_kv_tx_pool.test.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/tx_pool/aztec_kv_tx_pool.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/tx_pool/index.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/tx_pool/instrumentation.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/tx_pool/memory_tx_pool.test.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/tx_pool/memory_tx_pool.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/tx_pool/tx_pool.ts (100%) rename yarn-project/p2p/src/{ => mem_pools}/tx_pool/tx_pool_test_suite.ts (100%) diff --git a/yarn-project/p2p/src/client/index.ts b/yarn-project/p2p/src/client/index.ts index 237bc151801..faf2cdd575e 100644 --- a/yarn-project/p2p/src/client/index.ts +++ b/yarn-project/p2p/src/client/index.ts @@ -5,16 +5,16 @@ import { type DataStoreConfig, createStore } from '@aztec/kv-store/utils'; import { type TelemetryClient } from '@aztec/telemetry-client'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; -import { type AttestationPool } from '../attestation_pool/attestation_pool.js'; -import { InMemoryAttestationPool } from '../attestation_pool/memory_attestation_pool.js'; +import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; +import { InMemoryAttestationPool } from '../mem_pools/attestation_pool/memory_attestation_pool.js'; import { P2PClient } from '../client/p2p_client.js'; import { type P2PConfig } from '../config.js'; -import { type EpochProofQuotePool } from '../epoch_proof_quote_pool/epoch_proof_quote_pool.js'; -import { MemoryEpochProofQuotePool } from '../epoch_proof_quote_pool/memory_epoch_proof_quote_pool.js'; +import { type EpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.js'; +import { MemoryEpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.js'; import { DiscV5Service } from '../service/discV5_service.js'; import { DummyP2PService } from '../service/dummy_service.js'; import { LibP2PService, createLibP2PPeerId } from '../service/index.js'; -import { AztecKVTxPool, type TxPool } from '../tx_pool/index.js'; +import { AztecKVTxPool, type TxPool } from '../mem_pools/tx_pool/index.js'; import { getPublicIp, resolveAddressIfNecessary, splitAddressPort } from '../util.js'; export * from './p2p_client.js'; diff --git a/yarn-project/p2p/src/client/p2p_client.test.ts b/yarn-project/p2p/src/client/p2p_client.test.ts index 3d16237dfb1..29e819ab774 100644 --- a/yarn-project/p2p/src/client/p2p_client.test.ts +++ b/yarn-project/p2p/src/client/p2p_client.test.ts @@ -6,9 +6,9 @@ import { openTmpStore } from '@aztec/kv-store/utils'; import { expect, jest } from '@jest/globals'; -import { type AttestationPool } from '../attestation_pool/attestation_pool.js'; +import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; import { type EpochProofQuotePool, type P2PService } from '../index.js'; -import { type TxPool } from '../tx_pool/index.js'; +import { type TxPool } from '../mem_pools/tx_pool/index.js'; import { P2PClient } from './p2p_client.js'; /** diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index b22b42700be..fee91a359c3 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -14,12 +14,12 @@ import { type AztecKVStore, type AztecSingleton } from '@aztec/kv-store'; import { type ENR } from '@chainsafe/enr'; -import { type AttestationPool } from '../attestation_pool/attestation_pool.js'; +import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; import { getP2PConfigEnvVars } from '../config.js'; -import { type EpochProofQuotePool } from '../epoch_proof_quote_pool/epoch_proof_quote_pool.js'; +import { type EpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.js'; import { TX_REQ_PROTOCOL } from '../service/reqresp/interface.js'; import type { P2PService } from '../service/service.js'; -import { type TxPool } from '../tx_pool/index.js'; +import { type TxPool } from '../mem_pools/tx_pool/index.js'; /** * Enum defining the possible states of the p2p client. diff --git a/yarn-project/p2p/src/index.ts b/yarn-project/p2p/src/index.ts index 4a5c64fda7e..d1cf3187d46 100644 --- a/yarn-project/p2p/src/index.ts +++ b/yarn-project/p2p/src/index.ts @@ -1,8 +1,8 @@ -export * from './attestation_pool/index.js'; +export * from './mem_pools/attestation_pool/index.js'; export * from './bootstrap/bootstrap.js'; export * from './client/index.js'; export * from './config.js'; -export * from './epoch_proof_quote_pool/index.js'; +export * from './mem_pools/epoch_proof_quote_pool/index.js'; export * from './service/index.js'; -export * from './tx_pool/index.js'; +export * from './mem_pools/tx_pool/index.js'; export * from './tx_validator/index.js'; diff --git a/yarn-project/p2p/src/attestation_pool/attestation_pool.ts b/yarn-project/p2p/src/mem_pools/attestation_pool/attestation_pool.ts similarity index 100% rename from yarn-project/p2p/src/attestation_pool/attestation_pool.ts rename to yarn-project/p2p/src/mem_pools/attestation_pool/attestation_pool.ts diff --git a/yarn-project/p2p/src/attestation_pool/index.ts b/yarn-project/p2p/src/mem_pools/attestation_pool/index.ts similarity index 100% rename from yarn-project/p2p/src/attestation_pool/index.ts rename to yarn-project/p2p/src/mem_pools/attestation_pool/index.ts diff --git a/yarn-project/p2p/src/attestation_pool/memory_attestation_pool.test.ts b/yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.test.ts similarity index 100% rename from yarn-project/p2p/src/attestation_pool/memory_attestation_pool.test.ts rename to yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.test.ts diff --git a/yarn-project/p2p/src/attestation_pool/memory_attestation_pool.ts b/yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.ts similarity index 100% rename from yarn-project/p2p/src/attestation_pool/memory_attestation_pool.ts rename to yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.ts diff --git a/yarn-project/p2p/src/attestation_pool/mocks.ts b/yarn-project/p2p/src/mem_pools/attestation_pool/mocks.ts similarity index 100% rename from yarn-project/p2p/src/attestation_pool/mocks.ts rename to yarn-project/p2p/src/mem_pools/attestation_pool/mocks.ts diff --git a/yarn-project/p2p/src/epoch_proof_quote_pool/epoch_proof_quote_pool.ts b/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.ts similarity index 100% rename from yarn-project/p2p/src/epoch_proof_quote_pool/epoch_proof_quote_pool.ts rename to yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.ts diff --git a/yarn-project/p2p/src/epoch_proof_quote_pool/index.ts b/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/index.ts similarity index 100% rename from yarn-project/p2p/src/epoch_proof_quote_pool/index.ts rename to yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/index.ts diff --git a/yarn-project/p2p/src/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.test.ts b/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.test.ts similarity index 100% rename from yarn-project/p2p/src/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.test.ts rename to yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.test.ts diff --git a/yarn-project/p2p/src/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.ts b/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.ts similarity index 100% rename from yarn-project/p2p/src/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.ts rename to yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.ts diff --git a/yarn-project/p2p/src/epoch_proof_quote_pool/test_utils.ts b/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/test_utils.ts similarity index 100% rename from yarn-project/p2p/src/epoch_proof_quote_pool/test_utils.ts rename to yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/test_utils.ts diff --git a/yarn-project/p2p/src/mem_pools/index.ts b/yarn-project/p2p/src/mem_pools/index.ts new file mode 100644 index 00000000000..9b229e58787 --- /dev/null +++ b/yarn-project/p2p/src/mem_pools/index.ts @@ -0,0 +1,4 @@ +export { TxPool } from './tx_pool/tx_pool.js'; +export { AttestationPool } from './attestation_pool/attestation_pool.js'; +export { EpochProofQuotePool } from './epoch_proof_quote_pool/epoch_proof_quote_pool.js'; +export { type MemPools } from './interface.js'; \ No newline at end of file diff --git a/yarn-project/p2p/src/mem_pools/interface.ts b/yarn-project/p2p/src/mem_pools/interface.ts new file mode 100644 index 00000000000..f19b3dd1db6 --- /dev/null +++ b/yarn-project/p2p/src/mem_pools/interface.ts @@ -0,0 +1,12 @@ +import { type TxPool } from "./tx_pool/tx_pool.js"; +import { type AttestationPool } from "./attestation_pool/attestation_pool.js"; +import { type EpochProofQuotePool } from "./epoch_proof_quote_pool/epoch_proof_quote_pool.js"; + +/** + * A interface the combines all mempools + */ +export interface MemPools { + txPool: TxPool; + attestationPool: AttestationPool; + epochProofQuotePool: EpochProofQuotePool; +} diff --git a/yarn-project/p2p/src/tx_pool/aztec_kv_tx_pool.test.ts b/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.test.ts similarity index 100% rename from yarn-project/p2p/src/tx_pool/aztec_kv_tx_pool.test.ts rename to yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.test.ts diff --git a/yarn-project/p2p/src/tx_pool/aztec_kv_tx_pool.ts b/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts similarity index 100% rename from yarn-project/p2p/src/tx_pool/aztec_kv_tx_pool.ts rename to yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts diff --git a/yarn-project/p2p/src/tx_pool/index.ts b/yarn-project/p2p/src/mem_pools/tx_pool/index.ts similarity index 100% rename from yarn-project/p2p/src/tx_pool/index.ts rename to yarn-project/p2p/src/mem_pools/tx_pool/index.ts diff --git a/yarn-project/p2p/src/tx_pool/instrumentation.ts b/yarn-project/p2p/src/mem_pools/tx_pool/instrumentation.ts similarity index 100% rename from yarn-project/p2p/src/tx_pool/instrumentation.ts rename to yarn-project/p2p/src/mem_pools/tx_pool/instrumentation.ts diff --git a/yarn-project/p2p/src/tx_pool/memory_tx_pool.test.ts b/yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.test.ts similarity index 100% rename from yarn-project/p2p/src/tx_pool/memory_tx_pool.test.ts rename to yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.test.ts diff --git a/yarn-project/p2p/src/tx_pool/memory_tx_pool.ts b/yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.ts similarity index 100% rename from yarn-project/p2p/src/tx_pool/memory_tx_pool.ts rename to yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.ts diff --git a/yarn-project/p2p/src/tx_pool/tx_pool.ts b/yarn-project/p2p/src/mem_pools/tx_pool/tx_pool.ts similarity index 100% rename from yarn-project/p2p/src/tx_pool/tx_pool.ts rename to yarn-project/p2p/src/mem_pools/tx_pool/tx_pool.ts diff --git a/yarn-project/p2p/src/tx_pool/tx_pool_test_suite.ts b/yarn-project/p2p/src/mem_pools/tx_pool/tx_pool_test_suite.ts similarity index 100% rename from yarn-project/p2p/src/tx_pool/tx_pool_test_suite.ts rename to yarn-project/p2p/src/mem_pools/tx_pool/tx_pool_test_suite.ts diff --git a/yarn-project/p2p/src/service/libp2p_service.ts b/yarn-project/p2p/src/service/libp2p_service.ts index b432f6eb49e..c391389f37c 100644 --- a/yarn-project/p2p/src/service/libp2p_service.ts +++ b/yarn-project/p2p/src/service/libp2p_service.ts @@ -32,10 +32,10 @@ import { createFromJSON, createSecp256k1PeerId } from '@libp2p/peer-id-factory'; import { tcp } from '@libp2p/tcp'; import { createLibp2p } from 'libp2p'; -import { type AttestationPool } from '../attestation_pool/attestation_pool.js'; +import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; import { type P2PConfig } from '../config.js'; -import { type EpochProofQuotePool } from '../epoch_proof_quote_pool/epoch_proof_quote_pool.js'; -import { type TxPool } from '../tx_pool/index.js'; +import { type EpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.js'; +import { type TxPool } from '../mem_pools/tx_pool/index.js'; import { DataTxValidator, DoubleSpendTxValidator, diff --git a/yarn-project/p2p/src/service/reqresp/p2p_client.integration.test.ts b/yarn-project/p2p/src/service/reqresp/p2p_client.integration.test.ts index b813c799a69..1318230e805 100644 --- a/yarn-project/p2p/src/service/reqresp/p2p_client.integration.test.ts +++ b/yarn-project/p2p/src/service/reqresp/p2p_client.integration.test.ts @@ -13,13 +13,13 @@ import { describe, expect, it, jest } from '@jest/globals'; import { multiaddr } from '@multiformats/multiaddr'; import { generatePrivateKey } from 'viem/accounts'; -import { type AttestationPool } from '../../attestation_pool/attestation_pool.js'; +import { type AttestationPool } from '../../mem_pools/attestation_pool/attestation_pool.js'; import { createP2PClient } from '../../client/index.js'; import { type P2PClient } from '../../client/p2p_client.js'; import { type P2PConfig, getP2PDefaultConfig } from '../../config.js'; -import { type EpochProofQuotePool } from '../../epoch_proof_quote_pool/epoch_proof_quote_pool.js'; +import { type EpochProofQuotePool } from '../../mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.js'; import { AlwaysFalseCircuitVerifier, AlwaysTrueCircuitVerifier } from '../../mocks/index.js'; -import { type TxPool } from '../../tx_pool/index.js'; +import { type TxPool } from '../../mem_pools/tx_pool/index.js'; import { convertToMultiaddr } from '../../util.js'; import { AZTEC_ENR_KEY, AZTEC_NET } from '../discV5_service.js'; import { createLibP2PPeerId } from '../index.js'; From c3fd4273bc53e5d5c1e2596658b44610b373ec5f Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:08:48 +0000 Subject: [PATCH 4/7] chore: initalisation --- yarn-project/p2p/src/client/index.ts | 21 ++++++++++--------- yarn-project/p2p/src/client/p2p_client.ts | 13 +++++++++--- .../p2p/src/service/libp2p_service.ts | 21 +++++++------------ 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/yarn-project/p2p/src/client/index.ts b/yarn-project/p2p/src/client/index.ts index faf2cdd575e..1d860add38f 100644 --- a/yarn-project/p2p/src/client/index.ts +++ b/yarn-project/p2p/src/client/index.ts @@ -16,6 +16,7 @@ import { DummyP2PService } from '../service/dummy_service.js'; import { LibP2PService, createLibP2PPeerId } from '../service/index.js'; import { AztecKVTxPool, type TxPool } from '../mem_pools/tx_pool/index.js'; import { getPublicIp, resolveAddressIfNecessary, splitAddressPort } from '../util.js'; +import { MemPools } from '../mem_pools/interface.js'; export * from './p2p_client.js'; @@ -28,15 +29,19 @@ export const createP2PClient = async ( deps: { txPool?: TxPool; store?: AztecKVStore; - attestationsPool?: AttestationPool; + attestationPool?: AttestationPool; epochProofQuotePool?: EpochProofQuotePool; } = {}, ) => { let config = { ..._config }; const store = deps.store ?? (await createStore('p2p', config, createDebugLogger('aztec:p2p:lmdb'))); - const txPool = deps.txPool ?? new AztecKVTxPool(store, telemetry); - const attestationsPool = deps.attestationsPool ?? new InMemoryAttestationPool(); - const epochProofQuotePool = deps.epochProofQuotePool ?? new MemoryEpochProofQuotePool(); + + const mempools: MemPools = { + txPool: deps.txPool ?? new AztecKVTxPool(store, telemetry), + attestationPool: deps.attestationPool ?? new InMemoryAttestationPool(), + epochProofQuotePool: deps.epochProofQuotePool ?? new MemoryEpochProofQuotePool(), + }; + let p2pService; @@ -51,9 +56,7 @@ export const createP2PClient = async ( config, discoveryService, peerId, - txPool, - attestationsPool, - epochProofQuotePool, + mempools, l2BlockSource, proofVerifier, worldStateSynchronizer, @@ -65,9 +68,7 @@ export const createP2PClient = async ( return new P2PClient( store, l2BlockSource, - txPool, - attestationsPool, - epochProofQuotePool, + mempools, p2pService, config.keepProvenTxsInPoolFor, ); diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index fee91a359c3..25e31f4c336 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -20,6 +20,7 @@ import { type EpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/ep import { TX_REQ_PROTOCOL } from '../service/reqresp/interface.js'; import type { P2PService } from '../service/service.js'; import { type TxPool } from '../mem_pools/tx_pool/index.js'; +import { MemPools } from '../mem_pools/interface.js'; /** * Enum defining the possible states of the p2p client. @@ -190,6 +191,10 @@ export class P2PClient implements P2P { private synchedLatestBlockNumber: AztecSingleton; private synchedProvenBlockNumber: AztecSingleton; + private txPool: TxPool; + private attestationPool: AttestationPool; + private epochProofQuotePool: EpochProofQuotePool; + /** * In-memory P2P client constructor. * @param store - The client's instance of the KV store. @@ -202,9 +207,7 @@ export class P2PClient implements P2P { constructor( store: AztecKVStore, private l2BlockSource: L2BlockSource, - private txPool: TxPool, - private attestationPool: AttestationPool, - private epochProofQuotePool: EpochProofQuotePool, + mempools: MemPools, private p2pService: P2PService, private keepProvenTxsFor: number, private log = createDebugLogger('aztec:p2p'), @@ -219,6 +222,10 @@ export class P2PClient implements P2P { this.synchedLatestBlockNumber = store.openSingleton('p2p_pool_last_l2_block'); this.synchedProvenBlockNumber = store.openSingleton('p2p_pool_last_proven_l2_block'); + + this.txPool = mempools.txPool; + this.attestationPool = mempools.attestationPool; + this.epochProofQuotePool = mempools.epochProofQuotePool; } #assertIsReady() { diff --git a/yarn-project/p2p/src/service/libp2p_service.ts b/yarn-project/p2p/src/service/libp2p_service.ts index c391389f37c..355c9894e26 100644 --- a/yarn-project/p2p/src/service/libp2p_service.ts +++ b/yarn-project/p2p/src/service/libp2p_service.ts @@ -59,6 +59,7 @@ import { } from './reqresp/interface.js'; import { ReqResp } from './reqresp/reqresp.js'; import type { P2PService, PeerDiscoveryService } from './service.js'; +import { MemPools } from '../mem_pools/interface.js'; /** * Create a libp2p peer ID from the private key if provided, otherwise creates a new random ID. @@ -98,9 +99,7 @@ export class LibP2PService implements P2PService { private config: P2PConfig, private node: PubSubLibp2p, private peerDiscoveryService: PeerDiscoveryService, - private txPool: TxPool, - private attestationPool: AttestationPool, - private epochProofQuotePool: EpochProofQuotePool, + private mempools: MemPools, private l2BlockSource: L2BlockSource, private proofVerifier: ClientProtocolCircuitVerifier, private worldStateSynchronizer: WorldStateSynchronizer, @@ -203,9 +202,7 @@ export class LibP2PService implements P2PService { config: P2PConfig, peerDiscoveryService: PeerDiscoveryService, peerId: PeerId, - txPool: TxPool, - attestationPool: AttestationPool, - epochProofQuotePool: EpochProofQuotePool, + mempools: MemPools, l2BlockSource: L2BlockSource, proofVerifier: ClientProtocolCircuitVerifier, worldStateSynchronizer: WorldStateSynchronizer, @@ -278,7 +275,7 @@ export class LibP2PService implements P2PService { */ const txHandler = (msg: Buffer): Promise => { const txHash = TxHash.fromBuffer(msg); - const foundTx = txPool.getTxByHash(txHash); + const foundTx = mempools.txPool.getTxByHash(txHash); const asUint8Array = Uint8Array.from(foundTx ? foundTx.toBuffer() : Buffer.alloc(0)); return Promise.resolve(asUint8Array); }; @@ -293,9 +290,7 @@ export class LibP2PService implements P2PService { config, node, peerDiscoveryService, - txPool, - attestationPool, - epochProofQuotePool, + mempools, l2BlockSource, proofVerifier, worldStateSynchronizer, @@ -392,7 +387,7 @@ export class LibP2PService implements P2PService { */ private async processAttestationFromPeer(attestation: BlockAttestation): Promise { this.logger.verbose(`Received attestation ${attestation.p2pMessageIdentifier()} from external peer.`); - await this.attestationPool.addAttestations([attestation]); + await this.mempools.attestationPool.addAttestations([attestation]); } /**Process block from peer @@ -415,7 +410,7 @@ export class LibP2PService implements P2PService { private processEpochProofQuoteFromPeer(epochProofQuote: EpochProofQuote): void { this.logger.verbose(`Received epoch proof quote ${epochProofQuote.p2pMessageIdentifier()} from external peer.`); - this.epochProofQuotePool.addQuote(epochProofQuote); + this.mempools.epochProofQuotePool.addQuote(epochProofQuote); } /** @@ -434,7 +429,7 @@ export class LibP2PService implements P2PService { const isValidTx = await this.validatePropagatedTx(tx, peerId); if (isValidTx) { - await this.txPool.addTxs([tx]); + await this.mempools.txPool.addTxs([tx]); } } From d23f2f4ca352018a65c9700d03fafd53f0d6ae77 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:09:37 +0000 Subject: [PATCH 5/7] fmt --- yarn-project/p2p/src/client/index.ts | 17 +++++------------ yarn-project/p2p/src/client/p2p_client.test.ts | 2 +- yarn-project/p2p/src/client/p2p_client.ts | 6 +++--- yarn-project/p2p/src/mem_pools/index.ts | 2 +- yarn-project/p2p/src/mem_pools/interface.ts | 12 ++++++------ yarn-project/p2p/src/service/libp2p_service.ts | 5 +---- .../reqresp/p2p_client.integration.test.ts | 4 ++-- 7 files changed, 19 insertions(+), 29 deletions(-) diff --git a/yarn-project/p2p/src/client/index.ts b/yarn-project/p2p/src/client/index.ts index 1d860add38f..5cf0b03f2e9 100644 --- a/yarn-project/p2p/src/client/index.ts +++ b/yarn-project/p2p/src/client/index.ts @@ -5,18 +5,18 @@ import { type DataStoreConfig, createStore } from '@aztec/kv-store/utils'; import { type TelemetryClient } from '@aztec/telemetry-client'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; -import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; -import { InMemoryAttestationPool } from '../mem_pools/attestation_pool/memory_attestation_pool.js'; import { P2PClient } from '../client/p2p_client.js'; import { type P2PConfig } from '../config.js'; +import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; +import { InMemoryAttestationPool } from '../mem_pools/attestation_pool/memory_attestation_pool.js'; import { type EpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.js'; import { MemoryEpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.js'; +import { type MemPools } from '../mem_pools/interface.js'; +import { AztecKVTxPool, type TxPool } from '../mem_pools/tx_pool/index.js'; import { DiscV5Service } from '../service/discV5_service.js'; import { DummyP2PService } from '../service/dummy_service.js'; import { LibP2PService, createLibP2PPeerId } from '../service/index.js'; -import { AztecKVTxPool, type TxPool } from '../mem_pools/tx_pool/index.js'; import { getPublicIp, resolveAddressIfNecessary, splitAddressPort } from '../util.js'; -import { MemPools } from '../mem_pools/interface.js'; export * from './p2p_client.js'; @@ -42,7 +42,6 @@ export const createP2PClient = async ( epochProofQuotePool: deps.epochProofQuotePool ?? new MemoryEpochProofQuotePool(), }; - let p2pService; if (_config.p2pEnabled) { @@ -65,13 +64,7 @@ export const createP2PClient = async ( } else { p2pService = new DummyP2PService(); } - return new P2PClient( - store, - l2BlockSource, - mempools, - p2pService, - config.keepProvenTxsInPoolFor, - ); + return new P2PClient(store, l2BlockSource, mempools, p2pService, config.keepProvenTxsInPoolFor); }; async function configureP2PClientAddresses(_config: P2PConfig & DataStoreConfig): Promise { diff --git a/yarn-project/p2p/src/client/p2p_client.test.ts b/yarn-project/p2p/src/client/p2p_client.test.ts index 29e819ab774..33fdcfab15e 100644 --- a/yarn-project/p2p/src/client/p2p_client.test.ts +++ b/yarn-project/p2p/src/client/p2p_client.test.ts @@ -6,8 +6,8 @@ import { openTmpStore } from '@aztec/kv-store/utils'; import { expect, jest } from '@jest/globals'; -import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; import { type EpochProofQuotePool, type P2PService } from '../index.js'; +import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; import { type TxPool } from '../mem_pools/tx_pool/index.js'; import { P2PClient } from './p2p_client.js'; diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index 25e31f4c336..4c6c26de70f 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -14,13 +14,13 @@ import { type AztecKVStore, type AztecSingleton } from '@aztec/kv-store'; import { type ENR } from '@chainsafe/enr'; -import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; import { getP2PConfigEnvVars } from '../config.js'; +import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; import { type EpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.js'; +import { type MemPools } from '../mem_pools/interface.js'; +import { type TxPool } from '../mem_pools/tx_pool/index.js'; import { TX_REQ_PROTOCOL } from '../service/reqresp/interface.js'; import type { P2PService } from '../service/service.js'; -import { type TxPool } from '../mem_pools/tx_pool/index.js'; -import { MemPools } from '../mem_pools/interface.js'; /** * Enum defining the possible states of the p2p client. diff --git a/yarn-project/p2p/src/mem_pools/index.ts b/yarn-project/p2p/src/mem_pools/index.ts index 9b229e58787..683ac12e459 100644 --- a/yarn-project/p2p/src/mem_pools/index.ts +++ b/yarn-project/p2p/src/mem_pools/index.ts @@ -1,4 +1,4 @@ export { TxPool } from './tx_pool/tx_pool.js'; export { AttestationPool } from './attestation_pool/attestation_pool.js'; export { EpochProofQuotePool } from './epoch_proof_quote_pool/epoch_proof_quote_pool.js'; -export { type MemPools } from './interface.js'; \ No newline at end of file +export { type MemPools } from './interface.js'; diff --git a/yarn-project/p2p/src/mem_pools/interface.ts b/yarn-project/p2p/src/mem_pools/interface.ts index f19b3dd1db6..faf38e0638c 100644 --- a/yarn-project/p2p/src/mem_pools/interface.ts +++ b/yarn-project/p2p/src/mem_pools/interface.ts @@ -1,12 +1,12 @@ -import { type TxPool } from "./tx_pool/tx_pool.js"; -import { type AttestationPool } from "./attestation_pool/attestation_pool.js"; -import { type EpochProofQuotePool } from "./epoch_proof_quote_pool/epoch_proof_quote_pool.js"; +import { type AttestationPool } from './attestation_pool/attestation_pool.js'; +import { type EpochProofQuotePool } from './epoch_proof_quote_pool/epoch_proof_quote_pool.js'; +import { type TxPool } from './tx_pool/tx_pool.js'; /** * A interface the combines all mempools */ export interface MemPools { - txPool: TxPool; - attestationPool: AttestationPool; - epochProofQuotePool: EpochProofQuotePool; + txPool: TxPool; + attestationPool: AttestationPool; + epochProofQuotePool: EpochProofQuotePool; } diff --git a/yarn-project/p2p/src/service/libp2p_service.ts b/yarn-project/p2p/src/service/libp2p_service.ts index 355c9894e26..4725e3d2596 100644 --- a/yarn-project/p2p/src/service/libp2p_service.ts +++ b/yarn-project/p2p/src/service/libp2p_service.ts @@ -32,10 +32,8 @@ import { createFromJSON, createSecp256k1PeerId } from '@libp2p/peer-id-factory'; import { tcp } from '@libp2p/tcp'; import { createLibp2p } from 'libp2p'; -import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; import { type P2PConfig } from '../config.js'; -import { type EpochProofQuotePool } from '../mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.js'; -import { type TxPool } from '../mem_pools/tx_pool/index.js'; +import { type MemPools } from '../mem_pools/interface.js'; import { DataTxValidator, DoubleSpendTxValidator, @@ -59,7 +57,6 @@ import { } from './reqresp/interface.js'; import { ReqResp } from './reqresp/reqresp.js'; import type { P2PService, PeerDiscoveryService } from './service.js'; -import { MemPools } from '../mem_pools/interface.js'; /** * Create a libp2p peer ID from the private key if provided, otherwise creates a new random ID. diff --git a/yarn-project/p2p/src/service/reqresp/p2p_client.integration.test.ts b/yarn-project/p2p/src/service/reqresp/p2p_client.integration.test.ts index 1318230e805..eccf288e134 100644 --- a/yarn-project/p2p/src/service/reqresp/p2p_client.integration.test.ts +++ b/yarn-project/p2p/src/service/reqresp/p2p_client.integration.test.ts @@ -13,13 +13,13 @@ import { describe, expect, it, jest } from '@jest/globals'; import { multiaddr } from '@multiformats/multiaddr'; import { generatePrivateKey } from 'viem/accounts'; -import { type AttestationPool } from '../../mem_pools/attestation_pool/attestation_pool.js'; import { createP2PClient } from '../../client/index.js'; import { type P2PClient } from '../../client/p2p_client.js'; import { type P2PConfig, getP2PDefaultConfig } from '../../config.js'; +import { type AttestationPool } from '../../mem_pools/attestation_pool/attestation_pool.js'; import { type EpochProofQuotePool } from '../../mem_pools/epoch_proof_quote_pool/epoch_proof_quote_pool.js'; -import { AlwaysFalseCircuitVerifier, AlwaysTrueCircuitVerifier } from '../../mocks/index.js'; import { type TxPool } from '../../mem_pools/tx_pool/index.js'; +import { AlwaysFalseCircuitVerifier, AlwaysTrueCircuitVerifier } from '../../mocks/index.js'; import { convertToMultiaddr } from '../../util.js'; import { AZTEC_ENR_KEY, AZTEC_NET } from '../discV5_service.js'; import { createLibP2PPeerId } from '../index.js'; From 8dca755aef553ef79d875c279fabb7a60abee7a8 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 8 Oct 2024 22:18:49 +0000 Subject: [PATCH 6/7] fix: test --- yarn-project/p2p/src/client/p2p_client.test.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/yarn-project/p2p/src/client/p2p_client.test.ts b/yarn-project/p2p/src/client/p2p_client.test.ts index 33fdcfab15e..44a51a6c661 100644 --- a/yarn-project/p2p/src/client/p2p_client.test.ts +++ b/yarn-project/p2p/src/client/p2p_client.test.ts @@ -10,6 +10,7 @@ import { type EpochProofQuotePool, type P2PService } from '../index.js'; import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; import { type TxPool } from '../mem_pools/tx_pool/index.js'; import { P2PClient } from './p2p_client.js'; +import { MemPools } from '../mem_pools/interface.js'; /** * Mockify helper for testing purposes. @@ -22,6 +23,7 @@ describe('In-Memory P2P Client', () => { let txPool: Mockify; let attestationPool: Mockify; let epochProofQuotePool: Mockify; + let mempools: MemPools; let blockSource: MockBlockSource; let p2pService: Mockify; let kvStore: AztecKVStore; @@ -64,8 +66,14 @@ describe('In-Memory P2P Client', () => { blockSource = new MockBlockSource(); + mempools = { + txPool, + attestationPool, + epochProofQuotePool, + }; + kvStore = openTmpStore(); - client = new P2PClient(kvStore, blockSource, txPool, attestationPool, epochProofQuotePool, p2pService, 0); + client = new P2PClient(kvStore, blockSource, mempools, p2pService, 0); }); const advanceToProvenBlock = async (getProvenBlockNumber: number, provenEpochNumber = getProvenBlockNumber) => { @@ -135,7 +143,7 @@ describe('In-Memory P2P Client', () => { await client.start(); await client.stop(); - const client2 = new P2PClient(kvStore, blockSource, txPool, attestationPool, epochProofQuotePool, p2pService, 0); + const client2 = new P2PClient(kvStore, blockSource, mempools, p2pService, 0); expect(client2.getSyncedLatestBlockNum()).toEqual(client.getSyncedLatestBlockNum()); }); @@ -150,7 +158,7 @@ describe('In-Memory P2P Client', () => { }); it('deletes txs after waiting the set number of blocks', async () => { - client = new P2PClient(kvStore, blockSource, txPool, attestationPool, epochProofQuotePool, p2pService, 10); + client = new P2PClient(kvStore, blockSource, mempools, p2pService, 10); blockSource.setProvenBlockNumber(0); await client.start(); expect(txPool.deleteTxs).not.toHaveBeenCalled(); @@ -167,7 +175,7 @@ describe('In-Memory P2P Client', () => { }); it('stores and returns epoch proof quotes', async () => { - client = new P2PClient(kvStore, blockSource, txPool, attestationPool, epochProofQuotePool, p2pService, 0); + client = new P2PClient(kvStore, blockSource, mempools, p2pService, 0); blockSource.setProvenEpochNumber(2); await client.start(); @@ -198,7 +206,7 @@ describe('In-Memory P2P Client', () => { }); it('deletes expired proof quotes', async () => { - client = new P2PClient(kvStore, blockSource, txPool, attestationPool, epochProofQuotePool, p2pService, 0); + client = new P2PClient(kvStore, blockSource, mempools, p2pService, 0); blockSource.setProvenEpochNumber(1); blockSource.setProvenBlockNumber(1); From 13a172825a70f04dca5c138a25b6911ba64a89b1 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 8 Oct 2024 22:18:54 +0000 Subject: [PATCH 7/7] fmt --- yarn-project/p2p/src/client/p2p_client.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/p2p/src/client/p2p_client.test.ts b/yarn-project/p2p/src/client/p2p_client.test.ts index 44a51a6c661..cb2e6b27128 100644 --- a/yarn-project/p2p/src/client/p2p_client.test.ts +++ b/yarn-project/p2p/src/client/p2p_client.test.ts @@ -8,9 +8,9 @@ import { expect, jest } from '@jest/globals'; import { type EpochProofQuotePool, type P2PService } from '../index.js'; import { type AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js'; +import { type MemPools } from '../mem_pools/interface.js'; import { type TxPool } from '../mem_pools/tx_pool/index.js'; import { P2PClient } from './p2p_client.js'; -import { MemPools } from '../mem_pools/interface.js'; /** * Mockify helper for testing purposes.