@aztec/p2p 0.0.1-commit.fcb71a6 → 0.0.1-commit.fffb133c

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 (213) hide show
  1. package/dest/client/interface.d.ts +18 -5
  2. package/dest/client/interface.d.ts.map +1 -1
  3. package/dest/client/p2p_client.d.ts +10 -13
  4. package/dest/client/p2p_client.d.ts.map +1 -1
  5. package/dest/client/p2p_client.js +449 -118
  6. package/dest/config.js +2 -2
  7. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +61 -42
  8. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  9. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  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 +237 -263
  12. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -18
  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 +113 -108
  15. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -16
  16. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  17. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +89 -128
  18. package/dest/mem_pools/attestation_pool/mocks.d.ts +9 -6
  19. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  20. package/dest/mem_pools/attestation_pool/mocks.js +16 -12
  21. package/dest/mem_pools/instrumentation.d.ts +1 -1
  22. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  23. package/dest/mem_pools/instrumentation.js +4 -13
  24. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +15 -10
  25. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  26. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +91 -50
  27. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +19 -5
  28. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
  29. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +59 -3
  30. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +79 -5
  31. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
  32. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +47 -0
  33. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
  34. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  35. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
  36. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +2 -2
  37. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
  38. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +4 -4
  39. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
  40. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
  41. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +2 -2
  42. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
  44. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
  45. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
  46. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
  47. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  48. package/dest/msg_validators/attestation_validator/attestation_validator.js +51 -18
  49. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
  50. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  51. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +18 -14
  52. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  53. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  54. package/dest/msg_validators/clock_tolerance.js +37 -0
  55. package/dest/msg_validators/index.d.ts +2 -2
  56. package/dest/msg_validators/index.d.ts.map +1 -1
  57. package/dest/msg_validators/index.js +1 -1
  58. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
  59. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  60. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
  61. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
  62. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  63. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
  64. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  65. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  66. package/dest/msg_validators/proposal_validator/index.js +3 -0
  67. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
  68. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  69. package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
  70. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
  71. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
  72. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
  73. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +1 -1
  74. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  75. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  76. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  77. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  78. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  79. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  80. package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
  81. package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
  82. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  83. package/dest/msg_validators/tx_validator/gas_validator.js +8 -14
  84. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  85. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  86. package/dest/msg_validators/tx_validator/index.js +1 -0
  87. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  88. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  89. package/dest/msg_validators/tx_validator/size_validator.d.ts +6 -0
  90. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  91. package/dest/msg_validators/tx_validator/size_validator.js +20 -0
  92. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +1 -1
  93. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  94. package/dest/services/dummy_service.d.ts +6 -2
  95. package/dest/services/dummy_service.d.ts.map +1 -1
  96. package/dest/services/dummy_service.js +3 -0
  97. package/dest/services/encoding.d.ts +1 -1
  98. package/dest/services/encoding.d.ts.map +1 -1
  99. package/dest/services/encoding.js +6 -5
  100. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  101. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  102. package/dest/services/libp2p/instrumentation.js +20 -73
  103. package/dest/services/libp2p/libp2p_service.d.ts +28 -11
  104. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  105. package/dest/services/libp2p/libp2p_service.js +711 -152
  106. package/dest/services/peer-manager/metrics.d.ts +1 -1
  107. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  108. package/dest/services/peer-manager/metrics.js +6 -26
  109. package/dest/services/peer-manager/peer_manager.d.ts +2 -2
  110. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  111. package/dest/services/peer-manager/peer_manager.js +0 -10
  112. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  113. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  114. package/dest/services/peer-manager/peer_scoring.js +2 -5
  115. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -1
  116. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  117. package/dest/services/reqresp/constants.d.ts +12 -0
  118. package/dest/services/reqresp/constants.d.ts.map +1 -0
  119. package/dest/services/reqresp/constants.js +7 -0
  120. package/dest/services/reqresp/metrics.d.ts +1 -1
  121. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  122. package/dest/services/reqresp/metrics.js +5 -21
  123. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
  124. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  125. package/dest/services/reqresp/protocols/block_txs/bitvector.js +7 -0
  126. package/dest/services/reqresp/protocols/status.d.ts +1 -1
  127. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  128. package/dest/services/reqresp/protocols/status.js +4 -1
  129. package/dest/services/reqresp/reqresp.js +402 -24
  130. package/dest/services/service.d.ts +16 -3
  131. package/dest/services/service.d.ts.map +1 -1
  132. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  133. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  134. package/dest/services/tx_collection/instrumentation.js +4 -14
  135. package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
  136. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  137. package/dest/services/tx_collection/tx_collection.d.ts +5 -5
  138. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  139. package/dest/services/tx_provider.d.ts +3 -3
  140. package/dest/services/tx_provider.d.ts.map +1 -1
  141. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  142. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  143. package/dest/services/tx_provider_instrumentation.js +6 -19
  144. package/dest/testbench/p2p_client_testbench_worker.js +30 -17
  145. package/dest/testbench/worker_client_manager.d.ts +1 -1
  146. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  147. package/dest/testbench/worker_client_manager.js +6 -1
  148. package/package.json +16 -16
  149. package/src/client/interface.ts +19 -4
  150. package/src/client/p2p_client.ts +82 -132
  151. package/src/config.ts +2 -2
  152. package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
  153. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
  154. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
  155. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
  156. package/src/mem_pools/attestation_pool/mocks.ts +19 -13
  157. package/src/mem_pools/instrumentation.ts +9 -18
  158. package/src/mem_pools/tx_pool/README.md +28 -13
  159. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +130 -75
  160. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +66 -5
  161. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +119 -4
  162. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
  163. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
  164. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  165. package/src/msg_validators/attestation_validator/attestation_validator.ts +36 -21
  166. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +13 -16
  167. package/src/msg_validators/clock_tolerance.ts +51 -0
  168. package/src/msg_validators/index.ts +1 -1
  169. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
  170. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
  171. package/src/msg_validators/proposal_validator/index.ts +3 -0
  172. package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
  173. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
  174. package/src/msg_validators/tx_validator/block_header_validator.ts +3 -1
  175. package/src/msg_validators/tx_validator/data_validator.ts +12 -4
  176. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  177. package/src/msg_validators/tx_validator/gas_validator.ts +8 -25
  178. package/src/msg_validators/tx_validator/index.ts +1 -0
  179. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  180. package/src/msg_validators/tx_validator/size_validator.ts +18 -0
  181. package/src/msg_validators/tx_validator/timestamp_validator.ts +3 -1
  182. package/src/services/dummy_service.ts +6 -0
  183. package/src/services/encoding.ts +5 -4
  184. package/src/services/libp2p/instrumentation.ts +19 -73
  185. package/src/services/libp2p/libp2p_service.ts +351 -115
  186. package/src/services/peer-manager/metrics.ts +5 -26
  187. package/src/services/peer-manager/peer_manager.ts +1 -2
  188. package/src/services/peer-manager/peer_scoring.ts +1 -5
  189. package/src/services/reqresp/connection-sampler/connection_sampler.ts +3 -1
  190. package/src/services/reqresp/constants.ts +14 -0
  191. package/src/services/reqresp/metrics.ts +7 -23
  192. package/src/services/reqresp/protocols/block_txs/bitvector.ts +9 -0
  193. package/src/services/reqresp/protocols/status.ts +7 -4
  194. package/src/services/service.ts +19 -4
  195. package/src/services/tx_collection/instrumentation.ts +4 -21
  196. package/src/services/tx_collection/slow_tx_collection.ts +2 -2
  197. package/src/services/tx_collection/tx_collection.ts +4 -4
  198. package/src/services/tx_provider.ts +2 -2
  199. package/src/services/tx_provider_instrumentation.ts +11 -24
  200. package/src/testbench/p2p_client_testbench_worker.ts +40 -21
  201. package/src/testbench/worker_client_manager.ts +6 -1
  202. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
  203. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
  204. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
  205. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
  206. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  207. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
  208. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  209. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  210. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  211. package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
  212. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
  213. package/src/msg_validators/block_proposal_validator/index.ts +0 -1
