@aztec/p2p 0.0.1-commit.03f7ef2 → 0.0.1-commit.0b941701

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 (235) hide show
  1. package/dest/client/factory.js +1 -1
  2. package/dest/client/interface.d.ts +18 -5
  3. package/dest/client/interface.d.ts.map +1 -1
  4. package/dest/client/p2p_client.d.ts +10 -13
  5. package/dest/client/p2p_client.d.ts.map +1 -1
  6. package/dest/client/p2p_client.js +451 -120
  7. package/dest/config.d.ts +4 -7
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/config.js +8 -11
  10. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +61 -42
  11. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  12. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
  13. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
  14. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +237 -263
  15. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -18
  16. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  17. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +113 -108
  18. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -16
  19. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  20. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +89 -128
  21. package/dest/mem_pools/attestation_pool/mocks.d.ts +9 -6
  22. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  23. package/dest/mem_pools/attestation_pool/mocks.js +16 -12
  24. package/dest/mem_pools/instrumentation.d.ts +3 -3
  25. package/dest/mem_pools/instrumentation.d.ts.map +1 -1
  26. package/dest/mem_pools/instrumentation.js +10 -17
  27. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +35 -26
  28. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  29. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +312 -336
  30. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
  31. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
  32. package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
  33. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
  34. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
  35. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
  36. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
  37. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
  38. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
  39. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
  40. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
  41. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
  42. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
  43. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
  44. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
  45. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
  46. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
  47. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
  48. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
  49. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
  50. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
  51. package/dest/mem_pools/tx_pool/index.d.ts +1 -2
  52. package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
  53. package/dest/mem_pools/tx_pool/index.js +0 -1
  54. package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
  55. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  56. package/dest/mem_pools/tx_pool/priority.js +6 -1
  57. package/dest/mem_pools/tx_pool/tx_pool.d.ts +8 -4
  58. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  59. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +7 -7
  60. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
  61. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  62. package/dest/msg_validators/attestation_validator/attestation_validator.js +51 -18
  63. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
  64. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  65. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +18 -14
  66. package/dest/msg_validators/clock_tolerance.d.ts +21 -0
  67. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
  68. package/dest/msg_validators/clock_tolerance.js +37 -0
  69. package/dest/msg_validators/index.d.ts +2 -2
  70. package/dest/msg_validators/index.d.ts.map +1 -1
  71. package/dest/msg_validators/index.js +1 -1
  72. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
  73. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  74. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
  75. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
  76. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  77. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
  78. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  79. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  80. package/dest/msg_validators/proposal_validator/index.js +3 -0
  81. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
  82. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  83. package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
  84. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
  85. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
  86. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
  87. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +1 -1
  88. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  89. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  90. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  91. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  92. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  93. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  94. package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
  95. package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
  96. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  97. package/dest/msg_validators/tx_validator/gas_validator.js +8 -14
  98. package/dest/msg_validators/tx_validator/index.d.ts +2 -1
  99. package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
  100. package/dest/msg_validators/tx_validator/index.js +1 -0
  101. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  102. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  103. package/dest/msg_validators/tx_validator/size_validator.d.ts +6 -0
  104. package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
  105. package/dest/msg_validators/tx_validator/size_validator.js +20 -0
  106. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +1 -1
  107. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  108. package/dest/services/dummy_service.d.ts +6 -2
  109. package/dest/services/dummy_service.d.ts.map +1 -1
  110. package/dest/services/dummy_service.js +3 -0
  111. package/dest/services/encoding.d.ts +1 -1
  112. package/dest/services/encoding.d.ts.map +1 -1
  113. package/dest/services/encoding.js +6 -5
  114. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  115. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  116. package/dest/services/libp2p/instrumentation.js +20 -73
  117. package/dest/services/libp2p/libp2p_service.d.ts +28 -11
  118. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  119. package/dest/services/libp2p/libp2p_service.js +711 -152
  120. package/dest/services/peer-manager/metrics.d.ts +6 -1
  121. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  122. package/dest/services/peer-manager/metrics.js +18 -21
  123. package/dest/services/peer-manager/peer_manager.d.ts +2 -2
  124. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  125. package/dest/services/peer-manager/peer_manager.js +2 -10
  126. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  127. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  128. package/dest/services/peer-manager/peer_scoring.js +2 -5
  129. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -1
  130. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  131. package/dest/services/reqresp/constants.d.ts +12 -0
  132. package/dest/services/reqresp/constants.d.ts.map +1 -0
  133. package/dest/services/reqresp/constants.js +7 -0
  134. package/dest/services/reqresp/metrics.d.ts +1 -1
  135. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  136. package/dest/services/reqresp/metrics.js +5 -21
  137. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
  138. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  139. package/dest/services/reqresp/protocols/block_txs/bitvector.js +7 -0
  140. package/dest/services/reqresp/protocols/status.d.ts +1 -1
  141. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  142. package/dest/services/reqresp/protocols/status.js +4 -1
  143. package/dest/services/reqresp/reqresp.js +402 -24
  144. package/dest/services/service.d.ts +16 -3
  145. package/dest/services/service.d.ts.map +1 -1
  146. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  147. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  148. package/dest/services/tx_collection/instrumentation.js +4 -14
  149. package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
  150. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  151. package/dest/services/tx_collection/tx_collection.d.ts +5 -5
  152. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  153. package/dest/services/tx_provider.d.ts +3 -3
  154. package/dest/services/tx_provider.d.ts.map +1 -1
  155. package/dest/services/tx_provider.js +3 -1
  156. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  157. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  158. package/dest/services/tx_provider_instrumentation.js +6 -19
  159. package/dest/testbench/p2p_client_testbench_worker.js +31 -17
  160. package/dest/testbench/worker_client_manager.d.ts +1 -1
  161. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  162. package/dest/testbench/worker_client_manager.js +6 -1
  163. package/package.json +16 -16
  164. package/src/client/factory.ts +1 -1
  165. package/src/client/interface.ts +19 -4
  166. package/src/client/p2p_client.ts +84 -134
  167. package/src/config.ts +10 -16
  168. package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
  169. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
  170. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
  171. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
  172. package/src/mem_pools/attestation_pool/mocks.ts +19 -13
  173. package/src/mem_pools/instrumentation.ts +18 -25
  174. package/src/mem_pools/tx_pool/README.md +270 -0
  175. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +360 -368
  176. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
  177. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
  178. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
  179. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
  180. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
  181. package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
  182. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  183. package/src/mem_pools/tx_pool/index.ts +0 -1
  184. package/src/mem_pools/tx_pool/priority.ts +8 -1
  185. package/src/mem_pools/tx_pool/tx_pool.ts +8 -3
  186. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +7 -7
  187. package/src/msg_validators/attestation_validator/attestation_validator.ts +36 -21
  188. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +13 -16
  189. package/src/msg_validators/clock_tolerance.ts +51 -0
  190. package/src/msg_validators/index.ts +1 -1
  191. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
  192. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
  193. package/src/msg_validators/proposal_validator/index.ts +3 -0
  194. package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
  195. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
  196. package/src/msg_validators/tx_validator/block_header_validator.ts +3 -1
  197. package/src/msg_validators/tx_validator/data_validator.ts +12 -4
  198. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  199. package/src/msg_validators/tx_validator/gas_validator.ts +8 -25
  200. package/src/msg_validators/tx_validator/index.ts +1 -0
  201. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  202. package/src/msg_validators/tx_validator/size_validator.ts +18 -0
  203. package/src/msg_validators/tx_validator/timestamp_validator.ts +3 -1
  204. package/src/services/dummy_service.ts +6 -0
  205. package/src/services/encoding.ts +5 -4
  206. package/src/services/libp2p/instrumentation.ts +19 -73
  207. package/src/services/libp2p/libp2p_service.ts +351 -115
  208. package/src/services/peer-manager/metrics.ts +22 -21
  209. package/src/services/peer-manager/peer_manager.ts +3 -2
  210. package/src/services/peer-manager/peer_scoring.ts +1 -5
  211. package/src/services/reqresp/connection-sampler/connection_sampler.ts +3 -1
  212. package/src/services/reqresp/constants.ts +14 -0
  213. package/src/services/reqresp/metrics.ts +7 -23
  214. package/src/services/reqresp/protocols/block_txs/bitvector.ts +9 -0
  215. package/src/services/reqresp/protocols/status.ts +7 -4
  216. package/src/services/service.ts +19 -4
  217. package/src/services/tx_collection/instrumentation.ts +4 -21
  218. package/src/services/tx_collection/slow_tx_collection.ts +2 -2
  219. package/src/services/tx_collection/tx_collection.ts +4 -4
  220. package/src/services/tx_provider.ts +6 -3
  221. package/src/services/tx_provider_instrumentation.ts +11 -24
  222. package/src/testbench/p2p_client_testbench_worker.ts +41 -21
  223. package/src/testbench/worker_client_manager.ts +6 -1
  224. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -81
  225. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
  226. package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -242
  227. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
  228. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  229. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
  230. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  231. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  232. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  233. package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -288
  234. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
  235. package/src/msg_validators/block_proposal_validator/index.ts +0 -1
