@aztec/p2p 0.0.1-commit.5914bae → 0.0.1-commit.59a0419c6
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/client/factory.d.ts +4 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +17 -15
- 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 +30 -8
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +21 -7
- package/dest/config.d.ts +107 -103
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +17 -12
- 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 +16 -9
- 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/instrumentation.d.ts +4 -2
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +16 -14
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
- 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 +10 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +9 -7
- 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 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +26 -43
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +1 -1
- 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 +2 -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 +20 -2
- 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/factory.d.ts +2 -2
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +3 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +36 -4
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +50 -33
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- 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/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/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +14 -0
- package/dest/services/libp2p/libp2p_service.d.ts +19 -27
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +158 -133
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- 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 +39 -11
- 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 +82 -101
- 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 +19 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
- 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_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 +13 -3
- 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/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/test-helpers/make-test-p2p-clients.d.ts +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +4 -1
- 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 +36 -11
- 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 +5 -3
- 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 +21 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +73 -17
- 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 +51 -2
- package/dest/util.d.ts +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +25 -19
- package/src/client/interface.ts +9 -1
- package/src/client/p2p_client.ts +34 -9
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +21 -9
- package/src/config.ts +29 -17
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +17 -12
- 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/instrumentation.ts +17 -13
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
- 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 +10 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +24 -12
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +3 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +21 -1
- package/src/msg_validators/attestation_validator/README.md +1 -1
- 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 +4 -4
- 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 +11 -3
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/factory.ts +3 -1
- package/src/msg_validators/tx_validator/gas_validator.ts +82 -33
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/services/data_store.ts +5 -13
- package/src/services/dummy_service.ts +8 -2
- package/src/services/gossipsub/topic_score_params.ts +36 -4
- package/src/services/libp2p/instrumentation.ts +14 -0
- package/src/services/libp2p/libp2p_service.ts +154 -143
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +45 -11
- package/src/services/peer-manager/peer_scoring.ts +27 -5
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +78 -111
- 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 +68 -24
- 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_limits.ts +0 -10
- package/src/services/reqresp/reqresp.ts +21 -2
- package/src/services/service.ts +6 -1
- package/src/services/tx_collection/fast_tx_collection.ts +57 -83
- 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/test-helpers/make-test-p2p-clients.ts +3 -1
- package/src/test-helpers/mock-pubsub.ts +34 -5
- package/src/test-helpers/reqresp-nodes.ts +5 -3
- package/src/test-helpers/testbench-utils.ts +29 -3
- package/src/testbench/p2p_client_testbench_worker.ts +74 -15
- package/src/testbench/worker_client_manager.ts +57 -2
- package/src/util.ts +1 -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 -123
- 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 -402
- 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 -163
- 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 -321
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
|
@@ -1,15 +1,14 @@
|
|
|
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
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
11
|
+
import { type BlockMinFeesProvider, GasFees } from '@aztec/stdlib/gas';
|
|
13
12
|
import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
14
13
|
import {
|
|
15
14
|
BlockProposal,
|
|
@@ -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.
|
|
@@ -148,8 +146,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
148
146
|
private protocolVersion = '';
|
|
149
147
|
private topicStrings: Record<TopicType, string> = {} as Record<TopicType, string>;
|
|
150
148
|
|
|
151
|
-
private feesCache: { blockNumber: BlockNumber; gasFees: GasFees } | undefined;
|
|
152
|
-
|
|
153
149
|
/** Callback invoked when a duplicate proposal is detected (triggers slashing). */
|
|
154
150
|
private duplicateProposalCallback?: (info: {
|
|
155
151
|
slot: SlotNumber;
|
|
@@ -172,7 +168,13 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
172
168
|
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
173
169
|
* @returns The attestations for the checkpoint, if any.
|
|
174
170
|
*/
|
|
175
|
-
private
|
|
171
|
+
private allNodesCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
172
|
+
/**
|
|
173
|
+
* Callback for when a checkpoint proposal is received - specifically for validators - from a peer.
|
|
174
|
+
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
175
|
+
* @returns The attestations for the checkpoint, if any.
|
|
176
|
+
*/
|
|
177
|
+
private validatorCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
176
178
|
|
|
177
179
|
private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
|
|
178
180
|
|
|
@@ -193,6 +195,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
193
195
|
private epochCache: EpochCacheInterface,
|
|
194
196
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
195
197
|
private worldStateSynchronizer: WorldStateSynchronizer,
|
|
198
|
+
private blockMinFeesProvider: BlockMinFeesProvider,
|
|
196
199
|
telemetry: TelemetryClient,
|
|
197
200
|
logger: Logger = createLogger('p2p:libp2p_service'),
|
|
198
201
|
) {
|
|
@@ -224,15 +227,19 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
224
227
|
this.protocolVersion,
|
|
225
228
|
);
|
|
226
229
|
|
|
230
|
+
const p2pPropagationTime = config.attestationPropagationTime;
|
|
227
231
|
const proposalValidatorOpts = {
|
|
228
232
|
txsPermitted: !config.disableTransactions,
|
|
229
233
|
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
|
|
234
|
+
p2pPropagationTime,
|
|
230
235
|
};
|
|
231
236
|
this.blockProposalValidator = new BlockProposalValidator(epochCache, proposalValidatorOpts);
|
|
232
237
|
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, proposalValidatorOpts);
|
|
233
238
|
this.checkpointAttestationValidator = config.fishermanMode
|
|
234
|
-
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry
|
|
235
|
-
|
|
239
|
+
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry, {
|
|
240
|
+
l1PublishingTime: config.l1PublishingTime,
|
|
241
|
+
})
|
|
242
|
+
: new CheckpointAttestationValidator(epochCache, { l1PublishingTime: config.l1PublishingTime });
|
|
236
243
|
|
|
237
244
|
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
238
245
|
|
|
@@ -244,12 +251,15 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
244
251
|
return true;
|
|
245
252
|
};
|
|
246
253
|
|
|
247
|
-
this.
|
|
248
|
-
|
|
254
|
+
this.allNodesCheckpointReceivedCallback = (
|
|
255
|
+
_checkpoint: CheckpointProposalCore,
|
|
256
|
+
): Promise<CheckpointAttestation[] | undefined> => {
|
|
257
|
+
throw new CheckpointProposalReceivedCallbackNotRegisteredError();
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
this.validatorCheckpointReceivedCallback = (
|
|
261
|
+
_checkpoint: CheckpointProposalCore,
|
|
249
262
|
): 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
263
|
return Promise.resolve(undefined);
|
|
254
264
|
};
|
|
255
265
|
}
|
|
@@ -274,6 +284,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
274
284
|
proofVerifier: ClientProtocolCircuitVerifier;
|
|
275
285
|
worldStateSynchronizer: WorldStateSynchronizer;
|
|
276
286
|
peerStore: AztecAsyncKVStore;
|
|
287
|
+
blockMinFeesProvider: BlockMinFeesProvider;
|
|
277
288
|
telemetry: TelemetryClient;
|
|
278
289
|
logger: Logger;
|
|
279
290
|
packageVersion: string;
|
|
@@ -286,6 +297,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
286
297
|
mempools,
|
|
287
298
|
proofVerifier,
|
|
288
299
|
peerStore,
|
|
300
|
+
blockMinFeesProvider,
|
|
289
301
|
telemetry,
|
|
290
302
|
logger,
|
|
291
303
|
packageVersion,
|
|
@@ -339,9 +351,12 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
339
351
|
const l1Constants = epochCache.getL1Constants();
|
|
340
352
|
const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
|
|
341
353
|
slotDurationMs: l1Constants.slotDuration * 1000,
|
|
354
|
+
ethereumSlotDuration: l1Constants.ethereumSlotDuration,
|
|
342
355
|
heartbeatIntervalMs: config.gossipsubInterval,
|
|
343
356
|
targetCommitteeSize: l1Constants.targetCommitteeSize,
|
|
344
357
|
blockDurationMs: config.blockDurationMs,
|
|
358
|
+
l1PublishingTime: config.l1PublishingTime,
|
|
359
|
+
p2pPropagationTime: config.attestationPropagationTime,
|
|
345
360
|
expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot,
|
|
346
361
|
});
|
|
347
362
|
|
|
@@ -466,6 +481,9 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
466
481
|
epochCache,
|
|
467
482
|
);
|
|
468
483
|
|
|
484
|
+
// Gate req/resp data protocols for unauthenticated peers when p2pAllowOnlyValidators is enabled
|
|
485
|
+
reqresp.setShouldRejectPeer(peerId => peerManager.shouldDisableP2PGossip(peerId));
|
|
486
|
+
|
|
469
487
|
// Configure application-specific scoring for gossipsub.
|
|
470
488
|
// The weight scales app score to align with gossipsub thresholds:
|
|
471
489
|
// - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
|
|
@@ -486,6 +504,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
486
504
|
epochCache,
|
|
487
505
|
proofVerifier,
|
|
488
506
|
worldStateSynchronizer,
|
|
507
|
+
blockMinFeesProvider,
|
|
489
508
|
telemetry,
|
|
490
509
|
logger,
|
|
491
510
|
);
|
|
@@ -511,14 +530,12 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
511
530
|
// Create request response protocol handlers
|
|
512
531
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
513
532
|
const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
|
|
514
|
-
const blockHandler = reqRespBlockHandler(this.archiver);
|
|
515
533
|
const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
|
|
516
534
|
|
|
517
535
|
const requestResponseHandlers: Partial<ReqRespSubProtocolHandlers> = {
|
|
518
536
|
[ReqRespSubProtocol.PING]: pingHandler,
|
|
519
537
|
[ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
|
|
520
538
|
[ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
|
|
521
|
-
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this),
|
|
522
539
|
};
|
|
523
540
|
|
|
524
541
|
if (!this.config.disableTransactions) {
|
|
@@ -539,7 +556,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
539
556
|
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
540
557
|
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
541
558
|
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
542
|
-
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
|
|
543
559
|
};
|
|
544
560
|
|
|
545
561
|
await this.peerManager.initializePeers();
|
|
@@ -667,8 +683,16 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
667
683
|
this.blockReceivedCallback = callback;
|
|
668
684
|
}
|
|
669
685
|
|
|
670
|
-
public
|
|
671
|
-
this.
|
|
686
|
+
public registerValidatorCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
687
|
+
this.validatorCheckpointReceivedCallback = callback;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
public registerAllNodesCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
691
|
+
this.allNodesCheckpointReceivedCallback = callback;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
public async notifyOwnCheckpointProposal(checkpoint: CheckpointProposalCore): Promise<void> {
|
|
695
|
+
await this.allNodesCheckpointReceivedCallback(checkpoint, this.node.peerId);
|
|
672
696
|
}
|
|
673
697
|
|
|
674
698
|
/**
|
|
@@ -754,6 +778,9 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
754
778
|
if (!validator || !validator.addMessage(msgId)) {
|
|
755
779
|
this.instrumentation.incMessagePrevalidationStatus(false, topicType);
|
|
756
780
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
781
|
+
if (topicType === TopicType.tx) {
|
|
782
|
+
this.logger.verbose(`Ignoring already-seen tx gossip message`, { msgId, source: source.toString() });
|
|
783
|
+
}
|
|
757
784
|
return { result: false, topicType };
|
|
758
785
|
}
|
|
759
786
|
|
|
@@ -880,30 +907,67 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
880
907
|
source: PeerId,
|
|
881
908
|
topicType: TopicType,
|
|
882
909
|
): Promise<ReceivedMessageValidationResult<T, M>> {
|
|
883
|
-
|
|
910
|
+
// Default to reject result with a penalty if validation function throws an error
|
|
911
|
+
let resultAndObj: ReceivedMessageValidationResult<T, M> = {
|
|
912
|
+
result: TopicValidatorResult.Reject,
|
|
913
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
914
|
+
};
|
|
884
915
|
const timer = new Timer();
|
|
885
916
|
try {
|
|
886
917
|
resultAndObj = await validationFunc();
|
|
887
918
|
} catch (err) {
|
|
888
|
-
this.
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
919
|
+
this.logger.error(`Error validating gossipsub message`, err, { msgId, source: source.toString(), topicType });
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
const validationTimeMs = timer.ms();
|
|
923
|
+
const mcacheWindowMs = this.config.gossipsubMcacheLength * this.config.gossipsubInterval;
|
|
924
|
+
if (validationTimeMs > mcacheWindowMs * 0.75) {
|
|
925
|
+
this.instrumentation.incSlowValidation(topicType);
|
|
926
|
+
this.logger.warn(
|
|
927
|
+
`Gossip validation for ${topicType} took ${validationTimeMs}ms, approaching mcache eviction window of ${mcacheWindowMs}ms. ` +
|
|
928
|
+
`Message forwarding may be skipped if validation exceeds the window.`,
|
|
929
|
+
{ msgId, source: source.toString(), topicType, validationTimeMs, mcacheWindowMs },
|
|
930
|
+
);
|
|
894
931
|
}
|
|
895
932
|
|
|
896
933
|
if (resultAndObj.result === TopicValidatorResult.Accept) {
|
|
934
|
+
this.logger.debug(`Message ${topicType} accepted by validator`, { msgId, source: source.toString(), topicType });
|
|
897
935
|
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
936
|
+
} else if (resultAndObj.result === TopicValidatorResult.Reject) {
|
|
937
|
+
this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
|
|
938
|
+
msgId,
|
|
939
|
+
source: source.toString(),
|
|
940
|
+
topicType,
|
|
941
|
+
severity: resultAndObj.severity,
|
|
942
|
+
});
|
|
943
|
+
this.peerManager.penalizePeer(source, resultAndObj.severity);
|
|
944
|
+
} else {
|
|
945
|
+
this.logger.trace(`Message ${topicType} ignored by validator`, { msgId, source: source.toString(), topicType });
|
|
898
946
|
}
|
|
899
947
|
|
|
900
948
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
|
|
901
949
|
return resultAndObj;
|
|
902
950
|
}
|
|
903
951
|
|
|
952
|
+
private tryDeserialize<T>(deserializeFunc: () => T, msgId: string, source: PeerId): T | undefined {
|
|
953
|
+
try {
|
|
954
|
+
return deserializeFunc();
|
|
955
|
+
} catch (err) {
|
|
956
|
+
this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
|
|
957
|
+
err,
|
|
958
|
+
msgId,
|
|
959
|
+
source: source.toString(),
|
|
960
|
+
});
|
|
961
|
+
return undefined;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
|
|
904
965
|
protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
|
|
905
966
|
const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
|
|
906
|
-
const tx = Tx.fromBuffer(payloadData);
|
|
967
|
+
const tx = this.tryDeserialize(() => Tx.fromBuffer(payloadData), msgId, source);
|
|
968
|
+
if (!tx) {
|
|
969
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.LowToleranceError };
|
|
970
|
+
}
|
|
907
971
|
|
|
908
972
|
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
909
973
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
@@ -923,13 +987,20 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
923
987
|
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
924
988
|
}
|
|
925
989
|
|
|
926
|
-
this.
|
|
927
|
-
|
|
990
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
|
|
991
|
+
validator: name,
|
|
992
|
+
severity,
|
|
993
|
+
source: source.toString(),
|
|
994
|
+
});
|
|
995
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
928
996
|
}
|
|
929
997
|
|
|
930
998
|
// Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
|
|
931
999
|
const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
|
|
932
1000
|
if (canAdd === 'ignored') {
|
|
1001
|
+
this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
|
|
1002
|
+
source: source.toString(),
|
|
1003
|
+
});
|
|
933
1004
|
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
934
1005
|
}
|
|
935
1006
|
|
|
@@ -937,9 +1008,13 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
937
1008
|
const secondStageValidators = this.createSecondStageMessageValidators();
|
|
938
1009
|
const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
|
|
939
1010
|
if (!secondStageOutcome.allPassed) {
|
|
940
|
-
const { severity } = secondStageOutcome.failure;
|
|
941
|
-
this.
|
|
942
|
-
|
|
1011
|
+
const { severity, name } = secondStageOutcome.failure;
|
|
1012
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
|
|
1013
|
+
validator: name,
|
|
1014
|
+
severity,
|
|
1015
|
+
source: source.toString(),
|
|
1016
|
+
});
|
|
1017
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
943
1018
|
}
|
|
944
1019
|
|
|
945
1020
|
// Pool add: persist the tx
|
|
@@ -949,7 +1024,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
949
1024
|
const wasAccepted = addResult.accepted.some(h => h.equals(txHash));
|
|
950
1025
|
const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
|
|
951
1026
|
|
|
952
|
-
this.logger.
|
|
1027
|
+
this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
|
|
953
1028
|
wasAccepted,
|
|
954
1029
|
wasIgnored,
|
|
955
1030
|
[Attributes.P2P_ID]: source.toString(),
|
|
@@ -964,8 +1039,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
964
1039
|
source: source.toString(),
|
|
965
1040
|
txHash: txHash.toString(),
|
|
966
1041
|
});
|
|
967
|
-
|
|
968
|
-
return { result: TopicValidatorResult.Reject };
|
|
1042
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
969
1043
|
}
|
|
970
1044
|
};
|
|
971
1045
|
|
|
@@ -995,7 +1069,16 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
995
1069
|
source: PeerId,
|
|
996
1070
|
): Promise<void> {
|
|
997
1071
|
const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
|
|
998
|
-
() =>
|
|
1072
|
+
() => {
|
|
1073
|
+
const attestation = this.tryDeserialize(() => CheckpointAttestation.fromBuffer(payloadData), msgId, source);
|
|
1074
|
+
if (!attestation) {
|
|
1075
|
+
return Promise.resolve({
|
|
1076
|
+
result: TopicValidatorResult.Reject,
|
|
1077
|
+
severity: PeerErrorSeverity.LowToleranceError,
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
return this.validateAndStoreCheckpointAttestation(source, attestation);
|
|
1081
|
+
},
|
|
999
1082
|
msgId,
|
|
1000
1083
|
source,
|
|
1001
1084
|
TopicType.checkpoint_attestation,
|
|
@@ -1028,8 +1111,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1028
1111
|
|
|
1029
1112
|
if (validationResult.result === 'reject') {
|
|
1030
1113
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1031
|
-
|
|
1032
|
-
return { result: TopicValidatorResult.Reject };
|
|
1114
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1033
1115
|
}
|
|
1034
1116
|
|
|
1035
1117
|
if (validationResult.result === 'ignore') {
|
|
@@ -1055,16 +1137,16 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1055
1137
|
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
1056
1138
|
}
|
|
1057
1139
|
|
|
1058
|
-
// Could not add (cap reached for signer),
|
|
1140
|
+
// Could not add (cap reached for signer), penalize and do not re-broadcast
|
|
1059
1141
|
if (!added) {
|
|
1060
|
-
this.logger.warn(`
|
|
1142
|
+
this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
|
|
1061
1143
|
slot: slot.toString(),
|
|
1062
1144
|
archive: attestation.archive.toString(),
|
|
1063
1145
|
source: peerId.toString(),
|
|
1064
1146
|
attester: attestation.getSender()?.toString(),
|
|
1065
1147
|
count,
|
|
1066
1148
|
});
|
|
1067
|
-
return { result: TopicValidatorResult.
|
|
1149
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
1068
1150
|
}
|
|
1069
1151
|
|
|
1070
1152
|
// Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
|
|
@@ -1119,8 +1201,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1119
1201
|
|
|
1120
1202
|
if (validationResult.result === 'reject') {
|
|
1121
1203
|
this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1122
|
-
|
|
1123
|
-
return { result: TopicValidatorResult.Reject };
|
|
1204
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1124
1205
|
}
|
|
1125
1206
|
|
|
1126
1207
|
if (validationResult.result === 'ignore') {
|
|
@@ -1144,7 +1225,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1144
1225
|
|
|
1145
1226
|
// Too many blocks received for this slot and index, penalize peer and do not re-broadcast
|
|
1146
1227
|
if (!added) {
|
|
1147
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1148
1228
|
this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
|
|
1149
1229
|
...block.toBlockInfo(),
|
|
1150
1230
|
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
@@ -1152,7 +1232,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1152
1232
|
proposer: block.getSender()?.toString(),
|
|
1153
1233
|
source: peerId.toString(),
|
|
1154
1234
|
});
|
|
1155
|
-
return {
|
|
1235
|
+
return {
|
|
1236
|
+
result: TopicValidatorResult.Reject,
|
|
1237
|
+
metadata: { isEquivocated },
|
|
1238
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1239
|
+
};
|
|
1156
1240
|
}
|
|
1157
1241
|
|
|
1158
1242
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1245,8 +1329,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1245
1329
|
|
|
1246
1330
|
if (validationResult.result === 'reject') {
|
|
1247
1331
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1248
|
-
|
|
1249
|
-
return { result: TopicValidatorResult.Reject };
|
|
1332
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1250
1333
|
}
|
|
1251
1334
|
|
|
1252
1335
|
if (validationResult.result === 'ignore') {
|
|
@@ -1261,20 +1344,21 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1261
1344
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1262
1345
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1263
1346
|
});
|
|
1264
|
-
const
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
metadata: { isEquivocated } = {},
|
|
1268
|
-
} = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1269
|
-
if (result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1347
|
+
const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1348
|
+
const { obj, metadata: { isEquivocated } = {} } = blockProposalResult;
|
|
1349
|
+
if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1270
1350
|
this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
|
|
1271
1351
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1272
1352
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1273
1353
|
isEquivocated,
|
|
1274
|
-
result,
|
|
1354
|
+
result: blockProposalResult.result,
|
|
1275
1355
|
});
|
|
1276
|
-
return {
|
|
1277
|
-
|
|
1356
|
+
return {
|
|
1357
|
+
result: TopicValidatorResult.Reject,
|
|
1358
|
+
severity:
|
|
1359
|
+
'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError,
|
|
1360
|
+
};
|
|
1361
|
+
} else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated) {
|
|
1278
1362
|
processBlock = true;
|
|
1279
1363
|
}
|
|
1280
1364
|
}
|
|
@@ -1301,13 +1385,17 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1301
1385
|
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
|
|
1302
1386
|
// Note: We still return the checkpoint obj so the lastBlock can be processed if valid
|
|
1303
1387
|
if (!added) {
|
|
1304
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1305
1388
|
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1306
1389
|
...checkpoint.toCheckpointInfo(),
|
|
1307
1390
|
count,
|
|
1308
1391
|
source: peerId.toString(),
|
|
1309
1392
|
});
|
|
1310
|
-
return {
|
|
1393
|
+
return {
|
|
1394
|
+
result: TopicValidatorResult.Reject,
|
|
1395
|
+
obj: checkpoint,
|
|
1396
|
+
metadata: { isEquivocated, processBlock },
|
|
1397
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1398
|
+
};
|
|
1311
1399
|
}
|
|
1312
1400
|
|
|
1313
1401
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1352,9 +1440,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1352
1440
|
source: sender.toString(),
|
|
1353
1441
|
});
|
|
1354
1442
|
|
|
1443
|
+
await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
|
|
1444
|
+
|
|
1355
1445
|
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1356
1446
|
// to validate and potentially generate attestations
|
|
1357
|
-
const attestations = await this.
|
|
1447
|
+
const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
|
|
1358
1448
|
if (attestations && attestations.length > 0) {
|
|
1359
1449
|
// If the callback returned attestations, add them to the pool and propagate them
|
|
1360
1450
|
await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
@@ -1502,53 +1592,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1502
1592
|
}
|
|
1503
1593
|
}
|
|
1504
1594
|
|
|
1505
|
-
/**
|
|
1506
|
-
* Validates a BLOCK response.
|
|
1507
|
-
*
|
|
1508
|
-
* If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
|
|
1509
|
-
* Penalizes on block number mismatch or hash mismatch.
|
|
1510
|
-
*
|
|
1511
|
-
* @param requestedBlockNumber - The requested block number.
|
|
1512
|
-
* @param responseBlock - The block returned by the peer.
|
|
1513
|
-
* @param peerId - The peer that returned the block.
|
|
1514
|
-
* @returns True if the response is valid, false otherwise.
|
|
1515
|
-
*/
|
|
1516
|
-
@trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock) => ({
|
|
1517
|
-
[Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString(),
|
|
1518
|
-
}))
|
|
1519
|
-
protected async validateRequestedBlock(
|
|
1520
|
-
requestedBlockNumber: Fr,
|
|
1521
|
-
responseBlock: L2Block,
|
|
1522
|
-
peerId: PeerId,
|
|
1523
|
-
): Promise<boolean> {
|
|
1524
|
-
try {
|
|
1525
|
-
const reqNum = Number(requestedBlockNumber.toString());
|
|
1526
|
-
if (responseBlock.number !== reqNum) {
|
|
1527
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1528
|
-
return false;
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1531
|
-
const local = await this.archiver.getBlock(BlockNumber(reqNum));
|
|
1532
|
-
if (!local) {
|
|
1533
|
-
// We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
|
|
1534
|
-
// TODO: Consider extending this validator to accept an expected hash or
|
|
1535
|
-
// performing quorum-based checks when using P2P syncing prior to L1 sync.
|
|
1536
|
-
this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
|
|
1537
|
-
return false;
|
|
1538
|
-
}
|
|
1539
|
-
const [localHash, respHash] = await Promise.all([local.hash(), responseBlock.hash()]);
|
|
1540
|
-
if (!localHash.equals(respHash)) {
|
|
1541
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1542
|
-
return false;
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1545
|
-
return true;
|
|
1546
|
-
} catch (e) {
|
|
1547
|
-
this.logger.warn(`Error validating requested block`, e);
|
|
1548
|
-
return false;
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
1595
|
protected async validateRequestedTx(
|
|
1553
1596
|
tx: Tx,
|
|
1554
1597
|
peerId: PeerId,
|
|
@@ -1575,15 +1618,8 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1575
1618
|
});
|
|
1576
1619
|
}
|
|
1577
1620
|
|
|
1578
|
-
private
|
|
1579
|
-
|
|
1580
|
-
return this.feesCache.gasFees;
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
const header = await this.archiver.getBlockHeader(blockNumber);
|
|
1584
|
-
const gasFees = header?.globalVariables.gasFees ?? GasFees.empty();
|
|
1585
|
-
this.feesCache = { blockNumber, gasFees };
|
|
1586
|
-
return gasFees;
|
|
1621
|
+
private getGasFees(): Promise<GasFees> {
|
|
1622
|
+
return this.blockMinFeesProvider.getCurrentMinFees();
|
|
1587
1623
|
}
|
|
1588
1624
|
|
|
1589
1625
|
/**
|
|
@@ -1625,7 +1661,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1625
1661
|
currentBlockNumber: BlockNumber,
|
|
1626
1662
|
nextSlotTimestamp: UInt64,
|
|
1627
1663
|
): Promise<Record<string, TransactionValidator>> {
|
|
1628
|
-
const gasFees = await this.getGasFees(
|
|
1664
|
+
const gasFees = await this.getGasFees();
|
|
1629
1665
|
const allowedInSetup = [
|
|
1630
1666
|
...(await getDefaultAllowedSetupFunctions()),
|
|
1631
1667
|
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
@@ -1731,31 +1767,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1731
1767
|
return PeerErrorSeverity.HighToleranceError;
|
|
1732
1768
|
}
|
|
1733
1769
|
|
|
1734
|
-
/**
|
|
1735
|
-
* Validate a checkpoint attestation.
|
|
1736
|
-
*
|
|
1737
|
-
* @param attestation - The checkpoint attestation to validate.
|
|
1738
|
-
* @returns True if the checkpoint attestation is valid, false otherwise.
|
|
1739
|
-
*/
|
|
1740
|
-
@trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
|
|
1741
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
1742
|
-
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
1743
|
-
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
1744
|
-
}))
|
|
1745
|
-
public async validateCheckpointAttestation(
|
|
1746
|
-
peerId: PeerId,
|
|
1747
|
-
attestation: CheckpointAttestation,
|
|
1748
|
-
): Promise<P2PValidationResult> {
|
|
1749
|
-
const result = await this.checkpointAttestationValidator.validate(attestation);
|
|
1750
|
-
|
|
1751
|
-
if (result.result === 'reject') {
|
|
1752
|
-
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1753
|
-
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1754
|
-
}
|
|
1755
|
-
|
|
1756
|
-
return result;
|
|
1757
|
-
}
|
|
1758
|
-
|
|
1759
1770
|
public getPeerScore(peerId: PeerId): number {
|
|
1760
1771
|
return this.node.services.pubsub.score.score(peerId.toString());
|
|
1761
1772
|
}
|
|
@@ -18,6 +18,7 @@ export class PeerManagerMetrics {
|
|
|
18
18
|
private sentGoodbyes: UpDownCounter;
|
|
19
19
|
private receivedGoodbyes: UpDownCounter;
|
|
20
20
|
private peerCount: Gauge;
|
|
21
|
+
private healthyPeerCount: Gauge;
|
|
21
22
|
private lowScoreDisconnects: UpDownCounter;
|
|
22
23
|
private peerConnectionDuration: Histogram;
|
|
23
24
|
|
|
@@ -49,6 +50,7 @@ export class PeerManagerMetrics {
|
|
|
49
50
|
goodbyeReasonAttrs,
|
|
50
51
|
);
|
|
51
52
|
this.peerCount = meter.createGauge(Metrics.PEER_MANAGER_PEER_COUNT);
|
|
53
|
+
this.healthyPeerCount = meter.createGauge(Metrics.PEER_MANAGER_HEALTHY_PEER_COUNT);
|
|
52
54
|
this.lowScoreDisconnects = createUpDownCounterWithDefault(meter, Metrics.PEER_MANAGER_LOW_SCORE_DISCONNECTS, {
|
|
53
55
|
[Attributes.P2P_PEER_SCORE_STATE]: ['Banned', 'Disconnect'],
|
|
54
56
|
});
|
|
@@ -67,6 +69,10 @@ export class PeerManagerMetrics {
|
|
|
67
69
|
this.peerCount.record(count);
|
|
68
70
|
}
|
|
69
71
|
|
|
72
|
+
public recordHealthyPeerCount(count: number) {
|
|
73
|
+
this.healthyPeerCount.record(count);
|
|
74
|
+
}
|
|
75
|
+
|
|
70
76
|
public recordLowScoreDisconnect(scoreState: 'Banned' | 'Disconnect') {
|
|
71
77
|
this.lowScoreDisconnects.add(1, { [Attributes.P2P_PEER_SCORE_STATE]: scoreState });
|
|
72
78
|
}
|
|
@@ -79,6 +85,7 @@ export class PeerManagerMetrics {
|
|
|
79
85
|
const connectedAt = this.peerConnectedAt.get(id.toString());
|
|
80
86
|
if (connectedAt) {
|
|
81
87
|
this.peerConnectionDuration.record(Date.now() - connectedAt);
|
|
88
|
+
this.peerConnectedAt.delete(id.toString());
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
91
|
}
|