@aztec/p2p 0.85.0 → 0.86.0
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/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +6 -3
- package/dest/client/p2p_client.d.ts +41 -3
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +58 -18
- package/dest/config.d.ts +13 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +15 -3
- package/dest/enr/generate-enr.d.ts +1 -1
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +2 -2
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +11 -11
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +2 -2
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +4 -4
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +2 -2
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +3 -0
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +18 -0
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +3 -0
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +9 -0
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +17 -0
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +57 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.js +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +1 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +6 -1
- package/dest/services/discv5/discV5_service.d.ts +2 -1
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +22 -7
- package/dest/services/dummy_service.d.ts +2 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +2 -2
- package/dest/services/libp2p/libp2p_service.d.ts +3 -1
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +28 -12
- package/dest/services/peer-manager/peer_manager.d.ts +21 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +63 -18
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +2 -2
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +17 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +84 -36
- package/dest/services/reqresp/reqresp.d.ts +2 -2
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +7 -2
- package/dest/services/reqresp/status.d.ts +2 -1
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +3 -0
- package/dest/services/service.d.ts +4 -4
- package/dest/services/service.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts +6 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +19 -2
- package/dest/testbench/p2p_client_testbench_worker.js +4 -1
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +5 -1
- package/package.json +12 -14
- package/src/bootstrap/bootstrap.ts +8 -4
- package/src/client/p2p_client.ts +212 -131
- package/src/config.ts +34 -4
- package/src/enr/generate-enr.ts +2 -2
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +11 -15
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +2 -2
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +4 -4
- package/src/mem_pools/attestation_pool/mocks.ts +3 -3
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +21 -0
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +11 -0
- package/src/mem_pools/tx_pool/tx_pool.ts +20 -0
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +43 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +1 -1
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +10 -1
- package/src/services/discv5/discV5_service.ts +32 -6
- package/src/services/dummy_service.ts +2 -2
- package/src/services/libp2p/libp2p_service.ts +37 -12
- package/src/services/peer-manager/peer_manager.ts +79 -22
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +2 -2
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +82 -41
- package/src/services/reqresp/reqresp.ts +12 -6
- package/src/services/reqresp/status.ts +3 -0
- package/src/services/service.ts +4 -4
- package/src/test-helpers/make-test-p2p-clients.ts +20 -2
- package/src/testbench/p2p_client_testbench_worker.ts +3 -0
- package/src/util.ts +6 -1
|
@@ -15,5 +15,5 @@ export declare const generateAccount: () => LocalAccount;
|
|
|
15
15
|
* @param slot The slot number the attestation is for
|
|
16
16
|
* @returns A Block Attestation
|
|
17
17
|
*/
|
|
18
|
-
export declare const mockAttestation: (signer: Secp256k1Signer, slot?: number, archive?: Fr, txs?: TxHash[]) =>
|
|
18
|
+
export declare const mockAttestation: (signer: Secp256k1Signer, slot?: number, archive?: Fr, txs?: TxHash[]) => BlockAttestation;
|
|
19
19
|
//# sourceMappingURL=mocks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EACL,gBAAgB,EAIjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,KAAK,YAAY,EAA2C,MAAM,eAAe,CAAC;AAE3F;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAAO,YAGlC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,WAClB,eAAe,SACjB,MAAM,YACH,EAAE,QACN,MAAM,EAAE,KACZ,
|
|
1
|
+
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EACL,gBAAgB,EAIjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,KAAK,YAAY,EAA2C,MAAM,eAAe,CAAC;AAE3F;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAAO,YAGlC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,WAClB,eAAe,SACjB,MAAM,YACH,EAAE,QACN,MAAM,EAAE,KACZ,gBASF,CAAC"}
|
|
@@ -16,7 +16,7 @@ import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
|
16
16
|
* @param signer A viem signer to create a signature
|
|
17
17
|
* @param slot The slot number the attestation is for
|
|
18
18
|
* @returns A Block Attestation
|
|
19
|
-
*/ export const mockAttestation =
|
|
19
|
+
*/ export const mockAttestation = (signer, slot = 0, archive = Fr.random(), txs = [
|
|
20
20
|
0,
|
|
21
21
|
1,
|
|
22
22
|
2,
|
|
@@ -27,7 +27,7 @@ import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
|
27
27
|
// Use arbitrary numbers for all other than slot
|
|
28
28
|
const header = makeHeader(1, 2, slot);
|
|
29
29
|
const payload = new ConsensusPayload(header, archive, txs);
|
|
30
|
-
const hash =
|
|
30
|
+
const hash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockAttestation);
|
|
31
31
|
const signature = signer.sign(hash);
|
|
32
32
|
return new BlockAttestation(payload, signature);
|
|
33
33
|
};
|
|
@@ -34,6 +34,8 @@ export declare class AztecKVTxPool implements TxPool {
|
|
|
34
34
|
* @returns The transaction, if found, 'undefined' otherwise.
|
|
35
35
|
*/
|
|
36
36
|
getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
37
|
+
getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
38
|
+
hasTxs(txHashes: TxHash[]): Promise<boolean[]>;
|
|
37
39
|
/**
|
|
38
40
|
* Checks if an archived tx exists and returns it.
|
|
39
41
|
* @param txHash - The tx hash.
|
|
@@ -62,6 +64,7 @@ export declare class AztecKVTxPool implements TxPool {
|
|
|
62
64
|
* @returns An array of transaction hashes found in the tx pool.
|
|
63
65
|
*/
|
|
64
66
|
getAllTxHashes(): Promise<TxHash[]>;
|
|
67
|
+
setMaxTxPoolSize(maxSizeBytes: number | undefined): Promise<void>;
|
|
65
68
|
/**
|
|
66
69
|
* Creates a GasTxValidator instance.
|
|
67
70
|
* @param db - DB for the validator to use
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aztec_kv_tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/aztec_kv_tx_pool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE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efined;
|
|
152
152
|
}
|
|
153
|
+
async getTxsByHash(txHashes) {
|
|
154
|
+
const txs = await Promise.all(txHashes.map((txHash)=>this.#txs.getAsync(txHash.toString())));
|
|
155
|
+
return txs.map((buffer, index)=>{
|
|
156
|
+
if (buffer) {
|
|
157
|
+
const tx = Tx.fromBuffer(buffer);
|
|
158
|
+
tx.setTxHash(txHashes[index]);
|
|
159
|
+
return tx;
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
async hasTxs(txHashes) {
|
|
165
|
+
return await Promise.all(txHashes.map((txHash)=>this.#txs.hasAsync(txHash.toString())));
|
|
166
|
+
}
|
|
153
167
|
/**
|
|
154
168
|
* Checks if an archived tx exists and returns it.
|
|
155
169
|
* @param txHash - The tx hash.
|
|
@@ -249,6 +263,10 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
249
263
|
const vals = await toArray(this.#txs.keysAsync());
|
|
250
264
|
return vals.map((x)=>TxHash.fromString(x));
|
|
251
265
|
}
|
|
266
|
+
setMaxTxPoolSize(maxSizeBytes) {
|
|
267
|
+
this.#maxTxPoolSize = maxSizeBytes;
|
|
268
|
+
return Promise.resolve();
|
|
269
|
+
}
|
|
252
270
|
/**
|
|
253
271
|
* Creates a GasTxValidator instance.
|
|
254
272
|
* @param db - DB for the validator to use
|
|
@@ -29,6 +29,8 @@ export declare class InMemoryTxPool implements TxPool {
|
|
|
29
29
|
* @returns The transaction, if found, 'undefined' otherwise.
|
|
30
30
|
*/
|
|
31
31
|
getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
32
|
+
getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
33
|
+
hasTxs(txHashes: TxHash[]): Promise<boolean[]>;
|
|
32
34
|
getArchivedTxByHash(): Promise<Tx | undefined>;
|
|
33
35
|
/**
|
|
34
36
|
* Adds a list of transactions to the pool. Duplicates are ignored.
|
|
@@ -52,5 +54,6 @@ export declare class InMemoryTxPool implements TxPool {
|
|
|
52
54
|
* @returns An array of transaction hashes found in the tx pool.
|
|
53
55
|
*/
|
|
54
56
|
getAllTxHashes(): Promise<TxHash[]>;
|
|
57
|
+
setMaxTxPoolSize(_maxSizeBytes: number | undefined): Promise<void>;
|
|
55
58
|
}
|
|
56
59
|
//# sourceMappingURL=memory_tx_pool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory_tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/memory_tx_pool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAInF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;GAEG;AACH,qBAAa,cAAe,YAAW,MAAM;IAcoB,OAAO,CAAC,GAAG;IAb1E;;OAEG;IACH,OAAO,CAAC,GAAG,CAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,UAAU,CAAc;IAEhC,OAAO,CAAC,OAAO,CAA0B;IAEzC;;;OAGG;gBACS,SAAS,GAAE,eAAsC,EAAU,GAAG,yCAA8B;IAOjG,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWnE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B/C,kBAAkB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAQ7C,gBAAgB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAM/C,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAW5E;;;;OAIG;IACI,WAAW,C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C,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAIvC,mBAAmB,IAAI,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAIrD;;;;OAIG;IACU,MAAM,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB7C;;;;OAIG;IACI,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBnD;;;OAGG;IACI,SAAS,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;IAIjC;;;OAGG;IACI,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAI1C,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAGnE"}
|
|
@@ -83,6 +83,12 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
83
83
|
const result = this.txs.get(txHash.toBigInt());
|
|
84
84
|
return Promise.resolve(result === undefined ? undefined : Tx.clone(result));
|
|
85
85
|
}
|
|
86
|
+
getTxsByHash(txHashes) {
|
|
87
|
+
return Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash)));
|
|
88
|
+
}
|
|
89
|
+
hasTxs(txHashes) {
|
|
90
|
+
return Promise.resolve(txHashes.map((txHash)=>this.txs.has(txHash.toBigInt())));
|
|
91
|
+
}
|
|
86
92
|
getArchivedTxByHash() {
|
|
87
93
|
return Promise.resolve(undefined);
|
|
88
94
|
}
|
|
@@ -138,4 +144,7 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
138
144
|
*/ getAllTxHashes() {
|
|
139
145
|
return Promise.resolve(Array.from(this.txs.keys()).map((x)=>TxHash.fromBigInt(x)));
|
|
140
146
|
}
|
|
147
|
+
setMaxTxPoolSize(_maxSizeBytes) {
|
|
148
|
+
return Promise.resolve();
|
|
149
|
+
}
|
|
141
150
|
}
|
|
@@ -14,6 +14,18 @@ export interface TxPool {
|
|
|
14
14
|
* @returns The transaction, if found, 'undefined' otherwise.
|
|
15
15
|
*/
|
|
16
16
|
getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Checks if transactions exist in the pool and returns them.
|
|
19
|
+
* @param txHashes - The hashes of the transactions
|
|
20
|
+
* @returns The transactions, if found, 'undefined' otherwise.
|
|
21
|
+
*/
|
|
22
|
+
getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if transactions exist in the pool
|
|
25
|
+
* @param txHashes - The hashes of the transactions to check for
|
|
26
|
+
* @returns True or False for each tx hash
|
|
27
|
+
*/
|
|
28
|
+
hasTxs(txHashes: TxHash[]): Promise<boolean[]>;
|
|
17
29
|
/**
|
|
18
30
|
* Checks if an archived transaction exists in the pool and returns it.
|
|
19
31
|
* @param txHash - The hash of the transaction, used as an ID.
|
|
@@ -62,5 +74,10 @@ export interface TxPool {
|
|
|
62
74
|
* @returns Pending or mined depending on its status, or undefined if not found.
|
|
63
75
|
*/
|
|
64
76
|
getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined>;
|
|
77
|
+
/**
|
|
78
|
+
* Configure the maximum size of the tx pool
|
|
79
|
+
* @param maxSizeBytes - The maximum size in bytes of the mempool. Set to undefined to disable it
|
|
80
|
+
*/
|
|
81
|
+
setMaxTxPoolSize(maxSizeBytes: number | undefined): Promise<void>;
|
|
65
82
|
}
|
|
66
83
|
//# sourceMappingURL=tx_pool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/tx_pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,EAAE,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EtE;;;OAGG;IACH,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx_pool_test_suite.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/tx_pool_test_suite.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"tx_pool_test_suite.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/tx_pool_test_suite.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,MAAM,QAiKrD"}
|
|
@@ -142,6 +142,63 @@ import { mockTx } from '@aztec/stdlib/testing';
|
|
|
142
142
|
await tx3.getTxHash()
|
|
143
143
|
]));
|
|
144
144
|
});
|
|
145
|
+
it('Returns txs by their hash', async ()=>{
|
|
146
|
+
const tx1 = await mockTx(1);
|
|
147
|
+
const tx2 = await mockTx(2);
|
|
148
|
+
const tx3 = await mockTx(3);
|
|
149
|
+
await pool.addTxs([
|
|
150
|
+
tx1,
|
|
151
|
+
tx2,
|
|
152
|
+
tx3
|
|
153
|
+
]);
|
|
154
|
+
const requestedTxs = await pool.getTxsByHash([
|
|
155
|
+
await tx1.getTxHash(),
|
|
156
|
+
await tx3.getTxHash()
|
|
157
|
+
]);
|
|
158
|
+
expect(requestedTxs).toHaveLength(2);
|
|
159
|
+
expect(requestedTxs).toEqual(expect.arrayContaining([
|
|
160
|
+
tx1,
|
|
161
|
+
tx3
|
|
162
|
+
]));
|
|
163
|
+
});
|
|
164
|
+
it('Returns a large number of transactions by their hash', async ()=>{
|
|
165
|
+
const numTxs = 1000;
|
|
166
|
+
const txs = await Promise.all(Array.from({
|
|
167
|
+
length: numTxs
|
|
168
|
+
}, (_, i)=>mockTx(i)));
|
|
169
|
+
const hashes = await Promise.all(txs.map((tx)=>tx.getTxHash()));
|
|
170
|
+
await pool.addTxs(txs);
|
|
171
|
+
const requestedTxs = await pool.getTxsByHash(hashes);
|
|
172
|
+
expect(requestedTxs).toHaveLength(numTxs);
|
|
173
|
+
expect(requestedTxs).toEqual(expect.arrayContaining(txs));
|
|
174
|
+
});
|
|
175
|
+
it('Returns whether or not txs exist', async ()=>{
|
|
176
|
+
const tx1 = await mockTx(1);
|
|
177
|
+
const tx2 = await mockTx(2);
|
|
178
|
+
const tx3 = await mockTx(3);
|
|
179
|
+
await pool.addTxs([
|
|
180
|
+
tx1,
|
|
181
|
+
tx2,
|
|
182
|
+
tx3
|
|
183
|
+
]);
|
|
184
|
+
const tx4 = await mockTx(4);
|
|
185
|
+
const tx5 = await mockTx(5);
|
|
186
|
+
const availability = await pool.hasTxs([
|
|
187
|
+
await tx1.getTxHash(),
|
|
188
|
+
await tx2.getTxHash(),
|
|
189
|
+
await tx3.getTxHash(),
|
|
190
|
+
await tx4.getTxHash(),
|
|
191
|
+
await tx5.getTxHash()
|
|
192
|
+
]);
|
|
193
|
+
expect(availability).toHaveLength(5);
|
|
194
|
+
expect(availability).toEqual(expect.arrayContaining([
|
|
195
|
+
true,
|
|
196
|
+
true,
|
|
197
|
+
true,
|
|
198
|
+
false,
|
|
199
|
+
false
|
|
200
|
+
]));
|
|
201
|
+
});
|
|
145
202
|
it('Returns pending tx hashes sorted by priority', async ()=>{
|
|
146
203
|
const withPriorityFee = (tx, fee)=>{
|
|
147
204
|
unfreeze(tx.data.constants.txContext.gasSettings).maxPriorityFeesPerGas = new GasFees(fee, fee);
|
|
@@ -10,7 +10,7 @@ export class AttestationValidator {
|
|
|
10
10
|
if (slotNumberBigInt !== currentSlot && slotNumberBigInt !== nextSlot) {
|
|
11
11
|
return PeerErrorSeverity.HighToleranceError;
|
|
12
12
|
}
|
|
13
|
-
const attester =
|
|
13
|
+
const attester = message.getSender();
|
|
14
14
|
if (!await this.epochCache.isInCommittee(attester)) {
|
|
15
15
|
return PeerErrorSeverity.HighToleranceError;
|
|
16
16
|
}
|
|
@@ -2,6 +2,7 @@ import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
|
2
2
|
import { type BlockProposal, type P2PValidator, PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
3
3
|
export declare class BlockProposalValidator implements P2PValidator<BlockProposal> {
|
|
4
4
|
private epochCache;
|
|
5
|
+
private logger;
|
|
5
6
|
constructor(epochCache: EpochCacheInterface);
|
|
6
7
|
validate(block: BlockProposal): Promise<PeerErrorSeverity | undefined>;
|
|
7
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_proposal_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/block_proposal_validator/block_proposal_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"block_proposal_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/block_proposal_validator/block_proposal_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE7F,qBAAa,sBAAuB,YAAW,YAAY,CAAC,aAAa,CAAC;IACxE,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,MAAM,CAAS;gBAEX,UAAU,EAAE,mBAAmB;IAKrC,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;CAwB7E"}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
1
2
|
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
2
3
|
export class BlockProposalValidator {
|
|
3
4
|
epochCache;
|
|
5
|
+
logger;
|
|
4
6
|
constructor(epochCache){
|
|
5
7
|
this.epochCache = epochCache;
|
|
8
|
+
this.logger = createLogger('p2p:block_proposal_validator');
|
|
6
9
|
}
|
|
7
10
|
async validate(block) {
|
|
8
11
|
const { currentProposer, nextProposer, currentSlot, nextSlot } = await this.epochCache.getProposerInCurrentOrNextSlot();
|
|
9
12
|
// Check that the attestation is for the current or next slot
|
|
10
13
|
const slotNumberBigInt = block.payload.header.globalVariables.slotNumber.toBigInt();
|
|
11
14
|
if (slotNumberBigInt !== currentSlot && slotNumberBigInt !== nextSlot) {
|
|
15
|
+
this.logger.debug(`Penalizing peer for invalid slot number ${slotNumberBigInt}, current slot: ${currentSlot}, next slot: ${nextSlot}`);
|
|
12
16
|
return PeerErrorSeverity.HighToleranceError;
|
|
13
17
|
}
|
|
14
18
|
// Check that the block proposal is from the current or next proposer
|
|
15
|
-
const proposer =
|
|
19
|
+
const proposer = block.getSender();
|
|
16
20
|
if (!proposer.equals(currentProposer) && !proposer.equals(nextProposer)) {
|
|
21
|
+
this.logger.debug(`Penalizing peer for invalid proposer ${proposer.toString()}, current proposer: ${currentProposer.toString()}, next proposer: ${nextProposer.toString()}`);
|
|
17
22
|
return PeerErrorSeverity.HighToleranceError;
|
|
18
23
|
}
|
|
19
24
|
return undefined;
|
|
@@ -22,13 +22,14 @@ export declare class DiscV5Service extends EventEmitter implements PeerDiscovery
|
|
|
22
22
|
private currentState;
|
|
23
23
|
private bootstrapNodePeerIds;
|
|
24
24
|
bootstrapNodeEnrs: ENR[];
|
|
25
|
+
private trustedPeerEnrs;
|
|
25
26
|
private startTime;
|
|
26
27
|
private handlers;
|
|
27
28
|
constructor(peerId: PeerId, config: P2PConfig, telemetry?: TelemetryClient, logger?: import("@aztec/foundation/log").Logger, configOverrides?: Partial<IDiscv5CreateOptions>);
|
|
28
29
|
private onMultiaddrUpdated;
|
|
29
30
|
start(): Promise<void>;
|
|
30
31
|
runRandomNodesQuery(): Promise<void>;
|
|
31
|
-
|
|
32
|
+
getKadValues(): ENR[];
|
|
32
33
|
getEnr(): ENR;
|
|
33
34
|
getPeerId(): PeerId;
|
|
34
35
|
getStatus(): PeerDiscoveryState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discV5_service.d.ts","sourceRoot":"","sources":["../../../src/services/discv5/discV5_service.ts"],"names":[],"mappings":";AAGA,OAAO,EAAsB,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAEvG,OAAO,EAAmC,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC/F,OAAO,EAAE,GAAG,EAAe,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjD,OAAO,EAAE,KAAK,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAI9E;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAa,YAAW,oBAAoB;
|
|
1
|
+
{"version":3,"file":"discV5_service.d.ts","sourceRoot":"","sources":["../../../src/services/discv5/discV5_service.ts"],"names":[],"mappings":";AAGA,OAAO,EAAsB,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAEvG,OAAO,EAAmC,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC/F,OAAO,EAAE,GAAG,EAAe,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjD,OAAO,EAAE,KAAK,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;
|
|
26
27
|
startTime;
|
|
27
28
|
handlers;
|
|
28
29
|
constructor(peerId, config, telemetry = getTelemetryClient(), logger = createLogger('p2p:discv5_service'), configOverrides = {}){
|
|
29
|
-
super(), this.peerId = peerId, this.config = config, this.logger = logger, this.currentState = PeerDiscoveryState.STOPPED, this.bootstrapNodePeerIds = [], this.bootstrapNodeEnrs = [], this.startTime = 0, this.handlers = {
|
|
30
|
+
super(), this.peerId = peerId, this.config = config, this.logger = logger, this.currentState = PeerDiscoveryState.STOPPED, this.bootstrapNodePeerIds = [], this.bootstrapNodeEnrs = [], this.trustedPeerEnrs = [], this.startTime = 0, this.handlers = {
|
|
30
31
|
onMultiaddrUpdated: this.onMultiaddrUpdated.bind(this),
|
|
31
32
|
onDiscovered: this.onDiscovered.bind(this),
|
|
32
33
|
onEnrAdded: this.onEnrAdded.bind(this)
|
|
33
34
|
};
|
|
34
|
-
const { p2pIp, p2pPort, bootstrapNodes } = config;
|
|
35
|
+
const { p2pIp, p2pPort, p2pBroadcastPort, bootstrapNodes, trustedPeers, privatePeers } = config;
|
|
35
36
|
this.bootstrapNodeEnrs = bootstrapNodes.map((x)=>ENR.decodeTxt(x));
|
|
37
|
+
const privatePeerEnrs = new Set(privatePeers);
|
|
38
|
+
this.trustedPeerEnrs = trustedPeers.filter((x)=>!privatePeerEnrs.has(x)).map((x)=>ENR.decodeTxt(x));
|
|
36
39
|
// create ENR from PeerId
|
|
37
40
|
this.enr = SignableENR.createFromPeerId(peerId);
|
|
38
41
|
// Add aztec identification to ENR
|
|
39
42
|
this.versions = setAztecEnrKey(this.enr, config);
|
|
43
|
+
// If no overridden broadcast port is provided, use the p2p port as the broadcast port
|
|
44
|
+
if (!p2pBroadcastPort) {
|
|
45
|
+
this.logger.warn('No p2pBroadcastPort provided, using p2pPort as broadcast port');
|
|
46
|
+
config.p2pBroadcastPort = p2pPort;
|
|
47
|
+
}
|
|
40
48
|
const bindAddrs = {
|
|
41
49
|
ip4: multiaddr(convertToMultiaddr(config.listenAddress, p2pPort, 'udp'))
|
|
42
50
|
};
|
|
43
51
|
if (p2pIp) {
|
|
44
|
-
const multiAddrTcp = multiaddr(`${convertToMultiaddr(p2pIp,
|
|
45
|
-
|
|
46
|
-
const multiAddrUdp = multiaddr(`${convertToMultiaddr(p2pIp, p2pPort, 'udp')}/p2p/${peerId.toString()}`);
|
|
52
|
+
const multiAddrTcp = multiaddr(`${convertToMultiaddr(p2pIp, config.p2pBroadcastPort, 'tcp')}/p2p/${peerId.toString()}`);
|
|
53
|
+
const multiAddrUdp = multiaddr(`${convertToMultiaddr(p2pIp, config.p2pBroadcastPort, 'udp')}/p2p/${peerId.toString()}`);
|
|
47
54
|
// set location multiaddr in ENR record
|
|
48
55
|
this.enr.setLocationMultiaddr(multiAddrUdp);
|
|
49
56
|
this.enr.setLocationMultiaddr(multiAddrTcp);
|
|
@@ -86,7 +93,8 @@ const delayBeforeStart = 2000; // 2sec
|
|
|
86
93
|
}
|
|
87
94
|
onMultiaddrUpdated(m) {
|
|
88
95
|
// We want to update our tcp port to match the udp port
|
|
89
|
-
|
|
96
|
+
// p2pBroadcastPort is optional on config, however it is set to default within the p2p client factory
|
|
97
|
+
const multiAddrTcp = multiaddr(convertToMultiaddr(m.nodeAddress().address, this.config.p2pBroadcastPort, 'tcp'));
|
|
90
98
|
this.enr.setLocationMultiaddr(multiAddrTcp);
|
|
91
99
|
this.logger.info('Multiaddr updated', {
|
|
92
100
|
multiaddr: multiAddrTcp.toString()
|
|
@@ -127,6 +135,13 @@ const delayBeforeStart = 2000; // 2sec
|
|
|
127
135
|
}
|
|
128
136
|
}
|
|
129
137
|
}
|
|
138
|
+
// Add trusted peer ENRs if provided
|
|
139
|
+
if (this.trustedPeerEnrs?.length) {
|
|
140
|
+
this.logger.info(`Adding ${this.trustedPeerEnrs.length} trusted peer ENRs: ${this.trustedPeerEnrs.map((enr)=>enr.encodeTxt()).join(', ')}`);
|
|
141
|
+
for (const enr of this.trustedPeerEnrs){
|
|
142
|
+
this.discv5.addEnr(enr);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
130
145
|
}
|
|
131
146
|
async runRandomNodesQuery() {
|
|
132
147
|
if (this.currentState !== PeerDiscoveryState.RUNNING) {
|
|
@@ -144,7 +159,7 @@ const delayBeforeStart = 2000; // 2sec
|
|
|
144
159
|
this.logger.error(`Error running discV5 random node query: ${err}`);
|
|
145
160
|
}
|
|
146
161
|
}
|
|
147
|
-
|
|
162
|
+
getKadValues() {
|
|
148
163
|
return this.discv5.kadValues();
|
|
149
164
|
}
|
|
150
165
|
getEnr() {
|
|
@@ -75,9 +75,9 @@ export declare class DummyPeerDiscoveryService extends EventEmitter implements P
|
|
|
75
75
|
stop(): Promise<void>;
|
|
76
76
|
/**
|
|
77
77
|
* Called to discover peers in the network.
|
|
78
|
-
* @returns An array of
|
|
78
|
+
* @returns An array of Enrs.
|
|
79
79
|
*/
|
|
80
|
-
|
|
80
|
+
getKadValues(): never[];
|
|
81
81
|
runRandomNodesQuery(): Promise<void>;
|
|
82
82
|
isBootstrapPeer(_: PeerId): boolean;
|
|
83
83
|
getStatus(): PeerDiscoveryState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dummy_service.d.ts","sourceRoot":"","sources":["../../src/services/dummy_service.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,E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OAKG;IACI,gBAAgB,CAAC,QAAQ,SAAS,kBAAkB,EACzD,SAAS,EAAE,QAAQ,EACnB,SAAS,EAAE,YAAY,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,GAC7D,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;IAIhE;;;OAGG;IACI,MAAM,IAAI,SAAS;CAG3B;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,YAAa,YAAW,oBAAoB;IACzF,OAAO,CAAC,YAAY,CAA8B;IAC3C,iBAAiB,EAAE,GAAG,EAAE,CAAM;IAErC;;;OAGG;IACI,KAAK;IAIZ;;;OAGG;IACI,IAAI;IAIX;;;OAGG;IACI,YAAY;IAIZ,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;IAInC,SAAS,IAAI,kBAAkB;IAI/B,MAAM,IAAI,SAAS;CAG3B"}
|
|
@@ -73,8 +73,8 @@ import { PeerDiscoveryState } from './service.js';
|
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Called to discover peers in the network.
|
|
76
|
-
* @returns An array of
|
|
77
|
-
*/
|
|
76
|
+
* @returns An array of Enrs.
|
|
77
|
+
*/ getKadValues() {
|
|
78
78
|
return [];
|
|
79
79
|
}
|
|
80
80
|
runRandomNodesQuery() {
|
|
@@ -32,6 +32,8 @@ export declare class LibP2PService<T extends P2PClientType = P2PClientType.Full>
|
|
|
32
32
|
private discoveryRunningPromise?;
|
|
33
33
|
private attestationValidator;
|
|
34
34
|
private blockProposalValidator;
|
|
35
|
+
private protocolVersion;
|
|
36
|
+
private topicStrings;
|
|
35
37
|
reqresp: ReqResp;
|
|
36
38
|
private trustedPeersIds;
|
|
37
39
|
private feesCache;
|
|
@@ -79,7 +81,7 @@ export declare class LibP2PService<T extends P2PClientType = P2PClientType.Full>
|
|
|
79
81
|
* @param requests - The requests to send to the peers
|
|
80
82
|
* @returns The responses to the requests
|
|
81
83
|
*/
|
|
82
|
-
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(protocol: SubProtocol, requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[]): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>
|
|
84
|
+
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(protocol: SubProtocol, requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[]): Promise<(InstanceType<SubProtocolMap[SubProtocol]['response']> | undefined)[]>;
|
|
83
85
|
/**
|
|
84
86
|
* Get the ENR of the node
|
|
85
87
|
* @returns The ENR of the node
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p_service.d.ts","sourceRoot":"","sources":["../../../src/services/libp2p/libp2p_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAK9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACvH,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,KAAK,UAAU,EACf,aAAa,
|
|
1
|
+
{"version":3,"file":"libp2p_service.d.ts","sourceRoot":"","sources":["../../../src/services/libp2p/libp2p_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAK9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK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M,EAAE,MAAM,EAAE,MAAM;IAiB5E;;;;;OAKG;YACW,0BAA0B;YA+B1B,oBAAoB;YAyBpB,yBAAyB;IA4BvC;;;OAGG;YAOW,oBAAoB;IAIlC;;;OAGG;IACU,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,OAAO,EAAE,CAAC;IAYvD;;;;;;;;;;;;;OAaG;YAIW,mBAAmB;YAuBnB,oBAAoB;YAoBpB,UAAU;IAWxB;;;;;;;;OAQG;YACW,uBAAuB;IA+CrC;;;;;OAKG;YACW,cAAc;IA8B5B;;;;;;;;;;OAUG;YACW,wBAAwB;IAuBtC;;;;;OAKG;IAOU,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAUjG;;;;;OAKG;IAIU,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAWnF,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;YAI7B,WAAW;YAcX,UAAU;CAYzB"}
|
|
@@ -10,9 +10,10 @@ import { SerialQueue } from '@aztec/foundation/queue';
|
|
|
10
10
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
11
11
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
12
12
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
13
|
-
import { BlockAttestation, BlockProposal, P2PClientType, PeerErrorSeverity,
|
|
13
|
+
import { BlockAttestation, BlockProposal, P2PClientType, PeerErrorSeverity, TopicType, createTopicString, getTopicTypeForClientType, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
|
|
14
14
|
import { DatabasePublicStateSource, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
15
15
|
import { Tx } from '@aztec/stdlib/tx';
|
|
16
|
+
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
16
17
|
import { Attributes, OtelMetricsAdapter, WithTracer, trackSpan } from '@aztec/telemetry-client';
|
|
17
18
|
import { gossipsub } from '@chainsafe/libp2p-gossipsub';
|
|
18
19
|
import { createPeerScoreParams, createTopicScoreParams } from '@chainsafe/libp2p-gossipsub/score';
|
|
@@ -31,6 +32,7 @@ import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validat
|
|
|
31
32
|
import { DataTxValidator, DoubleSpendTxValidator, GasTxValidator, MetadataTxValidator, PhasesTxValidator, TxProofValidator } from '../../msg_validators/tx_validator/index.js';
|
|
32
33
|
import { GossipSubEvent } from '../../types/index.js';
|
|
33
34
|
import { convertToMultiaddr } from '../../util.js';
|
|
35
|
+
import { getVersions } from '../../versioning.js';
|
|
34
36
|
import { AztecDatastore } from '../data_store.js';
|
|
35
37
|
import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
|
|
36
38
|
import { gossipScoreThresholds } from '../gossipsub/scoring.js';
|
|
@@ -58,6 +60,8 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
58
60
|
// Message validators
|
|
59
61
|
attestationValidator;
|
|
60
62
|
blockProposalValidator;
|
|
63
|
+
protocolVersion;
|
|
64
|
+
topicStrings;
|
|
61
65
|
// Request and response sub service
|
|
62
66
|
reqresp;
|
|
63
67
|
// Trusted peers ids
|
|
@@ -70,7 +74,13 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
70
74
|
*/ blockReceivedCallback;
|
|
71
75
|
gossipSubEventHandler;
|
|
72
76
|
constructor(clientType, config, node, peerDiscoveryService, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger = createLogger('p2p:libp2p_service')){
|
|
73
|
-
super(telemetry, 'LibP2PService'), this.clientType = clientType, this.config = config, this.node = node, this.peerDiscoveryService = peerDiscoveryService, this.mempools = mempools, this.archiver = archiver, this.proofVerifier = proofVerifier, this.worldStateSynchronizer = worldStateSynchronizer, this.logger = logger, this.jobQueue = new SerialQueue(), this.trustedPeersIds = [];
|
|
77
|
+
super(telemetry, 'LibP2PService'), this.clientType = clientType, this.config = config, this.node = node, this.peerDiscoveryService = peerDiscoveryService, this.mempools = mempools, this.archiver = archiver, this.proofVerifier = proofVerifier, this.worldStateSynchronizer = worldStateSynchronizer, this.logger = logger, this.jobQueue = new SerialQueue(), this.protocolVersion = '', this.topicStrings = {}, this.trustedPeersIds = [];
|
|
78
|
+
const versions = getVersions(config);
|
|
79
|
+
this.protocolVersion = compressComponentVersions(versions);
|
|
80
|
+
logger.info(`Started libp2p service with protocol version ${this.protocolVersion}`);
|
|
81
|
+
this.topicStrings[TopicType.tx] = createTopicString(TopicType.tx, this.protocolVersion);
|
|
82
|
+
this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
|
|
83
|
+
this.topicStrings[TopicType.block_attestation] = createTopicString(TopicType.block_attestation, this.protocolVersion);
|
|
74
84
|
const peerScoring = new PeerScoring(config);
|
|
75
85
|
this.reqresp = new ReqResp(config, node, peerScoring);
|
|
76
86
|
this.peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, this.reqresp);
|
|
@@ -109,6 +119,11 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
109
119
|
list: bootstrapNodes
|
|
110
120
|
}));
|
|
111
121
|
}
|
|
122
|
+
const versions = getVersions(config);
|
|
123
|
+
const protocolVersion = compressComponentVersions(versions);
|
|
124
|
+
const txTopic = createTopicString(TopicType.tx, protocolVersion);
|
|
125
|
+
const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
|
|
126
|
+
const blockAttestationTopic = createTopicString(TopicType.block_attestation, protocolVersion);
|
|
112
127
|
const node = await createLibp2p({
|
|
113
128
|
start: false,
|
|
114
129
|
peerId,
|
|
@@ -168,24 +183,24 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
168
183
|
fastMsgIdFn: fastMsgIdFn,
|
|
169
184
|
dataTransform: new SnappyTransform(),
|
|
170
185
|
metricsRegister: otelMetricsAdapter,
|
|
171
|
-
metricsTopicStrToLabel: metricsTopicStrToLabels(),
|
|
186
|
+
metricsTopicStrToLabel: metricsTopicStrToLabels(protocolVersion),
|
|
172
187
|
asyncValidation: true,
|
|
173
188
|
scoreThresholds: gossipScoreThresholds,
|
|
174
189
|
scoreParams: createPeerScoreParams({
|
|
175
190
|
// IPColocation factor can be disabled for local testing - default to -5
|
|
176
191
|
IPColocationFactorWeight: config.debugDisableColocationPenalty ? 0 : -5.0,
|
|
177
192
|
topics: {
|
|
178
|
-
[
|
|
193
|
+
[txTopic]: createTopicScoreParams({
|
|
179
194
|
topicWeight: 1,
|
|
180
195
|
invalidMessageDeliveriesWeight: -20,
|
|
181
196
|
invalidMessageDeliveriesDecay: 0.5
|
|
182
197
|
}),
|
|
183
|
-
[
|
|
198
|
+
[blockAttestationTopic]: createTopicScoreParams({
|
|
184
199
|
topicWeight: 1,
|
|
185
200
|
invalidMessageDeliveriesWeight: -20,
|
|
186
201
|
invalidMessageDeliveriesDecay: 0.5
|
|
187
202
|
}),
|
|
188
|
-
[
|
|
203
|
+
[blockProposalTopic]: createTopicScoreParams({
|
|
189
204
|
topicWeight: 1,
|
|
190
205
|
invalidMessageDeliveriesWeight: -20,
|
|
191
206
|
invalidMessageDeliveriesDecay: 0.5
|
|
@@ -217,12 +232,12 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
217
232
|
const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
|
|
218
233
|
// Start job queue, peer discovery service and libp2p node
|
|
219
234
|
this.jobQueue.start();
|
|
220
|
-
await this.peerManager.
|
|
235
|
+
await this.peerManager.initializePeers();
|
|
221
236
|
await this.peerDiscoveryService.start();
|
|
222
237
|
await this.node.start();
|
|
223
238
|
// Subscribe to standard GossipSub topics by default
|
|
224
239
|
for (const topic of getTopicTypeForClientType(this.clientType)){
|
|
225
|
-
this.subscribeToTopic(
|
|
240
|
+
this.subscribeToTopic(this.topicStrings[topic]);
|
|
226
241
|
}
|
|
227
242
|
// Create request response protocol handlers
|
|
228
243
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
@@ -345,13 +360,13 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
345
360
|
* @param topic - The message's topic.
|
|
346
361
|
* @param data - The message data
|
|
347
362
|
*/ async handleNewGossipMessage(msg, msgId, source) {
|
|
348
|
-
if (msg.topic ===
|
|
363
|
+
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
349
364
|
await this.handleGossipedTx(msg, msgId, source);
|
|
350
365
|
}
|
|
351
|
-
if (msg.topic ===
|
|
366
|
+
if (msg.topic === this.topicStrings[TopicType.block_attestation] && this.clientType === P2PClientType.Full) {
|
|
352
367
|
await this.processAttestationFromPeer(msg, msgId, source);
|
|
353
368
|
}
|
|
354
|
-
if (msg.topic
|
|
369
|
+
if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
355
370
|
await this.processBlockFromPeer(msg, msgId, source);
|
|
356
371
|
}
|
|
357
372
|
return;
|
|
@@ -667,6 +682,7 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
667
682
|
*/ async validateBlockProposal(peerId, block) {
|
|
668
683
|
const severity = await this.blockProposalValidator.validate(block);
|
|
669
684
|
if (severity) {
|
|
685
|
+
this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
670
686
|
this.peerManager.penalizePeer(peerId, severity);
|
|
671
687
|
return false;
|
|
672
688
|
}
|
|
@@ -681,7 +697,7 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
681
697
|
this.logger.trace(`Sending message ${identifier}`, {
|
|
682
698
|
p2pMessageIdentifier: identifier
|
|
683
699
|
});
|
|
684
|
-
const recipientsNum = await this.publishToTopic(parent.p2pTopic, message.toBuffer());
|
|
700
|
+
const recipientsNum = await this.publishToTopic(this.topicStrings[parent.p2pTopic], message.toBuffer());
|
|
685
701
|
this.logger.debug(`Sent message ${identifier} to ${recipientsNum} peers`, {
|
|
686
702
|
p2pMessageIdentifier: identifier,
|
|
687
703
|
sourcePeer: this.node.peerId.toString()
|