@aztec/p2p 4.1.1 → 4.1.2-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/factory.d.ts +1 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +5 -4
- package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +39 -29
- package/dest/services/tx_collection/tx_source.d.ts +6 -5
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +9 -7
- package/package.json +14 -14
- package/src/client/factory.ts +10 -3
- package/src/services/tx_collection/file_store_tx_source.ts +43 -31
- package/src/services/tx_collection/tx_source.ts +8 -7
package/dest/client/factory.d.ts
CHANGED
|
@@ -28,4 +28,4 @@ export declare const P2P_ARCHIVE_STORE_NAME = "p2p-archive";
|
|
|
28
28
|
export declare const P2P_PEER_STORE_NAME = "p2p-peers";
|
|
29
29
|
export declare const P2P_ATTESTATION_STORE_NAME = "p2p-attestation";
|
|
30
30
|
export declare function createP2PClient(inputConfig: P2PConfig & DataStoreConfig & ChainConfig, archiver: L2BlockSource & ContractDataSource, proofVerifier: ClientProtocolCircuitVerifier, worldStateSynchronizer: WorldStateSynchronizer, epochCache: EpochCacheInterface, packageVersion: string, dateProvider?: DateProvider, telemetry?: TelemetryClient, deps?: P2PClientDeps): Promise<P2PClient>;
|
|
31
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
31
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NsaWVudC9mYWN0b3J5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixF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,CACnC,WAAW,EAAE,SAAS,GAAG,eAAe,GAAG,WAAW,EACtD,QAAQ,EAAE,aAAa,GAAG,kBAAkB,EAC5C,aAAa,EAAE,6BAA6B,EAC5C,sBAAsB,EAAE,sBAAsB,EAC9C,UAAU,EAAE,mBAAmB,EAC/B,cAAc,EAAE,MAAM,EACtB,YAAY,GAAE,YAAiC,EAC/C,SAAS,GAAE,eAAsC,EACjD,IAAI,GAAE,aAAkB,sBA2IzB"}
|
package/dest/client/factory.js
CHANGED
|
@@ -6,7 +6,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
6
6
|
import { P2PClient } from '../client/p2p_client.js';
|
|
7
7
|
import { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
|
|
8
8
|
import { AztecKVTxPoolV2 } from '../mem_pools/tx_pool_v2/tx_pool_v2.js';
|
|
9
|
-
import { createTxValidatorForTransactionsEnteringPendingTxPool } from '../msg_validators/index.js';
|
|
9
|
+
import { createTxValidatorForReqResponseReceivedTxs, createTxValidatorForTransactionsEnteringPendingTxPool } from '../msg_validators/index.js';
|
|
10
10
|
import { DummyP2PService } from '../services/dummy_service.js';
|
|
11
11
|
import { LibP2PService } from '../services/index.js';
|
|
12
12
|
import { createFileStoreTxSources } from '../services/tx_collection/file_store_tx_source.js';
|
|
@@ -60,9 +60,10 @@ export async function createP2PClient(inputConfig, archiver, proofVerifier, worl
|
|
|
60
60
|
attestationPool: deps.attestationPool ?? new AttestationPool(attestationStore, telemetry)
|
|
61
61
|
};
|
|
62
62
|
const p2pService = await createP2PService(config, archiver, proofVerifier, worldStateSynchronizer, epochCache, store, peerStore, mempools, deps.p2pServiceFactory, packageVersion, logger.createChild('libp2p_service'), telemetry);
|
|
63
|
+
const txValidatorForTxCollection = createTxValidatorForReqResponseReceivedTxs(proofVerifier, config);
|
|
63
64
|
const nodeSources = [
|
|
64
|
-
...createNodeRpcTxSources(config.txCollectionNodeRpcUrls, config),
|
|
65
|
-
...(deps.rpcTxProviders ?? []).map((node, i)=>new NodeRpcTxSource(node, `node-rpc-provider-${i}`)),
|
|
65
|
+
...createNodeRpcTxSources(config.txCollectionNodeRpcUrls, txValidatorForTxCollection, config),
|
|
66
|
+
...(deps.rpcTxProviders ?? []).map((node, i)=>new NodeRpcTxSource(node, txValidatorForTxCollection, `node-rpc-provider-${i}`)),
|
|
66
67
|
...deps.txCollectionNodeSources ?? []
|
|
67
68
|
];
|
|
68
69
|
if (nodeSources.length > 0) {
|
|
@@ -70,7 +71,7 @@ export async function createP2PClient(inputConfig, archiver, proofVerifier, worl
|
|
|
70
71
|
nodes: nodeSources.map((n)=>n.getInfo())
|
|
71
72
|
});
|
|
72
73
|
}
|
|
73
|
-
const fileStoreSources = await createFileStoreTxSources(config.txCollectionFileStoreUrls, txFileStoreBasePath, logger.createChild('file-store-tx-source'), telemetry);
|
|
74
|
+
const fileStoreSources = await createFileStoreTxSources(config.txCollectionFileStoreUrls, txFileStoreBasePath, txValidatorForTxCollection, logger.createChild('file-store-tx-source'), telemetry);
|
|
74
75
|
if (fileStoreSources.length > 0) {
|
|
75
76
|
logger.info(`Using ${fileStoreSources.length} file store sources for tx collection.`, {
|
|
76
77
|
stores: fileStoreSources.map((s)=>s.getInfo())
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Logger } from '@aztec/foundation/log';
|
|
2
|
-
import { type TxHash } from '@aztec/stdlib/tx';
|
|
2
|
+
import { type TxHash, type TxValidator } from '@aztec/stdlib/tx';
|
|
3
3
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
4
4
|
import type { TxSource, TxSourceCollectionResult } from './tx_source.js';
|
|
5
5
|
/** TxSource implementation that downloads txs from a file store. */
|
|
@@ -7,6 +7,7 @@ export declare class FileStoreTxSource implements TxSource {
|
|
|
7
7
|
private readonly fileStore;
|
|
8
8
|
private readonly baseUrl;
|
|
9
9
|
private readonly basePath;
|
|
10
|
+
private readonly txValidator;
|
|
10
11
|
private readonly log;
|
|
11
12
|
private downloadsSuccess;
|
|
12
13
|
private downloadsFailed;
|
|
@@ -21,7 +22,7 @@ export declare class FileStoreTxSource implements TxSource {
|
|
|
21
22
|
* @param telemetry - Optional telemetry client.
|
|
22
23
|
* @returns The FileStoreTxSource instance, or undefined if creation fails.
|
|
23
24
|
*/
|
|
24
|
-
static create(url: string, basePath: string, log?: Logger, telemetry?: TelemetryClient): Promise<FileStoreTxSource | undefined>;
|
|
25
|
+
static create(url: string, basePath: string, txValidator: TxValidator, log?: Logger, telemetry?: TelemetryClient): Promise<FileStoreTxSource | undefined>;
|
|
25
26
|
getInfo(): string;
|
|
26
27
|
getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult>;
|
|
27
28
|
}
|
|
@@ -33,5 +34,5 @@ export declare class FileStoreTxSource implements TxSource {
|
|
|
33
34
|
* @param telemetry - Optional telemetry client.
|
|
34
35
|
* @returns Array of successfully created FileStoreTxSource instances.
|
|
35
36
|
*/
|
|
36
|
-
export declare function createFileStoreTxSources(urls: string[], basePath: string, log?: Logger, telemetry?: TelemetryClient): Promise<FileStoreTxSource[]>;
|
|
37
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
37
|
+
export declare function createFileStoreTxSources(urls: string[], basePath: string, txValidator: TxValidator, log?: Logger, telemetry?: TelemetryClient): Promise<FileStoreTxSource[]>;
|
|
38
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmlsZV9zdG9yZV90eF9zb3VyY2UuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zZXJ2aWNlcy90eF9jb2xsZWN0aW9uL2ZpbGVfc3RvcmVfdHhfc291cmNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUdsRSxPQUFPLEVBQU0sS0FBSyxNQUFNLEVBQU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kFBc0Isd0JBQXdCLENBQzVDLElBQUksRUFBRSxNQUFNLEVBQUUsRUFDZCxRQUFRLEVBQUUsTUFBTSxFQUNoQixXQUFXLEVBQUUsV0FBVyxFQUN4QixHQUFHLEdBQUUsTUFBaUQsRUFDdEQsU0FBUyxHQUFFLGVBQXNDLEdBQ2hELE9BQU8sQ0FBQyxpQkFBaUIsRUFBRSxDQUFDLENBSzlCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file_store_tx_source.d.ts","sourceRoot":"","sources":["../../../src/services/tx_collection/file_store_tx_source.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file_store_tx_source.d.ts","sourceRoot":"","sources":["../../../src/services/tx_collection/file_store_tx_source.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAAM,KAAK,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAGL,KAAK,eAAe,EAGrB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,QAAQ,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAEzE,oEAAoE;AACpE,qBAAa,iBAAkB,YAAW,QAAQ;IAO9C,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG;IAVtB,OAAO,CAAC,gBAAgB,CAAgB;IACxC,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,YAAY,CAAY;IAEhC,OAAO,eAaN;IAED;;;;;;;OAOG;IACH,OAAoB,MAAM,CACxB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,EACxB,GAAG,GAAE,MAAiD,EACtD,SAAS,GAAE,eAAsC,GAChD,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAYxC;IAEM,OAAO,IAAI,MAAM,CAEvB;IAEY,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAqC/E;CACF;AAED;;;;;;;GAOG;AACH,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,MAAM,EAAE,EACd,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,EACxB,GAAG,GAAE,MAAiD,EACtD,SAAS,GAAE,eAAsC,GAChD,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAK9B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { partitionAsync } from '@aztec/foundation/collection';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
3
4
|
import { createReadOnlyFileStore } from '@aztec/stdlib/file-store';
|
|
@@ -7,15 +8,17 @@ import { Metrics, getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
7
8
|
fileStore;
|
|
8
9
|
baseUrl;
|
|
9
10
|
basePath;
|
|
11
|
+
txValidator;
|
|
10
12
|
log;
|
|
11
13
|
downloadsSuccess;
|
|
12
14
|
downloadsFailed;
|
|
13
15
|
downloadDuration;
|
|
14
16
|
downloadSize;
|
|
15
|
-
constructor(fileStore, baseUrl, basePath, log, telemetry){
|
|
17
|
+
constructor(fileStore, baseUrl, basePath, txValidator, log, telemetry){
|
|
16
18
|
this.fileStore = fileStore;
|
|
17
19
|
this.baseUrl = baseUrl;
|
|
18
20
|
this.basePath = basePath;
|
|
21
|
+
this.txValidator = txValidator;
|
|
19
22
|
this.log = log;
|
|
20
23
|
const meter = telemetry.getMeter('file-store-tx-source');
|
|
21
24
|
this.downloadsSuccess = meter.createUpDownCounter(Metrics.TX_FILE_STORE_DOWNLOADS_SUCCESS);
|
|
@@ -30,14 +33,14 @@ import { Metrics, getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
30
33
|
* @param log - Optional logger.
|
|
31
34
|
* @param telemetry - Optional telemetry client.
|
|
32
35
|
* @returns The FileStoreTxSource instance, or undefined if creation fails.
|
|
33
|
-
*/ static async create(url, basePath, log = createLogger('p2p:file_store_tx_source'), telemetry = getTelemetryClient()) {
|
|
36
|
+
*/ static async create(url, basePath, txValidator, log = createLogger('p2p:file_store_tx_source'), telemetry = getTelemetryClient()) {
|
|
34
37
|
try {
|
|
35
38
|
const fileStore = await createReadOnlyFileStore(url, log);
|
|
36
39
|
if (!fileStore) {
|
|
37
40
|
log.warn(`Failed to create file store for URL: ${url}`);
|
|
38
41
|
return undefined;
|
|
39
42
|
}
|
|
40
|
-
return new FileStoreTxSource(fileStore, url, basePath, log, telemetry);
|
|
43
|
+
return new FileStoreTxSource(fileStore, url, basePath, txValidator, log, telemetry);
|
|
41
44
|
} catch (err) {
|
|
42
45
|
log.warn(`Error creating file store for URL: ${url}`, {
|
|
43
46
|
error: err
|
|
@@ -49,31 +52,38 @@ import { Metrics, getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
49
52
|
return `file-store:${this.baseUrl}`;
|
|
50
53
|
}
|
|
51
54
|
async getTxsByHash(txHashes) {
|
|
52
|
-
const
|
|
55
|
+
const results = await Promise.all(txHashes.map(async (txHash)=>{
|
|
56
|
+
const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
|
|
57
|
+
const timer = new Timer();
|
|
58
|
+
try {
|
|
59
|
+
const buffer = await this.fileStore.read(path);
|
|
60
|
+
const tx = Tx.fromBuffer(buffer);
|
|
61
|
+
return {
|
|
62
|
+
tx,
|
|
63
|
+
downloadDuration: timer.ms(),
|
|
64
|
+
downloadSize: buffer.length
|
|
65
|
+
};
|
|
66
|
+
} catch {
|
|
67
|
+
this.downloadsFailed.add(1);
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
const txs = results.filter((tx)=>tx !== undefined);
|
|
72
|
+
const [validTxs, invalidTxs] = await partitionAsync(txs, async ({ tx, downloadDuration, downloadSize })=>{
|
|
73
|
+
const valid = await this.txValidator.validateTx(tx);
|
|
74
|
+
if (valid.result === 'valid') {
|
|
75
|
+
this.downloadsSuccess.add(1);
|
|
76
|
+
this.downloadDuration.record(Math.ceil(downloadDuration));
|
|
77
|
+
this.downloadSize.record(downloadSize);
|
|
78
|
+
return true;
|
|
79
|
+
} else {
|
|
80
|
+
this.downloadsFailed.add(1);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
53
84
|
return {
|
|
54
|
-
validTxs:
|
|
55
|
-
|
|
56
|
-
const timer = new Timer();
|
|
57
|
-
try {
|
|
58
|
-
const buffer = await this.fileStore.read(path);
|
|
59
|
-
const tx = Tx.fromBuffer(buffer);
|
|
60
|
-
if (await tx.validateTxHash() && txHash.equals(tx.txHash)) {
|
|
61
|
-
this.downloadsSuccess.add(1);
|
|
62
|
-
this.downloadDuration.record(Math.ceil(timer.ms()));
|
|
63
|
-
this.downloadSize.record(buffer.length);
|
|
64
|
-
return tx;
|
|
65
|
-
} else {
|
|
66
|
-
invalidTxHashes.push(tx.txHash.toString());
|
|
67
|
-
this.downloadsFailed.add(1);
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
} catch {
|
|
71
|
-
// Tx not found or error reading - return undefined
|
|
72
|
-
this.downloadsFailed.add(1);
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
}))).filter((tx)=>tx !== undefined),
|
|
76
|
-
invalidTxHashes: invalidTxHashes
|
|
85
|
+
validTxs: validTxs.map(({ tx })=>tx),
|
|
86
|
+
invalidTxHashes: invalidTxs.map(({ tx })=>tx.getTxHash().toString())
|
|
77
87
|
};
|
|
78
88
|
}
|
|
79
89
|
}
|
|
@@ -84,7 +94,7 @@ import { Metrics, getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
84
94
|
* @param log - Optional logger.
|
|
85
95
|
* @param telemetry - Optional telemetry client.
|
|
86
96
|
* @returns Array of successfully created FileStoreTxSource instances.
|
|
87
|
-
*/ export async function createFileStoreTxSources(urls, basePath, log = createLogger('p2p:file_store_tx_source'), telemetry = getTelemetryClient()) {
|
|
88
|
-
const sources = await Promise.all(urls.map((url)=>FileStoreTxSource.create(url, basePath, log, telemetry)));
|
|
97
|
+
*/ export async function createFileStoreTxSources(urls, basePath, txValidator, log = createLogger('p2p:file_store_tx_source'), telemetry = getTelemetryClient()) {
|
|
98
|
+
const sources = await Promise.all(urls.map((url)=>FileStoreTxSource.create(url, basePath, txValidator, log, telemetry)));
|
|
89
99
|
return sources.filter((s)=>s !== undefined);
|
|
90
100
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
2
2
|
import { type AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
3
|
-
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
3
|
+
import type { Tx, TxHash, TxValidator } from '@aztec/stdlib/tx';
|
|
4
4
|
import { type ComponentsVersions } from '@aztec/stdlib/versioning';
|
|
5
5
|
export type TxSourceCollectionResult = {
|
|
6
6
|
validTxs: Tx[];
|
|
@@ -12,12 +12,13 @@ export interface TxSource {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class NodeRpcTxSource implements TxSource {
|
|
14
14
|
private readonly client;
|
|
15
|
+
private readonly txValidator;
|
|
15
16
|
private readonly info;
|
|
16
|
-
constructor(client: Pick<AztecNode, 'getTxsByHash'>, info: string);
|
|
17
|
-
static fromUrl(nodeUrl: string, versions: ComponentsVersions): NodeRpcTxSource;
|
|
17
|
+
constructor(client: Pick<AztecNode, 'getTxsByHash'>, txValidator: TxValidator, info: string);
|
|
18
|
+
static fromUrl(nodeUrl: string, txValidator: TxValidator, versions: ComponentsVersions): NodeRpcTxSource;
|
|
18
19
|
getInfo(): string;
|
|
19
20
|
getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult>;
|
|
20
21
|
private verifyTxs;
|
|
21
22
|
}
|
|
22
|
-
export declare function createNodeRpcTxSources(urls: string[], chainConfig: ChainConfig): NodeRpcTxSource[];
|
|
23
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
23
|
+
export declare function createNodeRpcTxSources(urls: string[], txValidator: TxValidator, chainConfig: ChainConfig): NodeRpcTxSource[];
|
|
24
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfc291cmNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc2VydmljZXMvdHhfY29sbGVjdGlvbi90eF9zb3VyY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxLQUFLLEVBQUUsV0FBVyxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDeEQsT0FBTyxFQUFFLEtBQUssU0FBUyxFQUF5QixNQUFNLGlDQUFpQyxDQUFDO0FBQ3hGLE9BQU8sS0FBSyxFQUFFLEVBQUUsRUFBRSxNQUFNLEVBQUUsV0FBVyxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDaEUsT0FBTyxFQUFFLEtBQUssa0JBQWtCLEVBQW1DLE1BQU0sMEJBQTBCLENBQUM7QUFHcEcsTUFBTSxNQUFNLHdCQUF3QixHQUFHO0lBQUUsUUFBUSxFQUFFLEVBQUUsRUFBRSxDQUFDO0lBQUMsZUFBZSxFQUFFLE1BQU0sRUFBRSxDQUFBO0NBQUUsQ0FBQztBQUVyRixNQUFNLFdBQVcsUUFBUTtJQUN2QixPQUFPLElBQUksTUFBTSxDQUFDO0lBQ2xCLFlBQVksQ0FBQyxRQUFRLEVBQUUsTUFBTSxFQUFFLEdBQUcsT0FBTyxDQUFDLHdCQUF3QixDQUFDLENBQUM7Q0FDckU7QUFFRCxxQkFBYSxlQUFnQixZQUFXLFFBQVE7SUFFNUMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxNQUFNO0lBQ3ZCLE9BQU8sQ0FBQyxRQUFRLENBQUMsV0FBVztJQUM1QixPQUFPLENBQUMsUUFBUSxDQUFDLElBQUk7SUFIdkIsWUFDbUIsTUFBTSxFQUFFLElBQUksQ0FBQyxTQUFTLEVBQUUsY0FBYyxDQUFDLEVBQ3ZDLFdBQVcsRUFBRSxXQUFXLEVBQ3hCLElBQUksRUFBRSxNQUFNLEVBQzNCO0lBRUosT0FBYyxPQUFPLENBQUMsT0FBTyxFQUFFLE1BQU0sRUFBRSxXQUFXLEVBQUUsV0FBVyxFQUFFLFFBQVEsRUFBRSxrQkFBa0IsR0FBRyxlQUFlLENBRzlHO0lBRU0sT0FBTyxXQUViO0lBRVksWUFBWSxDQUFDLFFBQVEsRUFBRSxNQUFNLEVBQUUsR0FBRyxPQUFPLENBQUMsd0JBQXdCLENBQUMsQ0FFL0U7WUFFYSxTQUFTO0NBZ0J4QjtBQUVELHdCQUFnQixzQkFBc0IsQ0FBQyxJQUFJLEVBQUUsTUFBTSxFQUFFLEVBQUUsV0FBVyxFQUFFLFdBQVcsRUFBRSxXQUFXLEVBQUUsV0FBVyxxQkFHeEcifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx_source.d.ts","sourceRoot":"","sources":["../../../src/services/tx_collection/tx_source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,iCAAiC,CAAC;AACxF,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"tx_source.d.ts","sourceRoot":"","sources":["../../../src/services/tx_collection/tx_source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,iCAAiC,CAAC;AACxF,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,KAAK,kBAAkB,EAAmC,MAAM,0BAA0B,CAAC;AAGpG,MAAM,MAAM,wBAAwB,GAAG;IAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAAC,eAAe,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAErF,MAAM,WAAW,QAAQ;IACvB,OAAO,IAAI,MAAM,CAAC;IAClB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;CACrE;AAED,qBAAa,eAAgB,YAAW,QAAQ;IAE5C,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHvB,YACmB,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,EACvC,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,MAAM,EAC3B;IAEJ,OAAc,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,kBAAkB,GAAG,eAAe,CAG9G;IAEM,OAAO,WAEb;IAEY,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAE/E;YAEa,SAAS;CAgBxB;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,qBAGxG"}
|
|
@@ -5,18 +5,20 @@ import { getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
|
|
|
5
5
|
import { makeTracedFetch } from '@aztec/telemetry-client';
|
|
6
6
|
export class NodeRpcTxSource {
|
|
7
7
|
client;
|
|
8
|
+
txValidator;
|
|
8
9
|
info;
|
|
9
|
-
constructor(client, info){
|
|
10
|
+
constructor(client, txValidator, info){
|
|
10
11
|
this.client = client;
|
|
12
|
+
this.txValidator = txValidator;
|
|
11
13
|
this.info = info;
|
|
12
14
|
}
|
|
13
|
-
static fromUrl(nodeUrl, versions) {
|
|
15
|
+
static fromUrl(nodeUrl, txValidator, versions) {
|
|
14
16
|
const client = createAztecNodeClient(nodeUrl, versions, makeTracedFetch([
|
|
15
17
|
1,
|
|
16
18
|
2,
|
|
17
19
|
3
|
|
18
20
|
], false));
|
|
19
|
-
return new NodeRpcTxSource(client, nodeUrl);
|
|
21
|
+
return new NodeRpcTxSource(client, txValidator, nodeUrl);
|
|
20
22
|
}
|
|
21
23
|
getInfo() {
|
|
22
24
|
return this.info;
|
|
@@ -29,8 +31,8 @@ export class NodeRpcTxSource {
|
|
|
29
31
|
const validTxs = [];
|
|
30
32
|
const invalidTxHashes = [];
|
|
31
33
|
await Promise.all(txs.map(async (tx)=>{
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
+
const validation = await this.txValidator.validateTx(tx);
|
|
35
|
+
if (validation.result === 'valid') {
|
|
34
36
|
validTxs.push(tx);
|
|
35
37
|
} else {
|
|
36
38
|
invalidTxHashes.push(tx.getTxHash().toString());
|
|
@@ -42,7 +44,7 @@ export class NodeRpcTxSource {
|
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
|
-
export function createNodeRpcTxSources(urls, chainConfig) {
|
|
47
|
+
export function createNodeRpcTxSources(urls, txValidator, chainConfig) {
|
|
46
48
|
const versions = getComponentsVersionsFromConfig(chainConfig, protocolContractsHash, getVKTreeRoot());
|
|
47
|
-
return urls.map((url)=>NodeRpcTxSource.fromUrl(url, versions));
|
|
49
|
+
return urls.map((url)=>NodeRpcTxSource.fromUrl(url, txValidator, versions));
|
|
48
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/p2p",
|
|
3
|
-
"version": "4.1.1",
|
|
3
|
+
"version": "4.1.2-rc.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -67,17 +67,17 @@
|
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@aztec/constants": "4.1.1",
|
|
71
|
-
"@aztec/epoch-cache": "4.1.1",
|
|
72
|
-
"@aztec/ethereum": "4.1.1",
|
|
73
|
-
"@aztec/foundation": "4.1.1",
|
|
74
|
-
"@aztec/kv-store": "4.1.1",
|
|
75
|
-
"@aztec/noir-contracts.js": "4.1.1",
|
|
76
|
-
"@aztec/noir-protocol-circuits-types": "4.1.1",
|
|
77
|
-
"@aztec/protocol-contracts": "4.1.1",
|
|
78
|
-
"@aztec/simulator": "4.1.1",
|
|
79
|
-
"@aztec/stdlib": "4.1.1",
|
|
80
|
-
"@aztec/telemetry-client": "4.1.1",
|
|
70
|
+
"@aztec/constants": "4.1.2-rc.1",
|
|
71
|
+
"@aztec/epoch-cache": "4.1.2-rc.1",
|
|
72
|
+
"@aztec/ethereum": "4.1.2-rc.1",
|
|
73
|
+
"@aztec/foundation": "4.1.2-rc.1",
|
|
74
|
+
"@aztec/kv-store": "4.1.2-rc.1",
|
|
75
|
+
"@aztec/noir-contracts.js": "4.1.2-rc.1",
|
|
76
|
+
"@aztec/noir-protocol-circuits-types": "4.1.2-rc.1",
|
|
77
|
+
"@aztec/protocol-contracts": "4.1.2-rc.1",
|
|
78
|
+
"@aztec/simulator": "4.1.2-rc.1",
|
|
79
|
+
"@aztec/stdlib": "4.1.2-rc.1",
|
|
80
|
+
"@aztec/telemetry-client": "4.1.2-rc.1",
|
|
81
81
|
"@chainsafe/libp2p-gossipsub": "13.0.0",
|
|
82
82
|
"@chainsafe/libp2p-noise": "^15.0.0",
|
|
83
83
|
"@chainsafe/libp2p-yamux": "^6.0.2",
|
|
@@ -104,8 +104,8 @@
|
|
|
104
104
|
"xxhash-wasm": "^1.1.0"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
|
-
"@aztec/archiver": "4.1.1",
|
|
108
|
-
"@aztec/world-state": "4.1.1",
|
|
107
|
+
"@aztec/archiver": "4.1.2-rc.1",
|
|
108
|
+
"@aztec/world-state": "4.1.2-rc.1",
|
|
109
109
|
"@jest/globals": "^30.0.0",
|
|
110
110
|
"@types/jest": "^30.0.0",
|
|
111
111
|
"@types/node": "^22.15.17",
|
package/src/client/factory.ts
CHANGED
|
@@ -17,7 +17,10 @@ import { AttestationPool, type AttestationPoolApi } from '../mem_pools/attestati
|
|
|
17
17
|
import type { MemPools } from '../mem_pools/interface.js';
|
|
18
18
|
import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
|
|
19
19
|
import { AztecKVTxPoolV2 } from '../mem_pools/tx_pool_v2/tx_pool_v2.js';
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
createTxValidatorForReqResponseReceivedTxs,
|
|
22
|
+
createTxValidatorForTransactionsEnteringPendingTxPool,
|
|
23
|
+
} from '../msg_validators/index.js';
|
|
21
24
|
import { DummyP2PService } from '../services/dummy_service.js';
|
|
22
25
|
import { LibP2PService } from '../services/index.js';
|
|
23
26
|
import { createFileStoreTxSources } from '../services/tx_collection/file_store_tx_source.js';
|
|
@@ -130,9 +133,12 @@ export async function createP2PClient(
|
|
|
130
133
|
telemetry,
|
|
131
134
|
);
|
|
132
135
|
|
|
136
|
+
const txValidatorForTxCollection = createTxValidatorForReqResponseReceivedTxs(proofVerifier, config);
|
|
133
137
|
const nodeSources = [
|
|
134
|
-
...createNodeRpcTxSources(config.txCollectionNodeRpcUrls, config),
|
|
135
|
-
...(deps.rpcTxProviders ?? []).map(
|
|
138
|
+
...createNodeRpcTxSources(config.txCollectionNodeRpcUrls, txValidatorForTxCollection, config),
|
|
139
|
+
...(deps.rpcTxProviders ?? []).map(
|
|
140
|
+
(node, i) => new NodeRpcTxSource(node, txValidatorForTxCollection, `node-rpc-provider-${i}`),
|
|
141
|
+
),
|
|
136
142
|
...(deps.txCollectionNodeSources ?? []),
|
|
137
143
|
];
|
|
138
144
|
if (nodeSources.length > 0) {
|
|
@@ -144,6 +150,7 @@ export async function createP2PClient(
|
|
|
144
150
|
const fileStoreSources = await createFileStoreTxSources(
|
|
145
151
|
config.txCollectionFileStoreUrls,
|
|
146
152
|
txFileStoreBasePath,
|
|
153
|
+
txValidatorForTxCollection,
|
|
147
154
|
logger.createChild('file-store-tx-source'),
|
|
148
155
|
telemetry,
|
|
149
156
|
);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { partitionAsync } from '@aztec/foundation/collection';
|
|
1
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
3
4
|
import { type ReadOnlyFileStore, createReadOnlyFileStore } from '@aztec/stdlib/file-store';
|
|
4
|
-
import { Tx, type TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import { Tx, type TxHash, type TxValidator } from '@aztec/stdlib/tx';
|
|
5
6
|
import {
|
|
6
7
|
type Histogram,
|
|
7
8
|
Metrics,
|
|
@@ -23,6 +24,7 @@ export class FileStoreTxSource implements TxSource {
|
|
|
23
24
|
private readonly fileStore: ReadOnlyFileStore,
|
|
24
25
|
private readonly baseUrl: string,
|
|
25
26
|
private readonly basePath: string,
|
|
27
|
+
private readonly txValidator: TxValidator,
|
|
26
28
|
private readonly log: Logger,
|
|
27
29
|
telemetry: TelemetryClient,
|
|
28
30
|
) {
|
|
@@ -44,6 +46,7 @@ export class FileStoreTxSource implements TxSource {
|
|
|
44
46
|
public static async create(
|
|
45
47
|
url: string,
|
|
46
48
|
basePath: string,
|
|
49
|
+
txValidator: TxValidator,
|
|
47
50
|
log: Logger = createLogger('p2p:file_store_tx_source'),
|
|
48
51
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
49
52
|
): Promise<FileStoreTxSource | undefined> {
|
|
@@ -53,7 +56,7 @@ export class FileStoreTxSource implements TxSource {
|
|
|
53
56
|
log.warn(`Failed to create file store for URL: ${url}`);
|
|
54
57
|
return undefined;
|
|
55
58
|
}
|
|
56
|
-
return new FileStoreTxSource(fileStore, url, basePath, log, telemetry);
|
|
59
|
+
return new FileStoreTxSource(fileStore, url, basePath, txValidator, log, telemetry);
|
|
57
60
|
} catch (err) {
|
|
58
61
|
log.warn(`Error creating file store for URL: ${url}`, { error: err });
|
|
59
62
|
return undefined;
|
|
@@ -65,35 +68,41 @@ export class FileStoreTxSource implements TxSource {
|
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
public async getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult> {
|
|
68
|
-
const
|
|
71
|
+
const results = await Promise.all(
|
|
72
|
+
txHashes.map(async txHash => {
|
|
73
|
+
const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
|
|
74
|
+
const timer = new Timer();
|
|
75
|
+
try {
|
|
76
|
+
const buffer = await this.fileStore.read(path);
|
|
77
|
+
const tx = Tx.fromBuffer(buffer);
|
|
78
|
+
return { tx, downloadDuration: timer.ms(), downloadSize: buffer.length };
|
|
79
|
+
} catch {
|
|
80
|
+
this.downloadsFailed.add(1);
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const txs = results.filter(tx => tx !== undefined);
|
|
87
|
+
const [validTxs, invalidTxs] = await partitionAsync(
|
|
88
|
+
txs,
|
|
89
|
+
async ({ tx, downloadDuration, downloadSize }): Promise<boolean> => {
|
|
90
|
+
const valid = await this.txValidator.validateTx(tx);
|
|
91
|
+
if (valid.result === 'valid') {
|
|
92
|
+
this.downloadsSuccess.add(1);
|
|
93
|
+
this.downloadDuration.record(Math.ceil(downloadDuration));
|
|
94
|
+
this.downloadSize.record(downloadSize);
|
|
95
|
+
return true;
|
|
96
|
+
} else {
|
|
97
|
+
this.downloadsFailed.add(1);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
|
|
69
103
|
return {
|
|
70
|
-
validTxs: (
|
|
71
|
-
|
|
72
|
-
txHashes.map(async txHash => {
|
|
73
|
-
const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
|
|
74
|
-
const timer = new Timer();
|
|
75
|
-
try {
|
|
76
|
-
const buffer = await this.fileStore.read(path);
|
|
77
|
-
const tx = Tx.fromBuffer(buffer);
|
|
78
|
-
if ((await tx.validateTxHash()) && txHash.equals(tx.txHash)) {
|
|
79
|
-
this.downloadsSuccess.add(1);
|
|
80
|
-
this.downloadDuration.record(Math.ceil(timer.ms()));
|
|
81
|
-
this.downloadSize.record(buffer.length);
|
|
82
|
-
return tx;
|
|
83
|
-
} else {
|
|
84
|
-
invalidTxHashes.push(tx.txHash.toString());
|
|
85
|
-
this.downloadsFailed.add(1);
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
} catch {
|
|
89
|
-
// Tx not found or error reading - return undefined
|
|
90
|
-
this.downloadsFailed.add(1);
|
|
91
|
-
return undefined;
|
|
92
|
-
}
|
|
93
|
-
}),
|
|
94
|
-
)
|
|
95
|
-
).filter(tx => tx !== undefined),
|
|
96
|
-
invalidTxHashes: invalidTxHashes,
|
|
104
|
+
validTxs: validTxs.map(({ tx }) => tx),
|
|
105
|
+
invalidTxHashes: invalidTxs.map(({ tx }) => tx.getTxHash().toString()),
|
|
97
106
|
};
|
|
98
107
|
}
|
|
99
108
|
}
|
|
@@ -109,9 +118,12 @@ export class FileStoreTxSource implements TxSource {
|
|
|
109
118
|
export async function createFileStoreTxSources(
|
|
110
119
|
urls: string[],
|
|
111
120
|
basePath: string,
|
|
121
|
+
txValidator: TxValidator,
|
|
112
122
|
log: Logger = createLogger('p2p:file_store_tx_source'),
|
|
113
123
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
114
124
|
): Promise<FileStoreTxSource[]> {
|
|
115
|
-
const sources = await Promise.all(
|
|
125
|
+
const sources = await Promise.all(
|
|
126
|
+
urls.map(url => FileStoreTxSource.create(url, basePath, txValidator, log, telemetry)),
|
|
127
|
+
);
|
|
116
128
|
return sources.filter((s): s is FileStoreTxSource => s !== undefined);
|
|
117
129
|
}
|
|
@@ -2,7 +2,7 @@ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
|
2
2
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
3
3
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
4
4
|
import { type AztecNode, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
|
|
5
|
-
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { Tx, TxHash, TxValidator } from '@aztec/stdlib/tx';
|
|
6
6
|
import { type ComponentsVersions, getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
|
|
7
7
|
import { makeTracedFetch } from '@aztec/telemetry-client';
|
|
8
8
|
|
|
@@ -16,12 +16,13 @@ export interface TxSource {
|
|
|
16
16
|
export class NodeRpcTxSource implements TxSource {
|
|
17
17
|
constructor(
|
|
18
18
|
private readonly client: Pick<AztecNode, 'getTxsByHash'>,
|
|
19
|
+
private readonly txValidator: TxValidator,
|
|
19
20
|
private readonly info: string,
|
|
20
21
|
) {}
|
|
21
22
|
|
|
22
|
-
public static fromUrl(nodeUrl: string, versions: ComponentsVersions): NodeRpcTxSource {
|
|
23
|
+
public static fromUrl(nodeUrl: string, txValidator: TxValidator, versions: ComponentsVersions): NodeRpcTxSource {
|
|
23
24
|
const client = createAztecNodeClient(nodeUrl, versions, makeTracedFetch([1, 2, 3], false));
|
|
24
|
-
return new NodeRpcTxSource(client, nodeUrl);
|
|
25
|
+
return new NodeRpcTxSource(client, txValidator, nodeUrl);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
public getInfo() {
|
|
@@ -38,8 +39,8 @@ export class NodeRpcTxSource implements TxSource {
|
|
|
38
39
|
const invalidTxHashes: string[] = [];
|
|
39
40
|
await Promise.all(
|
|
40
41
|
txs.map(async tx => {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
42
|
+
const validation = await this.txValidator.validateTx(tx);
|
|
43
|
+
if (validation.result === 'valid') {
|
|
43
44
|
validTxs.push(tx);
|
|
44
45
|
} else {
|
|
45
46
|
invalidTxHashes.push(tx.getTxHash().toString());
|
|
@@ -50,7 +51,7 @@ export class NodeRpcTxSource implements TxSource {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
export function createNodeRpcTxSources(urls: string[], chainConfig: ChainConfig) {
|
|
54
|
+
export function createNodeRpcTxSources(urls: string[], txValidator: TxValidator, chainConfig: ChainConfig) {
|
|
54
55
|
const versions = getComponentsVersionsFromConfig(chainConfig, protocolContractsHash, getVKTreeRoot());
|
|
55
|
-
return urls.map(url => NodeRpcTxSource.fromUrl(url, versions));
|
|
56
|
+
return urls.map(url => NodeRpcTxSource.fromUrl(url, txValidator, versions));
|
|
56
57
|
}
|