@aztec/p2p 0.72.1 → 0.74.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.
Files changed (78) hide show
  1. package/dest/bootstrap/bootstrap.d.ts +2 -2
  2. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  3. package/dest/bootstrap/bootstrap.js +1 -1
  4. package/dest/client/factory.d.ts +2 -2
  5. package/dest/client/factory.d.ts.map +1 -1
  6. package/dest/client/factory.js +4 -4
  7. package/dest/client/p2p_client.d.ts +13 -16
  8. package/dest/client/p2p_client.d.ts.map +1 -1
  9. package/dest/client/p2p_client.js +50 -62
  10. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  11. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +11 -19
  12. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +6 -13
  13. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  14. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +74 -80
  15. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  16. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +5 -5
  17. package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -1
  18. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  19. package/dest/mem_pools/attestation_pool/mocks.js +3 -3
  20. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +9 -9
  21. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  22. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +59 -53
  23. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +7 -7
  24. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  25. package/dest/mem_pools/tx_pool/memory_tx_pool.js +17 -18
  26. package/dest/mem_pools/tx_pool/tx_pool.d.ts +7 -7
  27. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  28. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  29. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +48 -47
  30. package/dest/mocks/index.js +3 -3
  31. package/dest/msg_validators/attestation_validator/attestation_validator.js +2 -2
  32. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +2 -2
  33. package/dest/msg_validators/tx_validator/block_header_validator.js +3 -3
  34. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  35. package/dest/msg_validators/tx_validator/data_validator.js +7 -7
  36. package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -3
  37. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  38. package/dest/msg_validators/tx_validator/metadata_validator.js +9 -9
  39. package/dest/services/data_store.d.ts +4 -4
  40. package/dest/services/data_store.d.ts.map +1 -1
  41. package/dest/services/data_store.js +7 -7
  42. package/dest/services/libp2p/libp2p_service.d.ts +3 -3
  43. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  44. package/dest/services/libp2p/libp2p_service.js +56 -35
  45. package/dest/services/peer-manager/peer_manager.d.ts +1 -0
  46. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  47. package/dest/services/peer-manager/peer_manager.js +6 -3
  48. package/dest/services/reqresp/protocols/tx.js +4 -4
  49. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  50. package/dest/services/reqresp/reqresp.js +2 -2
  51. package/dest/util.d.ts +2 -2
  52. package/dest/util.d.ts.map +1 -1
  53. package/dest/util.js +2 -2
  54. package/package.json +7 -7
  55. package/src/bootstrap/bootstrap.ts +2 -2
  56. package/src/client/factory.ts +5 -5
  57. package/src/client/p2p_client.ts +63 -75
  58. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +14 -22
  59. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +100 -94
  60. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +4 -4
  61. package/src/mem_pools/attestation_pool/mocks.ts +3 -3
  62. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +84 -72
  63. package/src/mem_pools/tx_pool/memory_tx_pool.ts +26 -23
  64. package/src/mem_pools/tx_pool/tx_pool.ts +7 -7
  65. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +50 -47
  66. package/src/mocks/index.ts +2 -2
  67. package/src/msg_validators/attestation_validator/attestation_validator.ts +1 -1
  68. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +1 -1
  69. package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
  70. package/src/msg_validators/tx_validator/data_validator.ts +12 -9
  71. package/src/msg_validators/tx_validator/double_spend_validator.ts +2 -2
  72. package/src/msg_validators/tx_validator/metadata_validator.ts +8 -8
  73. package/src/services/data_store.ts +9 -9
  74. package/src/services/libp2p/libp2p_service.ts +70 -36
  75. package/src/services/peer-manager/peer_manager.ts +7 -2
  76. package/src/services/reqresp/protocols/tx.ts +3 -3
  77. package/src/services/reqresp/reqresp.ts +7 -1
  78. package/src/util.ts +7 -4
@@ -68,26 +68,29 @@ export class InMemoryTxPool implements TxPool {
68
68
  return Promise.resolve();
69
69
  }
70
70
 
