Skip to content

Commit

Permalink
fix: post merge epoch cache initalisation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Dec 17, 2024
1 parent 546d6fa commit 7737ab7
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 109 deletions.
4 changes: 2 additions & 2 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
type PublicDataTreeLeafPreimage,
} from '@aztec/circuits.js';
import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
import { createEpochCache } from '@aztec/epoch-cache';
import { EpochCache } from '@aztec/epoch-cache';
import { type L1ContractAddresses, createEthereumChain } from '@aztec/ethereum';
import { type ContractArtifact } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
Expand Down Expand Up @@ -168,7 +168,7 @@ export class AztecNodeService implements AztecNode, Traceable {
log.warn(`Aztec node is accepting fake proofs`);
}

const epochCache = await createEpochCache(config, config.l1Contracts.rollupAddress);
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, { dateProvider });

// create the tx pool and the p2p client, which will need the l2 block source
const p2pClient = await createP2PClient(
Expand Down
8 changes: 0 additions & 8 deletions yarn-project/epoch-cache/src/factory.ts

This file was deleted.

1 change: 0 additions & 1 deletion yarn-project/epoch-cache/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './epoch_cache.js';
export * from './config.js';
export * from './factory.js';
97 changes: 97 additions & 0 deletions yarn-project/p2p/src/client/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {
type ClientProtocolCircuitVerifier,
type L2BlockSource,
P2PClientType,
type WorldStateSynchronizer,
} from '@aztec/circuit-types';
import { type EpochCache } from '@aztec/epoch-cache';
import { createLogger } from '@aztec/foundation/log';
import { type AztecKVStore } from '@aztec/kv-store';
import { type DataStoreConfig } from '@aztec/kv-store/config';
import { createStore } from '@aztec/kv-store/lmdb';
import { type TelemetryClient } from '@aztec/telemetry-client';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';

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 '../services/discv5/discV5_service.js';
import { DummyP2PService } from '../services/dummy_service.js';
import { LibP2PService } from '../services/index.js';
import { configureP2PClientAddresses, createLibP2PPeerIdFromPrivateKey, getPeerIdPrivateKey } from '../util.js';

type P2PClientDeps<T extends P2PClientType> = {
txPool?: TxPool;
store?: AztecKVStore;
attestationPool?: T extends P2PClientType.Full ? AttestationPool : undefined;
epochProofQuotePool?: EpochProofQuotePool;
};

export const createP2PClient = async <T extends P2PClientType>(
clientType: T,
_config: P2PConfig & DataStoreConfig,
l2BlockSource: L2BlockSource,
proofVerifier: ClientProtocolCircuitVerifier,
worldStateSynchronizer: WorldStateSynchronizer,
epochCache: EpochCache,
telemetry: TelemetryClient = new NoopTelemetryClient(),
deps: P2PClientDeps<T> = {},
) => {
let config = { ..._config };
const logger = createLogger('p2p');
const store = deps.store ?? (await createStore('p2p', config, createLogger('p2p:lmdb')));

const mempools: MemPools<T> = {
txPool: deps.txPool ?? new AztecKVTxPool(store, telemetry),
epochProofQuotePool: deps.epochProofQuotePool ?? new MemoryEpochProofQuotePool(telemetry),
attestationPool:
clientType === P2PClientType.Full
? ((deps.attestationPool ?? new InMemoryAttestationPool(telemetry)) as T extends P2PClientType.Full
? AttestationPool
: undefined)
: undefined,
};

let p2pService;

if (_config.p2pEnabled) {
logger.verbose('P2P is enabled. Using LibP2P service.');
config = await configureP2PClientAddresses(_config);

// Create peer discovery service
const peerIdPrivateKey = await getPeerIdPrivateKey(config, store);
const peerId = await createLibP2PPeerIdFromPrivateKey(peerIdPrivateKey);
const discoveryService = new DiscV5Service(peerId, config, telemetry);

p2pService = await LibP2PService.new<T>(
clientType,
config,
discoveryService,
peerId,
mempools,
l2BlockSource,
epochCache,
proofVerifier,
worldStateSynchronizer,
store,
telemetry,
);
} else {
logger.verbose('P2P is disabled. Using dummy P2P service');
p2pService = new DummyP2PService();
}
return new P2PClient(
clientType,
store,
l2BlockSource,
mempools,
p2pService,
config.keepProvenTxsInPoolFor,
telemetry,
);
};
99 changes: 1 addition & 98 deletions yarn-project/p2p/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,99 +1,2 @@
import {
type ClientProtocolCircuitVerifier,
type L2BlockSource,
P2PClientType,
type WorldStateSynchronizer,
} from '@aztec/circuit-types';
import { type EpochCache } from '@aztec/epoch-cache';
import { createLogger } from '@aztec/foundation/log';
import { type AztecKVStore } from '@aztec/kv-store';
import { type DataStoreConfig } from '@aztec/kv-store/config';
import { createStore } from '@aztec/kv-store/lmdb';
import { type TelemetryClient } from '@aztec/telemetry-client';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';

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 '../services/discv5/discV5_service.js';
import { DummyP2PService } from '../services/dummy_service.js';
import { LibP2PService } from '../services/index.js';
import { configureP2PClientAddresses, createLibP2PPeerIdFromPrivateKey, getPeerIdPrivateKey } from '../util.js';

export * from './p2p_client.js';

type P2PClientDeps<T extends P2PClientType> = {
txPool?: TxPool;
store?: AztecKVStore;
attestationPool?: T extends P2PClientType.Full ? AttestationPool : undefined;
epochProofQuotePool?: EpochProofQuotePool;
};

export const createP2PClient = async <T extends P2PClientType>(
clientType: T,
_config: P2PConfig & DataStoreConfig,
l2BlockSource: L2BlockSource,
proofVerifier: ClientProtocolCircuitVerifier,
worldStateSynchronizer: WorldStateSynchronizer,
epochCache: EpochCache,
telemetry: TelemetryClient = new NoopTelemetryClient(),
deps: P2PClientDeps<T> = {},
) => {
let config = { ..._config };
const logger = createLogger('p2p');
const store = deps.store ?? (await createStore('p2p', config, createLogger('p2p:lmdb')));

const mempools: MemPools<T> = {
txPool: deps.txPool ?? new AztecKVTxPool(store, telemetry),
epochProofQuotePool: deps.epochProofQuotePool ?? new MemoryEpochProofQuotePool(telemetry),
attestationPool:
clientType === P2PClientType.Full
? ((deps.attestationPool ?? new InMemoryAttestationPool(telemetry)) as T extends P2PClientType.Full
? AttestationPool
: undefined)
: undefined,
};

let p2pService;

if (_config.p2pEnabled) {
logger.verbose('P2P is enabled. Using LibP2P service.');
config = await configureP2PClientAddresses(_config);

// Create peer discovery service
const peerIdPrivateKey = await getPeerIdPrivateKey(config, store);
const peerId = await createLibP2PPeerIdFromPrivateKey(peerIdPrivateKey);
const discoveryService = new DiscV5Service(peerId, config, telemetry);

p2pService = await LibP2PService.new<T>(
clientType,
config,
discoveryService,
peerId,
mempools,
l2BlockSource,
epochCache,
proofVerifier,
worldStateSynchronizer,
store,
telemetry,
);
} else {
logger.verbose('P2P is disabled. Using dummy P2P service');
p2pService = new DummyP2PService();
}
return new P2PClient(
clientType,
store,
l2BlockSource,
mempools,
p2pService,
config.keepProvenTxsInPoolFor,
telemetry,
);
};
export * from './factory.js';

0 comments on commit 7737ab7

Please sign in to comment.