@aztec/p2p 0.0.1-commit.2ed92850 → 0.0.1-commit.3469e52

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 (62) hide show
  1. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +3 -3
  2. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  3. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +2 -3
  4. package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
  5. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +2 -3
  6. package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
  7. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +3 -3
  8. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  9. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +1 -8
  10. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +3 -3
  11. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
  12. package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -2
  13. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +3 -3
  14. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  15. package/dest/msg_validators/attestation_validator/attestation_validator.js +9 -40
  16. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
  17. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
  18. package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -11
  19. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -3
  20. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  21. package/dest/msg_validators/proposal_validator/proposal_validator.js +12 -43
  22. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +3 -3
  23. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
  24. package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +11 -66
  25. package/dest/msg_validators/tx_validator/block_header_validator.d.ts +1 -1
  26. package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
  27. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  28. package/dest/services/libp2p/libp2p_service.d.ts +5 -5
  29. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  30. package/dest/services/libp2p/libp2p_service.js +24 -24
  31. package/dest/services/reqresp/interface.d.ts +3 -3
  32. package/dest/services/reqresp/interface.d.ts.map +1 -1
  33. package/dest/services/reqresp/interface.js +2 -2
  34. package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
  35. package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
  36. package/dest/services/tx_collection/tx_collection.d.ts +5 -5
  37. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  38. package/dest/services/tx_provider.d.ts +3 -3
  39. package/dest/services/tx_provider.d.ts.map +1 -1
  40. package/dest/testbench/p2p_client_testbench_worker.js +1 -2
  41. package/package.json +14 -14
  42. package/src/client/p2p_client.ts +5 -5
  43. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +2 -2
  44. package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +1 -2
  45. package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +1 -2
  46. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +7 -10
  47. package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +2 -4
  48. package/src/msg_validators/attestation_validator/attestation_validator.ts +13 -25
  49. package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +6 -6
  50. package/src/msg_validators/proposal_validator/proposal_validator.ts +11 -18
  51. package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +14 -53
  52. package/src/msg_validators/tx_validator/block_header_validator.ts +1 -3
  53. package/src/services/libp2p/libp2p_service.ts +29 -39
  54. package/src/services/reqresp/interface.ts +2 -2
  55. package/src/services/tx_collection/slow_tx_collection.ts +2 -2
  56. package/src/services/tx_collection/tx_collection.ts +4 -4
  57. package/src/services/tx_provider.ts +2 -2
  58. package/src/testbench/p2p_client_testbench_worker.ts +1 -1
  59. package/dest/msg_validators/clock_tolerance.d.ts +0 -21
  60. package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
  61. package/dest/msg_validators/clock_tolerance.js +0 -37
  62. package/src/msg_validators/clock_tolerance.ts +0 -51
@@ -1,12 +1,7 @@
1
1
  import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
2
  import type { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
3
3
  import type { EthAddress } from '@aztec/foundation/eth-address';
4
- import {
5
- type BlockProposal,
6
- type CheckpointProposal,
7
- PeerErrorSeverity,
8
- type ValidationResult,
9
- } from '@aztec/stdlib/p2p';
4
+ import { type BlockProposal, type CheckpointProposal, PeerErrorSeverity } from '@aztec/stdlib/p2p';
10
5
  import type { TxHash } from '@aztec/stdlib/tx';
11
6
 
12
7
  import type { MockProxy } from 'jest-mock-extended';
@@ -15,7 +10,7 @@ export interface ProposalValidatorTestParams<TProposal extends BlockProposal | C
15
10
  validatorFactory: (
16
11
  epochCache: EpochCacheInterface,
17
12
  opts: { txsPermitted: boolean },
18
- ) => { validate: (proposal: TProposal) => Promise<ValidationResult> };
13
+ ) => { validate: (proposal: TProposal) => Promise<PeerErrorSeverity | undefined> };
19
14
  makeProposal: (options?: any) => Promise<TProposal>;
20
15
  makeHeader: (epochNumber: number | bigint, slotNumber: number | bigint, blockNumber: number | bigint) => any;