@@ -0,0 +1,162 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
+ import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
4
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
6
+ import { DatabasePublicStateSource, type MerkleTreeReadOperations } from '@aztec/stdlib/trees';
7
+ import type { TxHash } from '@aztec/stdlib/tx';
8
+
9
+ import type { TxPoolOptions } from '../tx_pool.js';
10
+ import {
11
+ type EvictionContext,
12
+ EvictionEvent,
13
+ type EvictionResult,
14
+ type EvictionRule,
15
+ type FeePayerTxInfo,
16
+ type TxPoolOperations,
17
+ } from './eviction_strategy.js';
18
+
19
+ export class FeePayerBalanceEvictionRule implements EvictionRule {
20
+ public readonly name = 'FeePayerBalanceEviction';
21
+ public readonly reason = 'fee_payer_balance';
22
+
23
+ private log = createLogger('p2p:mempool:tx_pool:fee_payer_balance_eviction_rule');
24
+
25
+ constructor(private worldState: WorldStateSynchronizer) {}
26
+
27
+ async evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult> {
28
+ try {
29
+ if (context.event === EvictionEvent.TXS_ADDED) {
30
+ return await this.evictForFeePayers(context.feePayers, this.worldState.getCommitted(), txPool);
31
+ }
32
+
33
+ if (context.event === EvictionEvent.BLOCK_MINED) {
34
+ const blockNumber = context.block.getBlockNumber();
35
+ // Ensure world state is synced to this block before accessing the snapshot.
36
+ // This handles the race where a block is added to the archiver
37
+ // but the world state hasn't synced it yet.
38
+ await this.worldState.syncImmediate(blockNumber);
39
+ return await this.evictForFeePayers(context.feePayers, this.worldState.getSnapshot(blockNumber), txPool);
40
+ }
41
+
42
+ // TODO: fix this edge-case
43
+ // This can lead to a race condition if we are catching up in the p2p client.
44
+ // Let's say we have 3 txs for the same fee payer, which get mined in blocks 1, 2, 3.
45
+ // Tx1 consumes fee juice, tx2 increases it, tx3 consumes it again. We see block1 with tx1 first, run this rule, and evict tx3.
46
+ // But tx3 was valid (due to tx2) and mined on block3. And we have just removed from the mempool a tx we needed for proving/reexec.
47
+ //
48
+ // NOTE: this will happen only in case of that lower-priority-fee tx entered in e.g. block 2, and we have higher-priority-fee tx in block 3
49
+ // (simply because that was the timing of these txs). But, in case of higher-priority-fee txs being in block 2, the tx3 won't be evicted
50
+ // -----
51
+ // Proposed fix: evict only if node is synched
52
+ if (context.event === EvictionEvent.CHAIN_PRUNED) {
53
+ // Ensure world state is synced to this block before accessing the snapshot.
54
+ await this.worldState.syncImmediate(context.blockNumber);
55
+ const feePayers = await txPool.getPendingFeePayers();
56
+ return await this.evictForFeePayers(feePayers, this.worldState.getSnapshot(context.blockNumber), txPool);
57
+ }
58
+
59
+ return {
60
+ reason: this.reason,
61
+ success: true,
62
+ txsEvicted: [],
63
+ };
64
+ } catch (err) {
65
+ this.log.error('Failed to evict txs due to fee payer balance', { err });
66
+ return {
67
+ reason: this.reason,
68
+ success: false,
69
+ txsEvicted: [],
70
+ error: new Error('Failed to evict txs due to fee payer balance', { cause: err }),
71
+ };
72
+ }
73
+ }
74
+
75
+ updateConfig(_config: TxPoolOptions): void {}
76
+
77
+ private async evictForFeePayers(
78
+ feePayers: Array<AztecAddress>, // assumed to be unique
79
+ db: MerkleTreeReadOperations,
80
+ txPool: TxPoolOperations,
81
+ ): Promise<EvictionResult> {
82
+ const publicStateSource = this.createPublicStateSource(db);
83
+
84
+ const txsToEvict = (
85
+ await Promise.all(feePayers.map(feePayer => this.getEvictionsForFeePayer(feePayer, publicStateSource, txPool)))
86
+ ).flat();
87
+
88
+ if (txsToEvict.length > 0) {
89
+ await txPool.deleteTxs(txsToEvict);
90
+ }
91
+
92
+ return {
93
+ reason: this.reason,
94
+ success: true,
95
+ txsEvicted: txsToEvict,
96
+ };
97
+ }
98
+
99
+ private async getEvictionsForFeePayer(
100
+ feePayer: AztecAddress,
101
+ publicStateSource: DatabasePublicStateSource,
102
+ txPool: TxPoolOperations,
103
+ ): Promise<TxHash[]> {
104
+ const initialBalance = (
105
+ await publicStateSource.storageRead(
106
+ ProtocolContractAddress.FeeJuice,
107
+ //TODO: cache this LRU-style
108
+ await computeFeePayerBalanceStorageSlot(feePayer),
109
+ )
110
+ ).toBigInt();
111
+
112
+ const txs: FeePayerTxInfo[] = [];
113
+ for await (const entry of txPool.getFeePayerTxInfos(feePayer)) {
114
+ txs.push(entry);
115
+ }
116
+
117
+ if (txs.length === 0) {
118
+ return [];
119
+ }
120
+
121
+ const txsToEvict: TxHash[] = [];
122
+ let balance = initialBalance;
123
+ let hasNonEvictableOverBalance = false;
124
+
125
+ // Evaluate balance in priority order so later claims cannot fund earlier spends.
126
+ // This sorts so that higher priority txs come first.
127
+ txs.sort((a, b) => {
128
+ if (a.priority === b.priority) {
129
+ return a.txHash.toBigInt() >= b.txHash.toBigInt() ? -1 : 1;
130
+ }
131
+
132
+ return a.priority > b.priority ? -1 : 1;
133
+ });
134
+
135
+ for (const tx of txs) {
136
+ const available = balance + tx.claimAmount;
137
+ if (available >= tx.feeLimit) {
138
+ balance = available - tx.feeLimit;
139
+ continue;
140
+ }
141
+
142
+ if (tx.isEvictable) {
143
+ txsToEvict.push(tx.txHash);
144
+ } else {
145
+ hasNonEvictableOverBalance = true;
146
+ }
147
+ }
148
+
149
+ if (hasNonEvictableOverBalance) {
150
+ this.log.verbose('Fee payer balance cannot be satisfied due to non-evictable txs', {
151
+ feePayer: feePayer.toString(),
152
+ balance: initialBalance,
153
+ });
154
+ }
155
+
156
+ return txsToEvict;
157
+ }
158
+
159
+ private createPublicStateSource(db: MerkleTreeReadOperations): DatabasePublicStateSource {
160
+ return new DatabasePublicStateSource(db);
161
+ }
162
+ }
@@ -1,7 +1,7 @@
1
1
  import { findIndexInSortedArray, insertIntoSortedArray } from '@aztec/foundation/array';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
