@aztec/p2p 0.0.1-commit.f1df4d2 → 0.0.1-commit.f2ce05ee
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 +3 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +2 -2
- package/dest/client/interface.d.ts +9 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +4 -3
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +11 -5
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +1 -1
- package/dest/config.d.ts +5 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +94 -87
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +411 -3
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +351 -85
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -2
- package/dest/mem_pools/index.d.ts +2 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- package/dest/mem_pools/interface.d.ts +3 -3
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts +5 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/index.js +4 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +71 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +95 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +748 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/services/dummy_service.d.ts +6 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +3 -0
- package/dest/services/gossipsub/index.d.ts +3 -0
- package/dest/services/gossipsub/index.d.ts.map +1 -0
- package/dest/services/gossipsub/index.js +2 -0
- package/dest/services/gossipsub/scoring.d.ts +21 -3
- package/dest/services/gossipsub/scoring.d.ts.map +1 -1
- package/dest/services/gossipsub/scoring.js +24 -7
- package/dest/services/gossipsub/topic_score_params.d.ts +161 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +324 -0
- package/dest/services/libp2p/libp2p_service.d.ts +74 -33
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +317 -258
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +25 -2
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -4
- 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 +8 -8
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +6 -4
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +16 -11
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +15 -10
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +12 -11
- package/dest/services/service.d.ts +18 -1
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +3 -3
- package/dest/services/tx_collection/config.js +3 -3
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -5
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +10 -14
- package/dest/services/tx_collection/index.d.ts +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +12 -12
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +4 -5
- 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 +2 -1
- package/dest/test-helpers/testbench-utils.d.ts +10 -16
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +42 -31
- package/dest/testbench/p2p_client_testbench_worker.js +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +3 -4
- package/src/client/interface.ts +13 -1
- package/src/client/p2p_client.ts +20 -8
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +1 -1
- package/src/config.ts +10 -2
- package/src/mem_pools/attestation_pool/attestation_pool.ts +444 -90
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +436 -100
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/index.ts +1 -1
- package/src/mem_pools/interface.ts +2 -2
- package/src/mem_pools/tx_pool_v2/README.md +209 -0
- package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
- package/src/mem_pools/tx_pool_v2/index.ts +11 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +161 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +882 -0
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
- package/src/services/dummy_service.ts +6 -0
- package/src/services/gossipsub/README.md +626 -0
- package/src/services/gossipsub/index.ts +2 -0
- package/src/services/gossipsub/scoring.ts +29 -5
- package/src/services/gossipsub/topic_score_params.ts +451 -0
- package/src/services/libp2p/libp2p_service.ts +323 -261
- package/src/services/peer-manager/peer_scoring.ts +25 -0
- package/src/services/reqresp/batch-tx-requester/README.md +7 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +11 -11
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +22 -13
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +21 -15
- package/src/services/service.ts +20 -0
- package/src/services/tx_collection/config.ts +6 -6
- package/src/services/tx_collection/fast_tx_collection.ts +14 -24
- package/src/services/tx_collection/index.ts +1 -1
- package/src/services/tx_collection/proposal_tx_collector.ts +12 -14
- package/src/test-helpers/reqresp-nodes.ts +2 -1
- package/src/test-helpers/testbench-utils.ts +27 -39
- package/src/testbench/p2p_client_testbench_worker.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
|
@@ -370,7 +370,7 @@ function applyDecs2203RFactory() {
|
|
|
370
370
|
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
371
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
372
|
}
|
|
373
|
-
var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _initProto;
|
|
373
|
+
var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _initProto;
|
|
374
374
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
375
375
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
376
376
|
import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
@@ -384,7 +384,7 @@ import { Tx } from '@aztec/stdlib/tx';
|
|
|
384
384
|
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
385
385
|
import { Attributes, OtelMetricsAdapter, SpanStatusCode, WithTracer, trackSpan } from '@aztec/telemetry-client';
|
|
386
386
|
import { gossipsub } from '@chainsafe/libp2p-gossipsub';
|
|
387
|
-
import { createPeerScoreParams
|
|
387
|
+
import { createPeerScoreParams } from '@chainsafe/libp2p-gossipsub/score';
|
|
388
388
|
import { SignaturePolicy } from '@chainsafe/libp2p-gossipsub/types';
|
|
389
389
|
import { noise } from '@chainsafe/libp2p-noise';
|
|
390
390
|
import { yamux } from '@chainsafe/libp2p-yamux';
|
|
@@ -395,51 +395,50 @@ import { mplex } from '@libp2p/mplex';
|
|
|
395
395
|
import { tcp } from '@libp2p/tcp';
|
|
396
396
|
import { ENR } from '@nethermindeth/enr';
|
|
397
397
|
import { createLibp2p } from 'libp2p';
|
|
398
|
-
import {
|
|
399
|
-
import { BlockProposalValidator, CheckpointAttestationValidator, CheckpointProposalValidator, FishermanAttestationValidator } from '../../msg_validators/index.js';
|
|
398
|
+
import { BlockProposalValidator, CheckpointAttestationValidator, CheckpointProposalValidator, DoubleSpendTxValidator, FishermanAttestationValidator, getDefaultAllowedSetupFunctions } from '../../msg_validators/index.js';
|
|
400
399
|
import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
|
|
401
|
-
import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validator/allowed_public_setup.js';
|
|
402
400
|
import { createTxMessageValidators, createTxReqRespValidator } from '../../msg_validators/tx_validator/factory.js';
|
|
403
|
-
import { DoubleSpendTxValidator } from '../../msg_validators/tx_validator/index.js';
|
|
404
401
|
import { GossipSubEvent } from '../../types/index.js';
|
|
405
402
|
import { convertToMultiaddr } from '../../util.js';
|
|
406
403
|
import { getVersions } from '../../versioning.js';
|
|
407
404
|
import { AztecDatastore } from '../data_store.js';
|
|
408
405
|
import { DiscV5Service } from '../discv5/discV5_service.js';
|
|
409
406
|
import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
|
|
410
|
-
import { gossipScoreThresholds } from '../gossipsub/scoring.js';
|
|
407
|
+
import { APP_SPECIFIC_WEIGHT, gossipScoreThresholds } from '../gossipsub/scoring.js';
|
|
408
|
+
import { createAllTopicScoreParams } from '../gossipsub/topic_score_params.js';
|
|
411
409
|
import { PeerManager } from '../peer-manager/peer_manager.js';
|
|
412
410
|
import { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
413
|
-
import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol, ValidationError } from '../reqresp/
|
|
414
|
-
import { reqRespBlockTxsHandler } from '../reqresp/
|
|
415
|
-
import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js';
|
|
416
|
-
import { pingHandler, reqRespBlockHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/protocols/index.js';
|
|
411
|
+
import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol, ValidationError } from '../reqresp/index.js';
|
|
412
|
+
import { pingHandler, reqGoodbyeHandler, reqRespBlockHandler, reqRespBlockTxsHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/index.js';
|
|
417
413
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
418
414
|
import { P2PInstrumentation } from './instrumentation.js';
|
|
419
|
-
_dec = trackSpan('Libp2pService.
|
|
415
|
+
_dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId, attestation)=>({
|
|
416
|
+
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString()
|
|
417
|
+
})), _dec1 = trackSpan('Libp2pService.validateAndStoreBlockProposal', (_peerId, block)=>({
|
|
418
|
+
[Attributes.BLOCK_NUMBER]: block.blockNumber.toString(),
|
|
419
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber.toString()
|
|
420
|
+
})), _dec2 = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
420
421
|
[Attributes.SLOT_NUMBER]: block.slotNumber,
|
|
421
422
|
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
422
423
|
[Attributes.P2P_ID]: await block.p2pMessageLoggingIdentifier().then((i)=>i.toString())
|
|
423
|
-
})),
|
|
424
|
+
})), _dec3 = trackSpan('Libp2pService.validateAndStoreCheckpointProposal', (_peerId, checkpoint)=>({
|
|
425
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString()
|
|
426
|
+
})), _dec4 = trackSpan('Libp2pService.processValidCheckpointProposal', async (checkpoint)=>({
|
|
424
427
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
|
|
425
428
|
[Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
|
|
426
429
|
[Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then((i)=>i.toString())
|
|
427
|
-
})),
|
|
430
|
+
})), _dec5 = trackSpan('Libp2pService.validateRequestedBlockTxs', (request)=>({
|
|
428
431
|
[Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString()
|
|
429
|
-
})),
|
|
432
|
+
})), _dec6 = trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx)=>({
|
|
430
433
|
[Attributes.TX_HASH]: requestedTxHash.toString()
|
|
431
|
-
})),
|
|
434
|
+
})), _dec7 = trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock)=>({
|
|
432
435
|
[Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString()
|
|
433
|
-
})),
|
|
436
|
+
})), _dec8 = trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
|
|
434
437
|
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
435
|
-
})),
|
|
438
|
+
})), _dec9 = trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation)=>({
|
|
436
439
|
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
437
440
|
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
438
441
|
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
|
|
439
|
-
})), _dec7 = trackSpan('Libp2pService.validateBlockProposal', (_peerId, block)=>({
|
|
440
|
-
[Attributes.SLOT_NUMBER]: block.slotNumber.toString()
|
|
441
|
-
})), _dec8 = trackSpan('Libp2pService.validateCheckpointProposal', (_peerId, checkpoint)=>({
|
|
442
|
-
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString()
|
|
443
442
|
}));
|
|
444
443
|
/**
|
|
445
444
|
* Lib P2P implementation of the P2PService interface.
|
|
@@ -460,47 +459,52 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
460
459
|
[
|
|
461
460
|
_dec,
|
|
462
461
|
2,
|
|
463
|
-
"
|
|
462
|
+
"validateAndStoreCheckpointAttestation"
|
|
464
463
|
],
|
|
465
464
|
[
|
|
466
465
|
_dec1,
|
|
467
466
|
2,
|
|
468
|
-
"
|
|
467
|
+
"validateAndStoreBlockProposal"
|
|
469
468
|
],
|
|
470
469
|
[
|
|
471
470
|
_dec2,
|
|
472
471
|
2,
|
|
473
|
-
"
|
|
472
|
+
"processValidBlockProposal"
|
|
474
473
|
],
|
|
475
474
|
[
|
|
476
475
|
_dec3,
|
|
477
476
|
2,
|
|
478
|
-
"
|
|
477
|
+
"validateAndStoreCheckpointProposal"
|
|
479
478
|
],
|
|
480
479
|
[
|
|
481
480
|
_dec4,
|
|
482
481
|
2,
|
|
483
|
-
"
|
|
482
|
+
"processValidCheckpointProposal"
|
|
484
483
|
],
|
|
485
484
|
[
|
|
486
485
|
_dec5,
|
|
487
486
|
2,
|
|
488
|
-
"
|
|
487
|
+
"validateRequestedBlockTxs"
|
|
489
488
|
],
|
|
490
489
|
[
|
|
491
490
|
_dec6,
|
|
492
491
|
2,
|
|
493
|
-
"
|
|
492
|
+
"validateRequestedTxs"
|
|
494
493
|
],
|
|
495
494
|
[
|
|
496
495
|
_dec7,
|
|
497
496
|
2,
|
|
498
|
-
"
|
|
497
|
+
"validateRequestedBlock"
|
|
499
498
|
],
|
|
500
499
|
[
|
|
501
500
|
_dec8,
|
|
502
501
|
2,
|
|
503
|
-
"
|
|
502
|
+
"validatePropagatedTx"
|
|
503
|
+
],
|
|
504
|
+
[
|
|
505
|
+
_dec9,
|
|
506
|
+
2,
|
|
507
|
+
"validateCheckpointAttestation"
|
|
504
508
|
]
|
|
505
509
|
], []));
|
|
506
510
|
}
|
|
@@ -513,6 +517,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
513
517
|
protocolVersion;
|
|
514
518
|
topicStrings;
|
|
515
519
|
feesCache;
|
|
520
|
+
/** Callback invoked when a duplicate proposal is detected (triggers slashing). */ duplicateProposalCallback;
|
|
516
521
|
/**
|
|
517
522
|
* Callback for when a block is received from a peer.
|
|
518
523
|
* @param block - The block received from the peer.
|
|
@@ -591,10 +596,6 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
591
596
|
}
|
|
592
597
|
const versions = getVersions(config);
|
|
593
598
|
const protocolVersion = compressComponentVersions(versions);
|
|
594
|
-
const txTopic = createTopicString(TopicType.tx, protocolVersion);
|
|
595
|
-
const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
|
|
596
|
-
const checkpointProposalTopic = createTopicString(TopicType.checkpoint_proposal, protocolVersion);
|
|
597
|
-
const checkpointAttestationTopic = createTopicString(TopicType.checkpoint_attestation, protocolVersion);
|
|
598
599
|
const preferredPeersEnrs = config.preferredPeers.map((enr)=>ENR.decodeTxt(enr));
|
|
599
600
|
const directPeers = (await Promise.all(preferredPeersEnrs.map(async (enr)=>{
|
|
600
601
|
const peerId = await enr.peerId();
|
|
@@ -612,6 +613,14 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
612
613
|
const announceTcpMultiaddr = config.p2pIp ? [
|
|
613
614
|
convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')
|
|
614
615
|
] : [];
|
|
616
|
+
// Create dynamic topic score params based on network configuration
|
|
617
|
+
const l1Constants = epochCache.getL1Constants();
|
|
618
|
+
const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
|
|
619
|
+
slotDurationMs: l1Constants.slotDuration * 1000,
|
|
620
|
+
heartbeatIntervalMs: config.gossipsubInterval,
|
|
621
|
+
targetCommitteeSize: l1Constants.targetCommitteeSize,
|
|
622
|
+
blockDurationMs: config.blockDurationMs
|
|
623
|
+
});
|
|
615
624
|
const node = await createLibp2p({
|
|
616
625
|
start: false,
|
|
617
626
|
peerId,
|
|
@@ -712,28 +721,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
712
721
|
scoreParams: createPeerScoreParams({
|
|
713
722
|
// IPColocation factor can be disabled for local testing - default to -5
|
|
714
723
|
IPColocationFactorWeight: config.debugDisableColocationPenalty ? 0 : -5.0,
|
|
715
|
-
topics:
|
|
716
|
-
[txTopic]: createTopicScoreParams({
|
|
717
|
-
topicWeight: 1,
|
|
718
|
-
invalidMessageDeliveriesWeight: -20,
|
|
719
|
-
invalidMessageDeliveriesDecay: 0.5
|
|
720
|
-
}),
|
|
721
|
-
[blockProposalTopic]: createTopicScoreParams({
|
|
722
|
-
topicWeight: 1,
|
|
723
|
-
invalidMessageDeliveriesWeight: -20,
|
|
724
|
-
invalidMessageDeliveriesDecay: 0.5
|
|
725
|
-
}),
|
|
726
|
-
[checkpointProposalTopic]: createTopicScoreParams({
|
|
727
|
-
topicWeight: 1,
|
|
728
|
-
invalidMessageDeliveriesWeight: -20,
|
|
729
|
-
invalidMessageDeliveriesDecay: 0.5
|
|
730
|
-
}),
|
|
731
|
-
[checkpointAttestationTopic]: createTopicScoreParams({
|
|
732
|
-
topicWeight: 1,
|
|
733
|
-
invalidMessageDeliveriesWeight: -20,
|
|
734
|
-
invalidMessageDeliveriesDecay: 0.5
|
|
735
|
-
})
|
|
736
|
-
}
|
|
724
|
+
topics: topicScoreParams
|
|
737
725
|
})
|
|
738
726
|
}),
|
|
739
727
|
components: (components)=>({
|
|
@@ -745,8 +733,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
745
733
|
const peerScoring = new PeerScoring(config, telemetry);
|
|
746
734
|
const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
|
|
747
735
|
const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion, epochCache);
|
|
748
|
-
//
|
|
749
|
-
|
|
736
|
+
// Configure application-specific scoring for gossipsub.
|
|
737
|
+
// The weight scales app score to align with gossipsub thresholds:
|
|
738
|
+
// - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
|
|
739
|
+
// - Ban (-100) × 10 = -1000 = publishThreshold (cannot publish)
|
|
740
|
+
// Note: positive topic scores can offset penalties, so alignment is best-effort.
|
|
741
|
+
node.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
|
|
750
742
|
node.services.pubsub.score.params.appSpecificScore = (peerId)=>peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
751
743
|
return new LibP2PService(clientType, config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger);
|
|
752
744
|
}
|
|
@@ -776,7 +768,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
776
768
|
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this)
|
|
777
769
|
};
|
|
778
770
|
if (!this.config.disableTransactions) {
|
|
779
|
-
const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
|
|
771
|
+
const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.archiver, this.mempools.txPool);
|
|
780
772
|
requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
|
|
781
773
|
}
|
|
782
774
|
if (!this.config.disableTransactions) {
|
|
@@ -876,6 +868,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
876
868
|
this.checkpointReceivedCallback = callback;
|
|
877
869
|
}
|
|
878
870
|
/**
|
|
871
|
+
* Registers a callback to be invoked when a duplicate proposal is detected.
|
|
872
|
+
* This callback is triggered on the first duplicate (when count goes from 1 to 2).
|
|
873
|
+
*/ registerDuplicateProposalCallback(callback) {
|
|
874
|
+
this.duplicateProposalCallback = callback;
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
879
877
|
* Subscribes to a topic.
|
|
880
878
|
* @param topic - The topic to subscribe to.
|
|
881
879
|
*/ subscribeToTopic(topic) {
|
|
@@ -1102,114 +1100,159 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
1102
1100
|
* Process a checkpoint attestation from a peer.
|
|
1103
1101
|
* Validates the attestation and adds it to the pool.
|
|
1104
1102
|
*/ async processCheckpointAttestationFromPeer(payloadData, msgId, source) {
|
|
1105
|
-
const
|
|
1106
|
-
const attestation = CheckpointAttestation.fromBuffer(payloadData);
|
|
1107
|
-
const pool = this.mempools.attestationPool;
|
|
1108
|
-
const validationResult = await this.validateCheckpointAttestation(source, attestation);
|
|
1109
|
-
const isValid = validationResult.result === 'accept';
|
|
1110
|
-
const exists = isValid && await pool.hasCheckpointAttestation(attestation);
|
|
1111
|
-
let canAdd = true;
|
|
1112
|
-
if (isValid && !exists) {
|
|
1113
|
-
const slot = attestation.payload.header.slotNumber;
|
|
1114
|
-
const { committee } = await this.epochCache.getCommittee(slot);
|
|
1115
|
-
const committeeSize = committee?.length ?? 0;
|
|
1116
|
-
canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
|
|
1117
|
-
}
|
|
1118
|
-
this.logger.trace(`Validate propagated checkpoint attestation`, {
|
|
1119
|
-
isValid,
|
|
1120
|
-
exists,
|
|
1121
|
-
canAdd,
|
|
1122
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
|
|
1123
|
-
[Attributes.P2P_ID]: source.toString()
|
|
1124
|
-
});
|
|
1125
|
-
if (validationResult.result === 'reject') {
|
|
1126
|
-
return {
|
|
1127
|
-
result: TopicValidatorResult.Reject
|
|
1128
|
-
};
|
|
1129
|
-
} else if (validationResult.result === 'ignore' || exists) {
|
|
1130
|
-
return {
|
|
1131
|
-
result: TopicValidatorResult.Ignore,
|
|
1132
|
-
obj: attestation
|
|
1133
|
-
};
|
|
1134
|
-
} else if (!canAdd) {
|
|
1135
|
-
this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
|
|
1136
|
-
slot: attestation.payload.header.slotNumber.toString(),
|
|
1137
|
-
archive: attestation.archive.toString(),
|
|
1138
|
-
source: source.toString()
|
|
1139
|
-
});
|
|
1140
|
-
return {
|
|
1141
|
-
result: TopicValidatorResult.Ignore,
|
|
1142
|
-
obj: attestation
|
|
1143
|
-
};
|
|
1144
|
-
} else {
|
|
1145
|
-
return {
|
|
1146
|
-
result: TopicValidatorResult.Accept,
|
|
1147
|
-
obj: attestation
|
|
1148
|
-
};
|
|
1149
|
-
}
|
|
1150
|
-
};
|
|
1151
|
-
const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.checkpoint_attestation);
|
|
1103
|
+
const { result, obj: attestation } = await this.validateReceivedMessage(()=>this.validateAndStoreCheckpointAttestation(source, CheckpointAttestation.fromBuffer(payloadData)), msgId, source, TopicType.checkpoint_attestation);
|
|
1152
1104
|
if (result !== TopicValidatorResult.Accept || !attestation) {
|
|
1153
1105
|
return;
|
|
1154
1106
|
}
|
|
1155
|
-
this.logger.
|
|
1107
|
+
this.logger.verbose(`Received valid checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`, {
|
|
1156
1108
|
p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
|
|
1157
1109
|
slot: attestation.slotNumber,
|
|
1158
1110
|
archive: attestation.archive.toString(),
|
|
1159
1111
|
source: source.toString()
|
|
1160
1112
|
});
|
|
1161
|
-
await this.mempools.attestationPool.addCheckpointAttestations([
|
|
1162
|
-
attestation
|
|
1163
|
-
]);
|
|
1164
1113
|
}
|
|
1165
|
-
async
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1114
|
+
/** Validates a checkpoint attestation and adds it to the pool. Penalizes the peer if validation fails. */ async validateAndStoreCheckpointAttestation(peerId, attestation) {
|
|
1115
|
+
const validationResult = await this.checkpointAttestationValidator.validate(attestation);
|
|
1116
|
+
if (validationResult.result === 'reject') {
|
|
1117
|
+
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1118
|
+
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1119
|
+
return {
|
|
1120
|
+
result: TopicValidatorResult.Reject
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
if (validationResult.result === 'ignore') {
|
|
1124
|
+
return {
|
|
1125
|
+
result: TopicValidatorResult.Ignore,
|
|
1126
|
+
obj: attestation
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
// Get committee size for the attestation's slot
|
|
1130
|
+
const slot = attestation.payload.header.slotNumber;
|
|
1131
|
+
const { committee } = await this.epochCache.getCommittee(slot);
|
|
1132
|
+
const committeeSize = committee?.length ?? 0;
|
|
1133
|
+
// Try to add the attestation: this handles existence check, cap check, and adding in one call
|
|
1134
|
+
const { added, alreadyExists } = await this.mempools.attestationPool.tryAddCheckpointAttestation(attestation, committeeSize);
|
|
1135
|
+
this.logger.trace(`Validate propagated checkpoint attestation`, {
|
|
1136
|
+
added,
|
|
1137
|
+
alreadyExists,
|
|
1138
|
+
[Attributes.SLOT_NUMBER]: slot.toString(),
|
|
1139
|
+
[Attributes.P2P_ID]: peerId.toString()
|
|
1140
|
+
});
|
|
1141
|
+
// Duplicate attestation received, no need to re-broadcast
|
|
1142
|
+
if (alreadyExists) {
|
|
1143
|
+
return {
|
|
1144
|
+
result: TopicValidatorResult.Ignore,
|
|
1145
|
+
obj: attestation
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
// Could not add (cap reached), no need to re-broadcast
|
|
1149
|
+
if (!added) {
|
|
1150
|
+
this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
|
|
1151
|
+
slot: slot.toString(),
|
|
1152
|
+
archive: attestation.archive.toString(),
|
|
1153
|
+
source: peerId.toString()
|
|
1179
1154
|
});
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
} else if (!canAdd) {
|
|
1190
|
-
this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
|
|
1191
|
-
this.logger.warn(`Penalizing peer for block proposal exceeding per-slot cap`, {
|
|
1192
|
-
slot: block.slotNumber.toString(),
|
|
1193
|
-
archive: block.archive.toString(),
|
|
1194
|
-
source: source.toString()
|
|
1195
|
-
});
|
|
1196
|
-
return {
|
|
1197
|
-
result: TopicValidatorResult.Reject
|
|
1198
|
-
};
|
|
1199
|
-
} else {
|
|
1200
|
-
return {
|
|
1201
|
-
result: TopicValidatorResult.Accept,
|
|
1202
|
-
obj: block
|
|
1203
|
-
};
|
|
1204
|
-
}
|
|
1155
|
+
return {
|
|
1156
|
+
result: TopicValidatorResult.Ignore,
|
|
1157
|
+
obj: attestation
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
// Attestation was added successfully
|
|
1161
|
+
return {
|
|
1162
|
+
result: TopicValidatorResult.Accept,
|
|
1163
|
+
obj: attestation
|
|
1205
1164
|
};
|
|
1206
|
-
|
|
1207
|
-
|
|
1165
|
+
}
|
|
1166
|
+
async processBlockFromPeer(payloadData, msgId, source) {
|
|
1167
|
+
const { result, obj: block, metadata: { isEquivocated } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreBlockProposal(source, BlockProposal.fromBuffer(payloadData)), msgId, source, TopicType.block_proposal);
|
|
1168
|
+
// If not accepted or equivocated, return
|
|
1169
|
+
if (result !== TopicValidatorResult.Accept || !block || isEquivocated) {
|
|
1208
1170
|
return;
|
|
1209
1171
|
}
|
|
1210
1172
|
await this.processValidBlockProposal(block, source);
|
|
1211
1173
|
}
|
|
1212
|
-
|
|
1174
|
+
/** Validates a block proposal. Triggers a penalization to the peer that sent it if invalid. Adds to the mempool if valid. */ async validateAndStoreBlockProposal(peerId, block) {
|
|
1175
|
+
const validationResult = await this.blockProposalValidator.validate(block);
|
|
1176
|
+
if (validationResult.result === 'reject') {
|
|
1177
|
+
this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1178
|
+
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1179
|
+
return {
|
|
1180
|
+
result: TopicValidatorResult.Reject
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
if (validationResult.result === 'ignore') {
|
|
1184
|
+
return {
|
|
1185
|
+
result: TopicValidatorResult.Ignore,
|
|
1186
|
+
obj: block
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
// Try to add the proposal: this handles existence check, cap check, and adding in one call
|
|
1190
|
+
const { added, alreadyExists, totalForPosition } = await this.mempools.attestationPool.tryAddBlockProposal(block);
|
|
1191
|
+
const isEquivocated = totalForPosition !== undefined && totalForPosition > 1;
|
|
1192
|
+
// Duplicate proposal received, no need to re-broadcast
|
|
1193
|
+
if (alreadyExists) {
|
|
1194
|
+
this.logger.debug(`Ignoring duplicate block proposal received`, {
|
|
1195
|
+
...block.toBlockInfo(),
|
|
1196
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1197
|
+
proposer: block.getSender()?.toString(),
|
|
1198
|
+
source: peerId.toString()
|
|
1199
|
+
});
|
|
1200
|
+
return {
|
|
1201
|
+
result: TopicValidatorResult.Ignore,
|
|
1202
|
+
obj: block,
|
|
1203
|
+
metadata: {
|
|
1204
|
+
isEquivocated
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
// Too many blocks received for this slot and index, penalize peer and do not re-broadcast
|
|
1209
|
+
if (!added) {
|
|
1210
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1211
|
+
this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
|
|
1212
|
+
...block.toBlockInfo(),
|
|
1213
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1214
|
+
totalForPosition,
|
|
1215
|
+
proposer: block.getSender()?.toString(),
|
|
1216
|
+
source: peerId.toString()
|
|
1217
|
+
});
|
|
1218
|
+
return {
|
|
1219
|
+
result: TopicValidatorResult.Reject,
|
|
1220
|
+
metadata: {
|
|
1221
|
+
isEquivocated
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
1226
|
+
// and do re-broadcast it so other nodes in the network know to slash the proposer
|
|
1227
|
+
if (isEquivocated) {
|
|
1228
|
+
const proposer = block.getSender();
|
|
1229
|
+
this.logger.warn(`Detected duplicate block proposal (equivocation) at slot ${block.slotNumber}`, {
|
|
1230
|
+
...block.toBlockInfo(),
|
|
1231
|
+
source: peerId.toString(),
|
|
1232
|
+
proposer: proposer?.toString()
|
|
1233
|
+
});
|
|
1234
|
+
// Invoke the duplicate callback on the first duplicate spotted only
|
|
1235
|
+
if (proposer && totalForPosition === 2) {
|
|
1236
|
+
this.duplicateProposalCallback?.({
|
|
1237
|
+
slot: block.slotNumber,
|
|
1238
|
+
proposer,
|
|
1239
|
+
type: 'block'
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
return {
|
|
1243
|
+
result: TopicValidatorResult.Accept,
|
|
1244
|
+
obj: block,
|
|
1245
|
+
metadata: {
|
|
1246
|
+
isEquivocated
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
// Otherwise, we're good to go!
|
|
1251
|
+
return {
|
|
1252
|
+
result: TopicValidatorResult.Accept,
|
|
1253
|
+
obj: block
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1213
1256
|
// REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
|
|
1214
1257
|
// should not be here as it does not deal with p2p networking.
|
|
1215
1258
|
async processValidBlockProposal(block, sender) {
|
|
@@ -1219,21 +1262,6 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
1219
1262
|
source: sender.toString(),
|
|
1220
1263
|
...block.toBlockInfo()
|
|
1221
1264
|
});
|
|
1222
|
-
// Attempt to add proposal
|
|
1223
|
-
try {
|
|
1224
|
-
await this.mempools.attestationPool.addBlockProposal(block);
|
|
1225
|
-
} catch (err) {
|
|
1226
|
-
// Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
|
|
1227
|
-
if (err instanceof ProposalSlotCapExceededError) {
|
|
1228
|
-
this.logger.warn(`Dropping block proposal due to per-slot proposal cap`, {
|
|
1229
|
-
slot: String(slot),
|
|
1230
|
-
archive: block.archive.toString(),
|
|
1231
|
-
error: err.message
|
|
1232
|
-
});
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1235
|
-
throw err;
|
|
1236
|
-
}
|
|
1237
1265
|
// Mark the txs in this proposal as non-evictable
|
|
1238
1266
|
await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
|
|
1239
1267
|
// Call the block received callback to validate the proposal.
|
|
@@ -1247,57 +1275,135 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
1247
1275
|
* Handle a gossiped checkpoint proposal.
|
|
1248
1276
|
* Validates and processes the checkpoint proposal, then triggers the callback for attestation.
|
|
1249
1277
|
*/ async handleGossipedCheckpointProposal(payloadData, msgId, source) {
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1278
|
+
const { result, obj: checkpoint, metadata: { isEquivocated, processBlock } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreCheckpointProposal(source, CheckpointProposal.fromBuffer(payloadData)), msgId, source, TopicType.checkpoint_proposal);
|
|
1279
|
+
// If the checkpoint contained a valid last block, we process it even if the checkpoint itself is to be rejected
|
|
1280
|
+
// TODO(palla/mbps): Is this ok? Should we be considering a block from a checkpoint that was equivocated?
|
|
1281
|
+
if (processBlock && checkpoint?.getBlockProposal()) {
|
|
1282
|
+
await this.processValidBlockProposal(checkpoint.getBlockProposal(), source);
|
|
1283
|
+
}
|
|
1284
|
+
if (result !== TopicValidatorResult.Accept || !checkpoint || isEquivocated) {
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
await this.processValidCheckpointProposal(checkpoint.toCore(), source);
|
|
1288
|
+
}
|
|
1289
|
+
/**
|
|
1290
|
+
* Validates a checkpoint proposal. Penalizes peer if validation fails. Adds the checkpoint and
|
|
1291
|
+
* its last block (if present) to the mempool if valid. Triggers equivocation detection on both.
|
|
1292
|
+
*/ async validateAndStoreCheckpointProposal(peerId, checkpoint) {
|
|
1293
|
+
const validationResult = await this.checkpointProposalValidator.validate(checkpoint);
|
|
1294
|
+
if (validationResult.result === 'reject') {
|
|
1295
|
+
this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1296
|
+
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1297
|
+
return {
|
|
1298
|
+
result: TopicValidatorResult.Reject
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
if (validationResult.result === 'ignore') {
|
|
1302
|
+
return {
|
|
1303
|
+
result: TopicValidatorResult.Ignore,
|
|
1304
|
+
obj: checkpoint
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
// Extract and try to add the block proposal first if present
|
|
1308
|
+
const blockProposal = checkpoint.getBlockProposal();
|
|
1309
|
+
let processBlock = false;
|
|
1310
|
+
if (blockProposal) {
|
|
1311
|
+
this.logger.debug(`Validating block proposal from propagated checkpoint`, {
|
|
1262
1312
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1263
|
-
[Attributes.P2P_ID]:
|
|
1313
|
+
[Attributes.P2P_ID]: peerId.toString()
|
|
1264
1314
|
});
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
result
|
|
1272
|
-
obj: checkpoint
|
|
1273
|
-
};
|
|
1274
|
-
} else if (!canAdd) {
|
|
1275
|
-
this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
|
|
1276
|
-
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1277
|
-
slot: checkpoint.slotNumber.toString(),
|
|
1278
|
-
archive: checkpoint.archive.toString(),
|
|
1279
|
-
source: source.toString()
|
|
1315
|
+
const { result, obj, metadata: { isEquivocated } = {} } = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1316
|
+
if (result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1317
|
+
this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
|
|
1318
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1319
|
+
[Attributes.P2P_ID]: peerId.toString(),
|
|
1320
|
+
isEquivocated,
|
|
1321
|
+
result
|
|
1280
1322
|
});
|
|
1281
1323
|
return {
|
|
1282
1324
|
result: TopicValidatorResult.Reject
|
|
1283
1325
|
};
|
|
1284
|
-
} else {
|
|
1285
|
-
|
|
1286
|
-
result: TopicValidatorResult.Accept,
|
|
1287
|
-
obj: checkpoint
|
|
1288
|
-
};
|
|
1326
|
+
} else if (result === TopicValidatorResult.Accept && obj && !isEquivocated) {
|
|
1327
|
+
processBlock = true;
|
|
1289
1328
|
}
|
|
1290
|
-
};
|
|
1291
|
-
const { result, obj: checkpoint } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.checkpoint_proposal);
|
|
1292
|
-
if (result !== TopicValidatorResult.Accept || !checkpoint) {
|
|
1293
|
-
return;
|
|
1294
1329
|
}
|
|
1295
|
-
|
|
1330
|
+
// Try to add the checkpoint proposal core: this handles existence check, cap check, and adding in one call
|
|
1331
|
+
const checkpointCore = checkpoint.toCore();
|
|
1332
|
+
const tryAddResult = await this.mempools.attestationPool.tryAddCheckpointProposal(checkpointCore);
|
|
1333
|
+
const { added, alreadyExists, totalForPosition } = tryAddResult;
|
|
1334
|
+
const isEquivocated = totalForPosition !== undefined && totalForPosition > 1;
|
|
1335
|
+
// Duplicate proposal received, do not re-broadcast
|
|
1336
|
+
if (alreadyExists) {
|
|
1337
|
+
this.logger.debug(`Ignoring duplicate checkpoint proposal received`, {
|
|
1338
|
+
...checkpoint.toCheckpointInfo(),
|
|
1339
|
+
source: peerId.toString()
|
|
1340
|
+
});
|
|
1341
|
+
return {
|
|
1342
|
+
result: TopicValidatorResult.Ignore,
|
|
1343
|
+
obj: checkpoint,
|
|
1344
|
+
metadata: {
|
|
1345
|
+
isEquivocated,
|
|
1346
|
+
processBlock
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
|
|
1351
|
+
// Note: We still return the checkpoint obj so the lastBlock can be processed if valid
|
|
1352
|
+
if (!added) {
|
|
1353
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1354
|
+
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1355
|
+
...checkpoint.toCheckpointInfo(),
|
|
1356
|
+
totalForPosition,
|
|
1357
|
+
source: peerId.toString()
|
|
1358
|
+
});
|
|
1359
|
+
return {
|
|
1360
|
+
result: TopicValidatorResult.Reject,
|
|
1361
|
+
obj: checkpoint,
|
|
1362
|
+
metadata: {
|
|
1363
|
+
isEquivocated,
|
|
1364
|
+
processBlock
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
1369
|
+
// and do re-broadcast it so other nodes in the network know to slash the proposer
|
|
1370
|
+
if (isEquivocated) {
|
|
1371
|
+
const proposer = checkpoint.getSender();
|
|
1372
|
+
this.logger.warn(`Detected duplicate checkpoint proposal (equivocation) at slot ${checkpoint.slotNumber}`, {
|
|
1373
|
+
...checkpoint.toCheckpointInfo(),
|
|
1374
|
+
source: peerId.toString(),
|
|
1375
|
+
proposer: proposer?.toString()
|
|
1376
|
+
});
|
|
1377
|
+
// Invoke the duplicate callback on the first duplicate spotted only
|
|
1378
|
+
if (proposer && totalForPosition === 2) {
|
|
1379
|
+
this.duplicateProposalCallback?.({
|
|
1380
|
+
slot: checkpoint.slotNumber,
|
|
1381
|
+
proposer,
|
|
1382
|
+
type: 'checkpoint'
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
return {
|
|
1386
|
+
result: TopicValidatorResult.Accept,
|
|
1387
|
+
obj: checkpoint,
|
|
1388
|
+
metadata: {
|
|
1389
|
+
isEquivocated,
|
|
1390
|
+
processBlock
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
// Otherwise, we're good to go!
|
|
1395
|
+
return {
|
|
1396
|
+
result: TopicValidatorResult.Accept,
|
|
1397
|
+
obj: checkpoint,
|
|
1398
|
+
metadata: {
|
|
1399
|
+
processBlock,
|
|
1400
|
+
isEquivocated
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1296
1403
|
}
|
|
1297
1404
|
/**
|
|
1298
1405
|
* Process a validated checkpoint proposal.
|
|
1299
|
-
*
|
|
1300
|
-
* The block callback is invoked before the checkpoint callback.
|
|
1406
|
+
* Note: The proposal was already added to the pool by tryAddCheckpointProposal in handleGossipedCheckpointProposal.
|
|
1301
1407
|
*/ async processValidCheckpointProposal(checkpoint, sender) {
|
|
1302
1408
|
const slot = checkpoint.slotNumber;
|
|
1303
1409
|
this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
|
|
@@ -1306,33 +1412,12 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
1306
1412
|
archive: checkpoint.archive.toString(),
|
|
1307
1413
|
source: sender.toString()
|
|
1308
1414
|
});
|
|
1309
|
-
// Extract block proposal before adding to pool (pool stores them separately)
|
|
1310
|
-
const blockProposal = checkpoint.getBlockProposal();
|
|
1311
|
-
// Add proposal to the pool (this extracts and stores block proposal separately)
|
|
1312
|
-
await this.mempools.attestationPool.addCheckpointProposal(checkpoint);
|
|
1313
|
-
// Mark txs as non-evictable if present (from the last block)
|
|
1314
|
-
if (checkpoint.txHashes.length > 0) {
|
|
1315
|
-
await this.mempools.txPool.markTxsAsNonEvictable(checkpoint.txHashes);
|
|
1316
|
-
}
|
|
1317
|
-
// If there was a last block proposal, invoke the block callback first for validation.
|
|
1318
|
-
// Note: The block proposal is already stored in the pool by addCheckpointProposal.
|
|
1319
|
-
if (blockProposal) {
|
|
1320
|
-
const isValid = await this.blockReceivedCallback(blockProposal, sender);
|
|
1321
|
-
if (!isValid) {
|
|
1322
|
-
this.logger.warn(`Block proposal from checkpoint failed validation`, {
|
|
1323
|
-
slot: slot.toString(),
|
|
1324
|
-
archive: checkpoint.archive.toString(),
|
|
1325
|
-
blockNumber: blockProposal.blockNumber.toString()
|
|
1326
|
-
});
|
|
1327
|
-
return;
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
1415
|
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1331
1416
|
// to validate and potentially generate attestations
|
|
1332
|
-
const attestations = await this.checkpointReceivedCallback(checkpoint
|
|
1417
|
+
const attestations = await this.checkpointReceivedCallback(checkpoint, sender);
|
|
1333
1418
|
if (attestations && attestations.length > 0) {
|
|
1334
1419
|
// If the callback returned attestations, add them to the pool and propagate them
|
|
1335
|
-
await this.mempools.attestationPool.
|
|
1420
|
+
await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
1336
1421
|
for (const attestation of attestations){
|
|
1337
1422
|
await this.propagate(attestation);
|
|
1338
1423
|
}
|
|
@@ -1659,33 +1744,7 @@ _dec = trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
|
|
|
1659
1744
|
*/ async validateCheckpointAttestation(peerId, attestation) {
|
|
1660
1745
|
const result = await this.checkpointAttestationValidator.validate(attestation);
|
|
1661
1746
|
if (result.result === 'reject') {
|
|
1662
|
-
this.logger.
|
|
1663
|
-
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1664
|
-
}
|
|
1665
|
-
return result;
|
|
1666
|
-
}
|
|
1667
|
-
/**
|
|
1668
|
-
* Validate a block proposal.
|
|
1669
|
-
*
|
|
1670
|
-
* @param block - The block proposal to validate.
|
|
1671
|
-
* @returns True if the block proposal is valid, false otherwise.
|
|
1672
|
-
*/ async validateBlockProposal(peerId, block) {
|
|
1673
|
-
const result = await this.blockProposalValidator.validate(block);
|
|
1674
|
-
if (result.result === 'reject') {
|
|
1675
|
-
this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1676
|
-
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1677
|
-
}
|
|
1678
|
-
return result;
|
|
1679
|
-
}
|
|
1680
|
-
/**
|
|
1681
|
-
* Validate a checkpoint proposal.
|
|
1682
|
-
*
|
|
1683
|
-
* @param checkpoint - The checkpoint proposal to validate.
|
|
1684
|
-
* @returns True if the checkpoint proposal is valid, false otherwise.
|
|
1685
|
-
*/ async validateCheckpointProposal(peerId, checkpoint) {
|
|
1686
|
-
const result = await this.checkpointProposalValidator.validate(checkpoint);
|
|
1687
|
-
if (result.result === 'reject') {
|
|
1688
|
-
this.logger.debug(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1747
|
+
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1689
1748
|
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1690
1749
|
}
|
|
1691
1750
|
return result;
|