21
16
  getSigner: () => Secp256k1Signer;
@@ -34,12 +29,11 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
34
29
 
35
30
  describe('shared proposal validation logic', () => {
36
31
  let epochCache: MockProxy<EpochCacheInterface>;
37
- let validator: { validate: (proposal: TProposal) => Promise<ValidationResult> };
38
- const previousSlot = getSlot(99);
32
+ let validator: { validate: (proposal: TProposal) => Promise<PeerErrorSeverity | undefined> };
39
33
  const currentSlot = getSlot(100);
40
34
  const nextSlot = getSlot(101);
41
35
 
42
- function mockGetProposer(currentProposer: EthAddress, nextProposer: EthAddress, previousProposer?: EthAddress) {
36
+ function mockGetProposer(currentProposer: EthAddress, nextProposer: EthAddress) {
43
37
  epochCache.getProposerAttesterAddressInSlot.mockImplementation(slot => {
44
38
  if (slot === currentSlot) {
45
39
  return Promise.resolve(currentProposer);
@@ -47,9 +41,6 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
47
41
  if (slot === nextSlot) {
48
42
  return Promise.resolve(nextProposer);
49
43
  }
50
- if (slot === previousSlot && previousProposer) {
51
- return Promise.resolve(previousProposer);
52
- }
53
44
  throw new Error('Unexpected argument');
54
45
  });
55
46
  }
@@ -63,48 +54,18 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
63
54
  });
64
55
  });
65
56
 