- import type { ReadonlyWorldStateAccess } from '@aztec/stdlib/interfaces/server';
4
+ import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
5
5
  import { MerkleTreeId } from '@aztec/stdlib/trees';
6
6
  import type { TxHash } from '@aztec/stdlib/tx';
7
7
 
@@ -26,7 +26,7 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
26
26
 
27
27
  private log = createLogger('p2p:mempool:tx_pool:invalid_txs_after_reorg_rule');
28
28
 
29
- public constructor(private worldState: ReadonlyWorldStateAccess) {}
29
+ public constructor(private worldState: WorldStateSynchronizer) {}
30
30
 
31
31
  async evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult> {
32
32
  if (context.event !== EvictionEvent.CHAIN_PRUNED) {
@@ -46,6 +46,8 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
46
46
  insertIntoSortedArray(uniqueBlockHashes, blockHash, Fr.cmp, false);
47
47
  });
48
48
 
49
+ // Ensure world state is synced to this block before accessing the snapshot.
50
+ await this.worldState.syncImmediate(context.blockNumber);
49
51
  const db = this.worldState.getSnapshot(context.blockNumber);
50
52
  const blocksFromDb = await db.findLeafIndices(MerkleTreeId.ARCHIVE, uniqueBlockHashes);
51
53
 
