@aztec/p2p 0.0.1-commit.ef17749e1 → 0.0.1-commit.f103f88
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/README.md +129 -3
- package/dest/client/factory.d.ts +1 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +23 -10
- package/dest/client/interface.d.ts +9 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +3 -2
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +46 -14
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +17 -6
- package/dest/config.d.ts +111 -95
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +27 -2
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +7 -5
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +11 -8
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
- package/dest/mem_pools/index.d.ts +1 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +7 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +9 -2
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +13 -3
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +19 -5
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +5 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +20 -11
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +4 -2
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +2 -2
- package/dest/msg_validators/clock_tolerance.d.ts +12 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +54 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +19 -11
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +35 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +23 -4
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +36 -10
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +13 -4
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +49 -17
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +21 -1
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +28 -1
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +5 -5
- package/dest/services/dummy_service.d.ts +6 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +6 -1
- package/dest/services/encoding.d.ts +5 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -1
- package/dest/services/gossipsub/topic_score_params.d.ts +13 -2
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +21 -4
- package/dest/services/libp2p/libp2p_service.d.ts +15 -25
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +151 -118
- package/dest/services/peer-manager/peer_manager.d.ts +6 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +37 -10
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +32 -10
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +69 -65
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +3 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +3 -0
- package/dest/services/reqresp/config.d.ts +3 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/interface.d.ts +14 -9
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +10 -11
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +0 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +1 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +1 -3
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
- package/dest/services/reqresp/reqresp.d.ts +4 -2
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +28 -11
- package/dest/services/service.d.ts +5 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +57 -73
- package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +39 -29
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/slow_tx_collection.js +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +3 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.d.ts +6 -5
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +9 -7
- package/dest/test-helpers/mock-pubsub.d.ts +11 -3
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +35 -10
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +1 -2
- package/dest/test-helpers/testbench-utils.d.ts +1 -1
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +23 -3
- package/dest/testbench/p2p_client_testbench_worker.js +66 -15
- package/dest/testbench/worker_client_manager.d.ts +8 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +49 -1
- package/package.json +14 -14
- package/src/client/factory.ts +41 -13
- package/src/client/interface.ts +9 -1
- package/src/client/p2p_client.ts +50 -17
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +18 -8
- package/src/config.ts +48 -3
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +12 -8
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +2 -1
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/interfaces.ts +6 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +19 -3
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +13 -1
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +20 -5
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +21 -9
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +4 -1
- package/src/msg_validators/clock_tolerance.ts +72 -3
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +4 -1
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +4 -1
- package/src/msg_validators/proposal_validator/proposal_validator.ts +17 -10
- package/src/msg_validators/tx_validator/README.md +5 -1
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +42 -1
- package/src/msg_validators/tx_validator/factory.ts +43 -3
- package/src/msg_validators/tx_validator/gas_validator.ts +65 -16
- package/src/msg_validators/tx_validator/phases_validator.ts +31 -1
- package/src/services/data_store.ts +5 -13
- package/src/services/dummy_service.ts +8 -2
- package/src/services/encoding.ts +9 -1
- package/src/services/gossipsub/topic_score_params.ts +36 -4
- package/src/services/libp2p/libp2p_service.ts +150 -134
- package/src/services/peer-manager/peer_manager.ts +43 -10
- package/src/services/peer-manager/peer_scoring.ts +27 -5
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +64 -69
- package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +5 -0
- package/src/services/reqresp/config.ts +2 -2
- package/src/services/reqresp/interface.ts +21 -11
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +1 -3
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
- package/src/services/reqresp/reqresp.ts +37 -12
- package/src/services/service.ts +6 -1
- package/src/services/tx_collection/fast_tx_collection.ts +57 -83
- package/src/services/tx_collection/file_store_tx_source.ts +43 -31
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/slow_tx_collection.ts +1 -1
- package/src/services/tx_collection/tx_collection.ts +3 -5
- package/src/services/tx_collection/tx_source.ts +8 -7
- package/src/test-helpers/mock-pubsub.ts +31 -5
- package/src/test-helpers/reqresp-nodes.ts +2 -2
- package/src/test-helpers/testbench-utils.ts +30 -3
- package/src/testbench/p2p_client_testbench_worker.ts +70 -14
- package/src/testbench/worker_client_manager.ts +55 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
- package/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
- package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
2
|
import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { maxBy } from '@aztec/foundation/collection';
|
|
4
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
4
|
import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
6
5
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
7
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
8
7
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
9
8
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
10
|
-
import type { EthAddress,
|
|
9
|
+
import type { EthAddress, L2BlockSource } from '@aztec/stdlib/block';
|
|
11
10
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
12
11
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
13
12
|
import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
@@ -18,7 +17,6 @@ import {
|
|
|
18
17
|
type CheckpointProposalCore,
|
|
19
18
|
type Gossipable,
|
|
20
19
|
P2PMessage,
|
|
21
|
-
type ValidationResult as P2PValidationResult,
|
|
22
20
|
PeerErrorSeverity,
|
|
23
21
|
PeerErrorSeverityByHarshness,
|
|
24
22
|
TopicType,
|
|
@@ -59,6 +57,7 @@ import { ENR } from '@nethermindeth/enr';
|
|
|
59
57
|
import { createLibp2p } from 'libp2p';
|
|
60
58
|
|
|
61
59
|
import type { P2PConfig } from '../../config.js';
|
|
60
|
+
import { CheckpointProposalReceivedCallbackNotRegisteredError } from '../../errors/p2p-service.error.js';
|
|
62
61
|
import type { MemPools } from '../../mem_pools/interface.js';
|
|
63
62
|
import {
|
|
64
63
|
BlockProposalValidator,
|
|
@@ -105,7 +104,6 @@ import {
|
|
|
105
104
|
ValidationError,
|
|
106
105
|
pingHandler,
|
|
107
106
|
reqGoodbyeHandler,
|
|
108
|
-
reqRespBlockHandler,
|
|
109
107
|
reqRespBlockTxsHandler,
|
|
110
108
|
reqRespStatusHandler,
|
|
111
109
|
reqRespTxHandler,
|
|
@@ -131,7 +129,7 @@ type ValidationOutcome = { allPassed: true } | { allPassed: false; failure: Vali
|
|
|
131
129
|
// REFACTOR: Unify with the type above
|
|
132
130
|
type ReceivedMessageValidationResult<T, M = undefined> =
|
|
133
131
|
| { obj: T; result: Exclude<TopicValidatorResult, TopicValidatorResult.Reject>; metadata?: M }
|
|
134
|
-
| { obj?: T; result: TopicValidatorResult.Reject; metadata?: M };
|
|
132
|
+
| { obj?: T; result: TopicValidatorResult.Reject; metadata?: M; severity: PeerErrorSeverity };
|
|
135
133
|
|
|
136
134
|
/**
|
|
137
135
|
* Lib P2P implementation of the P2PService interface.
|
|
@@ -172,7 +170,13 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
172
170
|
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
173
171
|
* @returns The attestations for the checkpoint, if any.
|
|
174
172
|
*/
|
|
175
|
-
private
|
|
173
|
+
private allNodesCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
174
|
+
/**
|
|
175
|
+
* Callback for when a checkpoint proposal is received - specifically for validators - from a peer.
|
|
176
|
+
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
177
|
+
* @returns The attestations for the checkpoint, if any.
|
|
178
|
+
*/
|
|
179
|
+
private validatorCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
176
180
|
|
|
177
181
|
private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
|
|
178
182
|
|
|
@@ -224,32 +228,39 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
224
228
|
this.protocolVersion,
|
|
225
229
|
);
|
|
226
230
|
|
|
231
|
+
const p2pPropagationTime = config.attestationPropagationTime;
|
|
227
232
|
const proposalValidatorOpts = {
|
|
228
233
|
txsPermitted: !config.disableTransactions,
|
|
229
|
-
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
234
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
|
|
235
|
+
p2pPropagationTime,
|
|
230
236
|
};
|
|
231
237
|
this.blockProposalValidator = new BlockProposalValidator(epochCache, proposalValidatorOpts);
|
|
232
238
|
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, proposalValidatorOpts);
|
|
233
239
|
this.checkpointAttestationValidator = config.fishermanMode
|
|
234
|
-
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry
|
|
235
|
-
|
|
240
|
+
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry, {
|
|
241
|
+
l1PublishingTime: config.l1PublishingTime,
|
|
242
|
+
})
|
|
243
|
+
: new CheckpointAttestationValidator(epochCache, { l1PublishingTime: config.l1PublishingTime });
|
|
236
244
|
|
|
237
245
|
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
238
246
|
|
|
239
247
|
this.blockReceivedCallback = async (block: BlockProposal): Promise<boolean> => {
|
|
240
|
-
this.logger.
|
|
241
|
-
`Handler not yet registered
|
|
248
|
+
this.logger.warn(
|
|
249
|
+
`Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`,
|
|
242
250
|
{ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
|
|
243
251
|
);
|
|
244
|
-
return
|
|
252
|
+
return true;
|
|
245
253
|
};
|
|
246
254
|
|
|
247
|
-
this.
|
|
248
|
-
|
|
255
|
+
this.allNodesCheckpointReceivedCallback = (
|
|
256
|
+
_checkpoint: CheckpointProposalCore,
|
|
257
|
+
): Promise<CheckpointAttestation[] | undefined> => {
|
|
258
|
+
throw new CheckpointProposalReceivedCallbackNotRegisteredError();
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
this.validatorCheckpointReceivedCallback = (
|
|
262
|
+
_checkpoint: CheckpointProposalCore,
|
|
249
263
|
): Promise<CheckpointAttestation[] | undefined> => {
|
|
250
|
-
this.logger.debug(
|
|
251
|
-
`Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`,
|
|
252
|
-
);
|
|
253
264
|
return Promise.resolve(undefined);
|
|
254
265
|
};
|
|
255
266
|
}
|
|
@@ -339,9 +350,12 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
339
350
|
const l1Constants = epochCache.getL1Constants();
|
|
340
351
|
const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
|
|
341
352
|
slotDurationMs: l1Constants.slotDuration * 1000,
|
|
353
|
+
ethereumSlotDuration: l1Constants.ethereumSlotDuration,
|
|
342
354
|
heartbeatIntervalMs: config.gossipsubInterval,
|
|
343
355
|
targetCommitteeSize: l1Constants.targetCommitteeSize,
|
|
344
356
|
blockDurationMs: config.blockDurationMs,
|
|
357
|
+
l1PublishingTime: config.l1PublishingTime,
|
|
358
|
+
p2pPropagationTime: config.attestationPropagationTime,
|
|
345
359
|
expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot,
|
|
346
360
|
});
|
|
347
361
|
|
|
@@ -466,6 +480,9 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
466
480
|
epochCache,
|
|
467
481
|
);
|
|
468
482
|
|
|
483
|
+
// Gate req/resp data protocols for unauthenticated peers when p2pAllowOnlyValidators is enabled
|
|
484
|
+
reqresp.setShouldRejectPeer(peerId => peerManager.shouldDisableP2PGossip(peerId));
|
|
485
|
+
|
|
469
486
|
// Configure application-specific scoring for gossipsub.
|
|
470
487
|
// The weight scales app score to align with gossipsub thresholds:
|
|
471
488
|
// - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
|
|
@@ -511,14 +528,12 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
511
528
|
// Create request response protocol handlers
|
|
512
529
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
513
530
|
const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
|
|
514
|
-
const blockHandler = reqRespBlockHandler(this.archiver);
|
|
515
531
|
const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
|
|
516
532
|
|
|
517
533
|
const requestResponseHandlers: Partial<ReqRespSubProtocolHandlers> = {
|
|
518
534
|
[ReqRespSubProtocol.PING]: pingHandler,
|
|
519
535
|
[ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
|
|
520
536
|
[ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
|
|
521
|
-
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this),
|
|
522
537
|
};
|
|
523
538
|
|
|
524
539
|
if (!this.config.disableTransactions) {
|
|
@@ -539,7 +554,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
539
554
|
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
540
555
|
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
541
556
|
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
542
|
-
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
|
|
543
557
|
};
|
|
544
558
|
|
|
545
559
|
await this.peerManager.initializePeers();
|
|
@@ -667,8 +681,16 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
667
681
|
this.blockReceivedCallback = callback;
|
|
668
682
|
}
|
|
669
683
|
|
|
670
|
-
public
|
|
671
|
-
this.
|
|
684
|
+
public registerValidatorCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
685
|
+
this.validatorCheckpointReceivedCallback = callback;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
public registerAllNodesCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
689
|
+
this.allNodesCheckpointReceivedCallback = callback;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
public async notifyOwnCheckpointProposal(checkpoint: CheckpointProposalCore): Promise<void> {
|
|
693
|
+
await this.allNodesCheckpointReceivedCallback(checkpoint, this.node.peerId);
|
|
672
694
|
}
|
|
673
695
|
|
|
674
696
|
/**
|
|
@@ -754,6 +776,9 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
754
776
|
if (!validator || !validator.addMessage(msgId)) {
|
|
755
777
|
this.instrumentation.incMessagePrevalidationStatus(false, topicType);
|
|
756
778
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
779
|
+
if (topicType === TopicType.tx) {
|
|
780
|
+
this.logger.verbose(`Ignoring already-seen tx gossip message`, { msgId, source: source.toString() });
|
|
781
|
+
}
|
|
757
782
|
return { result: false, topicType };
|
|
758
783
|
}
|
|
759
784
|
|
|
@@ -880,30 +905,56 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
880
905
|
source: PeerId,
|
|
881
906
|
topicType: TopicType,
|
|
882
907
|
): Promise<ReceivedMessageValidationResult<T, M>> {
|
|
883
|
-
|
|
908
|
+
// Default to reject result with a penalty if validation function throws an error
|
|
909
|
+
let resultAndObj: ReceivedMessageValidationResult<T, M> = {
|
|
910
|
+
result: TopicValidatorResult.Reject,
|
|
911
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
912
|
+
};
|
|
884
913
|
const timer = new Timer();
|
|
885
914
|
try {
|
|
886
915
|
resultAndObj = await validationFunc();
|
|
887
916
|
} catch (err) {
|
|
888
|
-
this.
|
|
889
|
-
this.logger.error(`Error deserializing and validating gossipsub message`, err, {
|
|
890
|
-
msgId,
|
|
891
|
-
source: source.toString(),
|
|
892
|
-
topicType,
|
|
893
|
-
});
|
|
917
|
+
this.logger.error(`Error validating gossipsub message`, err, { msgId, source: source.toString(), topicType });
|
|
894
918
|
}
|
|
895
919
|
|
|
896
920
|
if (resultAndObj.result === TopicValidatorResult.Accept) {
|
|
921
|
+
this.logger.debug(`Message ${topicType} accepted by validator`, { msgId, source: source.toString(), topicType });
|
|
897
922
|
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
923
|
+
} else if (resultAndObj.result === TopicValidatorResult.Reject) {
|
|
924
|
+
this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
|
|
925
|
+
msgId,
|
|
926
|
+
source: source.toString(),
|
|
927
|
+
topicType,
|
|
928
|
+
severity: resultAndObj.severity,
|
|
929
|
+
});
|
|
930
|
+
this.peerManager.penalizePeer(source, resultAndObj.severity);
|
|
931
|
+
} else {
|
|
932
|
+
this.logger.trace(`Message ${topicType} ignored by validator`, { msgId, source: source.toString(), topicType });
|
|
898
933
|
}
|
|
899
934
|
|
|
900
935
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
|
|
901
936
|
return resultAndObj;
|
|
902
937
|
}
|
|
903
938
|
|
|
939
|
+
private tryDeserialize<T>(deserializeFunc: () => T, msgId: string, source: PeerId): T | undefined {
|
|
940
|
+
try {
|
|
941
|
+
return deserializeFunc();
|
|
942
|
+
} catch (err) {
|
|
943
|
+
this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
|
|
944
|
+
err,
|
|
945
|
+
msgId,
|
|
946
|
+
source: source.toString(),
|
|
947
|
+
});
|
|
948
|
+
return undefined;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
|
|
904
952
|
protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
|
|
905
953
|
const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
|
|
906
|
-
const tx = Tx.fromBuffer(payloadData);
|
|
954
|
+
const tx = this.tryDeserialize(() => Tx.fromBuffer(payloadData), msgId, source);
|
|
955
|
+
if (!tx) {
|
|
956
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.LowToleranceError };
|
|
957
|
+
}
|
|
907
958
|
|
|
908
959
|
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
909
960
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
@@ -923,13 +974,20 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
923
974
|
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
924
975
|
}
|
|
925
976
|
|
|
926
|
-
this.
|
|
927
|
-
|
|
977
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
|
|
978
|
+
validator: name,
|
|
979
|
+
severity,
|
|
980
|
+
source: source.toString(),
|
|
981
|
+
});
|
|
982
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
928
983
|
}
|
|
929
984
|
|
|
930
985
|
// Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
|
|
931
986
|
const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
|
|
932
987
|
if (canAdd === 'ignored') {
|
|
988
|
+
this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
|
|
989
|
+
source: source.toString(),
|
|
990
|
+
});
|
|
933
991
|
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
934
992
|
}
|
|
935
993
|
|
|
@@ -937,9 +995,13 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
937
995
|
const secondStageValidators = this.createSecondStageMessageValidators();
|
|
938
996
|
const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
|
|
939
997
|
if (!secondStageOutcome.allPassed) {
|
|
940
|
-
const { severity } = secondStageOutcome.failure;
|
|
941
|
-
this.
|
|
942
|
-
|
|
998
|
+
const { severity, name } = secondStageOutcome.failure;
|
|
999
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
|
|
1000
|
+
validator: name,
|
|
1001
|
+
severity,
|
|
1002
|
+
source: source.toString(),
|
|
1003
|
+
});
|
|
1004
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
943
1005
|
}
|
|
944
1006
|
|
|
945
1007
|
// Pool add: persist the tx
|
|
@@ -949,7 +1011,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
949
1011
|
const wasAccepted = addResult.accepted.some(h => h.equals(txHash));
|
|
950
1012
|
const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
|
|
951
1013
|
|
|
952
|
-
this.logger.
|
|
1014
|
+
this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
|
|
953
1015
|
wasAccepted,
|
|
954
1016
|
wasIgnored,
|
|
955
1017
|
[Attributes.P2P_ID]: source.toString(),
|
|
@@ -960,7 +1022,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
960
1022
|
} else if (wasIgnored) {
|
|
961
1023
|
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
962
1024
|
} else {
|
|
963
|
-
|
|
1025
|
+
this.logger.warn(`Gossiped tx ${txHash.toString()} unexpectedly rejected by pool`, {
|
|
1026
|
+
source: source.toString(),
|
|
1027
|
+
txHash: txHash.toString(),
|
|
1028
|
+
});
|
|
1029
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
964
1030
|
}
|
|
965
1031
|
};
|
|
966
1032
|
|
|
@@ -990,7 +1056,16 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
990
1056
|
source: PeerId,
|
|
991
1057
|
): Promise<void> {
|
|
992
1058
|
const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
|
|
993
|
-
() =>
|
|
1059
|
+
() => {
|
|
1060
|
+
const attestation = this.tryDeserialize(() => CheckpointAttestation.fromBuffer(payloadData), msgId, source);
|
|
1061
|
+
if (!attestation) {
|
|
1062
|
+
return Promise.resolve({
|
|
1063
|
+
result: TopicValidatorResult.Reject,
|
|
1064
|
+
severity: PeerErrorSeverity.LowToleranceError,
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
return this.validateAndStoreCheckpointAttestation(source, attestation);
|
|
1068
|
+
},
|
|
994
1069
|
msgId,
|
|
995
1070
|
source,
|
|
996
1071
|
TopicType.checkpoint_attestation,
|
|
@@ -1023,8 +1098,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1023
1098
|
|
|
1024
1099
|
if (validationResult.result === 'reject') {
|
|
1025
1100
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1026
|
-
|
|
1027
|
-
return { result: TopicValidatorResult.Reject };
|
|
1101
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1028
1102
|
}
|
|
1029
1103
|
|
|
1030
1104
|
if (validationResult.result === 'ignore') {
|
|
@@ -1050,16 +1124,16 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1050
1124
|
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
1051
1125
|
}
|
|
1052
1126
|
|
|
1053
|
-
// Could not add (cap reached for signer),
|
|
1127
|
+
// Could not add (cap reached for signer), penalize and do not re-broadcast
|
|
1054
1128
|
if (!added) {
|
|
1055
|
-
this.logger.warn(`
|
|
1129
|
+
this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
|
|
1056
1130
|
slot: slot.toString(),
|
|
1057
1131
|
archive: attestation.archive.toString(),
|
|
1058
1132
|
source: peerId.toString(),
|
|
1059
1133
|
attester: attestation.getSender()?.toString(),
|
|
1060
1134
|
count,
|
|
1061
1135
|
});
|
|
1062
|
-
return { result: TopicValidatorResult.
|
|
1136
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
1063
1137
|
}
|
|
1064
1138
|
|
|
1065
1139
|
// Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
|
|
@@ -1114,8 +1188,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1114
1188
|
|
|
1115
1189
|
if (validationResult.result === 'reject') {
|
|
1116
1190
|
this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1117
|
-
|
|
1118
|
-
return { result: TopicValidatorResult.Reject };
|
|
1191
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1119
1192
|
}
|
|
1120
1193
|
|
|
1121
1194
|
if (validationResult.result === 'ignore') {
|
|
@@ -1139,7 +1212,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1139
1212
|
|
|
1140
1213
|
// Too many blocks received for this slot and index, penalize peer and do not re-broadcast
|
|
1141
1214
|
if (!added) {
|
|
1142
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1143
1215
|
this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
|
|
1144
1216
|
...block.toBlockInfo(),
|
|
1145
1217
|
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
@@ -1147,7 +1219,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1147
1219
|
proposer: block.getSender()?.toString(),
|
|
1148
1220
|
source: peerId.toString(),
|
|
1149
1221
|
});
|
|
1150
|
-
return {
|
|
1222
|
+
return {
|
|
1223
|
+
result: TopicValidatorResult.Reject,
|
|
1224
|
+
metadata: { isEquivocated },
|
|
1225
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1226
|
+
};
|
|
1151
1227
|
}
|
|
1152
1228
|
|
|
1153
1229
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1192,7 +1268,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1192
1268
|
// Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
|
|
1193
1269
|
const isValid = await this.blockReceivedCallback(block, sender);
|
|
1194
1270
|
if (!isValid) {
|
|
1195
|
-
this.logger.
|
|
1271
|
+
this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
|
|
1196
1272
|
}
|
|
1197
1273
|
}
|
|
1198
1274
|
|
|
@@ -1240,8 +1316,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1240
1316
|
|
|
1241
1317
|
if (validationResult.result === 'reject') {
|
|
1242
1318
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1243
|
-
|
|
1244
|
-
return { result: TopicValidatorResult.Reject };
|
|
1319
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1245
1320
|
}
|
|
1246
1321
|
|
|
1247
1322
|
if (validationResult.result === 'ignore') {
|
|
@@ -1256,20 +1331,21 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1256
1331
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1257
1332
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1258
1333
|
});
|
|
1259
|
-
const
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
metadata: { isEquivocated } = {},
|
|
1263
|
-
} = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1264
|
-
if (result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1334
|
+
const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1335
|
+
const { obj, metadata: { isEquivocated } = {} } = blockProposalResult;
|
|
1336
|
+
if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1265
1337
|
this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
|
|
1266
1338
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1267
1339
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1268
1340
|
isEquivocated,
|
|
1269
|
-
result,
|
|
1341
|
+
result: blockProposalResult.result,
|
|
1270
1342
|
});
|
|
1271
|
-
return {
|
|
1272
|
-
|
|
1343
|
+
return {
|
|
1344
|
+
result: TopicValidatorResult.Reject,
|
|
1345
|
+
severity:
|
|
1346
|
+
'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError,
|
|
1347
|
+
};
|
|
1348
|
+
} else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated) {
|
|
1273
1349
|
processBlock = true;
|
|
1274
1350
|
}
|
|
1275
1351
|
}
|
|
@@ -1296,13 +1372,17 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1296
1372
|
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
|
|
1297
1373
|
// Note: We still return the checkpoint obj so the lastBlock can be processed if valid
|
|
1298
1374
|
if (!added) {
|
|
1299
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1300
1375
|
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1301
1376
|
...checkpoint.toCheckpointInfo(),
|
|
1302
1377
|
count,
|
|
1303
1378
|
source: peerId.toString(),
|
|
1304
1379
|
});
|
|
1305
|
-
return {
|
|
1380
|
+
return {
|
|
1381
|
+
result: TopicValidatorResult.Reject,
|
|
1382
|
+
obj: checkpoint,
|
|
1383
|
+
metadata: { isEquivocated, processBlock },
|
|
1384
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1385
|
+
};
|
|
1306
1386
|
}
|
|
1307
1387
|
|
|
1308
1388
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1347,9 +1427,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1347
1427
|
source: sender.toString(),
|
|
1348
1428
|
});
|
|
1349
1429
|
|
|
1430
|
+
await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
|
|
1431
|
+
|
|
1350
1432
|
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1351
1433
|
// to validate and potentially generate attestations
|
|
1352
|
-
const attestations = await this.
|
|
1434
|
+
const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
|
|
1353
1435
|
if (attestations && attestations.length > 0) {
|
|
1354
1436
|
// If the callback returned attestations, add them to the pool and propagate them
|
|
1355
1437
|
await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
@@ -1497,53 +1579,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1497
1579
|
}
|
|
1498
1580
|
}
|
|
1499
1581
|
|
|
1500
|
-
/**
|
|
1501
|
-
* Validates a BLOCK response.
|
|
1502
|
-
*
|
|
1503
|
-
* If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
|
|
1504
|
-
* Penalizes on block number mismatch or hash mismatch.
|
|
1505
|
-
*
|
|
1506
|
-
* @param requestedBlockNumber - The requested block number.
|
|
1507
|
-
* @param responseBlock - The block returned by the peer.
|
|
1508
|
-
* @param peerId - The peer that returned the block.
|
|
1509
|
-
* @returns True if the response is valid, false otherwise.
|
|
1510
|
-
*/
|
|
1511
|
-
@trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock) => ({
|
|
1512
|
-
[Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString(),
|
|
1513
|
-
}))
|
|
1514
|
-
protected async validateRequestedBlock(
|
|
1515
|
-
requestedBlockNumber: Fr,
|
|
1516
|
-
responseBlock: L2Block,
|
|
1517
|
-
peerId: PeerId,
|
|
1518
|
-
): Promise<boolean> {
|
|
1519
|
-
try {
|
|
1520
|
-
const reqNum = Number(requestedBlockNumber.toString());
|
|
1521
|
-
if (responseBlock.number !== reqNum) {
|
|
1522
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1523
|
-
return false;
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
|
-
const local = await this.archiver.getBlock(BlockNumber(reqNum));
|
|
1527
|
-
if (!local) {
|
|
1528
|
-
// We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
|
|
1529
|
-
// TODO: Consider extending this validator to accept an expected hash or
|
|
1530
|
-
// performing quorum-based checks when using P2P syncing prior to L1 sync.
|
|
1531
|
-
this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
|
|
1532
|
-
return false;
|
|
1533
|
-
}
|
|
1534
|
-
const [localHash, respHash] = await Promise.all([local.hash(), responseBlock.hash()]);
|
|
1535
|
-
if (!localHash.equals(respHash)) {
|
|
1536
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1537
|
-
return false;
|
|
1538
|
-
}
|
|
1539
|
-
|
|
1540
|
-
return true;
|
|
1541
|
-
} catch (e) {
|
|
1542
|
-
this.logger.warn(`Error validating requested block`, e);
|
|
1543
|
-
return false;
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
1582
|
protected async validateRequestedTx(
|
|
1548
1583
|
tx: Tx,
|
|
1549
1584
|
peerId: PeerId,
|
|
@@ -1626,6 +1661,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1626
1661
|
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1627
1662
|
];
|
|
1628
1663
|
const blockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1664
|
+
const l1Constants = await this.archiver.getL1Constants();
|
|
1629
1665
|
|
|
1630
1666
|
return createFirstStageTxValidationsForGossipedTransactions(
|
|
1631
1667
|
nextSlotTimestamp,
|
|
@@ -1639,6 +1675,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1639
1675
|
!this.config.disableTransactions,
|
|
1640
1676
|
allowedInSetup,
|
|
1641
1677
|
this.logger.getBindings(),
|
|
1678
|
+
{
|
|
1679
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1680
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1681
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1682
|
+
},
|
|
1642
1683
|
);
|
|
1643
1684
|
}
|
|
1644
1685
|
|
|
@@ -1720,31 +1761,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1720
1761
|
return PeerErrorSeverity.HighToleranceError;
|
|
1721
1762
|
}
|
|
1722
1763
|
|
|
1723
|
-
/**
|
|
1724
|
-
* Validate a checkpoint attestation.
|
|
1725
|
-
*
|
|
1726
|
-
* @param attestation - The checkpoint attestation to validate.
|
|
1727
|
-
* @returns True if the checkpoint attestation is valid, false otherwise.
|
|
1728
|
-
*/
|
|
1729
|
-
@trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
|
|
1730
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
1731
|
-
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
1732
|
-
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
1733
|
-
}))
|
|
1734
|
-
public async validateCheckpointAttestation(
|
|
1735
|
-
peerId: PeerId,
|
|
1736
|
-
attestation: CheckpointAttestation,
|
|
1737
|
-
): Promise<P2PValidationResult> {
|
|
1738
|
-
const result = await this.checkpointAttestationValidator.validate(attestation);
|
|
1739
|
-
|
|
1740
|
-
if (result.result === 'reject') {
|
|
1741
|
-
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1742
|
-
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
|
-
return result;
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1748
1764
|
public getPeerScore(peerId: PeerId): number {
|
|
1749
1765
|
return this.node.services.pubsub.score.score(peerId.toString());
|
|
1750
1766
|
}
|