66
- it('returns high tolerance error if slot number is not current or next slot (outside clock tolerance)', async () => {
57
+ it('returns high tolerance error if slot number is not current or next slot', async () => {
67
58
  const header = makeHeader(1, 99, 99);
68
59
  const mockProposal = await makeProposal({ blockHeader: header, lastBlockHeader: header });
69
60
 
70
- // Mock getEpochAndSlotNow to return time OUTSIDE clock tolerance (1000ms elapsed)
71
- epochCache.getEpochAndSlotNow.mockReturnValue({
72
- epoch: 1 as any,
73
- slot: currentSlot,
74
- ts: 1000n, // slot started at 1000 seconds
75
- nowMs: 1001000n, // 1000ms elapsed, outside 500ms tolerance
76
- });
77
-
78
61
  epochCache.getProposerAttesterAddressInSlot.mockResolvedValue(getAddress());
79
62
  const result = await validator.validate(mockProposal);
80
- expect(result).toEqual({ result: 'reject', severity: PeerErrorSeverity.HighToleranceError });
63
+ expect(result).toBe(PeerErrorSeverity.HighToleranceError);
81
64
 
82
65
  // Should not try to resolve proposers if base validation fails
83
66
  expect(epochCache.getProposerAttesterAddressInSlot).not.toHaveBeenCalled();
84
67
  });
85
68
 
86
- it('returns ignore if previous slot proposal is within clock tolerance', async () => {
87
- const previousProposer = getSigner();
88
- const header = makeHeader(1, 99, 99);
89
- const mockProposal = await makeProposal({
90
- blockHeader: header,
91
- lastBlockHeader: header,
92
- signer: previousProposer,
93
- });
94
-
95
- // Mock getEpochAndSlotNow to return time WITHIN clock tolerance (100ms elapsed)
96
- epochCache.getEpochAndSlotNow.mockReturnValue({
97
- epoch: 1 as any,
98
- slot: currentSlot,
99
- ts: 1000n, // slot started at 1000 seconds
100
- nowMs: 1000100n, // 100ms elapsed, within 500ms tolerance
101
- });
102
-
103
- mockGetProposer(getAddress(), getAddress(), getAddress(previousProposer));
104
- const result = await validator.validate(mockProposal);
105
- expect(result).toEqual({ result: 'ignore' });
106
- });
107
-
108
69
  it('returns mid tolerance error if proposer is not current proposer for current slot', async () => {
109
70
  const currentProposer = getSigner();
110
71
  const nextProposer = getSigner();
@@ -118,7 +79,7 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
118
79
 
119
80
  mockGetProposer(getAddress(currentProposer), getAddress(nextProposer));
120
81
  const result = await validator.validate(mockProposal);
121
- expect(result).toEqual({ result: 'reject', severity: PeerErrorSeverity.MidToleranceError });
82
+ expect(result).toBe(PeerErrorSeverity.MidToleranceError);
122
83
  });
123
84
 
124
85
  it('returns mid tolerance error if proposer is not next proposer for next slot', async () => {
@@ -134,7 +95,7 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
134
95
 
135
96
  mockGetProposer(getAddress(currentProposer), getAddress(nextProposer));
136
97
  const result = await validator.validate(mockProposal);
137
- expect(result).toEqual({ result: 'reject', severity: PeerErrorSeverity.MidToleranceError });
98
+ expect(result).toBe(PeerErrorSeverity.MidToleranceError);
138
99
  });
139
100
 
140
101
  it('returns mid tolerance error if proposer is current proposer but proposal is for next slot', async () => {
@@ -149,7 +110,7 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
149
110
 
150
111
  mockGetProposer(getAddress(currentProposer), getAddress(nextProposer));
151
112
  const result = await validator.validate(mockProposal);
152
- expect(result).toEqual({ result: 'reject', severity: PeerErrorSeverity.MidToleranceError });
113
+ expect(result).toBe(PeerErrorSeverity.MidToleranceError);
153
114
  });
154
115
 
155
116
  it('returns undefined if proposal is valid for current slot and proposer', async () => {
@@ -164,7 +125,7 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
164
125
 
165
126
  mockGetProposer(getAddress(currentProposer), getAddress(nextProposer));
166
127
  const result = await validator.validate(mockProposal);
167
- expect(result).toEqual({ result: 'accept' });
128
+ expect(result).toBeUndefined();
168
129
  });
169
130
 
170
131
  it('returns undefined if proposal is valid for next slot and proposer', async () => {
@@ -175,7 +136,7 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
175
136
 
176
137
  mockGetProposer(getAddress(currentProposer), getAddress(nextProposer));
177
138
  const result = await validator.validate(mockProposal);
178
- expect(result).toEqual({ result: 'accept' });
139
+ expect(result).toBeUndefined();
179
140
  });
180
141
 
181
142
  describe('transaction permission validation', () => {
@@ -192,7 +153,7 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
192
153
 
193
154
  mockGetProposer(getAddress(currentProposer), getAddress());
194
155
  const result = await validatorWithTxsDisabled.validate(mockProposal);
195
- expect(result).toEqual({ result: 'reject', severity: PeerErrorSeverity.MidToleranceError });
156
+ expect(result).toBe(PeerErrorSeverity.MidToleranceError);
196
157
  });
197
158
 
198
159
  it('returns undefined if txs not permitted but proposal has no txHashes', async () => {
@@ -208,7 +169,7 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
208
169
 
209
170
  mockGetProposer(getAddress(currentProposer), getAddress());
210
171
  const result = await validatorWithTxsDisabled.validate(mockProposal);
211
- expect(result).toEqual({ result: 'accept' });
172
+ expect(result).toBeUndefined();
212
173
  });
213
174
 
214
175
  it('returns undefined if txs permitted and proposal contains txHashes', async () => {
@@ -223,7 +184,7 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
223
184
 
224
185
  mockGetProposer(getAddress(currentProposer), getAddress());
225
186
  const result = await validator.validate(mockProposal);
226
- expect(result).toEqual({ result: 'accept' });
187
+ expect(result).toBeUndefined();
227
188
  });
228
189
  });
229
190
  });
@@ -15,9 +15,7 @@ export class BlockHeaderTxValidator<T extends AnyTx> implements TxValidator<T> {
15
15
  }
16
16
 
