@aztec/p2p 0.0.1-commit.033589e → 0.0.1-commit.03b9a845c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -3
- package/dest/client/factory.d.ts +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +22 -9
- package/dest/client/p2p_client.d.ts +1 -1
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +22 -34
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +3 -3
- package/dest/config.d.ts +24 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +66 -7
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +3 -3
- package/dest/mem_pools/attestation_pool/attestation_pool.js +3 -3
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +2 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +2 -2
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +4 -4
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +3 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +7 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +8 -6
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +9 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +25 -10
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +33 -10
- 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 +4 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +21 -6
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
- package/dest/msg_validators/clock_tolerance.d.ts +1 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +4 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +5 -4
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +5 -4
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +12 -9
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +51 -49
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +21 -32
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +35 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +23 -4
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +36 -10
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +13 -4
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +39 -9
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- 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/msg_validators/tx_validator/phases_validator.d.ts +21 -1
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +49 -2
- package/dest/services/discv5/discV5_service.d.ts +1 -1
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +4 -2
- package/dest/services/encoding.d.ts +5 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -1
- package/dest/services/libp2p/libp2p_service.d.ts +7 -9
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +161 -72
- package/dest/services/peer-manager/peer_manager.d.ts +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +4 -2
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +69 -65
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +3 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +3 -0
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +17 -9
- package/dest/services/service.d.ts +7 -1
- 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 +6 -1
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +9 -1
- 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/testbench-utils.d.ts +1 -1
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +22 -3
- package/dest/testbench/p2p_client_testbench_worker.js +5 -4
- package/dest/testbench/worker_client_manager.d.ts +3 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -2
- package/dest/util.d.ts +9 -4
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +2 -9
- package/package.json +14 -14
- package/src/client/factory.ts +37 -13
- package/src/client/p2p_client.ts +22 -34
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +4 -6
- package/src/config.ts +92 -4
- package/src/mem_pools/attestation_pool/attestation_pool.ts +3 -3
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +2 -1
- package/src/mem_pools/tx_pool/priority.ts +4 -4
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +3 -1
- package/src/mem_pools/tx_pool_v2/README.md +9 -1
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +2 -1
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +11 -1
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +15 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +2 -1
- package/src/mem_pools/tx_pool_v2/interfaces.ts +9 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +52 -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 +13 -1
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +23 -6
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
- package/src/msg_validators/clock_tolerance.ts +4 -3
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +13 -3
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +19 -6
- package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -53
- package/src/msg_validators/tx_validator/README.md +5 -1
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +16 -35
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +42 -1
- package/src/msg_validators/tx_validator/factory.ts +43 -3
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +41 -8
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/phases_validator.ts +60 -1
- package/src/services/discv5/discV5_service.ts +4 -2
- package/src/services/encoding.ts +9 -1
- package/src/services/libp2p/libp2p_service.ts +160 -83
- package/src/services/peer-manager/peer_manager.ts +5 -2
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +64 -69
- package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +5 -0
- package/src/services/reqresp/reqresp.ts +19 -11
- package/src/services/service.ts +7 -0
- 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 +9 -0
- package/src/test-helpers/reqresp-nodes.ts +1 -1
- package/src/test-helpers/testbench-utils.ts +29 -3
- package/src/testbench/p2p_client_testbench_worker.ts +5 -6
- package/src/testbench/worker_client_manager.ts +13 -5
- package/src/util.ts +9 -13
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -24
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -378
- 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/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -373
- package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
2
|
import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { maxBy } from '@aztec/foundation/collection';
|
|
3
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
5
6
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
@@ -17,8 +18,8 @@ import {
|
|
|
17
18
|
type CheckpointProposalCore,
|
|
18
19
|
type Gossipable,
|
|
19
20
|
P2PMessage,
|
|
20
|
-
type ValidationResult as P2PValidationResult,
|
|
21
21
|
PeerErrorSeverity,
|
|
22
|
+
PeerErrorSeverityByHarshness,
|
|
22
23
|
TopicType,
|
|
23
24
|
createTopicString,
|
|
24
25
|
getTopicsForConfig,
|
|
@@ -50,9 +51,10 @@ import { yamux } from '@chainsafe/libp2p-yamux';
|
|
|
50
51
|
import { bootstrap } from '@libp2p/bootstrap';
|
|
51
52
|
import { identify } from '@libp2p/identify';
|
|
52
53
|
import { type Message, type MultiaddrConnection, type PeerId, TopicValidatorResult } from '@libp2p/interface';
|
|
53
|
-
import type { ConnectionManager } from '@libp2p/interface-internal';
|
|
54
|
+
import type { AddressManager, ConnectionManager } from '@libp2p/interface-internal';
|
|
54
55
|
import { mplex } from '@libp2p/mplex';
|
|
55
56
|
import { tcp } from '@libp2p/tcp';
|
|
57
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
56
58
|
import { ENR } from '@nethermindeth/enr';
|
|
57
59
|
import { createLibp2p } from 'libp2p';
|
|
58
60
|
|
|
@@ -129,7 +131,7 @@ type ValidationOutcome = { allPassed: true } | { allPassed: false; failure: Vali
|
|
|
129
131
|
// REFACTOR: Unify with the type above
|
|
130
132
|
type ReceivedMessageValidationResult<T, M = undefined> =
|
|
131
133
|
| { obj: T; result: Exclude<TopicValidatorResult, TopicValidatorResult.Reject>; metadata?: M }
|
|
132
|
-
| { obj?: T; result: TopicValidatorResult.Reject; metadata?: M };
|
|
134
|
+
| { obj?: T; result: TopicValidatorResult.Reject; metadata?: M; severity: PeerErrorSeverity };
|
|
133
135
|
|
|
134
136
|
/**
|
|
135
137
|
* Lib P2P implementation of the P2PService interface.
|
|
@@ -173,6 +175,10 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
173
175
|
private checkpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
174
176
|
|
|
175
177
|
private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
|
|
178
|
+
private ipChangedHandler?: (ip: string) => void;
|
|
179
|
+
|
|
180
|
+
/** Discovered public IP address (set when queryForIp is enabled and no static IP was configured). */
|
|
181
|
+
private discoveredP2pIp?: string;
|
|
176
182
|
|
|
177
183
|
private instrumentation: P2PInstrumentation;
|
|
178
184
|
|
|
@@ -222,14 +228,12 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
222
228
|
this.protocolVersion,
|
|
223
229
|
);
|
|
224
230
|
|
|
225
|
-
|
|
226
|
-
txsPermitted: !config.disableTransactions,
|
|
227
|
-
maxTxsPerBlock: config.maxTxsPerBlock,
|
|
228
|
-
});
|
|
229
|
-
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
|
|
231
|
+
const proposalValidatorOpts = {
|
|
230
232
|
txsPermitted: !config.disableTransactions,
|
|
231
|
-
maxTxsPerBlock: config.
|
|
232
|
-
}
|
|
233
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
|
|
234
|
+
};
|
|
235
|
+
this.blockProposalValidator = new BlockProposalValidator(epochCache, proposalValidatorOpts);
|
|
236
|
+
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, proposalValidatorOpts);
|
|
233
237
|
this.checkpointAttestationValidator = config.fishermanMode
|
|
234
238
|
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
|
|
235
239
|
: new CheckpointAttestationValidator(epochCache);
|
|
@@ -237,11 +241,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
237
241
|
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
238
242
|
|
|
239
243
|
this.blockReceivedCallback = async (block: BlockProposal): Promise<boolean> => {
|
|
240
|
-
this.logger.
|
|
241
|
-
`Handler not yet registered
|
|
244
|
+
this.logger.warn(
|
|
245
|
+
`Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`,
|
|
242
246
|
{ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
|
|
243
247
|
);
|
|
244
|
-
return
|
|
248
|
+
return true;
|
|
245
249
|
};
|
|
246
250
|
|
|
247
251
|
this.checkpointReceivedCallback = (
|
|
@@ -443,8 +447,9 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
443
447
|
topics: topicScoreParams,
|
|
444
448
|
}),
|
|
445
449
|
}) as (components: GossipSubComponents) => GossipSub,
|
|
446
|
-
components: (components: { connectionManager: ConnectionManager }) => ({
|
|
450
|
+
components: (components: { connectionManager: ConnectionManager; addressManager: AddressManager }) => ({
|
|
447
451
|
connectionManager: components.connectionManager,
|
|
452
|
+
addressManager: components.addressManager,
|
|
448
453
|
}),
|
|
449
454
|
},
|
|
450
455
|
logger: createLibp2pComponentLogger(logger.module, logger.getBindings()),
|
|
@@ -503,10 +508,10 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
503
508
|
|
|
504
509
|
// Get listen & announce addresses for logging
|
|
505
510
|
const { p2pIp, p2pPort } = this.config;
|
|
506
|
-
if (!p2pIp) {
|
|
511
|
+
if (!p2pIp && !this.config.queryForIp) {
|
|
507
512
|
throw new Error('Announce address not provided.');
|
|
508
513
|
}
|
|
509
|
-
const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
|
|
514
|
+
const announceTcpMultiaddr = p2pIp ? convertToMultiaddr(p2pIp, p2pPort, 'tcp') : undefined;
|
|
510
515
|
|
|
511
516
|
// Create request response protocol handlers
|
|
512
517
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
@@ -560,6 +565,31 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
560
565
|
if (!this.config.p2pDiscoveryDisabled) {
|
|
561
566
|
await this.peerDiscoveryService.start();
|
|
562
567
|
}
|
|
568
|
+
|
|
569
|
+
// When queryForIp is enabled and no static IP was configured, bridge discv5 IP discovery to libp2p.
|
|
570
|
+
// Discv5 discovers our public IP via peer WHOAREYOU exchanges (enrUpdate=true) and emits 'ip:changed'.
|
|
571
|
+
// We confirm the discovered address in the libp2p AddressManager so it appears in getMultiaddrs()
|
|
572
|
+
// and is pushed to all connected peers via the identify protocol.
|
|
573
|
+
if (this.config.queryForIp && !p2pIp) {
|
|
574
|
+
this.ipChangedHandler = (ip: string) => {
|
|
575
|
+
const addressManager = this.node.services.components.addressManager;
|
|
576
|
+
const newAddr = multiaddr(convertToMultiaddr(ip, this.config.p2pPort, 'tcp'));
|
|
577
|
+
|
|
578
|
+
// Remove old discovered IP if one exists
|
|
579
|
+
if (this.discoveredP2pIp) {
|
|
580
|
+
const oldAddr = multiaddr(convertToMultiaddr(this.discoveredP2pIp, this.config.p2pPort, 'tcp'));
|
|
581
|
+
addressManager.removeObservedAddr(oldAddr);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
addressManager.addObservedAddr(newAddr);
|
|
585
|
+
addressManager.confirmObservedAddr(newAddr);
|
|
586
|
+
// Store discovered IP
|
|
587
|
+
this.discoveredP2pIp = ip;
|
|
588
|
+
this.logger.info('Public IP discovered via discv5', { ip });
|
|
589
|
+
};
|
|
590
|
+
this.peerDiscoveryService.on('ip:changed', this.ipChangedHandler);
|
|
591
|
+
}
|
|
592
|
+
|
|
563
593
|
this.discoveryRunningPromise = new RunningPromise(
|
|
564
594
|
async () => {
|
|
565
595
|
await this.peerManager.heartbeat();
|
|
@@ -572,7 +602,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
572
602
|
this.logger.info(`Started P2P service`, {
|
|
573
603
|
listen: this.config.listenAddress,
|
|
574
604
|
port: this.config.p2pPort,
|
|
575
|
-
announce: announceTcpMultiaddr,
|
|
605
|
+
announce: announceTcpMultiaddr ?? 'pending (queryForIp=true)',
|
|
576
606
|
peerId: this.node.peerId.toString(),
|
|
577
607
|
});
|
|
578
608
|
}
|
|
@@ -585,6 +615,12 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
585
615
|
// Remove gossip sub listener
|
|
586
616
|
this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
|
|
587
617
|
|
|
618
|
+
// Remove ip:changed listener if registered
|
|
619
|
+
if (this.ipChangedHandler) {
|
|
620
|
+
this.peerDiscoveryService.off('ip:changed', this.ipChangedHandler);
|
|
621
|
+
this.ipChangedHandler = undefined;
|
|
622
|
+
}
|
|
623
|
+
|
|
588
624
|
// Stop peer manager
|
|
589
625
|
this.logger.debug('Stopping peer manager...');
|
|
590
626
|
await this.peerManager.stop();
|
|
@@ -754,6 +790,9 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
754
790
|
if (!validator || !validator.addMessage(msgId)) {
|
|
755
791
|
this.instrumentation.incMessagePrevalidationStatus(false, topicType);
|
|
756
792
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
793
|
+
if (topicType === TopicType.tx) {
|
|
794
|
+
this.logger.verbose(`Ignoring already-seen tx gossip message`, { msgId, source: source.toString() });
|
|
795
|
+
}
|
|
757
796
|
return { result: false, topicType };
|
|
758
797
|
}
|
|
759
798
|
|
|
@@ -880,30 +919,56 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
880
919
|
source: PeerId,
|
|
881
920
|
topicType: TopicType,
|
|
882
921
|
): Promise<ReceivedMessageValidationResult<T, M>> {
|
|
883
|
-
|
|
922
|
+
// Default to reject result with a penalty if validation function throws an error
|
|
923
|
+
let resultAndObj: ReceivedMessageValidationResult<T, M> = {
|
|
924
|
+
result: TopicValidatorResult.Reject,
|
|
925
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
926
|
+
};
|
|
884
927
|
const timer = new Timer();
|
|
885
928
|
try {
|
|
886
929
|
resultAndObj = await validationFunc();
|
|
887
930
|
} catch (err) {
|
|
888
|
-
this.
|
|
889
|
-
this.logger.error(`Error deserializing and validating gossipsub message`, err, {
|
|
890
|
-
msgId,
|
|
891
|
-
source: source.toString(),
|
|
892
|
-
topicType,
|
|
893
|
-
});
|
|
931
|
+
this.logger.error(`Error validating gossipsub message`, err, { msgId, source: source.toString(), topicType });
|
|
894
932
|
}
|
|
895
933
|
|
|
896
934
|
if (resultAndObj.result === TopicValidatorResult.Accept) {
|
|
935
|
+
this.logger.debug(`Message ${topicType} accepted by validator`, { msgId, source: source.toString(), topicType });
|
|
897
936
|
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
937
|
+
} else if (resultAndObj.result === TopicValidatorResult.Reject) {
|
|
938
|
+
this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
|
|
939
|
+
msgId,
|
|
940
|
+
source: source.toString(),
|
|
941
|
+
topicType,
|
|
942
|
+
severity: resultAndObj.severity,
|
|
943
|
+
});
|
|
944
|
+
this.peerManager.penalizePeer(source, resultAndObj.severity);
|
|
945
|
+
} else {
|
|
946
|
+
this.logger.trace(`Message ${topicType} ignored by validator`, { msgId, source: source.toString(), topicType });
|
|
898
947
|
}
|
|
899
948
|
|
|
900
949
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
|
|
901
950
|
return resultAndObj;
|
|
902
951
|
}
|
|
903
952
|
|
|
953
|
+
private tryDeserialize<T>(deserializeFunc: () => T, msgId: string, source: PeerId): T | undefined {
|
|
954
|
+
try {
|
|
955
|
+
return deserializeFunc();
|
|
956
|
+
} catch (err) {
|
|
957
|
+
this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
|
|
958
|
+
err,
|
|
959
|
+
msgId,
|
|
960
|
+
source: source.toString(),
|
|
961
|
+
});
|
|
962
|
+
return undefined;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
|
|
904
966
|
protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
|
|
905
967
|
const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
|
|
906
|
-
const tx = Tx.fromBuffer(payloadData);
|
|
968
|
+
const tx = this.tryDeserialize(() => Tx.fromBuffer(payloadData), msgId, source);
|
|
969
|
+
if (!tx) {
|
|
970
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.LowToleranceError };
|
|
971
|
+
}
|
|
907
972
|
|
|
908
973
|
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
909
974
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
@@ -923,13 +988,20 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
923
988
|
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
924
989
|
}
|
|
925
990
|
|
|
926
|
-
this.
|
|
927
|
-
|
|
991
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
|
|
992
|
+
validator: name,
|
|
993
|
+
severity,
|
|
994
|
+
source: source.toString(),
|
|
995
|
+
});
|
|
996
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
928
997
|
}
|
|
929
998
|
|
|
930
999
|
// Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
|
|
931
1000
|
const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
|
|
932
1001
|
if (canAdd === 'ignored') {
|
|
1002
|
+
this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
|
|
1003
|
+
source: source.toString(),
|
|
1004
|
+
});
|
|
933
1005
|
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
934
1006
|
}
|
|
935
1007
|
|
|
@@ -937,9 +1009,13 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
937
1009
|
const secondStageValidators = this.createSecondStageMessageValidators();
|
|
938
1010
|
const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
|
|
939
1011
|
if (!secondStageOutcome.allPassed) {
|
|
940
|
-
const { severity } = secondStageOutcome.failure;
|
|
941
|
-
this.
|
|
942
|
-
|
|
1012
|
+
const { severity, name } = secondStageOutcome.failure;
|
|
1013
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
|
|
1014
|
+
validator: name,
|
|
1015
|
+
severity,
|
|
1016
|
+
source: source.toString(),
|
|
1017
|
+
});
|
|
1018
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
943
1019
|
}
|
|
944
1020
|
|
|
945
1021
|
// Pool add: persist the tx
|
|
@@ -949,7 +1025,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
949
1025
|
const wasAccepted = addResult.accepted.some(h => h.equals(txHash));
|
|
950
1026
|
const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
|
|
951
1027
|
|
|
952
|
-
this.logger.
|
|
1028
|
+
this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
|
|
953
1029
|
wasAccepted,
|
|
954
1030
|
wasIgnored,
|
|
955
1031
|
[Attributes.P2P_ID]: source.toString(),
|
|
@@ -960,7 +1036,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
960
1036
|
} else if (wasIgnored) {
|
|
961
1037
|
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
962
1038
|
} else {
|
|
963
|
-
|
|
1039
|
+
this.logger.warn(`Gossiped tx ${txHash.toString()} unexpectedly rejected by pool`, {
|
|
1040
|
+
source: source.toString(),
|
|
1041
|
+
txHash: txHash.toString(),
|
|
1042
|
+
});
|
|
1043
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
964
1044
|
}
|
|
965
1045
|
};
|
|
966
1046
|
|
|
@@ -990,7 +1070,16 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
990
1070
|
source: PeerId,
|
|
991
1071
|
): Promise<void> {
|
|
992
1072
|
const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
|
|
993
|
-
() =>
|
|
1073
|
+
() => {
|
|
1074
|
+
const attestation = this.tryDeserialize(() => CheckpointAttestation.fromBuffer(payloadData), msgId, source);
|
|
1075
|
+
if (!attestation) {
|
|
1076
|
+
return Promise.resolve({
|
|
1077
|
+
result: TopicValidatorResult.Reject,
|
|
1078
|
+
severity: PeerErrorSeverity.LowToleranceError,
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
return this.validateAndStoreCheckpointAttestation(source, attestation);
|
|
1082
|
+
},
|
|
994
1083
|
msgId,
|
|
995
1084
|
source,
|
|
996
1085
|
TopicType.checkpoint_attestation,
|
|
@@ -1023,8 +1112,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1023
1112
|
|
|
1024
1113
|
if (validationResult.result === 'reject') {
|
|
1025
1114
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1026
|
-
|
|
1027
|
-
return { result: TopicValidatorResult.Reject };
|
|
1115
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1028
1116
|
}
|
|
1029
1117
|
|
|
1030
1118
|
if (validationResult.result === 'ignore') {
|
|
@@ -1050,16 +1138,16 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1050
1138
|
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
1051
1139
|
}
|
|
1052
1140
|
|
|
1053
|
-
// Could not add (cap reached for signer),
|
|
1141
|
+
// Could not add (cap reached for signer), penalize and do not re-broadcast
|
|
1054
1142
|
if (!added) {
|
|
1055
|
-
this.logger.warn(`
|
|
1143
|
+
this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
|
|
1056
1144
|
slot: slot.toString(),
|
|
1057
1145
|
archive: attestation.archive.toString(),
|
|
1058
1146
|
source: peerId.toString(),
|
|
1059
1147
|
attester: attestation.getSender()?.toString(),
|
|
1060
1148
|
count,
|
|
1061
1149
|
});
|
|
1062
|
-
return { result: TopicValidatorResult.
|
|
1150
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
1063
1151
|
}
|
|
1064
1152
|
|
|
1065
1153
|
// Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
|
|
@@ -1114,8 +1202,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1114
1202
|
|
|
1115
1203
|
if (validationResult.result === 'reject') {
|
|
1116
1204
|
this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1117
|
-
|
|
1118
|
-
return { result: TopicValidatorResult.Reject };
|
|
1205
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1119
1206
|
}
|
|
1120
1207
|
|
|
1121
1208
|
if (validationResult.result === 'ignore') {
|
|
@@ -1139,7 +1226,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1139
1226
|
|
|
1140
1227
|
// Too many blocks received for this slot and index, penalize peer and do not re-broadcast
|
|
1141
1228
|
if (!added) {
|
|
1142
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1143
1229
|
this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
|
|
1144
1230
|
...block.toBlockInfo(),
|
|
1145
1231
|
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
@@ -1147,7 +1233,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1147
1233
|
proposer: block.getSender()?.toString(),
|
|
1148
1234
|
source: peerId.toString(),
|
|
1149
1235
|
});
|
|
1150
|
-
return {
|
|
1236
|
+
return {
|
|
1237
|
+
result: TopicValidatorResult.Reject,
|
|
1238
|
+
metadata: { isEquivocated },
|
|
1239
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1240
|
+
};
|
|
1151
1241
|
}
|
|
1152
1242
|
|
|
1153
1243
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1192,7 +1282,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1192
1282
|
// Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
|
|
1193
1283
|
const isValid = await this.blockReceivedCallback(block, sender);
|
|
1194
1284
|
if (!isValid) {
|
|
1195
|
-
this.logger.
|
|
1285
|
+
this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
|
|
1196
1286
|
}
|
|
1197
1287
|
}
|
|
1198
1288
|
|
|
@@ -1240,8 +1330,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1240
1330
|
|
|
1241
1331
|
if (validationResult.result === 'reject') {
|
|
1242
1332
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1243
|
-
|
|
1244
|
-
return { result: TopicValidatorResult.Reject };
|
|
1333
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1245
1334
|
}
|
|
1246
1335
|
|
|
1247
1336
|
if (validationResult.result === 'ignore') {
|
|
@@ -1256,20 +1345,21 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1256
1345
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1257
1346
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1258
1347
|
});
|
|
1259
|
-
const
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
metadata: { isEquivocated } = {},
|
|
1263
|
-
} = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1264
|
-
if (result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1348
|
+
const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1349
|
+
const { obj, metadata: { isEquivocated } = {} } = blockProposalResult;
|
|
1350
|
+
if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1265
1351
|
this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
|
|
1266
1352
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1267
1353
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1268
1354
|
isEquivocated,
|
|
1269
|
-
result,
|
|
1355
|
+
result: blockProposalResult.result,
|
|
1270
1356
|
});
|
|
1271
|
-
return {
|
|
1272
|
-
|
|
1357
|
+
return {
|
|
1358
|
+
result: TopicValidatorResult.Reject,
|
|
1359
|
+
severity:
|
|
1360
|
+
'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError,
|
|
1361
|
+
};
|
|
1362
|
+
} else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated) {
|
|
1273
1363
|
processBlock = true;
|
|
1274
1364
|
}
|
|
1275
1365
|
}
|
|
@@ -1296,13 +1386,17 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1296
1386
|
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
|
|
1297
1387
|
// Note: We still return the checkpoint obj so the lastBlock can be processed if valid
|
|
1298
1388
|
if (!added) {
|
|
1299
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1300
1389
|
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1301
1390
|
...checkpoint.toCheckpointInfo(),
|
|
1302
1391
|
count,
|
|
1303
1392
|
source: peerId.toString(),
|
|
1304
1393
|
});
|
|
1305
|
-
return {
|
|
1394
|
+
return {
|
|
1395
|
+
result: TopicValidatorResult.Reject,
|
|
1396
|
+
obj: checkpoint,
|
|
1397
|
+
metadata: { isEquivocated, processBlock },
|
|
1398
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1399
|
+
};
|
|
1306
1400
|
}
|
|
1307
1401
|
|
|
1308
1402
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1626,6 +1720,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1626
1720
|
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1627
1721
|
];
|
|
1628
1722
|
const blockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1723
|
+
const l1Constants = await this.archiver.getL1Constants();
|
|
1629
1724
|
|
|
1630
1725
|
return createFirstStageTxValidationsForGossipedTransactions(
|
|
1631
1726
|
nextSlotTimestamp,
|
|
@@ -1639,6 +1734,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1639
1734
|
!this.config.disableTransactions,
|
|
1640
1735
|
allowedInSetup,
|
|
1641
1736
|
this.logger.getBindings(),
|
|
1737
|
+
{
|
|
1738
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1739
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1740
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1741
|
+
},
|
|
1642
1742
|
);
|
|
1643
1743
|
}
|
|
1644
1744
|
|
|
@@ -1664,8 +1764,10 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1664
1764
|
|
|
1665
1765
|
// A promise that resolves when all validations have been run
|
|
1666
1766
|
const allValidations = await Promise.all(validationPromises);
|
|
1667
|
-
const
|
|
1668
|
-
if (
|
|
1767
|
+
const failures = allValidations.filter(x => !x.isValid);
|
|
1768
|
+
if (failures.length > 0) {
|
|
1769
|
+
// Pick the most severe failure (lowest tolerance = harshest penalty)
|
|
1770
|
+
const failed = maxBy(failures, f => PeerErrorSeverityByHarshness.indexOf(f.severity))!;
|
|
1669
1771
|
return {
|
|
1670
1772
|
allPassed: false,
|
|
1671
1773
|
failure: {
|
|
@@ -1718,31 +1820,6 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
1718
1820
|
return PeerErrorSeverity.HighToleranceError;
|
|
1719
1821
|
}
|
|
1720
1822
|
|
|
1721
|
-
/**
|
|
1722
|
-
* Validate a checkpoint attestation.
|
|
1723
|
-
*
|
|
1724
|
-
* @param attestation - The checkpoint attestation to validate.
|
|
1725
|
-
* @returns True if the checkpoint attestation is valid, false otherwise.
|
|
1726
|
-
*/
|
|
1727
|
-
@trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
|
|
1728
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
1729
|
-
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
1730
|
-
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
1731
|
-
}))
|
|
1732
|
-
public async validateCheckpointAttestation(
|
|
1733
|
-
peerId: PeerId,
|
|
1734
|
-
attestation: CheckpointAttestation,
|
|
1735
|
-
): Promise<P2PValidationResult> {
|
|
1736
|
-
const result = await this.checkpointAttestationValidator.validate(attestation);
|
|
1737
|
-
|
|
1738
|
-
if (result.result === 'reject') {
|
|
1739
|
-
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1740
|
-
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
return result;
|
|
1744
|
-
}
|
|
1745
|
-
|
|
1746
1823
|
public getPeerScore(peerId: PeerId): number {
|
|
1747
1824
|
return this.node.services.pubsub.score.score(peerId.toString());
|
|
1748
1825
|
}
|
|
@@ -32,7 +32,7 @@ import { PeerScoreState, type PeerScoring } from './peer_scoring.js';
|
|
|
32
32
|
const MAX_DIAL_ATTEMPTS = 3;
|
|
33
33
|
const MAX_CACHED_PEERS = 100;
|
|
34
34
|
const MAX_CACHED_PEER_AGE_MS = 5 * 60 * 1000; // 5 minutes
|
|
35
|
-
const
|
|
35
|
+
const DEFAULT_FAILED_PEER_BAN_TIME_MS = 5 * 60 * 1000; // 5 minutes timeout after failing MAX_DIAL_ATTEMPTS
|
|
36
36
|
const GOODBYE_DIAL_TIMEOUT_MS = 1000;
|
|
37
37
|
const FAILED_AUTH_HANDSHAKE_EXPIRY_MS = 60 * 60 * 1000; // 1 hour
|
|
38
38
|
|
|
@@ -776,7 +776,8 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
776
776
|
// Add to timed out peers
|
|
777
777
|
this.timedOutPeers.set(id, {
|
|
778
778
|
peerId: id,
|
|
779
|
-
timeoutUntilMs:
|
|
779
|
+
timeoutUntilMs:
|
|
780
|
+
this.dateProvider.now() + (this.config.peerFailedBanTimeMs ?? DEFAULT_FAILED_PEER_BAN_TIME_MS),
|
|
780
781
|
});
|
|
781
782
|
}
|
|
782
783
|
}
|
|
@@ -938,6 +939,8 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
938
939
|
`Received auth for validator ${sender.toString()} from peer ${peerIdString}, but this validator is already authenticated to peer ${peerForAddress.toString()}`,
|
|
939
940
|
{ ...logData, address: sender.toString() },
|
|
940
941
|
);
|
|
942
|
+
this.markAuthHandshakeFailed(peerId);
|
|
943
|
+
this.markPeerForDisconnect(peerId);
|
|
941
944
|
return;
|
|
942
945
|
}
|
|
943
946
|
|