@aztec/p2p 0.0.1-commit.d1f2d6c → 0.0.1-commit.d431d1c
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.
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +3 -3
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +2 -3
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +2 -3
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +1 -8
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +3 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +9 -40
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -11
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -3
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +12 -43
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +3 -3
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +11 -66
- package/dest/services/libp2p/libp2p_service.d.ts +5 -5
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +24 -24
- package/dest/services/reqresp/interface.d.ts +3 -3
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +2 -2
- package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +5 -5
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +1 -2
- package/package.json +14 -14
- package/src/client/p2p_client.ts +5 -5
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +2 -2
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +1 -2
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +1 -2
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +7 -10
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +2 -4
- package/src/msg_validators/attestation_validator/attestation_validator.ts +13 -25
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +6 -6
- package/src/msg_validators/proposal_validator/proposal_validator.ts +11 -18
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +14 -53
- package/src/services/libp2p/libp2p_service.ts +29 -39
- package/src/services/reqresp/interface.ts +2 -2
- package/src/services/tx_collection/slow_tx_collection.ts +2 -2
- package/src/services/tx_collection/tx_collection.ts +4 -4
- package/src/services/tx_provider.ts +2 -2
- package/src/testbench/p2p_client_testbench_worker.ts +1 -1
- package/dest/msg_validators/clock_tolerance.d.ts +0 -21
- package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
- package/dest/msg_validators/clock_tolerance.js +0 -37
- package/src/msg_validators/clock_tolerance.ts +0 -51
|
@@ -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,
|
|
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
|
|
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 (
|
|
946
|
+
if (!isValid) {
|
|
949
947
|
return { result: TopicValidatorResult.Reject };
|
|
950
|
-
} else if (
|
|
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
|
|
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 (
|
|
1003
|
+
if (!isValid) {
|
|
1007
1004
|
return { result: TopicValidatorResult.Reject };
|
|
1008
|
-
} else if (
|
|
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
|
|
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 (
|
|
1099
|
+
if (!isValid) {
|
|
1104
1100
|
return { result: TopicValidatorResult.Reject };
|
|
1105
|
-
} else if (
|
|
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:
|
|
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
|
-
|
|
1585
|
-
|
|
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,
|
|
1583
|
+
this.peerManager.penalizePeer(peerId, severity);
|
|
1584
|
+
return false;
|
|
1592
1585
|
}
|
|
1593
1586
|
|
|
1594
|
-
return
|
|
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<
|
|
1607
|
-
const
|
|
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,
|
|
1603
|
+
this.peerManager.penalizePeer(peerId, severity);
|
|
1604
|
+
return false;
|
|
1612
1605
|
}
|
|
1613
1606
|
|
|
1614
|
-
return
|
|
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
|
-
|
|
1628
|
-
|
|
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,
|
|
1623
|
+
this.peerManager.penalizePeer(peerId, severity);
|
|
1624
|
+
return false;
|
|
1635
1625
|
}
|
|
1636
1626
|
|
|
1637
|
-
return
|
|
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 {
|
|
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:
|
|
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 {
|
|
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:
|
|
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 {
|
|
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:
|
|
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:
|
|
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:
|
|
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 {
|
|
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:
|
|
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
|
|
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
|
-
}
|