@@ -1,30 +1,29 @@
1
- import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
1
+ import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
2
2
  import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { DateProvider } from '@aztec/foundation/timer';
5
- import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncSingleton } from '@aztec/kv-store';
6
- import type {
7
- EthAddress,
8
- L2BlockId,
9
- L2BlockNew,
10
- L2BlockSource,
5
+ import type { AztecAsyncKVStore, AztecAsyncSingleton } from '@aztec/kv-store';
6
+ import { L2TipsKVStore } from '@aztec/kv-store/stores';
7
+ import {
8
+ type EthAddress,
9
+ type L2Block,
10
+ type L2BlockSource,
11
11
  L2BlockStream,
12
- L2BlockStreamEvent,
13
- L2Tips,
12
+ type L2BlockStreamEvent,
13
+ type L2Tips,
14
+ type L2TipsStore,
14
15
  } from '@aztec/stdlib/block';
15
16
  import type { ContractDataSource } from '@aztec/stdlib/contract';
16
17
  import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
17
18
  import { type PeerInfo, tryStop } from '@aztec/stdlib/interfaces/server';
18
- import { BlockAttestation, type BlockProposal, type P2PClientType } from '@aztec/stdlib/p2p';
19
- import type { Tx, TxHash } from '@aztec/stdlib/tx';
20
19
  import {
21
- Attributes,
22
- type TelemetryClient,
23
- TraceableL2BlockStream,
24
- WithTracer,
25
- getTelemetryClient,
26
- trackSpan,
27
- } from '@aztec/telemetry-client';
20
+ type BlockProposal,
21
+ CheckpointAttestation,
22
+ type CheckpointProposal,
23
+ type P2PClientType,
24
+ } from '@aztec/stdlib/p2p';
25
+ import type { Tx, TxHash } from '@aztec/stdlib/tx';
26
+ import { Attributes, type TelemetryClient, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
28
27
 
29
28
  import type { PeerId } from '@libp2p/interface';
30
29
  import type { ENR } from '@nethermindeth/enr';
@@ -40,7 +39,7 @@ import {
40
39
  type ReqRespSubProtocolValidators,
41
40
  } from '../services/reqresp/interface.js';
42
41
  import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
43
- import type { P2PBlockReceivedCallback, P2PService } from '../services/service.js';
42
+ import type { P2PBlockReceivedCallback, P2PCheckpointReceivedCallback, P2PService } from '../services/service.js';
44
43
  import { TxCollection } from '../services/tx_collection/tx_collection.js';
45
44
  import { TxProvider } from '../services/tx_provider.js';
46
45
  import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
@@ -62,10 +61,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
62
61
  private provenBlockNumberAtStart = -1;
63
62
  private finalizedBlockNumberAtStart = -1;
64
63
 
65
- private synchedBlockHashes: AztecAsyncMap<BlockNumber, string>;
66
- private synchedLatestBlockNumber: AztecAsyncSingleton<BlockNumber>;
67
- private synchedProvenBlockNumber: AztecAsyncSingleton<BlockNumber>;
68
- private synchedFinalizedBlockNumber: AztecAsyncSingleton<BlockNumber>;
64
+ private l2Tips: L2TipsStore;
69
65
  private synchedLatestSlot: AztecAsyncSingleton<bigint>;
70
66
 
71
67
  private txPool: TxPool;
@@ -114,7 +110,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
114
110
  );
