@aztec/p2p 0.0.1-commit.c7c42ec → 0.0.1-commit.f295ac2

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 (188) 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 +13 -8
  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 +17 -4
  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 +77 -4
  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 +115 -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 +2 -2
  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/low_priority_eviction_rule.d.ts +2 -2
  41. package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
  43. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
  44. package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
  45. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
  46. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  47. package/dest/msg_validators/attestation_validator/attestation_validator.js +12 -10
  48. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
  49. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  50. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +7 -10
  51. package/dest/msg_validators/index.d.ts +2 -2
  52. package/dest/msg_validators/index.d.ts.map +1 -1
  53. package/dest/msg_validators/index.js +1 -1
  54. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
  55. package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
  56. package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
  57. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
  58. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
  59. package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
  60. package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
  61. package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
  62. package/dest/msg_validators/proposal_validator/index.js +3 -0
  63. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
  64. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
  65. package/dest/msg_validators/{block_proposal_validator/block_proposal_validator.js → proposal_validator/proposal_validator.js} +19 -21
  66. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
  67. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
  68. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +183 -0
  69. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  70. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  71. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
  72. package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
  73. package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
  74. package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
  75. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  76. package/dest/msg_validators/tx_validator/gas_validator.js +8 -14
  77. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
  78. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  79. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +1 -1
  80. package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
  81. package/dest/services/dummy_service.d.ts +6 -2
  82. package/dest/services/dummy_service.d.ts.map +1 -1
  83. package/dest/services/dummy_service.js +3 -0
  84. package/dest/services/encoding.d.ts +1 -1
  85. package/dest/services/encoding.d.ts.map +1 -1
  86. package/dest/services/encoding.js +4 -2
  87. package/dest/services/libp2p/instrumentation.d.ts +1 -1
  88. package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
  89. package/dest/services/libp2p/instrumentation.js +20 -73
  90. package/dest/services/libp2p/libp2p_service.d.ts +27 -10
  91. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  92. package/dest/services/libp2p/libp2p_service.js +696 -137
  93. package/dest/services/peer-manager/metrics.d.ts +1 -1
  94. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  95. package/dest/services/peer-manager/metrics.js +6 -26
  96. package/dest/services/peer-manager/peer_manager.d.ts +2 -2
  97. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  98. package/dest/services/peer-manager/peer_manager.js +0 -10
  99. package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
  100. package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
  101. package/dest/services/peer-manager/peer_scoring.js +2 -5
  102. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -1
  103. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  104. package/dest/services/reqresp/constants.d.ts +12 -0
  105. package/dest/services/reqresp/constants.d.ts.map +1 -0
  106. package/dest/services/reqresp/constants.js +7 -0
  107. package/dest/services/reqresp/interface.d.ts +3 -3
  108. package/dest/services/reqresp/interface.d.ts.map +1 -1
  109. package/dest/services/reqresp/interface.js +2 -2
  110. package/dest/services/reqresp/metrics.d.ts +1 -1
  111. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  112. package/dest/services/reqresp/metrics.js +5 -21
  113. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
  114. package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
  115. package/dest/services/reqresp/protocols/block_txs/bitvector.js +7 -0
  116. package/dest/services/reqresp/protocols/status.d.ts +1 -1
  117. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  118. package/dest/services/reqresp/protocols/status.js +4 -1
  119. package/dest/services/reqresp/reqresp.js +402 -24
  120. package/dest/services/service.d.ts +16 -3
  121. package/dest/services/service.d.ts.map +1 -1
  122. package/dest/services/tx_collection/instrumentation.d.ts +1 -1
  123. package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
  124. package/dest/services/tx_collection/instrumentation.js +4 -14
  125. package/dest/services/tx_provider_instrumentation.d.ts +1 -1
  126. package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
  127. package/dest/services/tx_provider_instrumentation.js +6 -19
  128. package/dest/testbench/p2p_client_testbench_worker.js +27 -12
  129. package/dest/testbench/worker_client_manager.d.ts +1 -1
  130. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  131. package/dest/testbench/worker_client_manager.js +6 -1
  132. package/package.json +16 -16
  133. package/src/client/interface.ts +19 -4
  134. package/src/client/p2p_client.ts +78 -128
  135. package/src/config.ts +2 -2
  136. package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
  137. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
  138. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
  139. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
  140. package/src/mem_pools/attestation_pool/mocks.ts +19 -13
  141. package/src/mem_pools/instrumentation.ts +9 -18
  142. package/src/mem_pools/tx_pool/README.md +28 -13
  143. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +128 -73
  144. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +64 -4
  145. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +117 -3
  146. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +159 -0
  147. package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
  148. package/src/msg_validators/attestation_validator/attestation_validator.ts +16 -13
  149. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +9 -12
  150. package/src/msg_validators/index.ts +1 -1
  151. package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
  152. package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
  153. package/src/msg_validators/proposal_validator/index.ts +3 -0
  154. package/src/msg_validators/{block_proposal_validator/block_proposal_validator.ts → proposal_validator/proposal_validator.ts} +23 -28
  155. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +206 -0
  156. package/src/msg_validators/tx_validator/data_validator.ts +12 -4
  157. package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
  158. package/src/msg_validators/tx_validator/gas_validator.ts +8 -25
  159. package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
  160. package/src/msg_validators/tx_validator/timestamp_validator.ts +3 -1
  161. package/src/services/dummy_service.ts +6 -0
  162. package/src/services/encoding.ts +3 -1
  163. package/src/services/libp2p/instrumentation.ts +19 -73
  164. package/src/services/libp2p/libp2p_service.ts +326 -102
  165. package/src/services/peer-manager/metrics.ts +5 -26
  166. package/src/services/peer-manager/peer_manager.ts +1 -2
  167. package/src/services/peer-manager/peer_scoring.ts +1 -5
  168. package/src/services/reqresp/connection-sampler/connection_sampler.ts +3 -1
  169. package/src/services/reqresp/constants.ts +14 -0
  170. package/src/services/reqresp/interface.ts +2 -2
  171. package/src/services/reqresp/metrics.ts +7 -23
  172. package/src/services/reqresp/protocols/block_txs/bitvector.ts +9 -0
  173. package/src/services/reqresp/protocols/status.ts +7 -4
  174. package/src/services/service.ts +19 -4
  175. package/src/services/tx_collection/instrumentation.ts +4 -21
  176. package/src/services/tx_provider_instrumentation.ts +11 -24
  177. package/src/testbench/p2p_client_testbench_worker.ts +35 -12
  178. package/src/testbench/worker_client_manager.ts +6 -1
  179. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
  180. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
  181. package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
  182. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
  183. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
  184. package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
  185. package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
  186. package/dest/msg_validators/block_proposal_validator/index.js +0 -1
  187. package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
  188. package/src/msg_validators/block_proposal_validator/index.ts +0 -1
