-
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.
feat(p2p): remaining p2p topic validators (#10734)
- Loading branch information
Showing
49 changed files
with
706 additions
and
200 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 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 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 |
---|---|---|
|
@@ -18,6 +18,9 @@ | |
{ | ||
"path": "../circuits.js" | ||
}, | ||
{ | ||
"path": "../epoch-cache" | ||
}, | ||
{ | ||
"path": "../ethereum" | ||
}, | ||
|
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 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,10 @@ | ||
import { type PeerErrorSeverity } from './peer_error.js'; | ||
|
||
/** | ||
* P2PValidator | ||
* | ||
* A validator for P2P messages, which returns a severity of error to be applied to the peer | ||
*/ | ||
export interface P2PValidator<T> { | ||
validate(message: T): Promise<PeerErrorSeverity | undefined>; | ||
} |
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,17 @@ | ||
export enum PeerErrorSeverity { | ||
/** | ||
* Not malicious action, but it must not be tolerated | ||
* ~2 occurrences will get the peer banned | ||
*/ | ||
LowToleranceError = 'LowToleranceError', | ||
/** | ||
* Negative action that can be tolerated only sometimes | ||
* ~10 occurrences will get the peer banned | ||
*/ | ||
MidToleranceError = 'MidToleranceError', | ||
/** | ||
* Some error that can be tolerated multiple times | ||
* ~50 occurrences will get the peer banned | ||
*/ | ||
HighToleranceError = 'HighToleranceError', | ||
} |
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 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,96 +1,2 @@ | ||
import { | ||
type ClientProtocolCircuitVerifier, | ||
type L2BlockSource, | ||
P2PClientType, | ||
type WorldStateSynchronizer, | ||
} from '@aztec/circuit-types'; | ||
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 { KvAttestationPool } from '../mem_pools/attestation_pool/kv_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, | ||
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 KvAttestationPool(store, 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, | ||
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'; |
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 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
Oops, something went wrong.