115
111
 
116
112
  // Default to collecting all txs when we see a valid proposal
117
- // This can be overridden by the validator client to attest, and it will call getTxsForBlockProposal on its own
113
+ // This can be overridden by the validator client to validate, and it will call getTxsForBlockProposal on its own
114
+ // Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
118
115
  // TODO(palla/txs): We should not trigger a request for txs on a proposal before fully validating it. We need to bring
119
116
  // validator-client code into here so we can validate a proposal is reasonable.
120
117
  this.registerBlockProposalHandler(async (block, sender) => {
@@ -123,21 +120,17 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
123
120
  const constants = this.txCollection.getConstants();
124
121
  const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
125
122
  const deadline = new Date(nextSlotTimestampSeconds * 1000);
126
- const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.payload.header.lastArchiveRoot);
123
+ const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.blockHeader.lastArchive.root);
127
124
  if (!parentBlock) {
128
125
  this.log.debug(`Cannot collect txs for proposal as parent block not found`);
129
- return;
126
+ return false;
130
127
  }
131
128
  const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
132
129
  await this.txProvider.getTxsForBlockProposal(block, blockNumber, { pinnedPeer: sender, deadline });
133
- return undefined;
130
+ return true;
134
131
  });
135
132
 
136
- // REFACTOR: Try replacing these with an L2TipsStore
137
- this.synchedBlockHashes = store.openMap('p2p_pool_block_hashes');
138
- this.synchedLatestBlockNumber = store.openSingleton('p2p_pool_last_l2_block');
139
- this.synchedProvenBlockNumber = store.openSingleton('p2p_pool_last_proven_l2_block');
140
- this.synchedFinalizedBlockNumber = store.openSingleton('p2p_pool_last_finalized_l2_block');
133
+ this.l2Tips = new L2TipsKVStore(store, 'p2p_client');
141
134
  this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
142
135
  }
143
136
 
@@ -163,7 +156,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
163
156
  }
164
157
 
165
158
  public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
166
- return this.synchedBlockHashes.getAsync(number);
159
+ return this.l2Tips.getL2BlockHash(number);
167
160
  }
168
161
 
169
162
  public updateP2PConfig(config: Partial<P2PConfig>): Promise<void> {
@@ -172,85 +165,45 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
172
165
  return Promise.resolve();
173
166
  }
174
167
 
