@aztec/p2p 0.85.0-nightly.20250424 → 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/client/p2p_client.d.ts +37 -2
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +42 -14
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +2 -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 +14 -0
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +2 -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 +6 -0
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +12 -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/testbench/p2p_client_testbench_worker.js +2 -0
- package/package.json +12 -12
- package/src/client/p2p_client.ts +188 -127
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +16 -0
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +7 -0
- package/src/mem_pools/tx_pool/tx_pool.ts +14 -0
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +43 -0
- package/src/testbench/p2p_client_testbench_worker.ts +2 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
2
|
import type { L2BlockId, L2BlockSource, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
|
|
3
3
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
4
|
-
import type { P2PApi, PeerInfo
|
|
4
|
+
import type { P2PApi, PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
5
5
|
import { BlockAttestation, type BlockProposal, type P2PClientType } from '@aztec/stdlib/p2p';
|
|
6
6
|
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
7
7
|
import { type TelemetryClient, WithTracer } from '@aztec/telemetry-client';
|
|
@@ -34,7 +34,7 @@ export interface P2PSyncState {
|
|
|
34
34
|
/**
|
|
35
35
|
* Interface of a P2P client.
|
|
36
36
|
**/
|
|
37
|
-
export type P2P<T extends P2PClientType = P2PClientType.Full> =
|
|
37
|
+
export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApi<T> & {
|
|
38
38
|
/**
|
|
39
39
|
* Broadcasts a block proposal to other peers.
|
|
40
40
|
*
|
|
@@ -64,6 +64,11 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = ProverCoordinati
|
|
|
64
64
|
* @param tx - The transaction.
|
|
65
65
|
**/
|
|
66
66
|
sendTx(tx: Tx): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Adds transactions to the pool. Does not send to peers or validate the tx.
|
|
69
|
+
* @param txs - The transactions.
|
|
70
|
+
**/
|
|
71
|
+
addTxs(txs: Tx[]): Promise<void>;
|
|
67
72
|
/**
|
|
68
73
|
* Deletes 'txs' from the pool, given hashes.
|
|
69
74
|
* NOT used if we use sendTx as reconcileTxPool will handle this.
|
|
@@ -76,12 +81,30 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = ProverCoordinati
|
|
|
76
81
|
* @returns A single tx or undefined.
|
|
77
82
|
*/
|
|
78
83
|
getTxByHashFromPool(txHash: TxHash): Promise<Tx | undefined>;
|
|
84
|
+
/**
|
|
85
|
+
* Returns transactions in the transaction pool by hash.
|
|
86
|
+
* @param txHashes - Hashes of txs to return.
|
|
87
|
+
* @returns An array of txs or undefined.
|
|
88
|
+
*/
|
|
89
|
+
getTxsByHashFromPool(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if transactions exist in the pool
|
|
92
|
+
* @param txHashes - The hashes of the transactions to check for
|
|
93
|
+
* @returns True or False for each hash
|
|
94
|
+
*/
|
|
95
|
+
hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]>;
|
|
79
96
|
/**
|
|
80
97
|
* Returns a transaction in the transaction pool by its hash, requesting it from the network if it is not found.
|
|
81
98
|
* @param txHash - Hash of tx to return.
|
|
82
99
|
* @returns A single tx or undefined.
|
|
83
100
|
*/
|
|
84
101
|
getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
102
|
+
/**
|
|
103
|
+
* Returns transactions in the transaction pool by hash, requesting from the network if not found.
|
|
104
|
+
* @param txHashes - Hashes of tx to return.
|
|
105
|
+
* @returns An array of tx or undefined.
|
|
106
|
+
*/
|
|
107
|
+
getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
85
108
|
/**
|
|
86
109
|
* Returns an archived transaction from the transaction pool by its hash.
|
|
87
110
|
* @param txHash - Hash of tx to return.
|
|
@@ -222,6 +245,13 @@ export declare class P2PClient<T extends P2PClientType = P2PClientType.Full> ext
|
|
|
222
245
|
* @returns A single tx or undefined.
|
|
223
246
|
*/
|
|
224
247
|
getTxByHashFromPool(txHash: TxHash): Promise<Tx | undefined>;
|
|
248
|
+
/**
|
|
249
|
+
* Returns transactions in the transaction pool by hash.
|
|
250
|
+
* @param txHashes - Hashes of the transactions to look for.
|
|
251
|
+
* @returns The txs found, not necessarily on the same order as the hashes.
|
|
252
|
+
*/
|
|
253
|
+
getTxsByHashFromPool(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
254
|
+
hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]>;
|
|
225
255
|
/**
|
|
226
256
|
* Returns a transaction in the transaction pool by its hash.
|
|
227
257
|
* If the transaction is not in the pool, it will be requested from the network.
|
|
@@ -248,6 +278,11 @@ export declare class P2PClient<T extends P2PClientType = P2PClientType.Full> ext
|
|
|
248
278
|
* @returns Empty promise.
|
|
249
279
|
**/
|
|
250
280
|
sendTx(tx: Tx): Promise<void>;
|
|
281
|
+
/**
|
|
282
|
+
* Adds transactions to the pool. Does not send to peers or validate the txs.
|
|
283
|
+
* @param txs - The transactions.
|
|
284
|
+
**/
|
|
285
|
+
addTxs(txs: Tx[]): Promise<void>;
|
|
251
286
|
/**
|
|
252
287
|
* Returns whether the given tx hash is flagged as pending or mined.
|
|
253
288
|
* @param txHash - Hash of the tx to query.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p2p_client.d.ts","sourceRoot":"","sources":["../../src/client/p2p_client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAsC,MAAM,iBAAiB,CAAC;AAC7F,OAAO,KAAK,EAEV,SAAS,EACT,aAAa,EACb,kBAAkB,EAClB,MAAM,EAEP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"p2p_client.d.ts","sourceRoot":"","sources":["../../src/client/p2p_client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAsC,MAAM,iBAAiB,CAAC;AAC7F,OAAO,KAAK,EAEV,SAAS,EACT,aAAa,EACb,kBAAkB,EAClB,MAAM,EAEP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAoB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC/G,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAEL,KAAK,eAAe,EAEpB,UAAU,EAGX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK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OAGG;IACI,OAAO;IAId;;;OAGG;IACU,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvD;;;OAGG;IACU,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvD,iEAAiE;IACpD,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAInD;;;OAGG;IACU,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC;IAgB/C;;;;OAIG;YACW,wBAAwB;YAOxB,qBAAqB;IAUnC;;;;OAIG;YACW,mBAAmB;IAQjC;;;;OAIG;YACW,oBAAoB;IAiBlC;;;;OAIG;YACW,oBAAoB;IAgClC;;;OAGG;YACW,mBAAmB;YAkDnB,qBAAqB;IAenC;;;OAGG;IACH,OAAO,CAAC,eAAe;CAKxB"}
|
|
@@ -303,6 +303,16 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
|
|
|
303
303
|
return this.txPool.getTxByHash(txHash);
|
|
304
304
|
}
|
|
305
305
|
/**
|
|
306
|
+
* Returns transactions in the transaction pool by hash.
|
|
307
|
+
* @param txHashes - Hashes of the transactions to look for.
|
|
308
|
+
* @returns The txs found, not necessarily on the same order as the hashes.
|
|
309
|
+
*/ getTxsByHashFromPool(txHashes) {
|
|
310
|
+
return this.txPool.getTxsByHash(txHashes);
|
|
311
|
+
}
|
|
312
|
+
hasTxsInPool(txHashes) {
|
|
313
|
+
return this.txPool.hasTxs(txHashes);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
306
316
|
* Returns a transaction in the transaction pool by its hash.
|
|
307
317
|
* If the transaction is not in the pool, it will be requested from the network.
|
|
308
318
|
* @param txHash - Hash of the transaction to look for in the pool.
|
|
@@ -344,13 +354,19 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
|
|
|
344
354
|
* @param tx - The tx to verify.
|
|
345
355
|
* @returns Empty promise.
|
|
346
356
|
**/ async sendTx(tx) {
|
|
347
|
-
this
|
|
348
|
-
await this.txPool.addTxs([
|
|
357
|
+
await this.addTxs([
|
|
349
358
|
tx
|
|
350
359
|
]);
|
|
351
360
|
this.p2pService.propagate(tx);
|
|
352
361
|
}
|
|
353
362
|
/**
|
|
363
|
+
* Adds transactions to the pool. Does not send to peers or validate the txs.
|
|
364
|
+
* @param txs - The transactions.
|
|
365
|
+
**/ async addTxs(txs) {
|
|
366
|
+
this.#assertIsReady();
|
|
367
|
+
await this.txPool.addTxs(txs);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
354
370
|
* Returns whether the given tx hash is flagged as pending or mined.
|
|
355
371
|
* @param txHash - Hash of the tx to query.
|
|
356
372
|
* @returns Pending or mined depending on its status, or undefined if not found.
|
|
@@ -488,28 +504,40 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
|
|
|
488
504
|
* Updates the tx pool after a chain prune.
|
|
489
505
|
* @param latestBlock - The block number the chain was pruned to.
|
|
490
506
|
*/ async handlePruneL2Blocks(latestBlock) {
|
|
491
|
-
|
|
507
|
+
// NOTE: temporary fix for alphanet, deleting ALL txs that were in the epoch from the pool #13723
|
|
508
|
+
// TODO: undo once fixed: #13770
|
|
509
|
+
const txsToDelete = new Set();
|
|
510
|
+
const minedTxs = await this.txPool.getMinedTxHashes();
|
|
511
|
+
for (const [txHash, blockNumber] of minedTxs){
|
|
512
|
+
if (blockNumber > latestBlock) {
|
|
513
|
+
txsToDelete.add(txHash);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
// Find transactions that reference pruned blocks in their historical header
|
|
492
517
|
for (const tx of (await this.txPool.getAllTxs())){
|
|
493
518
|
// every tx that's been generated against a block that has now been pruned is no longer valid
|
|
494
519
|
if (tx.data.constants.historicalHeader.globalVariables.blockNumber.toNumber() > latestBlock) {
|
|
495
|
-
|
|
520
|
+
const txHash = await tx.getTxHash();
|
|
521
|
+
txsToDelete.add(txHash);
|
|
496
522
|
}
|
|
497
523
|
}
|
|
498
|
-
this.log.info(`Detected chain prune. Removing invalid txs count=${txsToDelete.
|
|
524
|
+
this.log.info(`Detected chain prune. Removing invalid txs count=${txsToDelete.size} newLatestBlock=${latestBlock} previousLatestBlock=${await this.getSyncedLatestBlockNum()}`);
|
|
499
525
|
// delete invalid txs (both pending and mined)
|
|
500
|
-
await this.txPool.deleteTxs(txsToDelete);
|
|
526
|
+
await this.txPool.deleteTxs(Array.from(txsToDelete));
|
|
501
527
|
// everything left in the mined set was built against a block on the proven chain so its still valid
|
|
502
528
|
// move back to pending the txs that were reorged out of the chain
|
|
503
529
|
// NOTE: we can't move _all_ txs back to pending because the tx pool could keep hold of mined txs for longer
|
|
504
530
|
// (see this.keepProvenTxsFor)
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
531
|
+
// NOTE: given current fix for alphanet, the code below is redundant as all these txs will be deleted.
|
|
532
|
+
// TODO: bring back once fixed: #13770
|
|
533
|
+
// const txsToMoveToPending: TxHash[] = [];
|
|
534
|
+
// for (const [txHash, blockNumber] of minedTxs) {
|
|
535
|
+
// if (blockNumber > latestBlock) {
|
|
536
|
+
// txsToMoveToPending.push(txHash);
|
|
537
|
+
// }
|
|
538
|
+
// }
|
|
539
|
+
// this.log.info(`Moving ${txsToMoveToPending.length} mined txs back to pending`);
|
|
540
|
+
// await this.txPool.markMinedAsPending(txsToMoveToPending);
|
|
513
541
|
await this.synchedLatestBlockNumber.set(latestBlock);
|
|
514
542
|
// no need to update block hashes, as they will be updated as new blocks are added
|
|
515
543
|
}
|
|
@@ -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.
|
|
@@ -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,OAAO,KAAK,EAAE,iBAAiB,EAA0D,MAAM,iBAAiB,CAAC;AAGjH,OAAO,KAAK,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAIxG,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAEnF,OAAO,EAAE,YAAY,EAAE,MAAM,oDAAoD,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AAGpF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;GAEG;AACH,qBAAa,aAAc,YAAW,MAAM;;IA8C1C;;;;;;;OAOG;gBAED,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,iBAAiB,EAC1B,sBAAsB,EAAE,sBAAsB,EAC9C,SAAS,GAAE,eAAsC,EACjD,MAAM,GAAE;QACN,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,eAAe,CAAC,EAAE,MAAM,CAAC;KACrB,EACN,GAAG,SAA8B;IAsB5B,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsCnE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAqC/C,kBAAkB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKvC,gBAAgB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM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;OAIG;YACW,UAAU;IA4BxB;;;;;;OAMG;YACW,mBAAmB;IAsCjC;;;;;;;;;;OAUG;YACW,0BAA0B;IAwDxC;;;;;OAKG;YACW,yBAAyB;YAqCzB,mBAAmB;YAMnB,sBAAsB;CAMrC"}
|
|
@@ -150,6 +150,20 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
150
150
|
}
|
|
151
151
|
return undefined;
|
|
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.
|
|
@@ -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.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory_tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/memory_tx_pool.ts"],"names":[],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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
|
}
|
|
@@ -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.
|
|
@@ -1 +1 @@
|
|
|
1
|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H,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAEpC;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAExC;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAEjE;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;IAEtE;;;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);
|
|
@@ -29,6 +29,8 @@ function mockTxPool() {
|
|
|
29
29
|
getPendingTxHashes: ()=>Promise.resolve([]),
|
|
30
30
|
getMinedTxHashes: ()=>Promise.resolve([]),
|
|
31
31
|
getTxStatus: ()=>Promise.resolve(TxStatus.PENDING),
|
|
32
|
+
getTxsByHash: ()=>Promise.resolve([]),
|
|
33
|
+
hasTxs: ()=>Promise.resolve([]),
|
|
32
34
|
setMaxTxPoolSize: ()=>Promise.resolve()
|
|
33
35
|
};
|
|
34
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/p2p",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -63,16 +63,16 @@
|
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@aztec/constants": "0.
|
|
67
|
-
"@aztec/epoch-cache": "0.
|
|
68
|
-
"@aztec/foundation": "0.
|
|
69
|
-
"@aztec/kv-store": "0.
|
|
70
|
-
"@aztec/noir-contracts.js": "0.
|
|
71
|
-
"@aztec/noir-protocol-circuits-types": "0.
|
|
72
|
-
"@aztec/protocol-contracts": "0.
|
|
73
|
-
"@aztec/simulator": "0.
|
|
74
|
-
"@aztec/stdlib": "0.
|
|
75
|
-
"@aztec/telemetry-client": "0.
|
|
66
|
+
"@aztec/constants": "0.86.0",
|
|
67
|
+
"@aztec/epoch-cache": "0.86.0",
|
|
68
|
+
"@aztec/foundation": "0.86.0",
|
|
69
|
+
"@aztec/kv-store": "0.86.0",
|
|
70
|
+
"@aztec/noir-contracts.js": "0.86.0",
|
|
71
|
+
"@aztec/noir-protocol-circuits-types": "0.86.0",
|
|
72
|
+
"@aztec/protocol-contracts": "0.86.0",
|
|
73
|
+
"@aztec/simulator": "0.86.0",
|
|
74
|
+
"@aztec/stdlib": "0.86.0",
|
|
75
|
+
"@aztec/telemetry-client": "0.86.0",
|
|
76
76
|
"@chainsafe/discv5": "9.0.0",
|
|
77
77
|
"@chainsafe/enr": "3.0.0",
|
|
78
78
|
"@chainsafe/libp2p-gossipsub": "13.0.0",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"xxhash-wasm": "^1.1.0"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
|
-
"@aztec/archiver": "0.
|
|
104
|
+
"@aztec/archiver": "0.86.0",
|
|
105
105
|
"@jest/globals": "^29.5.0",
|
|
106
106
|
"@types/jest": "^29.5.0",
|
|
107
107
|
"@types/node": "^18.14.6",
|
package/src/client/p2p_client.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
PublishedL2Block,
|
|
11
11
|
} from '@aztec/stdlib/block';
|
|
12
12
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
13
|
-
import type { P2PApi, PeerInfo
|
|
13
|
+
import type { P2PApi, PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
14
14
|
import { BlockAttestation, type BlockProposal, ConsensusPayload, type P2PClientType } from '@aztec/stdlib/p2p';
|
|
15
15
|
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
16
16
|
import {
|
|
@@ -58,118 +58,144 @@ export interface P2PSyncState {
|
|
|
58
58
|
/**
|
|
59
59
|
* Interface of a P2P client.
|
|
60
60
|
**/
|
|
61
|
-
export type P2P<T extends P2PClientType = P2PClientType.Full> =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
61
|
+
export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApi<T> & {
|
|
62
|
+
/**
|
|
63
|
+
* Broadcasts a block proposal to other peers.
|
|
64
|
+
*
|
|
65
|
+
* @param proposal - the block proposal
|
|
66
|
+
*/
|
|
67
|
+
broadcastProposal(proposal: BlockProposal): void;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Registers a callback from the validator client that determines how to behave when
|
|
71
|
+
* foreign block proposals are received
|
|
72
|
+
*
|
|
73
|
+
* @param handler - A function taking a received block proposal and producing an attestation
|
|
74
|
+
*/
|
|
75
|
+
// REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
76
|
+
// ^ This pattern is not my favorite (md)
|
|
77
|
+
registerBlockProposalHandler(handler: (block: BlockProposal) => Promise<BlockAttestation | undefined>): void;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Request a list of transactions from another peer by their tx hashes.
|
|
81
|
+
* @param txHashes - Hashes of the txs to query.
|
|
82
|
+
* @returns A list of transactions or undefined if the transactions are not found.
|
|
83
|
+
*/
|
|
84
|
+
requestTxs(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Request a transaction from another peer by its tx hash.
|
|
88
|
+
* @param txHash - Hash of the tx to query.
|
|
89
|
+
*/
|
|
90
|
+
requestTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Verifies the 'tx' and, if valid, adds it to local tx pool and forwards it to other peers.
|
|
94
|
+
* @param tx - The transaction.
|
|
95
|
+
**/
|
|
96
|
+
sendTx(tx: Tx): Promise<void>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Adds transactions to the pool. Does not send to peers or validate the tx.
|
|
100
|
+
* @param txs - The transactions.
|
|
101
|
+
**/
|
|
102
|
+
addTxs(txs: Tx[]): Promise<void>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Deletes 'txs' from the pool, given hashes.
|
|
106
|
+
* NOT used if we use sendTx as reconcileTxPool will handle this.
|
|
107
|
+
* @param txHashes - Hashes to check.
|
|
108
|
+
**/
|
|
109
|
+
deleteTxs(txHashes: TxHash[]): Promise<void>;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Returns a transaction in the transaction pool by its hash.
|
|
113
|
+
* @param txHash - Hash of tx to return.
|
|
114
|
+
* @returns A single tx or undefined.
|
|
115
|
+
*/
|
|
116
|
+
getTxByHashFromPool(txHash: TxHash): Promise<Tx | undefined>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Returns transactions in the transaction pool by hash.
|
|
120
|
+
* @param txHashes - Hashes of txs to return.
|
|
121
|
+
* @returns An array of txs or undefined.
|
|
122
|
+
*/
|
|
123
|
+
getTxsByHashFromPool(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Checks if transactions exist in the pool
|
|
127
|
+
* @param txHashes - The hashes of the transactions to check for
|
|
128
|
+
* @returns True or False for each hash
|
|
129
|
+
*/
|
|
130
|
+
hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns a transaction in the transaction pool by its hash, requesting it from the network if it is not found.
|
|
134
|
+
* @param txHash - Hash of tx to return.
|
|
135
|
+
* @returns A single tx or undefined.
|
|
136
|
+
*/
|
|
137
|
+
getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Returns transactions in the transaction pool by hash, requesting from the network if not found.
|
|
141
|
+
* @param txHashes - Hashes of tx to return.
|
|
142
|
+
* @returns An array of tx or undefined.
|
|
143
|
+
*/
|
|
144
|
+
getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Returns an archived transaction from the transaction pool by its hash.
|
|
148
|
+
* @param txHash - Hash of tx to return.
|
|
149
|
+
* @returns A single tx or undefined.
|
|
150
|
+
*/
|
|
151
|
+
getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Returns whether the given tx hash is flagged as pending or mined.
|
|
155
|
+
* @param txHash - Hash of the tx to query.
|
|
156
|
+
* @returns Pending or mined depending on its status, or undefined if not found.
|
|
157
|
+
*/
|
|
158
|
+
getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined>;
|
|
159
|
+
|
|
160
|
+
/** Returns an iterator over pending txs on the mempool. */
|
|
161
|
+
iteratePendingTxs(): AsyncIterableIterator<Tx>;
|
|
162
|
+
|
|
163
|
+
/** Returns the number of pending txs in the mempool. */
|
|
164
|
+
getPendingTxCount(): Promise<number>;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Starts the p2p client.
|
|
168
|
+
* @returns A promise signalling the completion of the block sync.
|
|
169
|
+
*/
|
|
170
|
+
start(): Promise<void>;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Stops the p2p client.
|
|
174
|
+
* @returns A promise signalling the completion of the stop process.
|
|
175
|
+
*/
|
|
176
|
+
stop(): Promise<void>;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Indicates if the p2p client is ready for transaction submission.
|
|
180
|
+
* @returns A boolean flag indicating readiness.
|
|
181
|
+
*/
|
|
182
|
+
isReady(): boolean;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Returns the current status of the p2p client.
|
|
186
|
+
*/
|
|
187
|
+
getStatus(): Promise<P2PSyncState>;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Returns the ENR of this node, if any.
|
|
191
|
+
*/
|
|
192
|
+
getEnr(): ENR | undefined;
|
|
193
|
+
|
|
194
|
+
/** Identifies a p2p client. */
|
|
195
|
+
isP2PClient(): true;
|
|
196
|
+
|
|
197
|
+
updateP2PConfig(config: Partial<P2PConfig>): Promise<void>;
|
|
198
|
+
};
|
|
173
199
|
|
|
174
200
|
/**
|
|
175
201
|
* The P2P client implementation.
|
|
@@ -520,6 +546,19 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
520
546
|
return this.txPool.getTxByHash(txHash);
|
|
521
547
|
}
|
|
522
548
|
|
|
549
|
+
/**
|
|
550
|
+
* Returns transactions in the transaction pool by hash.
|
|
551
|
+
* @param txHashes - Hashes of the transactions to look for.
|
|
552
|
+
* @returns The txs found, not necessarily on the same order as the hashes.
|
|
553
|
+
*/
|
|
554
|
+
getTxsByHashFromPool(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
555
|
+
return this.txPool.getTxsByHash(txHashes);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]> {
|
|
559
|
+
return this.txPool.hasTxs(txHashes);
|
|
560
|
+
}
|
|
561
|
+
|
|
523
562
|
/**
|
|
524
563
|
* Returns a transaction in the transaction pool by its hash.
|
|
525
564
|
* If the transaction is not in the pool, it will be requested from the network.
|
|
@@ -571,11 +610,19 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
571
610
|
* @returns Empty promise.
|
|
572
611
|
**/
|
|
573
612
|
public async sendTx(tx: Tx): Promise<void> {
|
|
574
|
-
this
|
|
575
|
-
await this.txPool.addTxs([tx]);
|
|
613
|
+
await this.addTxs([tx]);
|
|
576
614
|
this.p2pService.propagate(tx);
|
|
577
615
|
}
|
|
578
616
|
|
|
617
|
+
/**
|
|
618
|
+
* Adds transactions to the pool. Does not send to peers or validate the txs.
|
|
619
|
+
* @param txs - The transactions.
|
|
620
|
+
**/
|
|
621
|
+
public async addTxs(txs: Tx[]): Promise<void> {
|
|
622
|
+
this.#assertIsReady();
|
|
623
|
+
await this.txPool.addTxs(txs);
|
|
624
|
+
}
|
|
625
|
+
|
|
579
626
|
/**
|
|
580
627
|
* Returns whether the given tx hash is flagged as pending or mined.
|
|
581
628
|
* @param txHash - Hash of the tx to query.
|
|
@@ -752,36 +799,50 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
752
799
|
* @param latestBlock - The block number the chain was pruned to.
|
|
753
800
|
*/
|
|
754
801
|
private async handlePruneL2Blocks(latestBlock: number): Promise<void> {
|
|
755
|
-
|
|
802
|
+
// NOTE: temporary fix for alphanet, deleting ALL txs that were in the epoch from the pool #13723
|
|
803
|
+
// TODO: undo once fixed: #13770
|
|
804
|
+
const txsToDelete = new Set<TxHash>();
|
|
805
|
+
const minedTxs = await this.txPool.getMinedTxHashes();
|
|
806
|
+
for (const [txHash, blockNumber] of minedTxs) {
|
|
807
|
+
if (blockNumber > latestBlock) {
|
|
808
|
+
txsToDelete.add(txHash);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// Find transactions that reference pruned blocks in their historical header
|
|
756
813
|
for (const tx of await this.txPool.getAllTxs()) {
|
|
757
814
|
// every tx that's been generated against a block that has now been pruned is no longer valid
|
|
758
815
|
if (tx.data.constants.historicalHeader.globalVariables.blockNumber.toNumber() > latestBlock) {
|
|
759
|
-
|
|
816
|
+
const txHash = await tx.getTxHash();
|
|
817
|
+
txsToDelete.add(txHash);
|
|
760
818
|
}
|
|
761
819
|
}
|
|
762
820
|
|
|
763
821
|
this.log.info(
|
|
764
822
|
`Detected chain prune. Removing invalid txs count=${
|
|
765
|
-
txsToDelete.
|
|
823
|
+
txsToDelete.size
|
|
766
824
|
} newLatestBlock=${latestBlock} previousLatestBlock=${await this.getSyncedLatestBlockNum()}`,
|
|
767
825
|
);
|
|
768
826
|
|
|
769
827
|
// delete invalid txs (both pending and mined)
|
|
770
|
-
await this.txPool.deleteTxs(txsToDelete);
|
|
828
|
+
await this.txPool.deleteTxs(Array.from(txsToDelete));
|
|
771
829
|
|
|
772
830
|
// everything left in the mined set was built against a block on the proven chain so its still valid
|
|
773
831
|
// move back to pending the txs that were reorged out of the chain
|
|
774
832
|
// NOTE: we can't move _all_ txs back to pending because the tx pool could keep hold of mined txs for longer
|
|
775
833
|
// (see this.keepProvenTxsFor)
|
|
776
|
-
const txsToMoveToPending: TxHash[] = [];
|
|
777
|
-
for (const [txHash, blockNumber] of await this.txPool.getMinedTxHashes()) {
|
|
778
|
-
if (blockNumber > latestBlock) {
|
|
779
|
-
txsToMoveToPending.push(txHash);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
834
|
|
|
783
|
-
|
|
784
|
-
|
|
835
|
+
// NOTE: given current fix for alphanet, the code below is redundant as all these txs will be deleted.
|
|
836
|
+
// TODO: bring back once fixed: #13770
|
|
837
|
+
// const txsToMoveToPending: TxHash[] = [];
|
|
838
|
+
// for (const [txHash, blockNumber] of minedTxs) {
|
|
839
|
+
// if (blockNumber > latestBlock) {
|
|
840
|
+
// txsToMoveToPending.push(txHash);
|
|
841
|
+
// }
|
|
842
|
+
// }
|
|
843
|
+
|
|
844
|
+
// this.log.info(`Moving ${txsToMoveToPending.length} mined txs back to pending`);
|
|
845
|
+
// await this.txPool.markMinedAsPending(txsToMoveToPending);
|
|
785
846
|
|
|
786
847
|
await this.synchedLatestBlockNumber.set(latestBlock);
|
|
787
848
|
// no need to update block hashes, as they will be updated as new blocks are added
|
|
@@ -218,6 +218,22 @@ export class AztecKVTxPool implements TxPool {
|
|
|
218
218
|
return undefined;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
async getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
222
|
+
const txs = await Promise.all(txHashes.map(txHash => this.#txs.getAsync(txHash.toString())));
|
|
223
|
+
return txs.map((buffer, index) => {
|
|
224
|
+
if (buffer) {
|
|
225
|
+
const tx = Tx.fromBuffer(buffer);
|
|
226
|
+
tx.setTxHash(txHashes[index]);
|
|
227
|
+
return tx;
|
|
228
|
+
}
|
|
229
|
+
return undefined;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async hasTxs(txHashes: TxHash[]): Promise<boolean[]> {
|
|
234
|
+
return await Promise.all(txHashes.map(txHash => this.#txs.hasAsync(txHash.toString())));
|
|
235
|
+
}
|
|
236
|
+
|
|
221
237
|
/**
|
|
222
238
|
* Checks if an archived tx exists and returns it.
|
|
223
239
|
* @param txHash - The tx hash.
|
|
@@ -103,6 +103,13 @@ export class InMemoryTxPool implements TxPool {
|
|
|
103
103
|
return Promise.resolve(result === undefined ? undefined : Tx.clone(result));
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
107
|
+
return Promise.all(txHashes.map(txHash => this.getTxByHash(txHash)));
|
|
108
|
+
}
|
|
109
|
+
hasTxs(txHashes: TxHash[]): Promise<boolean[]> {
|
|
110
|
+
return Promise.resolve(txHashes.map(txHash => this.txs.has(txHash.toBigInt())));
|
|
111
|
+
}
|
|
112
|
+
|
|
106
113
|
public getArchivedTxByHash(): Promise<Tx | undefined> {
|
|
107
114
|
return Promise.resolve(undefined);
|
|
108
115
|
}
|
|
@@ -17,6 +17,20 @@ export interface TxPool {
|
|
|
17
17
|
*/
|
|
18
18
|
getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Checks if transactions exist in the pool and returns them.
|
|
22
|
+
* @param txHashes - The hashes of the transactions
|
|
23
|
+
* @returns The transactions, if found, 'undefined' otherwise.
|
|
24
|
+
*/
|
|
25
|
+
getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Checks if transactions exist in the pool
|
|
29
|
+
* @param txHashes - The hashes of the transactions to check for
|
|
30
|
+
* @returns True or False for each tx hash
|
|
31
|
+
*/
|
|
32
|
+
hasTxs(txHashes: TxHash[]): Promise<boolean[]>;
|
|
33
|
+
|
|
20
34
|
/**
|
|
21
35
|
* Checks if an archived transaction exists in the pool and returns it.
|
|
22
36
|
* @param txHash - The hash of the transaction, used as an ID.
|
|
@@ -110,6 +110,49 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
110
110
|
);
|
|
111
111
|
});
|
|
112
112
|
|
|
113
|
+
it('Returns txs by their hash', async () => {
|
|
114
|
+
const tx1 = await mockTx(1);
|
|
115
|
+
const tx2 = await mockTx(2);
|
|
116
|
+
const tx3 = await mockTx(3);
|
|
117
|
+
|
|
118
|
+
await pool.addTxs([tx1, tx2, tx3]);
|
|
119
|
+
|
|
120
|
+
const requestedTxs = await pool.getTxsByHash([await tx1.getTxHash(), await tx3.getTxHash()]);
|
|
121
|
+
expect(requestedTxs).toHaveLength(2);
|
|
122
|
+
expect(requestedTxs).toEqual(expect.arrayContaining([tx1, tx3]));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('Returns a large number of transactions by their hash', async () => {
|
|
126
|
+
const numTxs = 1000;
|
|
127
|
+
const txs = await Promise.all(Array.from({ length: numTxs }, (_, i) => mockTx(i)));
|
|
128
|
+
const hashes = await Promise.all(txs.map(tx => tx.getTxHash()));
|
|
129
|
+
await pool.addTxs(txs);
|
|
130
|
+
const requestedTxs = await pool.getTxsByHash(hashes);
|
|
131
|
+
expect(requestedTxs).toHaveLength(numTxs);
|
|
132
|
+
expect(requestedTxs).toEqual(expect.arrayContaining(txs));
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('Returns whether or not txs exist', async () => {
|
|
136
|
+
const tx1 = await mockTx(1);
|
|
137
|
+
const tx2 = await mockTx(2);
|
|
138
|
+
const tx3 = await mockTx(3);
|
|
139
|
+
|
|
140
|
+
await pool.addTxs([tx1, tx2, tx3]);
|
|
141
|
+
|
|
142
|
+
const tx4 = await mockTx(4);
|
|
143
|
+
const tx5 = await mockTx(5);
|
|
144
|
+
|
|
145
|
+
const availability = await pool.hasTxs([
|
|
146
|
+
await tx1.getTxHash(),
|
|
147
|
+
await tx2.getTxHash(),
|
|
148
|
+
await tx3.getTxHash(),
|
|
149
|
+
await tx4.getTxHash(),
|
|
150
|
+
await tx5.getTxHash(),
|
|
151
|
+
]);
|
|
152
|
+
expect(availability).toHaveLength(5);
|
|
153
|
+
expect(availability).toEqual(expect.arrayContaining([true, true, true, false, false]));
|
|
154
|
+
});
|
|
155
|
+
|
|
113
156
|
it('Returns pending tx hashes sorted by priority', async () => {
|
|
114
157
|
const withPriorityFee = (tx: Tx, fee: number) => {
|
|
115
158
|
unfreeze(tx.data.constants.txContext.gasSettings).maxPriorityFeesPerGas = new GasFees(fee, fee);
|
|
@@ -45,6 +45,8 @@ function mockTxPool(): TxPool {
|
|
|
45
45
|
getPendingTxHashes: () => Promise.resolve([]),
|
|
46
46
|
getMinedTxHashes: () => Promise.resolve([]),
|
|
47
47
|
getTxStatus: () => Promise.resolve(TxStatus.PENDING),
|
|
48
|
+
getTxsByHash: () => Promise.resolve([]),
|
|
49
|
+
hasTxs: () => Promise.resolve([]),
|
|
48
50
|
setMaxTxPoolSize: () => Promise.resolve(),
|
|
49
51
|
};
|
|
50
52
|
}
|