@@ -1,5 +1,5 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
- import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { randomInt } from '@aztec/foundation/crypto/random';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
@@ -8,13 +8,15 @@ import { Timer } from '@aztec/foundation/timer';
8
8
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
9
9
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
10
10
  import { protocolContractsHash } from '@aztec/protocol-contracts';
11
- import type { EthAddress, L2Block, L2BlockSource } from '@aztec/stdlib/block';
11
+ import type { EthAddress, L2BlockNew, L2BlockSource } from '@aztec/stdlib/block';
12
12
  import type { ContractDataSource } from '@aztec/stdlib/contract';
13
13
  import { GasFees } from '@aztec/stdlib/gas';
14
14
  import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
15
15
  import {
16
- BlockAttestation,
17
16
  BlockProposal,
17
+ CheckpointAttestation,
18
+ CheckpointProposal,
19
+ type CheckpointProposalCore,
18
20
  type Gossipable,
19
21
  P2PClientType,
20
22
  P2PMessage,
@@ -28,7 +30,14 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
28
30
  import { Tx, type TxHash, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
29
31
  import type { UInt64 } from '@aztec/stdlib/types';
30
32
  import { compressComponentVersions } from '@aztec/stdlib/versioning';
31
- import { Attributes, OtelMetricsAdapter, type TelemetryClient, WithTracer, trackSpan } from '@aztec/telemetry-client';
33
+ import {
34
+ Attributes,
35
+ OtelMetricsAdapter,
36
+ SpanStatusCode,
37
+ type TelemetryClient,
38
+ WithTracer,
39
+ trackSpan,
40
+ } from '@aztec/telemetry-client';
32
41
 
33
42
  import {
34
43
  type GossipSub,
@@ -53,8 +62,9 @@ import type { P2PConfig } from '../../config.js';
53
62
  import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
54
63
  import type { MemPools } from '../../mem_pools/interface.js';
55
64
  import {
56
- AttestationValidator,
57
65
  BlockProposalValidator,
66
+ CheckpointAttestationValidator,
67
+ CheckpointProposalValidator,
58
68
  FishermanAttestationValidator,
59
69
  } from '../../msg_validators/index.js';
60
70
  import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
@@ -101,7 +111,12 @@ import {
101
111
  reqRespTxHandler,
102
112
  } from '../reqresp/protocols/index.js';
103
113
  import { ReqResp } from '../reqresp/reqresp.js';
104
- import type { P2PBlockReceivedCallback, P2PService, PeerDiscoveryService } from '../service.js';
114
+ import type {
115
+ P2PBlockReceivedCallback,
116
+ P2PCheckpointReceivedCallback,
117
+ P2PService,
118
+ PeerDiscoveryService,
119
+ } from '../service.js';
105
120
  import { P2PInstrumentation } from './instrumentation.js';
106
121
 
107
122
  interface ValidationResult {
@@ -125,8 +140,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
125
140
  private msgIdSeenValidators: Record<TopicType, MessageSeenValidator> = {} as Record<TopicType, MessageSeenValidator>;
126
141
 
127
142
  // Message validators
128
- private attestationValidator: AttestationValidator;
129
143
  private blockProposalValidator: BlockProposalValidator;
144
+ private checkpointProposalValidator: CheckpointProposalValidator;
145
+ private checkpointAttestationValidator: CheckpointAttestationValidator;
130
146
 
131
147
  private protocolVersion = '';
132
148
  private topicStrings: Record<TopicType, string> = {} as Record<TopicType, string>;
@@ -140,10 +156,19 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
140
156
  */
141
157
  private blockReceivedCallback: P2PBlockReceivedCallback;
142
158
 
159
+ /**
160
+ * Callback for when a checkpoint proposal is received from a peer.
161
+ * @param checkpoint - The checkpoint proposal received from the peer.
162
+ * @returns The attestations for the checkpoint, if any.
163
+ */
164
+ private checkpointReceivedCallback: P2PCheckpointReceivedCallback;
165
+
143
166
  private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
144
167
 
145
168
  private instrumentation: P2PInstrumentation;
146
169
 
170
+ private telemetry: TelemetryClient;
171
+
147
172
  protected logger: Logger;
148
173
 
149
174
  constructor(
@@ -162,6 +187,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
162
187
  logger: Logger = createLogger('p2p:libp2p_service'),
163
188
  ) {
164
189
  super(telemetry, 'LibP2PService');
190
+ this.telemetry = telemetry;
165
191
 
166
192
  // Create child logger with fisherman prefix if in fisherman mode
167
193
  this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
@@ -170,7 +196,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
170
196
 
171
197
  this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize);
172
198
  this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
173
- this.msgIdSeenValidators[TopicType.block_attestation] = new MessageSeenValidator(config.seenMessageCacheSize);
199
+ this.msgIdSeenValidators[TopicType.checkpoint_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
200
+ this.msgIdSeenValidators[TopicType.checkpoint_attestation] = new MessageSeenValidator(config.seenMessageCacheSize);
174
201
 
175
202
  const versions = getVersions(config);
176
203
  this.protocolVersion = compressComponentVersions(versions);
@@ -178,25 +205,40 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
178
205
 
179
206
  this.topicStrings[TopicType.tx] = createTopicString(TopicType.tx, this.protocolVersion);
180
207
  this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
181
- this.topicStrings[TopicType.block_attestation] = createTopicString(
182
- TopicType.block_attestation,
208
+ this.topicStrings[TopicType.checkpoint_proposal] = createTopicString(
209
+ TopicType.checkpoint_proposal,
210
+ this.protocolVersion,
211
+ );
212
+ this.topicStrings[TopicType.checkpoint_attestation] = createTopicString(
213
+ TopicType.checkpoint_attestation,
183
214
  this.protocolVersion,
184
215
  );
185
216
 
186
- // Use FishermanAttestationValidator in fisherman mode to validate attestation payloads against proposals
187
- this.attestationValidator = config.fishermanMode
188
- ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
189
- : new AttestationValidator(epochCache);
190
217
  this.blockProposalValidator = new BlockProposalValidator(epochCache, { txsPermitted: !config.disableTransactions });
218
+ this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
219
+ txsPermitted: !config.disableTransactions,
220
+ });
221
+ this.checkpointAttestationValidator = config.fishermanMode
222
+ ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
223
+ : new CheckpointAttestationValidator(epochCache);
191
224
 
192
225
  this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
193
226
 
194
- this.blockReceivedCallback = async (block: BlockProposal): Promise<BlockAttestation[] | undefined> => {
227
+ this.blockReceivedCallback = async (block: BlockProposal): Promise<boolean> => {
195
228
  this.logger.debug(
196
229
  `Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber} from peer.`,
197
230
  { p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
198
231
  );
199
- return undefined;
232
+ return false;
233
+ };
234
+
235
+ this.checkpointReceivedCallback = (
236
+ checkpoint: CheckpointProposalCore,
237
+ ): Promise<CheckpointAttestation[] | undefined> => {
238
+ this.logger.debug(
239
+ `Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`,
240
+ );
241
+ return Promise.resolve(undefined);
200
242
  };
201
243
  }
202
244
 
@@ -265,7 +307,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
265
307
 
266
308
  const txTopic = createTopicString(TopicType.tx, protocolVersion);
267
309
  const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
268
- const blockAttestationTopic = createTopicString(TopicType.block_attestation, protocolVersion);
310
+ const checkpointProposalTopic = createTopicString(TopicType.checkpoint_proposal, protocolVersion);
311
+ const checkpointAttestationTopic = createTopicString(TopicType.checkpoint_attestation, protocolVersion);
269
312
 
270
313
  const preferredPeersEnrs: ENR[] = config.preferredPeers.map(enr => ENR.decodeTxt(enr));
271
314
  const directPeers = (
@@ -387,12 +430,17 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
387
430
  invalidMessageDeliveriesWeight: -20,
388
431
  invalidMessageDeliveriesDecay: 0.5,
389
432
  }),
390
- [blockAttestationTopic]: createTopicScoreParams({
433
+ [blockProposalTopic]: createTopicScoreParams({
391
434
  topicWeight: 1,
392
435
  invalidMessageDeliveriesWeight: -20,
393
436
  invalidMessageDeliveriesDecay: 0.5,
394
437
  }),
395
- [blockProposalTopic]: createTopicScoreParams({
438
+ [checkpointProposalTopic]: createTopicScoreParams({
439
+ topicWeight: 1,
440
+ invalidMessageDeliveriesWeight: -20,
441
+ invalidMessageDeliveriesDecay: 0.5,
442
+ }),
443
+ [checkpointAttestationTopic]: createTopicScoreParams({
396
444
  topicWeight: 1,
397
445
  invalidMessageDeliveriesWeight: -20,
398
446
  invalidMessageDeliveriesDecay: 0.5,
@@ -462,17 +510,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
462
510
  }
463
511
  const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
464
512
 
465
- await this.peerManager.initializePeers();
466
- if (!this.config.p2pDiscoveryDisabled) {
467
- await this.peerDiscoveryService.start();
468
- }
469
- await this.node.start();
470
-
471
- // Subscribe to standard GossipSub topics by default
472
- for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)) {
473
- this.subscribeToTopic(this.topicStrings[topic]);
474
- }
475
-
476
513
  // Create request response protocol handlers
477
514
  const txHandler = reqRespTxHandler(this.mempools);
478
515
  const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
@@ -495,10 +532,32 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
495
532
  requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
496
533
  }
497
534
 
535
+ // Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
536
+ const reqrespSubProtocolValidators = {
537
+ ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
538
+ [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
539
+ [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
540
+ [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
541
+ };
542
+
543
+ await this.peerManager.initializePeers();
544
+
545
+ await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
546
+
547
+ await this.node.start();
548
+
549
+ // Subscribe to standard GossipSub topics by default
550
+ for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)) {
551
+ this.subscribeToTopic(this.topicStrings[topic]);
552
+ }
553
+
498
554
  // add GossipSub listener
499
555
  this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
500
556
 
501
557
  // Start running promise for peer discovery and metrics collection
558
+ if (!this.config.p2pDiscoveryDisabled) {
559
+ await this.peerDiscoveryService.start();
560
+ }
502
561
  this.discoveryRunningPromise = new RunningPromise(
503
562
  async () => {
504
563
  await this.peerManager.heartbeat();
@@ -508,14 +567,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
508
567
  );
509
568
  this.discoveryRunningPromise.start();
510
569
 
511
- // Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
512
- const reqrespSubProtocolValidators = {
513
- ...DEFAULT_SUB_PROTOCOL_VALIDATORS,
514
- [ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
515
- [ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
516
- [ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
517
- };
518
- await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
519
570
  this.logger.info(`Started P2P service`, {
520
571
  listen: this.config.listenAddress,
521
572
  port: this.config.p2pPort,
@@ -601,6 +652,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
601
652
  this.blockReceivedCallback = callback;
602
653
  }
603
654
 
655
+ public registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
656
+ this.checkpointReceivedCallback = callback;
657
+ }
658
+
604
659
  /**
605
660
  * Subscribes to a topic.
606
661
  * @param topic - The topic to subscribe to.
@@ -622,7 +677,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
622
677
  if (!this.node.services.pubsub) {
623
678
  throw new Error('Pubsub service not available.');
624
679
  }
625
- const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages);
680
+ const isBlockProposal = topic === this.topicStrings[TopicType.block_proposal];
681
+ const traceContext =
682
+ this.config.debugP2PInstrumentMessages && isBlockProposal ? this.telemetry.getTraceContext() : undefined;
683
+ const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages, traceContext);
626
684
  const result = await this.node.services.pubsub.publish(topic, p2pMessage.toMessageData());
627
685
  return result.recipients.length;
628
686
  }
@@ -643,12 +701,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
643
701
  case this.topicStrings[TopicType.tx]:
644
702
  topicType = TopicType.tx;
645
703
  break;
646
- case this.topicStrings[TopicType.block_attestation]:
647
- topicType = TopicType.block_attestation;
648
- break;
649
704
  case this.topicStrings[TopicType.block_proposal]:
650
705
  topicType = TopicType.block_proposal;
651
706
  break;
707
+ case this.topicStrings[TopicType.checkpoint_proposal]:
708
+ topicType = TopicType.checkpoint_proposal;
709
+ break;
710
+ case this.topicStrings[TopicType.checkpoint_attestation]:
711
+ topicType = TopicType.checkpoint_attestation;
712
+ break;
652
713
  default:
653
714
  this.logger.error(`Received message on unknown topic: ${msg.topic}`);
654
715
  break;
@@ -707,23 +768,74 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
707
768
  return;
708
769
  }
709
770
 
771
+ // Determine topic type for attributes
710
772
  if (msg.topic === this.topicStrings[TopicType.tx]) {
711
773
  topicType = TopicType.tx;
712
- await this.handleGossipedTx(p2pMessage.payload, msgId, source);
774
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
775
+ topicType = TopicType.checkpoint_attestation;
776
+ } else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
777
+ topicType = TopicType.block_proposal;
778
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
779
+ topicType = TopicType.checkpoint_proposal;
713
780
  }
714
- if (msg.topic === this.topicStrings[TopicType.block_attestation]) {
715
- topicType = TopicType.block_attestation;
716
- if (this.clientType === P2PClientType.Full) {
717
- await this.processAttestationFromPeer(p2pMessage.payload, msgId, source);
781
+
782
+ // Process the message, optionally within a linked span for trace propagation
783
+ const processMessage = async () => {
784
+ if (msg.topic === this.topicStrings[TopicType.tx]) {
785
+ await this.handleGossipedTx(p2pMessage.payload, msgId, source);
786
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
787
+ if (this.clientType === P2PClientType.Full) {
788
+ await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
789
+ }
790
+ } else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
791
+ await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
792
+ } else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
793
+ await this.handleGossipedCheckpointProposal(p2pMessage.payload, msgId, source);
794
+ } else {
795
+ this.logger.error(`Received message on unknown topic: ${msg.topic}`);
718
796
  }
719
- }
720
- if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
721
- topicType = TopicType.block_proposal;
722
- await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
797
+ };
798
+
799
+ const latency = p2pMessage.timestamp !== undefined ? msgReceivedTime - p2pMessage.timestamp.getTime() : undefined;
800
+ const propagatedContext = p2pMessage.traceContext
801
+ ? this.telemetry.extractPropagatedContext(p2pMessage.traceContext)
802
+ : undefined;
803
+
804
+ if (propagatedContext) {
805
+ await this.tracer.startActiveSpan(
806
+ 'LibP2PService.processMessage',
807
+ {
808
+ attributes: {
809
+ [Attributes.TOPIC_NAME]: topicType!,
810
+ [Attributes.PEER_ID]: source.toString(),
811
+ },
812
+ },
813
+ propagatedContext,
814
+ async span => {
815
+ try {
816
+ await processMessage();
817
+ span.setStatus({
818
+ code: SpanStatusCode.OK,
819
+ });
820
+ } catch (err) {
821
+ span.setStatus({
822
+ code: SpanStatusCode.ERROR,
823
+ message: String(err),
824
+ });
825
+ if (typeof err === 'string' || (err && err instanceof Error)) {
826
+ span.recordException(err);
827
+ }
828
+ throw err;
829
+ } finally {
830
+ span.end();
831
+ }
832
+ },
833
+ );
834
+ } else {
835
+ await processMessage();
723
836
  }
724
837
 
725
- if (p2pMessage.timestamp !== undefined && topicType !== undefined) {
726
- const latency = msgReceivedTime - p2pMessage.timestamp.getTime();
838
+ if (latency !== undefined && topicType !== undefined) {
727
839
  this.instrumentation.recordMessageLatency(topicType, latency);
728
840
  }
729
841
 
@@ -800,27 +912,29 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
800
912
  }
801
913
 
802
914
  /**
803
- * Process Attestation From Peer
804
- * When a proposal is received from a peer, we add it to the attestation pool, so it can be accessed by other services.
805
- *
806
- * @param attestation - The attestation to process.
915
+ * Process a checkpoint attestation from a peer.
916
+ * Validates the attestation and adds it to the pool.
807
917
  */
808
- private async processAttestationFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
809
- const validationFunc: () => Promise<ReceivedMessageValidationResult<BlockAttestation>> = async () => {
810
- const attestation = BlockAttestation.fromBuffer(payloadData);
918
+ private async processCheckpointAttestationFromPeer(
919
+ payloadData: Buffer,
920
+ msgId: string,
921
+ source: PeerId,
922
+ ): Promise<void> {
923
+ const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointAttestation>> = async () => {
924
+ const attestation = CheckpointAttestation.fromBuffer(payloadData);
811
925
  const pool = this.mempools.attestationPool;
812
- const isValid = await this.validateAttestation(source, attestation);
813
- const exists = isValid && (await pool.hasAttestation(attestation));
926
+ const isValid = await this.validateCheckpointAttestation(source, attestation);
927
+ const exists = isValid && (await pool.hasCheckpointAttestation(attestation));
814
928
 
815
929
  let canAdd = true;
816
930
  if (isValid && !exists) {
817
931
  const slot = attestation.payload.header.slotNumber;
818
932
  const { committee } = await this.epochCache.getCommittee(slot);
819
933
  const committeeSize = committee?.length ?? 0;
820
- canAdd = await pool.canAddAttestation(attestation, committeeSize);
934
+ canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
821
935
  }
822
936
 
823
- this.logger.trace(`Validate propagated block attestation`, {
937
+ this.logger.trace(`Validate propagated checkpoint attestation`, {
824
938
  isValid,
825
939
  exists,
826
940
  canAdd,
@@ -833,7 +947,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
833
947
  } else if (exists) {
834
948
  return { result: TopicValidatorResult.Ignore, obj: attestation };
835
949
  } else if (!canAdd) {
836
- this.logger.warn(`Dropping block attestation due to per-(slot, proposalId) attestation cap`, {
950
+ this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
837
951
  slot: attestation.payload.header.slotNumber.toString(),
838
952
  archive: attestation.archive.toString(),
839
953
  source: source.toString(),
@@ -844,11 +958,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
844
958
  }
845
959
  };
846
960
 
847
- const { result, obj: attestation } = await this.validateReceivedMessage<BlockAttestation>(
961
+ const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
848
962
  validationFunc,
849
963
  msgId,
850
964
  source,
851
- TopicType.block_attestation,
965
+ TopicType.checkpoint_attestation,
852
966
  );
853
967
 
854
968
  if (result !== TopicValidatorResult.Accept || !attestation) {
@@ -856,7 +970,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
856
970
  }
857
971
 
858
972
  this.logger.debug(
859
- `Received attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
973
+ `Received checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
860
974
  {
861
975
  p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
862
976
  slot: attestation.slotNumber,
@@ -865,7 +979,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
865
979
  },
866
980
  );
867
981
 
868
- await this.mempools.attestationPool.addAttestations([attestation]);
982
+ await this.mempools.attestationPool.addCheckpointAttestations([attestation]);
869
983
  }
870
984
 
871
985
  private async processBlockFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
@@ -881,7 +995,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
881
995
  isValid,
882
996
  exists,
883
997
  canAdd,
884
- [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString(),
998
+ [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
885
999
  [Attributes.P2P_ID]: source.toString(),
886
1000
  });
887
1001
 
@@ -917,6 +1031,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
917
1031
  }
918
1032
 
919
1033
  // REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
1034
+ // REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
1035
+ // should not be here as it does not deal with p2p networking.
920
1036
  @trackSpan('Libp2pService.processValidBlockProposal', async block => ({
921
1037
  [Attributes.SLOT_NUMBER]: block.slotNumber,
922
1038
  [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
@@ -924,17 +1040,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
924
1040
  }))
925
1041
  private async processValidBlockProposal(block: BlockProposal, sender: PeerId) {
926
1042
  const slot = block.slotNumber;
927
- const previousSlot = SlotNumber(slot - 1);
928
1043
  this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
929
1044
  p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
930
- slot: block.slotNumber,
931
- archive: block.archive.toString(),
932
1045
  source: sender.toString(),
1046
+ ...block.toBlockInfo(),
933
1047
  });
934
- const attestationsForPreviousSlot = await this.mempools.attestationPool.getAttestationsForSlot(previousSlot);
935
- this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
936
1048
 
937
- // Attempt to add proposal, then mark the txs in this proposal as non-evictable
1049
+ // Attempt to add proposal
938
1050
  try {
939
1051
  await this.mempools.attestationPool.addBlockProposal(block);
940
1052
  } catch (err: unknown) {
@@ -949,34 +1061,125 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
949
1061
  }
950
1062
  throw err;
951
1063
  }
1064
+
1065
+ // Mark the txs in this proposal as non-evictable
952
1066
  await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
953
- const attestations = await this.blockReceivedCallback(block, sender);
954
1067
 
955
- // TODO: fix up this pattern - the abstraction is not nice
956
- // The attestation can be undefined if no handler is registered / the validator deems the block invalid / in fisherman mode
957
- if (attestations?.length) {
958
- for (const attestation of attestations) {
959
- this.logger.verbose(`Broadcasting attestation for slot ${attestation.slotNumber}`, {
960
- p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
961
- slot: attestation.slotNumber,
962
- archive: attestation.archive.toString(),
1068
+ // Call the block received callback to validate the proposal.
1069
+ // Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
1070
+ const isValid = await this.blockReceivedCallback(block, sender);
1071
+ if (!isValid) {
1072
+ this.logger.warn(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
1073
+ }
1074
+ }
1075
+
1076
+ /**
1077
+ * Handle a gossiped checkpoint proposal.
1078
+ * Validates and processes the checkpoint proposal, then triggers the callback for attestation.
1079
+ */
1080
+ private async handleGossipedCheckpointProposal(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
1081
+ // TODO(palla/mbps): This pattern is repeated across multiple message handlers, consider abstracting it.
1082
+ const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointProposal>> = async () => {
1083
+ const checkpoint = CheckpointProposal.fromBuffer(payloadData);
1084
+ const isValid = await this.validateCheckpointProposal(source, checkpoint);
1085
+ const pool = this.mempools.attestationPool;
1086
+
1087
+ const exists = isValid && (await pool.hasCheckpointProposal(checkpoint));
1088
+ const canAdd = isValid && (await pool.canAddCheckpointProposal(checkpoint));
1089
+
1090
+ this.logger.trace(`Validate propagated checkpoint proposal`, {
1091
+ isValid,
1092
+ exists,
1093
+ canAdd,
1094
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1095
+ [Attributes.P2P_ID]: source.toString(),
1096
+ });
1097
+
1098
+ if (!isValid) {
1099
+ return { result: TopicValidatorResult.Reject };
1100
+ } else if (exists) {
1101
+ return { result: TopicValidatorResult.Ignore, obj: checkpoint };
1102
+ } else if (!canAdd) {
1103
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
1104
+ this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
1105
+ slot: checkpoint.slotNumber.toString(),
1106
+ archive: checkpoint.archive.toString(),
1107
+ source: source.toString(),
963
1108
  });
964
- await this.broadcastAttestation(attestation);
1109
+ return { result: TopicValidatorResult.Reject };
1110
+ } else {
1111
+ return { result: TopicValidatorResult.Accept, obj: checkpoint };
965
1112
  }
1113
+ };
1114
+
1115
+ const { result, obj: checkpoint } = await this.validateReceivedMessage<CheckpointProposal>(
1116
+ validationFunc,
1117
+ msgId,
1118
+ source,
1119
+ TopicType.checkpoint_proposal,
1120
+ );
1121
+
1122
+ if (result !== TopicValidatorResult.Accept || !checkpoint) {
1123
+ return;
966
1124
  }
1125
+
1126
+ await this.processValidCheckpointProposal(checkpoint, source);
967
1127
  }
968
1128
 
969
1129
  /**
970
- * Broadcast an attestation to all peers.
971
- * @param attestation - The attestation to broadcast.
1130
+ * Process a validated checkpoint proposal.
1131
+ * Extracts and processes the last block proposal (if present) first, then processes the checkpoint.
1132
+ * The block callback is invoked before the checkpoint callback.
972
1133
  */
973
- @trackSpan('Libp2pService.broadcastAttestation', async attestation => ({
974
- [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
975
- [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
976
- [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
1134
+ @trackSpan('Libp2pService.processValidCheckpointProposal', async checkpoint => ({
1135
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
1136
+ [Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
1137
+ [Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then(i => i.toString()),
977
1138
  }))
978
- private async broadcastAttestation(attestation: BlockAttestation) {
979
- await this.propagate(attestation);
1139
+ private async processValidCheckpointProposal(checkpoint: CheckpointProposal, sender: PeerId) {
1140
+ const slot = checkpoint.slotNumber;
1141
+ this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
1142
+ p2pMessageIdentifier: await checkpoint.p2pMessageLoggingIdentifier(),
1143
+ slot: checkpoint.slotNumber,
1144
+ archive: checkpoint.archive.toString(),
1145
+ source: sender.toString(),
1146
+ });
1147
+
1148
+ // Extract block proposal before adding to pool (pool stores them separately)
1149
+ const blockProposal = checkpoint.getBlockProposal();
1150
+
1151
+ // Add proposal to the pool (this extracts and stores block proposal separately)
1152
+ await this.mempools.attestationPool.addCheckpointProposal(checkpoint);
1153
+
1154
+ // Mark txs as non-evictable if present (from the last block)
1155
+ if (checkpoint.txHashes.length > 0) {
1156
+ await this.mempools.txPool.markTxsAsNonEvictable(checkpoint.txHashes);
1157
+ }
1158
+
1159
+ // If there was a last block proposal, invoke the block callback first for validation.
1160
+ // Note: The block proposal is already stored in the pool by addCheckpointProposal.
1161
+ if (blockProposal) {
1162
+ const isValid = await this.blockReceivedCallback(blockProposal, sender);
1163
+ if (!isValid) {
1164
+ this.logger.warn(`Block proposal from checkpoint failed validation`, {
1165
+ slot: slot.toString(),
1166
+ archive: checkpoint.archive.toString(),
1167
+ blockNumber: blockProposal.blockNumber.toString(),
1168
+ });
1169
+ return;
1170
+ }
1171
+ }
1172
+
1173
+ // Call the checkpoint received callback with the core version (without lastBlock)
1174
+ // to validate and potentially generate attestations
1175
+ const attestations = await this.checkpointReceivedCallback(checkpoint.toCore(), sender);
1176
+ if (attestations && attestations.length > 0) {
1177
+ // If the callback returned attestations, add them to the pool and propagate them
1178
+ await this.mempools.attestationPool.addCheckpointAttestations(attestations);
1179
+ for (const attestation of attestations) {
1180
+ await this.propagate(attestation);
1181
+ }
1182
+ }
980
1183
  }
981
1184
 
982
1185
  /**
@@ -1133,7 +1336,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1133
1336
  }))
1134
1337
  private async validateRequestedBlock(
1135
1338
  requestedBlockNumber: Fr,
1136
- responseBlock: L2Block,
1339
+ responseBlock: L2BlockNew,
1137
1340
  peerId: PeerId,
1138
1341
  ): Promise<boolean> {
1139
1342
  try {
@@ -1361,19 +1564,20 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1361
1564
  }
1362
1565
 
1363
1566
  /**
1364
- * Validate an attestation.
1567
+ * Validate a checkpoint attestation.
1365
1568
  *
1366
- * @param attestation - The attestation to validate.
1367
- * @returns True if the attestation is valid, false otherwise.
1569
+ * @param attestation - The checkpoint attestation to validate.
1570
+ * @returns True if the checkpoint attestation is valid, false otherwise.
1368
1571
  */
1369
- @trackSpan('Libp2pService.validateAttestation', async (_, attestation) => ({
1572
+ @trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
1370
1573
  [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
1371
1574
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
1372
1575
  [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
1373
1576
  }))
1374
- public async validateAttestation(peerId: PeerId, attestation: BlockAttestation): Promise<boolean> {
1375
- const severity = await this.attestationValidator.validate(attestation);
1577
+ public async validateCheckpointAttestation(peerId: PeerId, attestation: CheckpointAttestation): Promise<boolean> {
1578
+ const severity = await this.checkpointAttestationValidator.validate(attestation);
1376
1579
  if (severity) {
1580
+ this.logger.debug(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1377
1581
  this.peerManager.penalizePeer(peerId, severity);
1378
1582
  return false;
1379
1583
  }
@@ -1388,7 +1592,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1388
1592
  * @returns True if the block proposal is valid, false otherwise.
1389
1593
  */
1390
1594
  @trackSpan('Libp2pService.validateBlockProposal', (_peerId, block) => ({
1391
- [Attributes.SLOT_NUMBER]: block.payload.header.slotNumber.toString(),
1595
+ [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
1392
1596
  }))
1393
1597
  public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<boolean> {
1394
1598
  const severity = await this.blockProposalValidator.validate(block);
@@ -1401,6 +1605,26 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1401
1605
  return true;
1402
1606
  }
1403
1607
 
1608
+ /**
1609
+ * Validate a checkpoint proposal.
1610
+ *
1611
+ * @param checkpoint - The checkpoint proposal to validate.
1612
+ * @returns True if the checkpoint proposal is valid, false otherwise.
1613
+ */
1614
+ @trackSpan('Libp2pService.validateCheckpointProposal', (_peerId, checkpoint) => ({
1615
+ [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1616
+ }))
1617
+ public async validateCheckpointProposal(peerId: PeerId, checkpoint: CheckpointProposal): Promise<boolean> {
1618
+ const severity = await this.checkpointProposalValidator.validate(checkpoint);
1619
+ if (severity) {
1620
+ this.logger.debug(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1621
+ this.peerManager.penalizePeer(peerId, severity);
1622
+ return false;
1623
+ }
1624
+
1625
+ return true;
1626
+ }
1627
+
1404
1628
  public getPeerScore(peerId: PeerId): number {
1405
1629
  return this.node.services.pubsub.score.score(peerId.toString());
1406
1630
  }