175
- public async getL2Tips(): Promise<L2Tips> {
176
- const latestBlockNumber = await this.getSyncedLatestBlockNum();
177
- let latestBlockHash: string | undefined;
178
-
179
- const provenBlockNumber = await this.getSyncedProvenBlockNum();
180
- let provenBlockHash: string | undefined;
181
-
182
- const finalizedBlockNumber = await this.getSyncedFinalizedBlockNum();
183
- let finalizedBlockHash: string | undefined;
184
-
185
- if (latestBlockNumber > 0) {
186
- latestBlockHash = await this.synchedBlockHashes.getAsync(latestBlockNumber);
187
- if (typeof latestBlockHash === 'undefined') {
188
- throw new Error(`Block hash for latest block ${latestBlockNumber} not found in p2p client`);
189
- }
190
- }
191
-
192
- if (provenBlockNumber > 0) {
193
- provenBlockHash = await this.synchedBlockHashes.getAsync(provenBlockNumber);
194
- if (typeof provenBlockHash === 'undefined') {
195
- throw new Error(`Block hash for proven block ${provenBlockNumber} not found in p2p client`);
196
- }
197
- }
198
-
199
- if (finalizedBlockNumber > 0) {
200
- finalizedBlockHash = await this.synchedBlockHashes.getAsync(finalizedBlockNumber);
201
- if (typeof finalizedBlockHash === 'undefined') {
202
- throw new Error(`Block hash for finalized block ${finalizedBlockNumber} not found in p2p client`);
203
- }
204
- }
205
-
206
- const genesisHash = GENESIS_BLOCK_HEADER_HASH.toString();
207
-
208
- return {
209
- latest: { hash: latestBlockHash ?? genesisHash, number: latestBlockNumber },
210
- proven: { hash: provenBlockHash ?? genesisHash, number: provenBlockNumber },
211
- finalized: { hash: finalizedBlockHash ?? genesisHash, number: finalizedBlockNumber },
212
- };
168
+ public getL2Tips(): Promise<L2Tips> {
169
+ return this.l2Tips.getL2Tips();
213
170
  }
214
171
 
215
172
  public async handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
216
173
  this.log.debug(`Handling block stream event ${event.type}`);
174
+
217
175
  switch (event.type) {
218
176
  case 'blocks-added':
219
- await this.handleLatestL2Blocks(event.blocks.map(b => b.block.toL2Block()));
177
+ await this.handleLatestL2Blocks(event.blocks);
220
178
  break;
221
179
  case 'chain-finalized': {
222
- // TODO (alexg): I think we can prune the block hashes map here
223
- await this.setBlockHash(event.block);
224
- const from = BlockNumber((await this.getSyncedFinalizedBlockNum()) + 1);
180
+ const oldFinalizedBlockNum = await this.getSyncedFinalizedBlockNum();
181
+ const from = BlockNumber(oldFinalizedBlockNum + 1);
225
182
  const limit = event.block.number - from + 1;
226
183
  if (limit > 0) {
227
184
  const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
228
- await this.handleFinalizedL2Blocks(oldBlocks.map(b => b.toL2Block()));
185
+ await this.handleFinalizedL2Blocks(oldBlocks);
229
186
  }
230
187
  break;
231
188
  }
232
- case 'chain-proven': {
233
- await this.setBlockHash(event.block);
189
+ case 'chain-proven':
234
190
  this.txCollection.stopCollectingForBlocksUpTo(event.block.number);
235
- await this.synchedProvenBlockNumber.set(event.block.number);
236
191
  break;
237
- }
238
192
  case 'chain-pruned':
239
- await this.setBlockHash(event.block);
240
193
  this.txCollection.stopCollectingForBlocksAfter(event.block.number);
241
194
  await this.handlePruneL2Blocks(event.block.number);
242
195
  break;
196
+ case 'chain-checkpointed':
197
+ break;
243
198
  default: {
244
199
  const _: never = event;
245
200
  break;
246
201
  }
247
202
  }
248
- }
249
203
 
250
- private async setBlockHash(block: L2BlockId): Promise<void> {
251
- if (block.hash !== undefined) {
252
- await this.synchedBlockHashes.set(block.number, block.hash.toString());
253
- }
204
+ // Pass the event through to our l2 tips store
205
+ await this.l2Tips.handleBlockStreamEvent(event);
206
+ await this.startServiceIfSynched();
254
207
  }
255
208
 
256
209
  #assertIsReady() {
@@ -274,9 +227,9 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
274
227
 
275
228
  // get the current latest block numbers
276
229
  const latestBlockNumbers = await this.l2BlockSource.getL2Tips();
277
- this.latestBlockNumberAtStart = latestBlockNumbers.latest.number;
278
- this.provenBlockNumberAtStart = latestBlockNumbers.proven.number;
279
- this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.number;
230
+ this.latestBlockNumberAtStart = latestBlockNumbers.proposed.number;
231
+ this.provenBlockNumberAtStart = latestBlockNumbers.proven.block.number;
232
+ this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.block.number;
280
233
 
281
234
  const syncedLatestBlock = (await this.getSyncedLatestBlockNum()) + 1;
282
235
  const syncedProvenBlock = (await this.getSyncedProvenBlockNum()) + 1;