71
- public getPendingTxHashes(): TxHash[] {
72
- return this.getAllTxs()
73
- .sort((tx1, tx2) => -getPendingTxPriority(tx1).localeCompare(getPendingTxPriority(tx2)))
74
- .map(tx => tx.getTxHash())
75
- .filter(txHash => this.pendingTxs.has(txHash.toBigInt()));
71
+ public async getPendingTxHashes(): Promise<TxHash[]> {
72
+ const txs = (await this.getAllTxs()).sort(
73
+ (tx1, tx2) => -getPendingTxPriority(tx1).localeCompare(getPendingTxPriority(tx2)),
74
+ );
75
+ const txHashes = await Promise.all(txs.map(tx => tx.getTxHash()));
76
+ return txHashes.filter(txHash => this.pendingTxs.has(txHash.toBigInt()));
76
77
  }
77
78
 
78
- public getMinedTxHashes(): [TxHash, number][] {
79
- return Array.from(this.minedTxs.entries()).map(([txHash, blockNumber]) => [TxHash.fromBigInt(txHash), blockNumber]);
79
+ public getMinedTxHashes(): Promise<[TxHash, number][]> {
80
+ return Promise.resolve(
81
+ Array.from(this.minedTxs.entries()).map(([txHash, blockNumber]) => [TxHash.fromBigInt(txHash), blockNumber]),
82
+ );
80
83
  }
81
84
 
82
- public getTxStatus(txHash: TxHash): 'pending' | 'mined' | undefined {
85
+ public getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
83
86
  const key = txHash.toBigInt();
84
87
  if (this.pendingTxs.has(key)) {
85
- return 'pending';
88
+ return Promise.resolve('pending');
86
89
  }
87
90
  if (this.minedTxs.has(key)) {
88
- return 'mined';
91
+ return Promise.resolve('mined');
89
92
  }
90
- return undefined;
93
+ return Promise.resolve(undefined);
91
94
  }
92
95
 
93
96
  /**
@@ -95,13 +98,13 @@ export class InMemoryTxPool implements TxPool {
95
98
  * @param txHash - The generated tx hash.
96
99
  * @returns The transaction, if found, 'undefined' otherwise.
97
100
  */
98
- public getTxByHash(txHash: TxHash): Tx | undefined {
101
+ public getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
99
102
  const result = this.txs.get(txHash.toBigInt());
100
- return result === undefined ? undefined : Tx.clone(result);
103
+ return Promise.resolve(result === undefined ? undefined : Tx.clone(result));
101
104
  }
102
105
 
103
- public getArchivedTxByHash(): Tx | undefined {
104
- return undefined;
106
+ public getArchivedTxByHash(): Promise<Tx | undefined> {
107
+ return Promise.resolve(undefined);
105
108
  }
106
109
 
107
110
  /**
@@ -109,13 +112,13 @@ export class InMemoryTxPool implements TxPool {
109
112
  * @param txs - An array of txs to be added to the pool.
110
113
  * @returns Empty promise.
111
114
  */
112
- public addTxs(txs: Tx[]): Promise<void> {
115
+ public async addTxs(txs: Tx[]): Promise<void> {
113
116
  let pending = 0;
114
117
  for (const tx of txs) {
115
- const txHash = tx.getTxHash();
118
+ const txHash = await tx.getTxHash();
116
119
  this.log.verbose(`Adding tx ${txHash.toString()} to pool`, {
117
120
  eventName: 'tx-added-to-pool',
118
- ...tx.getStats(),
121
+ ...(await tx.getStats()),
119
122
  } satisfies TxAddedToPoolStats);
120
123
 
121
124
  const key = txHash.toBigInt();
@@ -128,7 +131,7 @@ export class InMemoryTxPool implements TxPool {
128
131
  }
129
132
 
130
133
  this.metrics.recordAddedObjects(pending, 'pending');
131
- return Promise.resolve();
134
+ return;
132
135
  }
133
136
 
134
137
  /**
@@ -157,15 +160,15 @@ export class InMemoryTxPool implements TxPool {
157
160
  * Gets all the transactions stored in the pool.
158
161
  * @returns Array of tx objects in the order they were added to the pool.
159
162
  */
160
- public getAllTxs(): Tx[] {
161
- return Array.from(this.txs.values()).map(x => Tx.clone(x));
163
+ public getAllTxs(): Promise<Tx[]> {
164
+ return Promise.resolve(Array.from(this.txs.values()).map(x => Tx.clone(x)));
162
165
  }
163
166
 
164
167
  /**
165
168
  * Gets the hashes of all transactions currently in the tx pool.
166
169
  * @returns An array of transaction hashes found in the tx pool.
167
170
  */
168
- public getAllTxHashes(): TxHash[] {
169
- return Array.from(this.txs.keys()).map(x => TxHash.fromBigInt(x));
171
+ public getAllTxHashes(): Promise<TxHash[]> {
172
+ return Promise.resolve(Array.from(this.txs.keys()).map(x => TxHash.fromBigInt(x)));
170
173
  }
171
174
  }
@@ -15,14 +15,14 @@ export interface TxPool {
15
15
  * @param txHash - The hash of the transaction, used as an ID.
16
16
  * @returns The transaction, if found, 'undefined' otherwise.
17
17
  */
18
- getTxByHash(txHash: TxHash): Tx | undefined;
18
+ getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
19
19
 
20
20
  /**
21
21
  * Checks if an archived transaction exists in the pool and returns it.
22
22
  * @param txHash - The hash of the transaction, used as an ID.
23
23
  * @returns The transaction, if found, 'undefined' otherwise.
24
24
  */
25
- getArchivedTxByHash(txHash: TxHash): Tx | undefined;
25
+ getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined>;
26
26
 
27
27
  /**
28
28
  * Marks the set of txs as mined, as opposed to pending.
@@ -47,30 +47,30 @@ export interface TxPool {
47
47
  * Gets all transactions currently in the tx pool.
48
48
  * @returns An array of transaction objects found in the tx pool.
49
49
  */
50
- getAllTxs(): Tx[];
50
+ getAllTxs(): Promise<Tx[]>;
51
51
 
52
52
  /**
53
53
  * Gets the hashes of all transactions currently in the tx pool.
54
54
  * @returns An array of transaction hashes found in the tx pool.
55
55
  */
56
- getAllTxHashes(): TxHash[];
56
+ getAllTxHashes(): Promise<TxHash[]>;
57
57
 
58
58
  /**
59
59
  * Gets the hashes of pending transactions currently in the tx pool sorted by priority (see getPendingTxPriority).
60
60
  * @returns An array of pending transaction hashes found in the tx pool.
61
61
  */
62
- getPendingTxHashes(): TxHash[];
62
+ getPendingTxHashes(): Promise<TxHash[]>;
63
63
 
64
64
  /**
65
65
  * Gets the hashes of mined transactions currently in the tx pool.
66
66
  * @returns An array of mined transaction hashes found in the tx pool.
67
67
  */
68
- getMinedTxHashes(): [tx: TxHash, blockNumber: number][];
68
+ getMinedTxHashes(): Promise<[tx: TxHash, blockNumber: number][]>;
69
69
 
70
70
  /**
71
71
  * Returns whether the given tx hash is flagged as pending or mined.
72
72
  * @param txHash - Hash of the tx to query.
73
73
  * @returns Pending or mined depending on its status, or undefined if not found.
74
74
  */
75
- getTxStatus(txHash: TxHash): 'pending' | 'mined' | undefined;
75
+ getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined>;
76
76
  }
@@ -16,94 +16,97 @@ export function describeTxPool(getTxPool: () => TxPool) {
16
16
  });
17
17
 
18
18
  it('Adds txs to the pool as pending', async () => {
19
- const tx1 = mockTx();
19
+ const tx1 = await mockTx();
20
20
 
21
21
  await pool.addTxs([tx1]);
22
- const poolTx = pool.getTxByHash(tx1.getTxHash());
23
- expect(poolTx!.getTxHash()).toEqual(tx1.getTxHash());
24
- expect(pool.getTxStatus(tx1.getTxHash())).toEqual('pending');
25
- expect(pool.getPendingTxHashes()).toEqual([tx1.getTxHash()]);
22
+ const poolTx = await pool.getTxByHash(await tx1.getTxHash());
23
+ expect(await poolTx!.getTxHash()).toEqual(await tx1.getTxHash());
24
+ await expect(pool.getTxStatus(await tx1.getTxHash())).resolves.toEqual('pending');
25
+ await expect(pool.getPendingTxHashes()).resolves.toEqual([await tx1.getTxHash()]);
26
26
  });
27
27
 
28
28
  it('Removes txs from the pool', async () => {
29
- const tx1 = mockTx();
29
+ const tx1 = await mockTx();
30
30
 
31
31
  await pool.addTxs([tx1]);
32
- await pool.deleteTxs([tx1.getTxHash()]);
32
+ await pool.deleteTxs([await tx1.getTxHash()]);
33
33
 
34
- expect(pool.getTxByHash(tx1.getTxHash())).toBeFalsy();
35
- expect(pool.getTxStatus(tx1.getTxHash())).toBeUndefined();
34
+ await expect(pool.getTxByHash(await tx1.getTxHash())).resolves.toBeFalsy();
35
+ await expect(pool.getTxStatus(await tx1.getTxHash())).resolves.toBeUndefined();
36
36
  });
37
37
 
38
38
  it('Marks txs as mined', async () => {
39
- const tx1 = mockTx(1);
40
- const tx2 = mockTx(2);
39
+ const tx1 = await mockTx(1);
40
+ const tx2 = await mockTx(2);
41
41
 
42
42
  await pool.addTxs([tx1, tx2]);
43
- await pool.markAsMined([tx1.getTxHash()], 1);
43
+ await pool.markAsMined([await tx1.getTxHash()], 1);
44
44
 
45
- expect(pool.getTxByHash(tx1.getTxHash())).toEqual(tx1);
46
- expect(pool.getTxStatus(tx1.getTxHash())).toEqual('mined');
47
- expect(pool.getMinedTxHashes()).toEqual([[tx1.getTxHash(), 1]]);
48
- expect(pool.getPendingTxHashes()).toEqual([tx2.getTxHash()]);
45
+ await expect(pool.getTxByHash(await tx1.getTxHash())).resolves.toEqual(tx1);
46
+ await expect(pool.getTxStatus(await tx1.getTxHash())).resolves.toEqual('mined');
47
+ await expect(pool.getMinedTxHashes()).resolves.toEqual([[await tx1.getTxHash(), 1]]);
48
+ await expect(pool.getPendingTxHashes()).resolves.toEqual([await tx2.getTxHash()]);
49
49
  });
50
50
 
51
51
  it('Marks txs as pending after being mined', async () => {
52
- const tx1 = mockTx(1);
53
- const tx2 = mockTx(2);
52
+ const tx1 = await mockTx(1);
53
+ const tx2 = await mockTx(2);
54
54
 
55
55
  await pool.addTxs([tx1, tx2]);
56
- await pool.markAsMined([tx1.getTxHash()], 1);
56
+ await pool.markAsMined([await tx1.getTxHash()], 1);
57
57
 
58
- await pool.markMinedAsPending([tx1.getTxHash()]);
59
- expect(pool.getMinedTxHashes()).toEqual([]);
60
- const pending = pool.getPendingTxHashes();
58
+ await pool.markMinedAsPending([await tx1.getTxHash()]);
59
+ await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
60
+ const pending = await pool.getPendingTxHashes();
61
61
  expect(pending).toHaveLength(2);
62
- expect(pending).toEqual(expect.arrayContaining([tx1.getTxHash(), tx2.getTxHash()]));
62
+ expect(pending).toEqual(expect.arrayContaining([await tx1.getTxHash(), await tx2.getTxHash()]));
63
63
  });
64
64
 
65
65
  it('Only marks txs as pending if they are known', async () => {
66
- const tx1 = mockTx(1);
66
+ const tx1 = await mockTx(1);
67
67
  // simulate a situation where not all peers have all the txs
68
- const someTxHashThatThisPeerDidNotSee = mockTx(2).getTxHash();
68
+ const tx2 = await mockTx(2);
69
+ const someTxHashThatThisPeerDidNotSee = await tx2.getTxHash();
69
70
  await pool.addTxs([tx1]);
70
71
  // this peer knows that tx2 was mined, but it does not have the tx object
71
- await pool.markAsMined([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee], 1);
72
- expect(new Set(pool.getMinedTxHashes())).toEqual(
73
- new Set([
74
- [tx1.getTxHash(), 1],
72
+ await pool.markAsMined([await tx1.getTxHash(), someTxHashThatThisPeerDidNotSee], 1);
73
+ expect(await pool.getMinedTxHashes()).toEqual(
74
+ expect.arrayContaining([
75
+ [await tx1.getTxHash(), 1],
75
76
  [someTxHashThatThisPeerDidNotSee, 1],
76
77
  ]),
77
78
  );
78
79
 
79
80
  // reorg: both txs should now become available again
80
- await pool.markMinedAsPending([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee]);
81
- expect(pool.getMinedTxHashes()).toEqual([]);
82
- expect(pool.getPendingTxHashes()).toEqual([tx1.getTxHash()]); // tx2 is not in the pool
81
+ await pool.markMinedAsPending([await tx1.getTxHash(), someTxHashThatThisPeerDidNotSee]);
82
+ await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
83
+ await expect(pool.getPendingTxHashes()).resolves.toEqual([await tx1.getTxHash()]); // tx2 is not in the pool
83
84
  });
84
85
 
85
86
  it('Returns all transactions in the pool', async () => {
86
- const tx1 = mockTx(1);
87
- const tx2 = mockTx(2);
88
- const tx3 = mockTx(3);
87
+ const tx1 = await mockTx(1);
88
+ const tx2 = await mockTx(2);
89
+ const tx3 = await mockTx(3);
89
90
 
90
91
  await pool.addTxs([tx1, tx2, tx3]);
91
92
 
92
- const poolTxs = pool.getAllTxs();
93
+ const poolTxs = await pool.getAllTxs();
93
94
  expect(poolTxs).toHaveLength(3);
94
95
  expect(poolTxs).toEqual(expect.arrayContaining([tx1, tx2, tx3]));
95
96
  });
96
97
 
97
98
  it('Returns all txHashes in the pool', async () => {
98
- const tx1 = mockTx(1);
99
- const tx2 = mockTx(2);
100
- const tx3 = mockTx(3);
99
+ const tx1 = await mockTx(1);
100
+ const tx2 = await mockTx(2);
101
+ const tx3 = await mockTx(3);
101
102
 
102
103
  await pool.addTxs([tx1, tx2, tx3]);
103
104
 
104
- const poolTxHashes = pool.getAllTxHashes();
105
+ const poolTxHashes = await pool.getAllTxHashes();
105
106
  expect(poolTxHashes).toHaveLength(3);
106
- expect(poolTxHashes).toEqual(expect.arrayContaining([tx1.getTxHash(), tx2.getTxHash(), tx3.getTxHash()]));
107
+ expect(poolTxHashes).toEqual(
108
+ expect.arrayContaining([await tx1.getTxHash(), await tx2.getTxHash(), await tx3.getTxHash()]),
109
+ );
107
110
  });
108
111
 
109
112
  it('Returns pending tx hashes sorted by priority', async () => {
@@ -112,15 +115,15 @@ export function describeTxPool(getTxPool: () => TxPool) {
112
115
  return tx;
113
116
  };
114
117
 
115
- const tx1 = withPriorityFee(mockTx(0), 1000);
116
- const tx2 = withPriorityFee(mockTx(1), 100);
117
- const tx3 = withPriorityFee(mockTx(2), 200);
118
- const tx4 = withPriorityFee(mockTx(3), 3000);
118
+ const tx1 = withPriorityFee(await mockTx(0), 1000);
119
+ const tx2 = withPriorityFee(await mockTx(1), 100);
120
+ const tx3 = withPriorityFee(await mockTx(2), 200);
121
+ const tx4 = withPriorityFee(await mockTx(3), 3000);
119
122
 
120
123
  await pool.addTxs([tx1, tx2, tx3, tx4]);
121
124
 
122
- const poolTxHashes = pool.getPendingTxHashes();
125
+ const poolTxHashes = await pool.getPendingTxHashes();
123
126
  expect(poolTxHashes).toHaveLength(4);
124
- expect(poolTxHashes).toEqual([tx4, tx1, tx3, tx2].map(tx => tx.getTxHash()));
127
+ expect(poolTxHashes).toEqual(await Promise.all([tx4, tx1, tx3, tx2].map(tx => tx.getTxHash())));
125
128
  });
126
129
  }
@@ -8,7 +8,7 @@ import {
8
8
  import { type EpochCache } from '@aztec/epoch-cache';
9
9
  import { timesParallel } from '@aztec/foundation/collection';
10
10
  import { type DataStoreConfig } from '@aztec/kv-store/config';
11
- import { openTmpStore } from '@aztec/kv-store/lmdb';
11
+ import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
12
12
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
13
13
 
14
14
  import { gossipsub } from '@chainsafe/libp2p-gossipsub';
@@ -263,7 +263,7 @@ export async function createBootstrapNode(
263
263
 
264
264
  async function startBootstrapNode(config: BootnodeConfig, telemetry: TelemetryClient) {
265
265
  // Open an ephemeral store that will only exist in memory
266
- const store = openTmpStore(true);
266
+ const store = await openTmpStore('bootstrap-node', true);
267
267
  const bootstrapNode = new BootstrapNode(store, telemetry);
268
268
  await bootstrapNode.start(config);
269
269
  return bootstrapNode;
@@ -16,7 +16,7 @@ export class AttestationValidator implements P2PValidator<BlockAttestation> {
16
16
  return PeerErrorSeverity.HighToleranceError;
17
17
  }
18
18
 
19
- const attester = message.getSender();
19
+ const attester = await message.getSender();
20
20
  if (!(await this.epochCache.isInCommittee(attester))) {
21
21
  return PeerErrorSeverity.HighToleranceError;
22
22
  }
@@ -19,7 +19,7 @@ export class BlockProposalValidator implements P2PValidator<BlockProposal> {
19
19
  }
20
20
 
21
21
  // Check that the block proposal is from the current or next proposer
22
- const proposer = block.getSender();
22
+ const proposer = await block.getSender();
23
23
  if (!proposer.equals(currentProposer) && !proposer.equals(nextProposer)) {
24
24
  return PeerErrorSeverity.HighToleranceError;
25
25
  }
@@ -15,9 +15,9 @@ export class BlockHeaderTxValidator<T extends AnyTx> implements TxValidator<T> {
15
15
  }
16
16
 
17
17
  async validateTx(tx: T): Promise<TxValidationResult> {
18
- const [index] = await this.#archiveSource.getArchiveIndices([tx.data.constants.historicalHeader.hash()]);
18
+ const [index] = await this.#archiveSource.getArchiveIndices([await tx.data.constants.historicalHeader.hash()]);
19
19
  if (index === undefined) {
20
- this.#log.warn(`Rejecting tx ${Tx.getHash(tx)} for referencing an unknown block header`);
20
+ this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for referencing an unknown block header`);
21
21
  return { result: 'invalid', reason: ['Block header not found'] };
22
22
  }
23
23
  return { result: 'valid' };
@@ -5,10 +5,10 @@ export class DataTxValidator implements TxValidator<Tx> {
5
5
  #log = createLogger('p2p:tx_validator:tx_data');
6
6
 
7
7
  validateTx(tx: Tx): Promise<TxValidationResult> {
8
- return Promise.resolve(this.#hasCorrectExecutionRequests(tx));
8
+ return this.#hasCorrectExecutionRequests(tx);
9
9
  }
10
10
 
11
- #hasCorrectExecutionRequests(tx: Tx): TxValidationResult {
11
+ async #hasCorrectExecutionRequests(tx: Tx): Promise<TxValidationResult> {
12
12
  const callRequests = [
13
13
  ...tx.data.getRevertiblePublicCallRequests(),
14
14
  ...tx.data.getNonRevertiblePublicCallRequests(),
@@ -21,13 +21,16 @@ export class DataTxValidator implements TxValidator<Tx> {
21
21
  );
22
22
  return { result: 'invalid', reason: ['Wrong number of execution requests for public calls'] };
23
23
  }
24
-
25
- const invalidExecutionRequestIndex = tx.enqueuedPublicFunctionCalls.findIndex(
26
- (execRequest, i) => !execRequest.isForCallRequest(callRequests[i]),
27
- );
24
+ const invalidExecutionRequestIndex = (
25
+ await Promise.all(
26
+ tx.enqueuedPublicFunctionCalls.map(
27
+ async (execRequest, i) => !(await execRequest.isForCallRequest(callRequests[i])),
28
+ ),
29
+ )
30
+ ).findIndex(Boolean);
28
31
  if (invalidExecutionRequestIndex !== -1) {
29
32
  this.#log.warn(
30
- `Rejecting tx ${Tx.getHash(
33
+ `Rejecting tx ${await Tx.getHash(
31
34
  tx,
32
35
  )} because of incorrect execution requests for public call at index ${invalidExecutionRequestIndex}.`,
33
36
  );
@@ -37,9 +40,9 @@ export class DataTxValidator implements TxValidator<Tx> {
37
40
  const teardownCallRequest = tx.data.getTeardownPublicCallRequest();
38
41
  const isInvalidTeardownExecutionRequest =
39
42
  (!teardownCallRequest && !tx.publicTeardownFunctionCall.isEmpty()) ||
40
- (teardownCallRequest && !tx.publicTeardownFunctionCall.isForCallRequest(teardownCallRequest));
43
+ (teardownCallRequest && !(await tx.publicTeardownFunctionCall.isForCallRequest(teardownCallRequest)));
41
44
  if (isInvalidTeardownExecutionRequest) {
42
- this.#log.warn(`Rejecting tx ${Tx.getHash(tx)} because of incorrect teardown execution requests.`);
45
+ this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} because of incorrect teardown execution requests.`);
43
46
  return { result: 'invalid', reason: ['Incorrect teardown execution request'] };
44
47
  }
45
48
 
@@ -19,12 +19,12 @@ export class DoubleSpendTxValidator<T extends AnyTx> implements TxValidator<T> {
19
19
  // Ditch this tx if it has repeated nullifiers
20
20
  const uniqueNullifiers = new Set(nullifiers);
21
21
  if (uniqueNullifiers.size !== nullifiers.length) {
22
- this.#log.warn(`Rejecting tx ${Tx.getHash(tx)} for emitting duplicate nullifiers`);
22
+ this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for emitting duplicate nullifiers`);
23
23
  return { result: 'invalid', reason: ['Duplicate nullifier in tx'] };
24
24
  }
25
25
 
26
26
  if ((await this.#nullifierSource.nullifiersExist(nullifiers.map(n => n.toBuffer()))).some(Boolean)) {
27
- this.#log.warn(`Rejecting tx ${Tx.getHash(tx)} for repeating a nullifier`);
27
+ this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for repeating a nullifier`);
28
28
  return { result: 'invalid', reason: ['Existing nullifier'] };
29
29
  }
30
30
 
@@ -7,21 +7,21 @@ export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
7
7
 
8
8
  constructor(private chainId: Fr, private blockNumber: Fr) {}
9
9
 
10
- validateTx(tx: T): Promise<TxValidationResult> {
10
+ async validateTx(tx: T): Promise<TxValidationResult> {
11
11
  const errors = [];
12
- if (!this.#hasCorrectChainId(tx)) {
12
+ if (!(await this.#hasCorrectChainId(tx))) {
13
13
  errors.push('Incorrect chain id');
14
14
  }
15
- if (!this.#isValidForBlockNumber(tx)) {
15
+ if (!(await this.#isValidForBlockNumber(tx))) {
16
16
  errors.push('Invalid block number');
17
17
  }
18
- return Promise.resolve(errors.length > 0 ? { result: 'invalid', reason: errors } : { result: 'valid' });
18
+ return errors.length > 0 ? { result: 'invalid', reason: errors } : { result: 'valid' };
19
19
  }
20
20
 
21
- #hasCorrectChainId(tx: T): boolean {
21
+ async #hasCorrectChainId(tx: T): Promise<boolean> {
22
22
  if (!tx.data.constants.txContext.chainId.equals(this.chainId)) {
23
23
  this.#log.warn(
24
- `Rejecting tx ${Tx.getHash(
24
+ `Rejecting tx ${await Tx.getHash(
25
25
  tx,
26
26
  )} because of incorrect chain ${tx.data.constants.txContext.chainId.toNumber()} != ${this.chainId.toNumber()}`,
27
27
  );
@@ -31,12 +31,12 @@ export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
31
31
  }
32
32
  }
33
33
 
34
- #isValidForBlockNumber(tx: T): boolean {
34
+ async #isValidForBlockNumber(tx: T): Promise<boolean> {
35
35
  const maxBlockNumber = tx.data.rollupValidationRequests.maxBlockNumber;
36
36
 
37
37
  if (maxBlockNumber.isSome && maxBlockNumber.value < this.blockNumber) {
38
38
  this.#log.warn(
39
- `Rejecting tx ${Tx.getHash(tx)} for low max block number. Tx max block number: ${
39
+ `Rejecting tx ${await Tx.getHash(tx)} for low max block number. Tx max block number: ${
40
40
  maxBlockNumber.value
41
41
  }, current block number: ${this.blockNumber}.`,
42
42
  );
@@ -1,5 +1,5 @@
1
1
  import { filter, map, sort, take } from '@aztec/foundation/iterable';
2
- import type { AztecKVStore, AztecMap } from '@aztec/kv-store';
2
+ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
3
3
 
4
4
  import { type Batch, type Datastore, Key, type KeyQuery, type Pair, type Query } from 'interface-datastore';
5
5
  import type { AwaitIterable } from 'interface-store';
@@ -25,31 +25,31 @@ class KeyNotFoundError extends Error {
25
25
 
26
26
  export class AztecDatastore implements Datastore {
27
27
  #memoryDatastore: Map<string, MemoryItem>;
28
- #dbDatastore: AztecMap<string, Uint8Array>;
28
+ #dbDatastore: AztecAsyncMap<string, Uint8Array>;
29
29
 
30
30
  #batchOps: BatchOp[] = [];
31
31
 
32
32
  private maxMemoryItems: number;
33
33
 
34
- constructor(db: AztecKVStore, { maxMemoryItems } = { maxMemoryItems: 50 }) {
34
+ constructor(db: AztecAsyncKVStore, { maxMemoryItems } = { maxMemoryItems: 50 }) {
35
35
  this.#memoryDatastore = new Map();
36
36
  this.#dbDatastore = db.openMap('p2p_datastore');
37
37
 
38
38
  this.maxMemoryItems = maxMemoryItems;
39
39
  }
40
40
 
41
- has(key: Key): boolean {
42
- return this.#memoryDatastore.has(key.toString()) || this.#dbDatastore.has(key.toString());
41
+ async has(key: Key): Promise<boolean> {
42
+ return this.#memoryDatastore.has(key.toString()) || (await this.#dbDatastore.hasAsync(key.toString()));
43
43
  }
44
44
 
45
- get(key: Key): Uint8Array {
45
+ async get(key: Key): Promise<Uint8Array> {
46
46
  const keyStr = key.toString();
47
47
  const memoryItem = this.#memoryDatastore.get(keyStr);
48
48
  if (memoryItem) {
49
49
  memoryItem.lastAccessedMs = Date.now();
50
50
  return memoryItem.data;
51
51
  }
52
- const dbItem = this.#dbDatastore.get(keyStr);
52
+ const dbItem = await this.#dbDatastore.getAsync(keyStr);
53
53
 
54
54
  if (!dbItem) {
55
55
  throw new KeyNotFoundError(`Key not found`);
@@ -73,7 +73,7 @@ export class AztecDatastore implements Datastore {
73
73
  for await (const key of source) {
74
74
  yield {
75
75
  key,
76
- value: this.get(key),
76
+ value: await this.get(key),
77
77
  };
78
78
  }
79
79
  }
@@ -202,7 +202,7 @@ export class AztecDatastore implements Datastore {
202
202
  };
203
203
  }
204
204
 
205
- for (const [key, value] of this.#dbDatastore.entries()) {
205
+ for await (const [key, value] of this.#dbDatastore.entriesAsync()) {
206
206
  if (!this.#memoryDatastore.has(key)) {
207
207
  yield {
208
208
  key: new Key(key),