@aztec/p2p 0.0.1-commit.8c0b8ff → 0.0.1-commit.8cb2d04d8
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 +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +1 -0
- 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 +17 -6
- 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/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/interfaces.js +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +5 -6
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +6 -2
- 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 +18 -1
- 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/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +11 -9
- 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 +15 -25
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +150 -115
- 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/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 +21 -2
- 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 +51 -2
- package/dest/util.d.ts +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +2 -1
- 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 +19 -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/invalid_txs_after_reorg_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/interfaces.ts +7 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +12 -6
- 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 +19 -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/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/gas_validator.ts +25 -9
- 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 +146 -130
- 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 +1 -1
- package/src/test-helpers/mock-pubsub.ts +31 -5
- package/src/test-helpers/reqresp-nodes.ts +3 -3
- package/src/test-helpers/testbench-utils.ts +29 -3
- package/src/testbench/p2p_client_testbench_worker.ts +71 -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,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,15 +228,19 @@ 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
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
|
|
|
@@ -244,12 +252,15 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
244
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,67 @@ 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
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
917
|
+
this.logger.error(`Error validating gossipsub message`, err, { msgId, source: source.toString(), topicType });
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
const validationTimeMs = timer.ms();
|
|
921
|
+
const mcacheWindowMs = this.config.gossipsubMcacheLength * this.config.gossipsubInterval;
|
|
922
|
+
if (validationTimeMs > mcacheWindowMs * 0.75) {
|
|
923
|
+
this.instrumentation.incSlowValidation(topicType);
|
|
924
|
+
this.logger.warn(
|
|
925
|
+
`Gossip validation for ${topicType} took ${validationTimeMs}ms, approaching mcache eviction window of ${mcacheWindowMs}ms. ` +
|
|
926
|
+
`Message forwarding may be skipped if validation exceeds the window.`,
|
|
927
|
+
{ msgId, source: source.toString(), topicType, validationTimeMs, mcacheWindowMs },
|
|
928
|
+
);
|
|
894
929
|
}
|
|
895
930
|
|
|
896
931
|
if (resultAndObj.result === TopicValidatorResult.Accept) {
|
|
932
|
+
this.logger.debug(`Message ${topicType} accepted by validator`, { msgId, source: source.toString(), topicType });
|
|
897
933
|
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
934
|
+
} else if (resultAndObj.result === TopicValidatorResult.Reject) {
|
|
935
|
+
this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
|
|
936
|
+
msgId,
|
|
937
|
+
source: source.toString(),
|
|
938
|
+
topicType,
|
|
939
|
+
severity: resultAndObj.severity,
|
|
940
|
+
});
|
|
941
|
+
this.peerManager.penalizePeer(source, resultAndObj.severity);
|
|
942
|
+
} else {
|
|
943
|
+
this.logger.trace(`Message ${topicType} ignored by validator`, { msgId, source: source.toString(), topicType });
|
|
898
944
|
}
|
|
899
945
|
|
|
900
946
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
|
|
901
947
|
return resultAndObj;
|
|
902
948
|
}
|
|
903
949
|
|
|
950
|
+
private tryDeserialize<T>(deserializeFunc: () => T, msgId: string, source: PeerId): T | undefined {
|
|
951
|
+
try {
|
|
952
|
+
return deserializeFunc();
|
|
953
|
+
} catch (err) {
|
|
954
|
+
this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
|
|
955
|
+
err,
|
|
956
|
+
msgId,
|
|
957
|
+
source: source.toString(),
|
|
958
|
+
});
|
|
959
|
+
return undefined;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
904
963
|
protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
|
|
905
964
|
const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
|
|
906
|
-
const tx = Tx.fromBuffer(payloadData);
|
|
965
|
+
const tx = this.tryDeserialize(() => Tx.fromBuffer(payloadData), msgId, source);
|
|
966
|
+
if (!tx) {
|
|
967
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.LowToleranceError };
|
|
968
|
+
}
|
|
907
969
|
|
|
908
970
|
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
909
971
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
@@ -923,13 +985,20 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
923
985
|
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
924
986
|
}
|
|
925
987
|
|
|
926
|
-
this.
|
|
927
|
-
|
|
988
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
|
|
989
|
+
validator: name,
|
|
990
|
+
severity,
|
|
991
|
+
source: source.toString(),
|
|
992
|
+
});
|
|
993
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
928
994
|
}
|
|
929
995
|
|
|
930
996
|
// Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
|
|
931
997
|
const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
|
|
932
998
|
if (canAdd === 'ignored') {
|
|
999
|
+
this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
|
|
1000
|
+
source: source.toString(),
|
|
1001
|
+
});
|
|
933
1002
|
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
934
1003
|
}
|
|
935
1004
|
|
|
@@ -937,9 +1006,13 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
937
1006
|
const secondStageValidators = this.createSecondStageMessageValidators();
|
|
938
1007
|
const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
|
|
939
1008
|
if (!secondStageOutcome.allPassed) {
|
|
940
|
-
const { severity } = secondStageOutcome.failure;
|
|
941
|
-
this.
|
|
942
|
-
|
|
1009
|
+
const { severity, name } = secondStageOutcome.failure;
|
|
1010
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
|
|
1011
|
+
validator: name,
|
|
1012
|
+
severity,
|
|
1013
|
+
source: source.toString(),
|
|
1014
|
+
});
|
|
1015
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
943
1016
|
}
|
|
944
1017
|
|
|
945
1018
|
// Pool add: persist the tx
|
|
@@ -949,7 +1022,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
949
1022
|
const wasAccepted = addResult.accepted.some(h => h.equals(txHash));
|
|
950
1023
|
const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
|
|
951
1024
|
|
|
952
|
-
this.logger.
|
|
1025
|
+
this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
|
|
953
1026
|
wasAccepted,
|
|
954
1027
|
wasIgnored,
|
|
955
1028
|
[Attributes.P2P_ID]: source.toString(),
|
|
@@ -964,8 +1037,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
964
1037
|
source: source.toString(),
|
|
965
1038
|
txHash: txHash.toString(),
|
|
966
1039
|
});
|
|
967
|
-
|
|
968
|
-
return { result: TopicValidatorResult.Reject };
|
|
1040
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
969
1041
|
}
|
|
970
1042
|
};
|
|
971
1043
|
|
|
@@ -995,7 +1067,16 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
995
1067
|
source: PeerId,
|
|
996
1068
|
): Promise<void> {
|
|
997
1069
|
const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
|
|
998
|
-
() =>
|
|
1070
|
+
() => {
|
|
1071
|
+
const attestation = this.tryDeserialize(() => CheckpointAttestation.fromBuffer(payloadData), msgId, source);
|
|
1072
|
+
if (!attestation) {
|
|
1073
|
+
return Promise.resolve({
|
|
1074
|
+
result: TopicValidatorResult.Reject,
|
|
1075
|
+
severity: PeerErrorSeverity.LowToleranceError,
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
return this.validateAndStoreCheckpointAttestation(source, attestation);
|
|
1079
|
+
},
|
|
999
1080
|
msgId,
|
|
1000
1081
|
source,
|
|
1001
1082
|
TopicType.checkpoint_attestation,
|
|
@@ -1028,8 +1109,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1028
1109
|
|
|
1029
1110
|
if (validationResult.result === 'reject') {
|
|
1030
1111
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1031
|
-
|
|
1032
|
-
return { result: TopicValidatorResult.Reject };
|
|
1112
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1033
1113
|
}
|
|
1034
1114
|
|
|
1035
1115
|
if (validationResult.result === 'ignore') {
|
|
@@ -1055,16 +1135,16 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1055
1135
|
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
1056
1136
|
}
|
|
1057
1137
|
|
|
1058
|
-
// Could not add (cap reached for signer),
|
|
1138
|
+
// Could not add (cap reached for signer), penalize and do not re-broadcast
|
|
1059
1139
|
if (!added) {
|
|
1060
|
-
this.logger.warn(`
|
|
1140
|
+
this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
|
|
1061
1141
|
slot: slot.toString(),
|
|
1062
1142
|
archive: attestation.archive.toString(),
|
|
1063
1143
|
source: peerId.toString(),
|
|
1064
1144
|
attester: attestation.getSender()?.toString(),
|
|
1065
1145
|
count,
|
|
1066
1146
|
});
|
|
1067
|
-
return { result: TopicValidatorResult.
|
|
1147
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
1068
1148
|
}
|
|
1069
1149
|
|
|
1070
1150
|
// Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
|
|
@@ -1119,8 +1199,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1119
1199
|
|
|
1120
1200
|
if (validationResult.result === 'reject') {
|
|
1121
1201
|
this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1122
|
-
|
|
1123
|
-
return { result: TopicValidatorResult.Reject };
|
|
1202
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1124
1203
|
}
|
|
1125
1204
|
|
|
1126
1205
|
if (validationResult.result === 'ignore') {
|
|
@@ -1144,7 +1223,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1144
1223
|
|
|
1145
1224
|
// Too many blocks received for this slot and index, penalize peer and do not re-broadcast
|
|
1146
1225
|
if (!added) {
|
|
1147
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1148
1226
|
this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
|
|
1149
1227
|
...block.toBlockInfo(),
|
|
1150
1228
|
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
@@ -1152,7 +1230,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1152
1230
|
proposer: block.getSender()?.toString(),
|
|
1153
1231
|
source: peerId.toString(),
|
|
1154
1232
|
});
|
|
1155
|
-
return {
|
|
1233
|
+
return {
|
|
1234
|
+
result: TopicValidatorResult.Reject,
|
|
1235
|
+
metadata: { isEquivocated },
|
|
1236
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1237
|
+
};
|
|
1156
1238
|
}
|
|
1157
1239
|
|
|
1158
1240
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1245,8 +1327,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1245
1327
|
|
|
1246
1328
|
if (validationResult.result === 'reject') {
|
|
1247
1329
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1248
|
-
|
|
1249
|
-
return { result: TopicValidatorResult.Reject };
|
|
1330
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1250
1331
|
}
|
|
1251
1332
|
|
|
1252
1333
|
if (validationResult.result === 'ignore') {
|
|
@@ -1261,20 +1342,21 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1261
1342
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1262
1343
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1263
1344
|
});
|
|
1264
|
-
const
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
metadata: { isEquivocated } = {},
|
|
1268
|
-
} = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1269
|
-
if (result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1345
|
+
const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1346
|
+
const { obj, metadata: { isEquivocated } = {} } = blockProposalResult;
|
|
1347
|
+
if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1270
1348
|
this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
|
|
1271
1349
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1272
1350
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1273
1351
|
isEquivocated,
|
|
1274
|
-
result,
|
|
1352
|
+
result: blockProposalResult.result,
|
|
1275
1353
|
});
|
|
1276
|
-
return {
|
|
1277
|
-
|
|
1354
|
+
return {
|
|
1355
|
+
result: TopicValidatorResult.Reject,
|
|
1356
|
+
severity:
|
|
1357
|
+
'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError,
|
|
1358
|
+
};
|
|
1359
|
+
} else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated) {
|
|
1278
1360
|
processBlock = true;
|
|
1279
1361
|
}
|
|
1280
1362
|
}
|
|
@@ -1301,13 +1383,17 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1301
1383
|
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
|
|
1302
1384
|
// Note: We still return the checkpoint obj so the lastBlock can be processed if valid
|
|
1303
1385
|
if (!added) {
|
|
1304
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1305
1386
|
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1306
1387
|
...checkpoint.toCheckpointInfo(),
|
|
1307
1388
|
count,
|
|
1308
1389
|
source: peerId.toString(),
|
|
1309
1390
|
});
|
|
1310
|
-
return {
|
|
1391
|
+
return {
|
|
1392
|
+
result: TopicValidatorResult.Reject,
|
|
1393
|
+
obj: checkpoint,
|
|
1394
|
+
metadata: { isEquivocated, processBlock },
|
|
1395
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1396
|
+
};
|
|
1311
1397
|
}
|
|
1312
1398
|
|
|
1313
1399
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1352,9 +1438,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1352
1438
|
source: sender.toString(),
|
|
1353
1439
|
});
|
|
1354
1440
|
|
|
1441
|
+
await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
|
|
1442
|
+
|
|
1355
1443
|
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1356
1444
|
// to validate and potentially generate attestations
|
|
1357
|
-
const attestations = await this.
|
|
1445
|
+
const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
|
|
1358
1446
|
if (attestations && attestations.length > 0) {
|
|
1359
1447
|
// If the callback returned attestations, add them to the pool and propagate them
|
|
1360
1448
|
await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
@@ -1502,53 +1590,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1502
1590
|
}
|
|
1503
1591
|
}
|
|
1504
1592
|
|
|
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
1593
|
protected async validateRequestedTx(
|
|
1553
1594
|
tx: Tx,
|
|
1554
1595
|
peerId: PeerId,
|
|
@@ -1731,31 +1772,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1731
1772
|
return PeerErrorSeverity.HighToleranceError;
|
|
1732
1773
|
}
|
|
1733
1774
|
|
|
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
1775
|
public getPeerScore(peerId: PeerId): number {
|
|
1760
1776
|
return this.node.services.pubsub.score.score(peerId.toString());
|
|
1761
1777
|
}
|
|
@@ -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
|
}
|