@@ -0,0 +1,75 @@
1
+ import { findIndexInSortedArray, insertIntoSortedArray } from '@aztec/foundation/array';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { type Tx, TxHash } from '@aztec/stdlib/tx';
5
+
6
+ import type { PreAddEvictionResult, PreAddEvictionRule, PreAddPoolAccess } from './eviction_strategy.js';
7
+
8
+ const cmpTxHash = (a: TxHash, b: TxHash) => Fr.cmp(a.hash, b.hash);
9
+
10
+ /**
11
+ * Pre-add eviction rule that checks for nullifier conflicts between incoming and existing transactions.
12
+ *
13
+ * When an incoming tx shares nullifiers with existing pending txs:
14
+ * - If the incoming tx has strictly higher priority fee, evict all conflicting txs
15
+ * - If any conflicting tx has equal or higher priority fee, reject the incoming tx
16
+ *
17
+ * This prevents nullifier spam attacks where an attacker floods the mempool with
18
+ * transactions spending the same nullifiers.
19
+ */
20
+ export class NullifierConflictPreAddRule implements PreAddEvictionRule {
21
+ public readonly name = 'NullifierConflictPreAdd';
22
+
23
+ private log = createLogger('p2p:mempool:tx_pool:nullifier_conflict_pre_add_rule');
24
+
25
+ /**
26
+ * Check if the incoming transaction conflicts with existing transactions via nullifiers.
27
+ *
28
+ * @param tx - The incoming transaction
29
+ * @param poolAccess - Read-only access to pool state
30
+ * @returns Result with rejection status and txs to evict
31
+ */
32
+ async check(tx: Tx, poolAccess: PreAddPoolAccess): Promise<PreAddEvictionResult> {
33
+ const txHash = tx.getTxHash();
34
+ const nullifiers = tx.data.getNonEmptyNullifiers();
35
+ const txHashesToEvict: TxHash[] = [];
36
+ const incomingPriority = poolAccess.getTxPriority(tx);
37
+
38
+ for (const nullifier of nullifiers) {
39
+ const conflictingHash = await poolAccess.getTxHashByNullifier(nullifier);
40
+
41
+ if (
42
+ !conflictingHash ||
43
+ conflictingHash.equals(txHash) ||
44
+ findIndexInSortedArray(txHashesToEvict, conflictingHash, cmpTxHash) !== -1
45
+ ) {
46
+ continue;
47
+ }
48
+
49
+ // Get the conflicting tx's priority
50
+ const conflictingTx = await poolAccess.getPendingTxByHash(conflictingHash);
51
+ if (!conflictingTx) {
52
+ continue;
53
+ }
54
+
55
+ const conflictingPriority = poolAccess.getTxPriority(conflictingTx);
56
+
57
+ // If incoming tx has strictly higher priority, mark for eviction
58
+ // Otherwise, reject incoming tx (ties go to existing tx)
59
+ if (incomingPriority > conflictingPriority) {
60
+ insertIntoSortedArray(txHashesToEvict, conflictingHash, cmpTxHash);
61
+ } else {
62
+ this.log.debug(
63
+ `Rejecting tx ${txHash.toString()}: nullifier conflict with ${conflictingHash.toString()} which has higher or equal fee`,
64
+ );
65
+ return {
66
+ shouldReject: true,
67
+ txHashesToEvict: [],
68
+ reason: `nullifier conflict with ${conflictingHash.toString()}`,
69
+ };
70
+ }
71
+ }
72
+
73
+ return { shouldReject: false, txHashesToEvict };
74
+ }
75
+ }
@@ -1,67 +1,82 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
2
  import { NoCommitteeError } from '@aztec/ethereum/contracts';