@@ -335,12 +288,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
335
288
  private initBlockStream(startingBlock?: BlockNumber) {
336
289
  if (!this.blockStream) {
337
290
  const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
338
- this.blockStream = new TraceableL2BlockStream(
291
+ this.blockStream = new L2BlockStream(
339
292
  this.l2BlockSource,
340
293
  this,
341
294
  this,
342
- this.telemetry.getTracer('P2PL2BlockStream'),
343
- 'P2PL2BlockStream',
344
295
  createLogger(`${this.log.module}:l2-block-stream`),
345
296
  { batchSize, pollIntervalMS, startingBlock },
346
297
  );
@@ -380,23 +331,32 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
380
331
  return this.p2pService.propagate(proposal);
381
332
  }
382
333
 
383
- public async broadcastAttestations(attestations: BlockAttestation[]): Promise<void> {
384
- this.log.verbose(`Broadcasting ${attestations.length} attestations to peers`);
385
- await Promise.all(attestations.map(att => this.p2pService.propagate(att)));
334
+ @trackSpan('p2pClient.broadcastCheckpointProposal', async proposal => ({
335
+ [Attributes.SLOT_NUMBER]: proposal.slotNumber,
336
+ [Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
337
+ [Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
338
+ }))
339
+ public broadcastCheckpointProposal(proposal: CheckpointProposal): Promise<void> {
340
+ this.log.verbose(`Broadcasting checkpoint proposal for slot ${proposal.slotNumber} to peers`);
341
+ return this.p2pService.propagate(proposal);
386
342
  }
387
343
 
388
- public async getAttestationsForSlot(slot: SlotNumber, proposalId?: string): Promise<BlockAttestation[]> {
389
- return await (proposalId
390
- ? this.attestationPool.getAttestationsForSlotAndProposal(slot, proposalId)
391
- : this.attestationPool.getAttestationsForSlot(slot));
344
+ public async broadcastCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
345
+ this.log.verbose(`Broadcasting ${attestations.length} checkpoint attestations to peers`);
346
+ await Promise.all(attestations.map(att => this.p2pService.propagate(att)));
392
347
  }
393
348
 
394
- public addAttestations(attestations: BlockAttestation[]): Promise<void> {
395
- return this.attestationPool.addAttestations(attestations);
349
+ public async getCheckpointAttestationsForSlot(
350
+ slot: SlotNumber,
351
+ proposalId?: string,
352
+ ): Promise<CheckpointAttestation[]> {
353
+ return await (proposalId
354
+ ? this.attestationPool.getCheckpointAttestationsForSlotAndProposal(slot, proposalId)
355
+ : this.attestationPool.getCheckpointAttestationsForSlot(slot));
396
356
  }
397
357
 
398
- public deleteAttestation(attestation: BlockAttestation): Promise<void> {
399
- return this.attestationPool.deleteAttestations([attestation]);
358
+ public addCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
359
+ return this.attestationPool.addCheckpointAttestations(attestations);
400
360
  }
401
361
 
402
362
  // REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
@@ -405,6 +365,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
405
365
  this.p2pService.registerBlockReceivedCallback(handler);
406
366
  }
407
367
 
368
+ public registerCheckpointProposalHandler(handler: P2PCheckpointReceivedCallback): void {
369
+ this.p2pService.registerCheckpointReceivedCallback(handler);
370
+ }
371
+
408
372
  /**
409
373
  * Uses the batched Request Response protocol to request a set of transactions from the network.
410
374
  */
@@ -647,7 +611,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
647
611
  * @returns Block number of latest L2 Block we've synced with.
648
612
  */
649
613
  public async getSyncedLatestBlockNum(): Promise<BlockNumber> {
650
- return (await this.synchedLatestBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
614
+ const tips = await this.l2Tips.getL2Tips();
615
+ return tips.proposed.number;
651
616
  }
652
617
 
653
618
  /**
@@ -655,11 +620,13 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
655
620
  * @returns Block number of latest proven L2 Block we've synced with.
656
621
  */
657
622
  public async getSyncedProvenBlockNum(): Promise<BlockNumber> {
658
- return (await this.synchedProvenBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
623
+ const tips = await this.l2Tips.getL2Tips();
624
+ return tips.proven.block.number;
659
625
  }
660
626
 
661
627
  public async getSyncedFinalizedBlockNum(): Promise<BlockNumber> {
662
- return (await this.synchedFinalizedBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
628
+ const tips = await this.l2Tips.getL2Tips();
629
+ return tips.finalized.block.number;
663
630
  }
664
631
 
665
632
  /** Returns latest L2 slot for which we have seen an L2 block. */
@@ -692,7 +659,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
692
659
  * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
693
660
  * @returns Empty promise.
694
661
  */
695
- private async markTxsAsMinedFromBlocks(blocks: L2BlockNew[]): Promise<void> {
662
+ private async markTxsAsMinedFromBlocks(blocks: L2Block[]): Promise<void> {
696
663
  for (const block of blocks) {
697
664
  const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
698
665
  await this.txPool.markAsMined(txHashes, block.header);
@@ -704,33 +671,22 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
704
671
  * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
705
672
  * @returns Empty promise.
706
673
  */
707
- private async handleLatestL2Blocks(blocks: L2BlockNew[]): Promise<void> {
674
+ private async handleLatestL2Blocks(blocks: L2Block[]): Promise<void> {
708
675
  if (!blocks.length) {
709
676
  return Promise.resolve();
710
677
  }
711
678
 
712
679
  await this.markTxsAsMinedFromBlocks(blocks);
680
+ await this.txPool.clearNonEvictableTxs();
713
681
  await this.startCollectingMissingTxs(blocks);
714
682
 
715
683
  const lastBlock = blocks.at(-1)!;
716
-
717
- await Promise.all(
718
- blocks.map(async block =>
719
- this.setBlockHash({
720
- number: block.number,
721
- hash: await block.hash().then(h => h.toString()),
722
- }),
723
- ),
724
- );
725
-
726
- await this.synchedLatestBlockNumber.set(lastBlock.number);
727
684
  await this.synchedLatestSlot.set(BigInt(lastBlock.header.getSlot()));
728
685
  this.log.verbose(`Synched to latest block ${lastBlock.number}`);
729
- await this.startServiceIfSynched();
730
686
  }
731
687
 
732
688
  /** Request txs for unproven blocks so the prover node has more chances to get them. */
733
- private async startCollectingMissingTxs(blocks: L2BlockNew[]): Promise<void> {
689
+ private async startCollectingMissingTxs(blocks: L2Block[]): Promise<void> {
734
690
  try {
735
691
  // TODO(#15435): If the archiver has lagged behind L1, the reported proven block number may
736
692
  // be much lower than the actual one, and it does not update until the pending chain is
@@ -763,7 +719,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
763
719
  * @param blocks - A list of finalized L2 blocks.
764
720
  * @returns Empty promise.
765
721
  */
766
- private async handleFinalizedL2Blocks(blocks: L2BlockNew[]): Promise<void> {
722
+ private async handleFinalizedL2Blocks(blocks: L2Block[]): Promise<void> {
767
723
  if (!blocks.length) {
768
724
  return Promise.resolve();
769
725
  }
@@ -777,12 +733,9 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
777
733
  await this.txPool.deleteTxs(txHashes, { permanently: true });
778
734
  await this.txPool.cleanupDeletedMinedTxs(lastBlockNum);
779
735
 
780
- await this.attestationPool.deleteAttestationsOlderThan(lastBlockSlot);
736
+ await this.attestationPool.deleteCheckpointAttestationsOlderThan(lastBlockSlot);
781
737
 
782
- await this.synchedFinalizedBlockNumber.set(lastBlockNum);
783
738
  this.log.debug(`Synched to finalized block ${lastBlockNum} at slot ${lastBlockSlot}`);
784
-
785
- await this.startServiceIfSynched();
786
739
  }
787
740
 
788
741
  /**
@@ -828,21 +781,18 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
828
781
  this.log.info(`Deleting ${minedTxsFromReorg.length} mined txs from reorg`);
829
782
  await this.txPool.deleteTxs(minedTxsFromReorg);
830
783
  } else {
831
- this.log.info(`Moving ${minedTxsFromReorg.length} mined txs from reorg back to pending`);
832
- await this.txPool.markMinedAsPending(minedTxsFromReorg);
784
+ await this.txPool.markMinedAsPending(minedTxsFromReorg, latestBlock);
833
785
  }
834
-
835
- await this.synchedLatestBlockNumber.set(latestBlock);
836
- // no need to update block hashes, as they will be updated as new blocks are added
837
786
  }
838
787
 
839
788
  private async startServiceIfSynched() {
840
789
  if (this.currentState !== P2PClientState.SYNCHING) {
841
790
  return;
842
791
  }
843
- const syncedFinalizedBlock = await this.getSyncedFinalizedBlockNum();
844
- const syncedProvenBlock = await this.getSyncedProvenBlockNum();
845
- const syncedLatestBlock = await this.getSyncedLatestBlockNum();
792
+ const tips = await this.l2Tips.getL2Tips();
793
+ const syncedFinalizedBlock = tips.finalized.block.number;
794
+ const syncedProvenBlock = tips.proven.block.number;
795
+ const syncedLatestBlock = tips.proposed.number;
846
796
 
847
797
  if (
848
798
  syncedLatestBlock >= this.latestBlockNumberAtStart &&
package/src/config.ts CHANGED
@@ -2,10 +2,10 @@ import {
2
2
  type ConfigMappingsType,
3
3
  SecretValue,
4
4
  booleanConfigHelper,
5
- floatConfigHelper,
6
5
  getConfigFromMappings,
7
6
  getDefaultConfig,
8
7
  numberConfigHelper,
8
+ percentageConfigHelper,
9
9
  pickConfigMappings,
10
10
  secretStringConfigHelper,
11
11
  } from '@aztec/foundation/config';
@@ -133,11 +133,8 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig, TxCollectionCo
133
133
  /** Which calls are allowed in the public setup phase of a tx. */
134
134
  txPublicSetupAllowList: AllowedElement[];
135
135
 
136
- /** The maximum cumulative tx size (in bytes) of pending txs before evicting lower priority txs. */
137
- maxTxPoolSize: number;
138
-
139
- /** If the pool is full, it will still accept a few more txs until it reached maxTxPoolOverspillFactor * maxTxPoolSize. Then it will evict */
140
- txPoolOverflowFactor: number;
136
+ /** The maximum number of pending txs before evicting lower priority txs. */
137
+ maxPendingTxCount: number;
141
138
 
142
139
  /** The node's seen message ID cache size */
143
140
  seenMessageCacheSize: number;
@@ -375,15 +372,12 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
375
372
  printDefault: () =>
376
373
  'AuthRegistry, FeeJuice.increase_public_balance, Token.increase_public_balance, FPC.prepare_fee',
377
374
  },
378
- maxTxPoolSize: {
379
- env: 'P2P_MAX_TX_POOL_SIZE',
380
- description: 'The maximum cumulative tx size of pending txs (in bytes) before evicting lower priority txs.',
381
- ...numberConfigHelper(100_000_000), // 100MB
382
- },
383
- txPoolOverflowFactor: {
384
- env: 'P2P_TX_POOL_OVERFLOW_FACTOR',
385
- description: 'How much the tx pool can overflow before it starts evicting txs. Must be greater than 1',
386
- ...floatConfigHelper(1.1), // 10% overflow
375
+ maxPendingTxCount: {
376
+ env: 'P2P_MAX_PENDING_TX_COUNT',
377
+ description: 'The maximum number of pending txs before evicting lower priority txs.',
378
+ // Worst case scenario: Uncompressed public/private tx is ~ 156kb
379
+ // This implies we are using ~156MB of memory for pending pool
380
+ ...numberConfigHelper(1_000),
387
381
  },
388
382
  seenMessageCacheSize: {
389
383
  env: 'P2P_SEEN_MSG_CACHE_SIZE',
@@ -413,7 +407,7 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
413
407
  dropTransactionsProbability: {
414
408
  env: 'P2P_DROP_TX_CHANCE',
415
409
  description: 'The probability that a transaction is discarded (0 - 1). - For testing purposes only',
416
- ...floatConfigHelper(0),
410
+ ...percentageConfigHelper(0),
417
411
  },
418
412
  disableTransactions: {
419
413
  env: 'TRANSACTIONS_DISABLED',
@@ -1,5 +1,10 @@
1
1
  import type { SlotNumber } from '@aztec/foundation/branded-types';
2
- import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
2
+ import type {
3
+ BlockProposal,
4
+ CheckpointAttestation,
5
+ CheckpointProposal,
6
+ CheckpointProposalCore,
7
+ } from '@aztec/stdlib/p2p';
3
8
 
4
9
  /**
5
10
  * An Attestation Pool contains attestations collected by a validator
@@ -32,75 +37,74 @@ export interface AttestationPool {
32
37
  hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean>;
33
38
 
34
39
  /**
35
- * AddAttestations
40
+ * Adds a checkpoint proposal to the pool.
36
41
  *
37
- * @param attestations - Attestations to add into the pool
42
+ * If the proposal contains a lastBlock, the BlockProposal is automatically extracted
43
+ * and stored separately via addBlockProposal. The checkpoint proposal is then stored
44
+ * without the lastBlock info (as CheckpointProposalCore).
45
+ *
46
+ * @param proposal - The checkpoint proposal to add
47
+ * @throws ProposalSlotCapExceededError if the slot has reached the maximum number of proposals
38
48
  */
39
- addAttestations(attestations: BlockAttestation[]): Promise<void>;
49
+ addCheckpointProposal(proposal: CheckpointProposal): Promise<void>;
40
50
 
41
51
  /**
42
- * DeleteAttestation
52
+ * Get checkpoint proposal by its ID.
53
+ *
54
+ * Returns a CheckpointProposalCore (without lastBlock info) since the lastBlock
55
+ * is extracted and stored separately as a BlockProposal when added.
43
56
  *
44
- * @param attestations - Attestations to remove from the pool
57
+ * @param id - The ID of the checkpoint proposal to retrieve (proposal.archive)
58
+ * @return The checkpoint proposal core if it exists, otherwise undefined.
45
59
  */
46
- deleteAttestations(attestations: BlockAttestation[]): Promise<void>;
60
+ getCheckpointProposal(id: string): Promise<CheckpointProposalCore | undefined>;
47
61
 
48
62
  /**
49
- * Delete Attestations with a slot number smaller than the given slot
50
- *
51
- * Removes all attestations associated with a slot
63
+ * Check if a checkpoint proposal exists in the pool
52
64
  *
53
- * @param slot - The oldest slot to keep.
65
+ * @param idOrProposal - The ID of the checkpoint proposal or the proposal itself
66
+ * @return True if the proposal exists, false otherwise.
54
67
  */
55
- deleteAttestationsOlderThan(slot: SlotNumber): Promise<void>;
68
+ hasCheckpointProposal(idOrProposal: string | CheckpointProposal): Promise<boolean>;
56
69
 
57
70
  /**
58
- * Delete Attestations for slot
59
- *
60
- * Removes all attestations associated with a slot
71
+ * Add checkpoint attestations to the pool
61
72
  *
62
- * @param slot - The slot to delete.
73
+ * @param attestations - Checkpoint attestations to add into the pool
63
74
  */
64
- deleteAttestationsForSlot(slot: SlotNumber): Promise<void>;
75
+ addCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void>;
65
76
 
66
77
  /**
67
- * Delete Attestations for slot and proposal
68
- *
69
- * Removes all attestations associated with a slot and proposal
78
+ * Delete checkpoint attestations older than the given slot
70
79
  *
71
- * @param slot - The slot to delete.
72
- * @param proposalId - The proposal to delete.
80
+ * @param slot - The oldest slot to keep.
73
81
  */
74
- deleteAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<void>;
82
+ deleteCheckpointAttestationsOlderThan(slot: SlotNumber): Promise<void>;
75
83
 
76
84
  /**
77
- * Get all Attestations for all proposals for a given slot
78
- *
79
- * Retrieve all of the attestations observed pertaining to a given slot
85
+ * Get all checkpoint attestations for a given slot
80
86
  *
81
87
  * @param slot - The slot to query
82
- * @return BlockAttestations
88
+ * @return CheckpointAttestations
83
89
  */
84
- getAttestationsForSlot(slot: SlotNumber): Promise<BlockAttestation[]>;
90
+ getCheckpointAttestationsForSlot(slot: SlotNumber): Promise<CheckpointAttestation[]>;
85
91
 
86
92
  /**
87
- * Get Attestations for slot and given proposal
88
- *
89
- * Retrieve all of the attestations observed pertaining to a given slot
93
+ * Get checkpoint attestations for slot and given proposal
90
94
  *
91
95
  * @param slot - The slot to query
92
96
  * @param proposalId - The proposal to query
93
- * @return BlockAttestations
97
+ * @return CheckpointAttestations
94
98
  */
95
- getAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<BlockAttestation[]>;
99
+ getCheckpointAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<CheckpointAttestation[]>;
96
100
 
97
101
  /**
98
- * Check if a specific attestation exists in the pool
102
+ * Check if a specific checkpoint attestation exists in the pool
99
103
  *
100
104
  * @param attestation - The attestation to check
101
105
  * @return True if the attestation exists, false otherwise
102
106
  */
103
- hasAttestation(attestation: BlockAttestation): Promise<boolean>;
107
+ hasCheckpointAttestation(attestation: CheckpointAttestation): Promise<boolean>;
104
108
 
105
109
  /**
106
110
  * Returns whether adding this proposal is permitted at current capacity:
@@ -114,16 +118,39 @@ export interface AttestationPool {
114
118
  canAddProposal(block: BlockProposal): Promise<boolean>;
115
119
 
116
120
  /**
117
- * Returns whether an attestation would be accepted for (slot, proposalId):
118
- * - True if the attestation already exists for this sender.
119
- * - True if the attestation cap for (slot, proposalId) has not been reached.
120
- * - False if the cap is reached and this attestation would be a new unique entry.
121
+ * Returns whether adding this checkpoint proposal is permitted at current capacity.
122
+ *
123
+ * @param proposal - The checkpoint proposal to check
124
+ * @returns True if the proposal can be added, false otherwise.
125
+ */
126
+ canAddCheckpointProposal(proposal: CheckpointProposal): Promise<boolean>;
127
+
128
+ /**
129
+ * Returns whether a checkpoint attestation would be accepted for (slot, proposalId).
121
130
  *
122
131
  * @param attestation - The attestation to check
123
- * @param committeeSize - Committee size for the attestation's slot, implementation may add a small buffer
132
+ * @param committeeSize - Committee size for the attestation's slot
124
133
  * @returns True if the attestation can be added, false otherwise.
125
134
  */
126
- canAddAttestation(attestation: BlockAttestation, committeeSize: number): Promise<boolean>;
135
+ canAddCheckpointAttestation(attestation: CheckpointAttestation, committeeSize: number): Promise<boolean>;
136
+
137
+ /**
138
+ * Returns whether the checkpoint proposal cap for the given slot has been reached.
139
+ *
140
+ * @param slot - The slot to check
141
+ * @returns True if the cap has been reached, false otherwise.
142
+ */
143
+ hasReachedCheckpointProposalCap(slot: SlotNumber): Promise<boolean>;
144
+
145
+ /**
146
+ * Returns whether the checkpoint attestation cap for the given slot and proposal has been reached.
147
+ *
148
+ * @param slot - The slot to check
149
+ * @param proposalId - The proposal to check
150
+ * @param committeeSize - Committee size for the slot
151
+ * @returns True if the cap has been reached, false otherwise.
152
+ */
153
+ hasReachedCheckpointAttestationCap(slot: SlotNumber, proposalId: string, committeeSize: number): Promise<boolean>;
127
154
 
128
155
  /** Returns whether the pool is empty. */
129
156
  isEmpty(): Promise<boolean>;