17
17
  async validateTx(tx: T): Promise<TxValidationResult> {
18
- const [index] = await this.#archiveSource.getArchiveIndices([
19
- (await tx.data.constants.anchorBlockHeader.hash()).toField(),
20
- ]);
18
+ const [index] = await this.#archiveSource.getArchiveIndices([await tx.data.constants.anchorBlockHeader.hash()]);
21
19
  if (index === undefined) {
22
20
  this.#log.verbose(`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} for referencing an unknown block header`);
23
21
  return { result: 'invalid', reason: [TX_ERROR_BLOCK_HEADER] };
@@ -8,7 +8,7 @@ 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';
@@ -20,7 +20,6 @@ import {
20
20
  type Gossipable,
21
21
  P2PClientType,
22
22
  P2PMessage,
23
- type ValidationResult as P2PValidationResult,
24
23
  PeerErrorSeverity,
25
24
  TopicType,
26
25
  createTopicString,
@@ -925,8 +924,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
925
924
  const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointAttestation>> = async () => {
926
925
  const attestation = CheckpointAttestation.fromBuffer(payloadData);
927
926
  const pool = this.mempools.attestationPool;
928
- const validationResult = await this.validateCheckpointAttestation(source, attestation);
929
- const isValid = validationResult.result === 'accept';
927
+ const isValid = await this.validateCheckpointAttestation(source, attestation);
930
928
  const exists = isValid && (await pool.hasCheckpointAttestation(attestation));
931
929
 
932
930
  let canAdd = true;
@@ -945,9 +943,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
945
943
  [Attributes.P2P_ID]: source.toString(),
946
944
  });
947
945
 
948
- if (validationResult.result === 'reject') {
946
+ if (!isValid) {
949
947
  return { result: TopicValidatorResult.Reject };
950
- } else if (validationResult.result === 'ignore' || exists) {
948
+ } else if (exists) {
951
949
  return { result: TopicValidatorResult.Ignore, obj: attestation };
952
950
  } else if (!canAdd) {
953
951
  this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
@@ -988,8 +986,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
988
986
  private async processBlockFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
989
987
  const validationFunc: () => Promise<ReceivedMessageValidationResult<BlockProposal>> = async () => {
990
988
  const block = BlockProposal.fromBuffer(payloadData);
991
- const validationResult = await this.validateBlockProposal(source, block);
992
- const isValid = validationResult.result === 'accept';
989
+ const isValid = await this.validateBlockProposal(source, block);
993
990
  const pool = this.mempools.attestationPool;
994
991
 
995
992
  const exists = isValid && (await pool.hasBlockProposal(block));
@@ -1003,9 +1000,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1003
1000
  [Attributes.P2P_ID]: source.toString(),
1004
1001
  });
1005
1002
 
1006
- if (validationResult.result === 'reject') {
1003
+ if (!isValid) {
1007
1004
  return { result: TopicValidatorResult.Reject };
1008
- } else if (validationResult.result === 'ignore' || exists) {
1005
+ } else if (exists) {
1009
1006
  return { result: TopicValidatorResult.Ignore, obj: block };
1010
1007
  } else if (!canAdd) {
1011
1008
  this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
@@ -1085,8 +1082,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1085
1082
  // TODO(palla/mbps): This pattern is repeated across multiple message handlers, consider abstracting it.
1086
1083
  const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointProposal>> = async () => {
1087
1084
  const checkpoint = CheckpointProposal.fromBuffer(payloadData);
1088
- const validationResult = await this.validateCheckpointProposal(source, checkpoint);
1089
- const isValid = validationResult.result === 'accept';
1085
+ const isValid = await this.validateCheckpointProposal(source, checkpoint);
1090
1086
  const pool = this.mempools.attestationPool;
1091
1087
 
1092
1088
  const exists = isValid && (await pool.hasCheckpointProposal(checkpoint));
@@ -1100,9 +1096,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1100
1096
  [Attributes.P2P_ID]: source.toString(),
1101
1097
  });
1102
1098
 
1103
- if (validationResult.result === 'reject') {
1099
+ if (!isValid) {
1104
1100
  return { result: TopicValidatorResult.Reject };
1105
- } else if (validationResult.result === 'ignore' || exists) {
1101
+ } else if (exists) {
1106
1102
  return { result: TopicValidatorResult.Ignore, obj: checkpoint };
1107
1103
  } else if (!canAdd) {
1108
1104
  this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
@@ -1341,7 +1337,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1341
1337
  }))
1342
1338
  private async validateRequestedBlock(
1343
1339
  requestedBlockNumber: Fr,
1344
- responseBlock: L2Block,
1340
+ responseBlock: L2BlockNew,
1345
1341
  peerId: PeerId,
1346
1342
  ): Promise<boolean> {
1347
1343
  try {
@@ -1580,18 +1576,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1580
1576
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
1581
1577
  [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
1582
1578
  }))
1583
- public async validateCheckpointAttestation(
1584
- peerId: PeerId,
1585
- attestation: CheckpointAttestation,
1586
- ): Promise<P2PValidationResult> {
1587
- const result = await this.checkpointAttestationValidator.validate(attestation);
1588
-
1589
- if (result.result === 'reject') {
1579
+ public async validateCheckpointAttestation(peerId: PeerId, attestation: CheckpointAttestation): Promise<boolean> {
1580
+ const severity = await this.checkpointAttestationValidator.validate(attestation);
1581
+ if (severity) {
1590
1582
  this.logger.debug(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
1591
- this.peerManager.penalizePeer(peerId, result.severity);
1583
+ this.peerManager.penalizePeer(peerId, severity);
1584
+ return false;
1592
1585
  }
1593
1586
 
1594
- return result;
1587
+ return true;
1595
1588
  }
1596
1589
 
1597
1590
  /**
@@ -1603,15 +1596,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1603
1596
  @trackSpan('Libp2pService.validateBlockProposal', (_peerId, block) => ({
1604
1597
  [Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
1605
1598
  }))
1606
- public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<P2PValidationResult> {
1607
- const result = await this.blockProposalValidator.validate(block);
1608
-
1609
- if (result.result === 'reject') {
1599
+ public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<boolean> {
1600
+ const severity = await this.blockProposalValidator.validate(block);
1601
+ if (severity) {
1610
1602
  this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
1611
- this.peerManager.penalizePeer(peerId, result.severity);
1603
+ this.peerManager.penalizePeer(peerId, severity);
1604
+ return false;
1612
1605
  }
1613
1606
 
1614
- return result;
1607
+ return true;
1615
1608
  }
1616
1609
 
1617
1610
  /**
@@ -1623,18 +1616,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1623
1616
  @trackSpan('Libp2pService.validateCheckpointProposal', (_peerId, checkpoint) => ({
1624
1617
  [Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
1625
1618
  }))
1626
- public async validateCheckpointProposal(
1627
- peerId: PeerId,
1628
- checkpoint: CheckpointProposal,
1629
- ): Promise<P2PValidationResult> {
1630
- const result = await this.checkpointProposalValidator.validate(checkpoint);
1631
-
1632
- if (result.result === 'reject') {
1619
+ public async validateCheckpointProposal(peerId: PeerId, checkpoint: CheckpointProposal): Promise<boolean> {
1620
+ const severity = await this.checkpointProposalValidator.validate(checkpoint);
1621
+ if (severity) {
1633
1622
  this.logger.debug(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
1634
- this.peerManager.penalizePeer(peerId, result.severity);
1623
+ this.peerManager.penalizePeer(peerId, severity);
1624
+ return false;
1635
1625
  }
1636
1626
 
1637
- return result;
1627
+ return true;
1638
1628
  }
1639
1629
 
1640
1630
  public getPeerScore(peerId: PeerId): number {
@@ -1,5 +1,5 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { L2Block } from '@aztec/stdlib/block';
2
+ import { L2BlockNew } from '@aztec/stdlib/block';
3
3
  import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
4
4
 
5
5
  import type { PeerId } from '@libp2p/interface';
@@ -198,7 +198,7 @@ export const subProtocolMap = {
198
198
  },
199
199
  [ReqRespSubProtocol.BLOCK]: {
200
200
  request: Fr, // block number
201
- response: L2Block,
201
+ response: L2BlockNew,
202
202
  },
203
203
  [ReqRespSubProtocol.AUTH]: {
204
204
  request: AuthRequest,
@@ -4,7 +4,7 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
4
4
  import { boundInclusive } from '@aztec/foundation/number';
5
5
  import { RunningPromise } from '@aztec/foundation/promise';
6
6
  import { DateProvider } from '@aztec/foundation/timer';
7
- import type { L2Block } from '@aztec/stdlib/block';
7
+ import type { L2BlockNew } from '@aztec/stdlib/block';
8
8
  import { type L1RollupConstants, getEpochAtSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
9
9
  import { type Tx, TxHash } from '@aztec/stdlib/tx';
10
10
 
@@ -76,7 +76,7 @@ export class SlowTxCollection {
76
76
  }
77
77
 
78
78
  /** Starts collecting the given tx hashes for the given L2Block in the slow loop */
79
- public startCollecting(block: L2Block, txHashes: TxHash[]) {
79
+ public startCollecting(block: L2BlockNew, txHashes: TxHash[]) {
80
80
  const slot = block.header.getSlot();
81
81
  const deadline = this.getDeadlineForSlot(slot);
82
82
  if (+deadline < this.dateProvider.now()) {
@@ -3,7 +3,7 @@ import { compactArray } from '@aztec/foundation/collection';
3
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
4
  import { type PromiseWithResolvers, RunningPromise } from '@aztec/foundation/promise';
5
5
  import { DateProvider } from '@aztec/foundation/timer';
6
- import type { L2Block, L2BlockInfo } from '@aztec/stdlib/block';
6
+ import type { L2BlockInfo, L2BlockNew } from '@aztec/stdlib/block';
7
7
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
8
8
  import type { BlockProposal } from '@aztec/stdlib/p2p';
9
9
  import { Tx, TxHash } from '@aztec/stdlib/tx';
@@ -25,7 +25,7 @@ export type CollectionMethod = 'fast-req-resp' | 'fast-node-rpc' | 'slow-req-res
25
25
  export type MissingTxInfo = { blockNumber: BlockNumber; deadline: Date; readyForReqResp: boolean };
26
26
 
27
27
  export type FastCollectionRequestInput =
28
- | { type: 'block'; block: L2Block }
28
+ | { type: 'block'; block: L2BlockNew }
29
29
  | { type: 'proposal'; blockProposal: BlockProposal; blockNumber: BlockNumber };
30
30
 
31
31
  export type FastCollectionRequest = FastCollectionRequestInput & {
@@ -146,7 +146,7 @@ export class TxCollection {
146
146
  }
147
147
 
148
148
  /** Starts collecting the given tx hashes for the given L2Block in the slow loop */
149
- public startCollecting(block: L2Block, txHashes: TxHash[]) {
149
+ public startCollecting(block: L2BlockNew, txHashes: TxHash[]) {
150
150
  return this.slowCollection.startCollecting(block, txHashes);
151
151
  }
152
152
 
@@ -162,7 +162,7 @@ export class TxCollection {
162
162
 
163
163
  /** Collects the set of txs for the given mined block as fast as possible */
164
164
  public collectFastForBlock(
165
- block: L2Block,
165
+ block: L2BlockNew,
166
166
  txHashes: TxHash[] | string[],
167
167
  opts: { deadline: Date; pinnedPeer?: PeerId },
168
168
  ) {
@@ -2,7 +2,7 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { compactArray } from '@aztec/foundation/collection';
3
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
4
  import { elapsed } from '@aztec/foundation/timer';
5
- import type { L2Block, L2BlockInfo } from '@aztec/stdlib/block';
5
+ import type { L2BlockInfo, L2BlockNew } from '@aztec/stdlib/block';
6
6
  import type { ITxProvider } from '@aztec/stdlib/interfaces/server';
7
7
  import type { BlockProposal } from '@aztec/stdlib/p2p';
8
8
  import { Tx, TxHash } from '@aztec/stdlib/tx';
@@ -68,7 +68,7 @@ export class TxProvider implements ITxProvider {
68
68
  }
69
69
 
70
70
  /** Gathers txs from the tx pool, remote rpc nodes, and reqresp. */
71
- public getTxsForBlock(block: L2Block, opts: { deadline: Date }): Promise<{ txs: Tx[]; missingTxs: TxHash[] }> {
71
+ public getTxsForBlock(block: L2BlockNew, opts: { deadline: Date }): Promise<{ txs: Tx[]; missingTxs: TxHash[] }> {
72
72
  return this.getOrderedTxsFromAllSources(
73
73
  { type: 'block', block },
74
74
  block.toBlockInfo(),
@@ -89,7 +89,7 @@ function mockEpochCache(): EpochCacheInterface {
89
89
  return {
90
90
  getCommittee: () => Promise.resolve({ committee: [], seed: 1n, epoch: EpochNumber.ZERO, isEscapeHatchOpen: false }),
91
91
  getProposerIndexEncoding: () => '0x' as `0x${string}`,
92
- getEpochAndSlotNow: () => ({ epoch: EpochNumber.ZERO, slot: SlotNumber.ZERO, ts: 0n, nowMs: 0n }),
92
+ getEpochAndSlotNow: () => ({ epoch: EpochNumber.ZERO, slot: SlotNumber.ZERO, ts: 0n }),
93
93
  computeProposerIndex: () => 0n,
94
94
  getCurrentAndNextSlot: () => ({
95
95
  currentSlot: SlotNumber.ZERO,
@@ -1,21 +0,0 @@
1
- import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
- import { SlotNumber } from '@aztec/foundation/branded-types';
3
- /**
4
- * Maximum clock disparity tolerance for P2P message validation (in milliseconds).
5
- * Messages for the previous slot are accepted if we're within this many milliseconds
6
- * of the current slot start. This prevents penalizing peers for messages that
7
- * were valid when sent but arrived slightly late due to network latency.
8
- *
9
- * This follows Ethereum's MAXIMUM_GOSSIP_CLOCK_DISPARITY approach.
10
- */
11
- export declare const MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS = 500;
12
- /**
13
- * Checks if a message for the previous slot should be accepted due to clock tolerance.
14
- *
15
- * @param messageSlot - The slot number from the received message
16
- * @param currentSlot - The current slot number
17
- * @param epochCache - EpochCache to get timing information
18
- * @returns true if the message is for the previous slot AND we're within the clock tolerance window
19
- */
20
- export declare function isWithinClockTolerance(messageSlot: SlotNumber, currentSlot: SlotNumber, epochCache: EpochCacheInterface): boolean;
21
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xvY2tfdG9sZXJhbmNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbXNnX3ZhbGlkYXRvcnMvY2xvY2tfdG9sZXJhbmNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDOUQsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRTdEOzs7Ozs7O0dBT0c7QUFDSCxlQUFPLE1BQU0saUNBQWlDLE1BQU0sQ0FBQztBQUVyRDs7Ozs7OztHQU9HO0FBQ0gsd0JBQWdCLHNCQUFzQixDQUNwQyxXQUFXLEVBQUUsVUFBVSxFQUN2QixXQUFXLEVBQUUsVUFBVSxFQUN2QixVQUFVLEVBQUUsbUJBQW1CLEdBQzlCLE9BQU8sQ0F5QlQifQ==
@@ -1 +0,0 @@
1
- {"version":3,"file":"clock_tolerance.d.ts","sourceRoot":"","sources":["../../src/msg_validators/clock_tolerance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,MAAM,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,UAAU,EACvB,WAAW,EAAE,UAAU,EACvB,UAAU,EAAE,mBAAmB,GAC9B,OAAO,CAyBT"}
@@ -1,37 +0,0 @@
1
- import { SlotNumber } from '@aztec/foundation/branded-types';
2
- /**
3
- * Maximum clock disparity tolerance for P2P message validation (in milliseconds).
4
- * Messages for the previous slot are accepted if we're within this many milliseconds
5
- * of the current slot start. This prevents penalizing peers for messages that
6
- * were valid when sent but arrived slightly late due to network latency.
7
- *
8
- * This follows Ethereum's MAXIMUM_GOSSIP_CLOCK_DISPARITY approach.
9
- */ export const MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS = 500;
10
- /**
11
- * Checks if a message for the previous slot should be accepted due to clock tolerance.
12
- *
13
- * @param messageSlot - The slot number from the received message
14
- * @param currentSlot - The current slot number
15
- * @param epochCache - EpochCache to get timing information
16
- * @returns true if the message is for the previous slot AND we're within the clock tolerance window
17
- */ export function isWithinClockTolerance(messageSlot, currentSlot, epochCache) {
18
- // Guard against slot 0 edge case (genesis)
19
- if (currentSlot === SlotNumber.ZERO) {
20
- return false;
21
- }
22
- // Only apply tolerance to messages for the previous slot
23
- const previousSlot = SlotNumber(currentSlot - 1);
24
- if (messageSlot !== previousSlot) {
25
- return false;
26
- }
27
- // Check how far we are into the current slot (in milliseconds)
28
- const { ts: slotStartTs, nowMs, slot } = epochCache.getEpochAndSlotNow();
29
- // Sanity check: ensure the epoch cache's current slot matches the expected current slot
30
- if (slot !== currentSlot) {
31
- return false;
32
- }
33
- // ts is in seconds, convert to ms; nowMs is already in milliseconds
34
- const slotStartMs = slotStartTs * 1000n;
35
- const elapsedMs = Number(nowMs - slotStartMs);
36
- return elapsedMs < MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS;
37
- }
@@ -1,51 +0,0 @@
1
- import type { EpochCacheInterface } from '@aztec/epoch-cache';
2
- import { SlotNumber } from '@aztec/foundation/branded-types';
3
-
4
- /**
5
- * Maximum clock disparity tolerance for P2P message validation (in milliseconds).
6
- * Messages for the previous slot are accepted if we're within this many milliseconds
7
- * of the current slot start. This prevents penalizing peers for messages that
8
- * were valid when sent but arrived slightly late due to network latency.
9
- *
10
- * This follows Ethereum's MAXIMUM_GOSSIP_CLOCK_DISPARITY approach.
11
- */
12
- export const MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS = 500;
13
-
14
- /**
15
- * Checks if a message for the previous slot should be accepted due to clock tolerance.
16
- *
17
- * @param messageSlot - The slot number from the received message
18
- * @param currentSlot - The current slot number
19
- * @param epochCache - EpochCache to get timing information
20
- * @returns true if the message is for the previous slot AND we're within the clock tolerance window
21
- */
22
- export function isWithinClockTolerance(
23
- messageSlot: SlotNumber,
24
- currentSlot: SlotNumber,
25
- epochCache: EpochCacheInterface,
26
- ): boolean {
27
- // Guard against slot 0 edge case (genesis)
28
- if (currentSlot === SlotNumber.ZERO) {
29
- return false;
30
- }
31
-
32
- // Only apply tolerance to messages for the previous slot
33
- const previousSlot = SlotNumber(currentSlot - 1);
34
- if (messageSlot !== previousSlot) {
35
- return false;
36
- }
37
-
38
- // Check how far we are into the current slot (in milliseconds)
39
- const { ts: slotStartTs, nowMs, slot } = epochCache.getEpochAndSlotNow();
40
-
41
- // Sanity check: ensure the epoch cache's current slot matches the expected current slot
42
- if (slot !== currentSlot) {
43
- return false;
44
- }
45
-
46
- // ts is in seconds, convert to ms; nowMs is already in milliseconds
47
- const slotStartMs = slotStartTs * 1000n;
48
- const elapsedMs = Number(nowMs - slotStartMs);
49
-
50
- return elapsedMs < MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS;
51
- }