3
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
- import { type BlockAttestation, type P2PValidator, PeerErrorSeverity } from '@aztec/stdlib/p2p';
4
+ import {
5
+ type CheckpointAttestation,
6
+ type P2PValidator,
7
+ PeerErrorSeverity,
8
+ type ValidationResult,
9
+ } from '@aztec/stdlib/p2p';
5
10
 
6
- export class AttestationValidator implements P2PValidator<BlockAttestation> {
11
+ import { isWithinClockTolerance } from '../clock_tolerance.js';
12
+
13
+ export class CheckpointAttestationValidator implements P2PValidator<CheckpointAttestation> {
7
14
  protected epochCache: EpochCacheInterface;
8
15
  protected logger: Logger;
9
16
 
10
17
  constructor(epochCache: EpochCacheInterface) {
11
18
  this.epochCache = epochCache;
12
- this.logger = createLogger('p2p:attestation-validator');
19
+ this.logger = createLogger('p2p:checkpoint-attestation-validator');
13
20
  }
14
21
 
15
- async validate(message: BlockAttestation): Promise<PeerErrorSeverity | undefined> {
22
+ async validate(message: CheckpointAttestation): Promise<ValidationResult> {
16
23
  const slotNumber = message.payload.header.slotNumber;
17
24
 
18
25
  try {
19
- const { currentProposer, nextProposer, currentSlot, nextSlot } =
20
- await this.epochCache.getProposerAttesterAddressInCurrentOrNextSlot();
26
+ const { currentSlot, nextSlot } = this.epochCache.getCurrentAndNextSlot();
21
27
 
22
28
  if (slotNumber !== currentSlot && slotNumber !== nextSlot) {
23
- this.logger.warn(`Attestation slot ${slotNumber} is not current (${currentSlot}) or next (${nextSlot}) slot`);
24
- return PeerErrorSeverity.HighToleranceError;
29
+ // Check if message is for previous slot and within clock tolerance
30
+ if (!isWithinClockTolerance(slotNumber, currentSlot, this.epochCache)) {
31
+ this.logger.warn(
32
+ `Checkpoint attestation slot ${slotNumber} is not current (${currentSlot}) or next (${nextSlot}) slot`,
33
+ );
34
+ return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
35
+ }
36
+ this.logger.debug(`Ignoring checkpoint attestation for previous slot ${slotNumber} within clock tolerance`);
37
+ return { result: 'ignore' };
25
38
  }
26
39
 
27
40
  // Verify the signature is valid
28
41
  const attester = message.getSender();
29
42
  if (attester === undefined) {
30
- this.logger.warn(`Invalid signature in attestation for slot ${slotNumber}`);
31
- return PeerErrorSeverity.LowToleranceError;
43
+ this.logger.warn(`Invalid signature in checkpoint attestation for slot ${slotNumber}`);
44
+ return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
32
45
  }
33
46
 
34
47
  // Verify the attester is in the committee for this slot
35
48
  if (!(await this.epochCache.isInCommittee(slotNumber, attester))) {
36
49
  this.logger.warn(`Attester ${attester.toString()} is not in committee for slot ${slotNumber}`);
37
- return PeerErrorSeverity.HighToleranceError;
50
+ return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
38
51
  }
39
52
 
40
- // Verify the proposer signature matches the expected proposer for this slot
53
+ // Verify the proposer signature matches the expected proposer for the attestation's slot
54
+ // We look up the proposer for the specific slot rather than using currentSlot/nextSlot
55
+ // since timing differences could cause mismatches
41
56
  const proposer = message.getProposer();
42
- const expectedProposer = slotNumber === currentSlot ? currentProposer : nextProposer;
57
+ const expectedProposer = await this.epochCache.getProposerAttesterAddressInSlot(slotNumber);
43
58
  if (!expectedProposer) {
44
59
  this.logger.warn(`No proposer defined for slot ${slotNumber}`);
45
- return PeerErrorSeverity.HighToleranceError;
60
+ return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
46
61
  }
47
62
  if (!proposer) {
48
- this.logger.warn(`Invalid proposer signature in attestation for slot ${slotNumber}`);
49
- return PeerErrorSeverity.LowToleranceError;
63
+ this.logger.warn(`Invalid proposer signature in checkpoint attestation for slot ${slotNumber}`);
64
+ return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
50
65
  }
51
66
  if (!proposer.equals(expectedProposer)) {
52
67
  this.logger.warn(
53
- `Proposer signature mismatch in attestation. ` +
68
+ `Proposer signature mismatch in checkpoint attestation. ` +
54
69
  `Expected ${expectedProposer?.toString() ?? 'none'} but got ${proposer.toString()} for slot ${slotNumber}`,
55
70
  );
56
- return PeerErrorSeverity.HighToleranceError;
71
+ return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
57
72
  }
58
73
 
59
- return undefined;
74
+ return { result: 'accept' };
60
75
  } catch (e) {
61
76
  // People shouldn't be sending us attestations if the committee doesn't exist
62
77
  if (e instanceof NoCommitteeError) {
63
- this.logger.warn(`No committee exists for attestation for slot ${slotNumber}`);
64
- return PeerErrorSeverity.LowToleranceError;
78
+ this.logger.warn(`No committee exists for checkpoint attestation for slot ${slotNumber}`);
79
+ return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
65
80
  }
66
81
  throw e;
67
82
  }
@@ -1,9 +1,9 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
- import { type BlockAttestation, PeerErrorSeverity } from '@aztec/stdlib/p2p';
3
- import { Attributes, Metrics, type TelemetryClient, ValueType } from '@aztec/telemetry-client';
2
+ import { type CheckpointAttestation, PeerErrorSeverity, type ValidationResult } from '@aztec/stdlib/p2p';
3
+ import { Attributes, Metrics, type TelemetryClient } from '@aztec/telemetry-client';
4
4
 
5
5
  import type { AttestationPool } from '../../mem_pools/attestation_pool/attestation_pool.js';
6
- import { AttestationValidator } from './attestation_validator.js';
6
+ import { CheckpointAttestationValidator } from './attestation_validator.js';
7
7
 
8
8
  /**
9
9
  * FishermanAttestationValidator extends the base AttestationValidator to add
@@ -13,7 +13,7 @@ import { AttestationValidator } from './attestation_validator.js';
13
13
  * handled by LibP2PService based on the fishermanMode config to ensure a better
14
14
  * view of the network.
15
15
  */
16
- export class FishermanAttestationValidator extends AttestationValidator {
16
+ export class FishermanAttestationValidator extends CheckpointAttestationValidator {
17
17
  private invalidAttestationCounter;
18
18
 
19
19
  constructor(
@@ -25,16 +25,13 @@ export class FishermanAttestationValidator extends AttestationValidator {
25
25
  this.logger = this.logger.createChild('[FISHERMAN]');
26
26
 
27
27
  const meter = telemetryClient.getMeter('FishermanAttestationValidator');
28
- this.invalidAttestationCounter = meter.createUpDownCounter(Metrics.VALIDATOR_INVALID_ATTESTATION_RECEIVED_COUNT, {
29
- description: 'The number of invalid attestations received',
30
- valueType: ValueType.INT,
31
- });
28
+ this.invalidAttestationCounter = meter.createUpDownCounter(Metrics.VALIDATOR_INVALID_ATTESTATION_RECEIVED_COUNT);
32
29
  }
33
30
 
34
- override async validate(message: BlockAttestation): Promise<PeerErrorSeverity | undefined> {
31
+ override async validate(message: CheckpointAttestation): Promise<ValidationResult> {
35
32
  // First run the standard validation
36
33
  const baseValidationResult = await super.validate(message);
37
- if (baseValidationResult !== undefined) {
34
+ if (baseValidationResult.result !== 'accept') {
38
35
  // Track base validation failures (invalid signature, wrong committee, etc.)
39
36
  this.invalidAttestationCounter.add(1, {
40
37
  [Attributes.ERROR_TYPE]: 'base_validation_failed',
@@ -48,15 +45,15 @@ export class FishermanAttestationValidator extends AttestationValidator {
48
45
  const proposer = message.getProposer();
49
46
 
50
47
  if (!attester || !proposer) {
51
- return undefined;
48
+ return { result: 'accept' };
52
49
  }
53
50
 
54
51
  const proposalId = message.archive.toString();
55
- const proposal = await this.attestationPool.getBlockProposal(proposalId);
52
+ const proposal = await this.attestationPool.getCheckpointProposal(proposalId);
56
53
 
57
54
  if (proposal) {
58
55
  // Compare the attestation payload with the proposal payload
59
- if (!message.payload.equals(proposal.payload)) {
56
+ if (!message.payload.equals(proposal)) {
60
57
  this.logger.error(
61
58
  `Attestation payload mismatch for slot ${slotNumberBigInt}! ` +
62
59
  `Attester ${attester.toString()} signed different data than the proposal.`,
@@ -66,7 +63,7 @@ export class FishermanAttestationValidator extends AttestationValidator {
66
63
  proposer: proposer.toString(),
67
64
  proposalArchive: proposal.archive.toString(),
68
65
  attestationArchive: message.archive.toString(),
69
- proposalHeader: proposal.payload.header.hash().toString(),
66
+ proposalHeader: proposal.checkpointHeader.hash().toString(),
70
67
  attestationHeader: message.payload.header.hash().toString(),
71
68
  },
72
69
  );
@@ -77,7 +74,7 @@ export class FishermanAttestationValidator extends AttestationValidator {
77
74
  });
78
75
 
79
76
  // Return error to reject the message, but LibP2PService won't penalize in fisherman mode
80
- return PeerErrorSeverity.LowToleranceError;
77
+ return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
81
78
  }
82
79
  } else {
83
80
  // We might receive attestations before proposals in some cases
@@ -86,6 +83,6 @@ export class FishermanAttestationValidator extends AttestationValidator {
86
83
  );
87
84
  }
88
85
 
89
- return undefined;
86
+ return { result: 'accept' };
90
87
  }
91
88
  }
@@ -0,0 +1,51 @@
1
+ import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
+ import { SlotNumber } from '@aztec/foundation/branded-types';
3
+
4
+ /**
5
+ * Maximum clock disparity tolerance for P2P message validation (in milliseconds).
6
+ * Messages for the previous slot are accepted if we're within this many milliseconds
7
+ * of the current slot start. This prevents penalizing peers for messages that
8
+ * were valid when sent but arrived slightly late due to network latency.
9
+ *
10
+ * This follows Ethereum's MAXIMUM_GOSSIP_CLOCK_DISPARITY approach.
11
+ */
12
+ export const MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS = 500;
13
+
14
+ /**
15
+ * Checks if a message for the previous slot should be accepted due to clock tolerance.
16
+ *
17
+ * @param messageSlot - The slot number from the received message
18
+ * @param currentSlot - The current slot number
19
+ * @param epochCache - EpochCache to get timing information
20
+ * @returns true if the message is for the previous slot AND we're within the clock tolerance window
21
+ */
22
+ export function isWithinClockTolerance(
23
+ messageSlot: SlotNumber,
24
+ currentSlot: SlotNumber,
25
+ epochCache: EpochCacheInterface,
26
+ ): boolean {
27
+ // Guard against slot 0 edge case (genesis)
28
+ if (currentSlot === SlotNumber.ZERO) {
29
+ return false;
30
+ }
31
+
32
+ // Only apply tolerance to messages for the previous slot
33
+ const previousSlot = SlotNumber(currentSlot - 1);
34
+ if (messageSlot !== previousSlot) {
35
+ return false;
36
+ }
37
+
38
+ // Check how far we are into the current slot (in milliseconds)
39
+ const { ts: slotStartTs, nowMs, slot } = epochCache.getEpochAndSlotNow();
40
+
41
+ // Sanity check: ensure the epoch cache's current slot matches the expected current slot
42
+ if (slot !== currentSlot) {
43
+ return false;
44
+ }
45
+
46
+ // ts is in seconds, convert to ms; nowMs is already in milliseconds
47
+ const slotStartMs = slotStartTs * 1000n;
48
+ const elapsedMs = Number(nowMs - slotStartMs);
49
+
50
+ return elapsedMs < MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS;
51
+ }
@@ -1,3 +1,3 @@
1
1
  export * from './tx_validator/index.js';
2
- export * from './block_proposal_validator/index.js';
2
+ export * from './proposal_validator/index.js';
3
3
  export * from './attestation_validator/index.js';
@@ -0,0 +1,10 @@
1
+ import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
+ import type { BlockProposal, P2PValidator } from '@aztec/stdlib/p2p';
3
+
4
+ import { ProposalValidator } from '../proposal_validator/proposal_validator.js';
5
+
6
+ export class BlockProposalValidator extends ProposalValidator<BlockProposal> implements P2PValidator<BlockProposal> {
7
+ constructor(epochCache: EpochCacheInterface, opts: { txsPermitted: boolean }) {
8
+ super(epochCache, opts, 'p2p:block_proposal_validator');
9
+ }
10
+ }
@@ -0,0 +1,13 @@
1
+ import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
+ import type { CheckpointProposal, P2PValidator } from '@aztec/stdlib/p2p';
3
+
4
+ import { ProposalValidator } from '../proposal_validator/proposal_validator.js';
5
+
6
+ export class CheckpointProposalValidator
7
+ extends ProposalValidator<CheckpointProposal>
8
+ implements P2PValidator<CheckpointProposal>
9
+ {
10
+ constructor(epochCache: EpochCacheInterface, opts: { txsPermitted: boolean }) {
11
+ super(epochCache, opts, 'p2p:checkpoint_proposal_validator');
12
+ }
13
+ }
@@ -0,0 +1,3 @@
1
+ export * from './block_proposal_validator.js';
2
+ export * from './checkpoint_proposal_validator.js';
3
+ export * from './proposal_validator.js';
@@ -0,0 +1,92 @@
1
+ import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
+ import { NoCommitteeError } from '@aztec/ethereum/contracts';
3
+ import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { BlockProposal, CheckpointProposal, PeerErrorSeverity, type ValidationResult } from '@aztec/stdlib/p2p';
5
+
6
+ import { isWithinClockTolerance } from '../clock_tolerance.js';
7
+
8
+ export abstract class ProposalValidator<TProposal extends BlockProposal | CheckpointProposal> {
9
+ protected epochCache: EpochCacheInterface;
10
+ protected logger: Logger;
11
+ protected txsPermitted: boolean;
12
+
13
+ constructor(epochCache: EpochCacheInterface, opts: { txsPermitted: boolean }, loggerName: string) {
14
+ this.epochCache = epochCache;
15
+ this.txsPermitted = opts.txsPermitted;
16
+ this.logger = createLogger(loggerName);
17
+ }
18
+
19
+ public async validate(proposal: TProposal): Promise<ValidationResult> {
20
+ try {
21
+ // Slot check
22
+ const { currentSlot, nextSlot } = this.epochCache.getCurrentAndNextSlot();
23
+ const slotNumber = proposal.slotNumber;
24
+ if (slotNumber !== currentSlot && slotNumber !== nextSlot) {
25
+ // Check if message is for previous slot and within clock tolerance
26
+ if (!isWithinClockTolerance(slotNumber, currentSlot, this.epochCache)) {
27
+ this.logger.debug(`Penalizing peer for invalid slot number ${slotNumber}`, { currentSlot, nextSlot });
28
+ return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
29
+ }
30
+ this.logger.debug(`Ignoring proposal for previous slot ${slotNumber} within clock tolerance`);
31
+ return { result: 'ignore' };
32
+ }
33
+
34
+ // Signature validity
35
+ const proposer = proposal.getSender();
36
+ if (!proposer) {
37
+ this.logger.debug(`Penalizing peer for proposal with invalid signature`);
38
+ return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
39
+ }
40
+
41
+ // Transactions permitted check
42
+ const embeddedTxCount = proposal.txs?.length ?? 0;
43
+ if (!this.txsPermitted && (proposal.txHashes.length > 0 || embeddedTxCount > 0)) {
44
+ this.logger.debug(
45
+ `Penalizing peer for proposal with ${proposal.txHashes.length} transaction(s) when transactions are not permitted`,
46
+ );
47
+ return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
48
+ }
49
+
50
+ // Embedded txs must be listed in txHashes
51
+ const hashSet = new Set(proposal.txHashes.map(h => h.toString()));
52
+ const missingTxHashes =
53
+ embeddedTxCount > 0
54
+ ? proposal.txs!.filter(tx => !hashSet.has(tx.getTxHash().toString())).map(tx => tx.getTxHash().toString())
55
+ : [];
56
+ if (embeddedTxCount > 0 && missingTxHashes.length > 0) {
57
+ this.logger.warn('Penalizing peer for embedded transaction(s) not included in txHashes', {
58
+ embeddedTxCount,
59
+ txHashesLength: proposal.txHashes.length,
60
+ missingTxHashes,
61
+ });
62
+ return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
63
+ }
64
+
65
+ // Proposer check
66
+ const expectedProposer = await this.epochCache.getProposerAttesterAddressInSlot(slotNumber);
67
+ if (expectedProposer !== undefined && !proposer.equals(expectedProposer)) {
68
+ this.logger.debug(`Penalizing peer for invalid proposer for current slot ${slotNumber}`, {
69
+ expectedProposer,
70
+ proposer: proposer.toString(),
71
+ });
72
+ return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
73
+ }
74
+
75
+ // Validate tx hashes for all txs embedded in the proposal
76
+ if (!(await Promise.all(proposal.txs?.map(tx => tx.validateTxHash()) ?? [])).every(v => v)) {
77
+ this.logger.warn(`Penalizing peer for invalid tx hashes in proposal`, {
78
+ proposer,
79
+ slotNumber,
80
+ });
81
+ return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
82
+ }
83
+
84
+ return { result: 'accept' };
85
+ } catch (e) {
86
+ if (e instanceof NoCommitteeError) {
87
+ return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
88
+ }
89
+ throw e;
90
+ }
91
+ }
92
+ }