-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: post merge epoch cache initalisation issue
- Loading branch information
Showing
5 changed files
with
100 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |