@aztec/p2p 0.16.4 → 0.16.5
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/package.json +4 -4
- package/src/bootstrap/bootstrap.ts +0 -116
- package/src/client/index.ts +0 -14
- package/src/client/mocks.ts +0 -87
- package/src/client/p2p_client.ts +0 -306
- package/src/config.ts +0 -113
- package/src/index.ts +0 -5
- package/src/service/dummy_service.ts +0 -36
- package/src/service/index.ts +0 -2
- package/src/service/known_txs.ts +0 -56
- package/src/service/libp2p_service.ts +0 -404
- package/src/service/service.ts +0 -30
- package/src/service/tx_messages.ts +0 -211
- package/src/tx_pool/index.ts +0 -2
- package/src/tx_pool/memory_tx_pool.ts +0 -86
- package/src/tx_pool/tx_pool.ts +0 -44
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
2
|
-
import { Tx, TxHash } from '@aztec/types';
|
|
3
|
-
import { TxAddedToPoolStats } from '@aztec/types/stats';
|
|
4
|
-
|
|
5
|
-
import { TxPool } from './tx_pool.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* In-memory implementation of the Transaction Pool.
|
|
9
|
-
*/
|
|
10
|
-
export class InMemoryTxPool implements TxPool {
|
|
11
|
-
/**
|
|
12
|
-
* Our tx pool, stored as a Map in-memory, with K: tx hash and V: the transaction.
|
|
13
|
-
*/
|
|
14
|
-
private txs: Map<bigint, Tx>;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Class constructor for in-memory TxPool. Initiates our transaction pool as a JS Map.
|
|
18
|
-
* @param log - A logger.
|
|
19
|
-
*/
|
|
20
|
-
constructor(private log = createDebugLogger('aztec:tx_pool')) {
|
|
21
|
-
this.txs = new Map<bigint, Tx>();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Checks if a transaction exists in the pool and returns it.
|
|
26
|
-
* @param txHash - The generated tx hash.
|
|
27
|
-
* @returns The transaction, if found, 'undefined' otherwise.
|
|
28
|
-
*/
|
|
29
|
-
public getTxByHash(txHash: TxHash): Tx | undefined {
|
|
30
|
-
const result = this.txs.get(txHash.toBigInt());
|
|
31
|
-
return result === undefined ? undefined : Tx.clone(result);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Adds a list of transactions to the pool. Duplicates are ignored.
|
|
36
|
-
* @param txs - An array of txs to be added to the pool.
|
|
37
|
-
* @returns Empty promise.
|
|
38
|
-
*/
|
|
39
|
-
public async addTxs(txs: Tx[]): Promise<void> {
|
|
40
|
-
for (const tx of txs) {
|
|
41
|
-
const txHash = await tx.getTxHash();
|
|
42
|
-
this.log(`Adding tx with id ${txHash.toString()}`, {
|
|
43
|
-
eventName: 'tx-added-to-pool',
|
|
44
|
-
...tx.getStats(),
|
|
45
|
-
} satisfies TxAddedToPoolStats);
|
|
46
|
-
this.txs.set(txHash.toBigInt(), tx);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
52
|
-
* @param txHashes - An array of tx hashes to be removed from the tx pool.
|
|
53
|
-
* @returns The number of transactions that was deleted from the pool.
|
|
54
|
-
*/
|
|
55
|
-
public deleteTxs(txHashes: TxHash[]): number {
|
|
56
|
-
const numTxsRemoved = txHashes
|
|
57
|
-
.map(txHash => this.txs.delete(txHash.toBigInt()))
|
|
58
|
-
.filter(result => result === true).length;
|
|
59
|
-
return numTxsRemoved;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Gets all the transactions stored in the pool.
|
|
64
|
-
* @returns Array of tx objects in the order they were added to the pool.
|
|
65
|
-
*/
|
|
66
|
-
public getAllTxs(): Tx[] {
|
|
67
|
-
return Array.from(this.txs.values()).map(x => Tx.clone(x));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Gets the hashes of all transactions currently in the tx pool.
|
|
72
|
-
* @returns An array of transaction hashes found in the tx pool.
|
|
73
|
-
*/
|
|
74
|
-
public getAllTxHashes(): TxHash[] {
|
|
75
|
-
return Array.from(this.txs.keys()).map(x => TxHash.fromBigInt(x));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Returns a boolean indicating if the transaction is present in the pool.
|
|
80
|
-
* @param txHash - The hash of the transaction to be queried.
|
|
81
|
-
* @returns True if the transaction present, false otherwise.
|
|
82
|
-
*/
|
|
83
|
-
public hasTx(txHash: TxHash): boolean {
|
|
84
|
-
return this.txs.has(txHash.toBigInt());
|
|
85
|
-
}
|
|
86
|
-
}
|
package/src/tx_pool/tx_pool.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Tx, TxHash } from '@aztec/types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Interface of a transaction pool. The pool includes tx requests and is kept up-to-date by a P2P client.
|
|
5
|
-
*/
|
|
6
|
-
export interface TxPool {
|
|
7
|
-
/**
|
|
8
|
-
* Adds a list of transactions to the pool. Duplicates are ignored.
|
|
9
|
-
* @param txs - An array of txs to be added to the pool.
|
|
10
|
-
*/
|
|
11
|
-
addTxs(txs: Tx[]): Promise<void>;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Checks if a transaction exists in the pool and returns it.
|
|
15
|
-
* @param txHash - The hash of the transaction, used as an ID.
|
|
16
|
-
* @returns The transaction, if found, 'undefined' otherwise.
|
|
17
|
-
*/
|
|
18
|
-
getTxByHash(txHash: TxHash): Tx | undefined;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
22
|
-
* @param txHashes - An array of tx hashes to be removed from the tx pool.
|
|
23
|
-
*/
|
|
24
|
-
deleteTxs(txHashes: TxHash[]): void;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Gets all transactions currently in the tx pool.
|
|
28
|
-
* @returns An array of transaction objects found in the tx pool.
|
|
29
|
-
*/
|
|
30
|
-
getAllTxs(): Tx[];
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Gets the hashes of all transactions currently in the tx pool.
|
|
34
|
-
* @returns An array of transaction hashes found in the tx pool.
|
|
35
|
-
*/
|
|
36
|
-
getAllTxHashes(): TxHash[];
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Returns a boolean indicating if the transaction is present in the pool.
|
|
40
|
-
* @param txHash - The hash of the transaction to be queried.
|
|
41
|
-
* @returns True if the transaction present, false otherwise.
|
|
42
|
-
*/
|
|
43
|
-
hasTx(txHash: TxHash): boolean;
|
|
44
|
-
}
|