@aztec/p2p 0.0.1-commit.cd76b27 → 0.0.1-commit.ce4f8c4f2
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 +5 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +28 -26
- package/dest/client/interface.d.ts +6 -13
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +5 -13
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +25 -92
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +4 -5
- package/dest/config.d.ts +33 -15
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +86 -37
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +4 -4
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +8 -4
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
- package/dest/mem_pools/instrumentation.d.ts +4 -2
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +16 -14
- package/dest/mem_pools/tx_pool/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 +3 -2
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +2 -0
- 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/invalid_txs_after_reorg_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +10 -6
- 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/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +15 -9
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +3 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +48 -11
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +81 -17
- 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 -44
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +5 -3
- 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 +6 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +3 -2
- 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 +196 -151
- 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 +6 -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 +6 -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 +13 -8
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +53 -41
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -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 +24 -20
- 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 +133 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +247 -60
- 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 +67 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -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/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
- 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/dummy_service.d.ts +2 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +1 -4
- package/dest/services/encoding.d.ts +6 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +14 -8
- package/dest/services/libp2p/libp2p_service.d.ts +20 -20
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +221 -143
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- package/dest/services/peer-manager/peer_manager.d.ts +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +6 -3
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +82 -101
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- 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 +19 -10
- package/dest/services/service.d.ts +8 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +57 -73
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/slow_tx_collection.js +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +3 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +4 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +7 -3
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +11 -3
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -2
- package/dest/test-helpers/testbench-utils.d.ts +2 -2
- 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 +10 -9
- 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 +45 -45
- package/src/client/interface.ts +5 -19
- package/src/client/p2p_client.ts +26 -122
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +5 -8
- package/src/config.ts +125 -43
- package/src/mem_pools/attestation_pool/attestation_pool.ts +8 -7
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
- package/src/mem_pools/instrumentation.ts +17 -13
- 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 +3 -2
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +3 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +11 -1
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +2 -2
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +10 -6
- 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/index.ts +1 -1
- package/src/mem_pools/tx_pool_v2/interfaces.ts +16 -8
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +115 -20
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +17 -2
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +207 -154
- 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 +14 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +69 -45
- package/src/msg_validators/tx_validator/README.md +119 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
- 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 +394 -78
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
- package/src/msg_validators/tx_validator/index.ts +2 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
- package/src/services/discv5/discV5_service.ts +4 -2
- package/src/services/dummy_service.ts +1 -5
- package/src/services/encoding.ts +14 -7
- package/src/services/libp2p/libp2p_service.ts +235 -166
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +7 -3
- 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 +78 -111
- package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/reqresp.ts +22 -12
- package/src/services/service.ts +8 -1
- package/src/services/tx_collection/fast_tx_collection.ts +57 -83
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/slow_tx_collection.ts +1 -1
- package/src/services/tx_collection/tx_collection.ts +3 -5
- package/src/services/tx_provider.ts +2 -2
- package/src/test-helpers/make-test-p2p-clients.ts +1 -3
- package/src/test-helpers/mock-pubsub.ts +12 -6
- package/src/test-helpers/reqresp-nodes.ts +3 -6
- package/src/test-helpers/testbench-utils.ts +30 -4
- package/src/testbench/p2p_client_testbench_worker.ts +7 -12
- 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 -23
- 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 -212
- 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 -230
- package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
|
@@ -45,6 +45,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
45
45
|
export interface TxPoolV2Callbacks {
|
|
46
46
|
onTxsAdded: (txs: Tx[], opts: { source?: string }) => void;
|
|
47
47
|
onTxsRemoved: (txHashes: string[] | bigint[]) => void;
|
|
48
|
+
onTxsMined: (txHashes: string[]) => void;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
/**
|
|
@@ -61,6 +62,7 @@ export class TxPoolV2Impl {
|
|
|
61
62
|
#l2BlockSource: L2BlockSource;
|
|
62
63
|
#worldStateSynchronizer: WorldStateSynchronizer;
|
|
63
64
|
#createTxValidator: TxPoolV2Dependencies['createTxValidator'];
|
|
65
|
+
#checkAllowedSetupCalls: TxPoolV2Dependencies['checkAllowedSetupCalls'];
|
|
64
66
|
|
|
65
67
|
// === In-Memory Indices ===
|
|
66
68
|
#indices: TxPoolIndices = new TxPoolIndices();
|
|
@@ -92,6 +94,7 @@ export class TxPoolV2Impl {
|
|
|
92
94
|
this.#l2BlockSource = deps.l2BlockSource;
|
|
93
95
|
this.#worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
94
96
|
this.#createTxValidator = deps.createTxValidator;
|
|
97
|
+
this.#checkAllowedSetupCalls = deps.checkAllowedSetupCalls;
|
|
95
98
|
|
|
96
99
|
this.#config = { ...DEFAULT_TX_POOL_V2_CONFIG, ...config };
|
|
97
100
|
this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
|
|
@@ -187,9 +190,35 @@ export class TxPoolV2Impl {
|
|
|
187
190
|
const errors = new Map<string, TxPoolRejectionError>();
|
|
188
191
|
const acceptedPending = new Set<string>();
|
|
189
192
|
|
|
193
|
+
// Phase 1: Pre-compute all throwable I/O outside the transaction.
|
|
194
|
+
// If any pre-computation throws, the entire call fails before mutations happen.
|
|
195
|
+
const precomputed = new Map<string, { meta: TxMetaData; minedBlockId: L2BlockId | undefined; isValid: boolean }>();
|
|
196
|
+
|
|
197
|
+
const validator = await this.#createTxValidator();
|
|
198
|
+
|
|
199
|
+
for (const tx of txs) {
|
|
200
|
+
const txHash = tx.getTxHash();
|
|
201
|
+
const txHashStr = txHash.toString();
|
|
202
|
+
|
|
203
|
+
const meta = await buildTxMetaData(tx);
|
|
204
|
+
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
205
|
+
|
|
206
|
+
// Validate non-mined txs (mined and pre-protected txs bypass validation inside the transaction)
|
|
207
|
+
let isValid = true;
|
|
208
|
+
if (!minedBlockId) {
|
|
209
|
+
isValid = await this.#validateMeta(meta, validator);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
precomputed.set(txHashStr, { meta, minedBlockId, isValid });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Phase 2: Apply mutations inside the transaction using only pre-computed results,
|
|
216
|
+
// in-memory reads, and buffered DB writes. Nothing here can throw an unhandled exception.
|
|
190
217
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
191
218
|
const preAddContext: PreAddContext | undefined =
|
|
192
|
-
opts.feeComparisonOnly !== undefined
|
|
219
|
+
opts.feeComparisonOnly !== undefined
|
|
220
|
+
? { feeComparisonOnly: opts.feeComparisonOnly, priceBumpPercentage: this.#config.priceBumpPercentage }
|
|
221
|
+
: undefined;
|
|
193
222
|
|
|
194
223
|
await this.#store.transactionAsync(async () => {
|
|
195
224
|
for (const tx of txs) {
|
|
@@ -202,22 +231,25 @@ export class TxPoolV2Impl {
|
|
|
202
231
|
continue;
|
|
203
232
|
}
|
|
204
233
|
|
|
205
|
-
|
|
206
|
-
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
234
|
+
const { meta, minedBlockId, isValid } = precomputed.get(txHashStr)!;
|
|
207
235
|
const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
|
|
208
236
|
|
|
209
237
|
if (minedBlockId) {
|
|
210
238
|
// Already mined - add directly (protection already set if pre-protected)
|
|
211
|
-
await this.#addTx(tx, { mined: minedBlockId }, opts);
|
|
239
|
+
await this.#addTx(tx, { mined: minedBlockId }, opts, meta);
|
|
212
240
|
accepted.push(txHash);
|
|
213
241
|
} else if (preProtectedSlot !== undefined) {
|
|
214
242
|
// Pre-protected and not mined - add as protected (bypass validation)
|
|
215
|
-
await this.#addTx(tx, { protected: preProtectedSlot }, opts);
|
|
243
|
+
await this.#addTx(tx, { protected: preProtectedSlot }, opts, meta);
|
|
216
244
|
accepted.push(txHash);
|
|
245
|
+
} else if (!isValid) {
|
|
246
|
+
// Failed pre-computed validation
|
|
247
|
+
rejected.push(txHash);
|
|
217
248
|
} else {
|
|
218
|
-
// Regular pending tx -
|
|
249
|
+
// Regular pending tx - run pre-add rules using pre-computed metadata
|
|
219
250
|
const result = await this.#tryAddRegularPendingTx(
|
|
220
251
|
tx,
|
|
252
|
+
meta,
|
|
221
253
|
opts,
|
|
222
254
|
poolAccess,
|
|
223
255
|
acceptedPending,
|
|
@@ -227,13 +259,18 @@ export class TxPoolV2Impl {
|
|
|
227
259
|
);
|
|
228
260
|
if (result.status === 'accepted') {
|
|
229
261
|
acceptedPending.add(txHashStr);
|
|
230
|
-
} else if (result.status === 'rejected') {
|
|
231
|
-
rejected.push(txHash);
|
|
232
262
|
} else {
|
|
233
263
|
ignored.push(txHash);
|
|
234
264
|
}
|
|
235
265
|
}
|
|
236
266
|
}
|
|
267
|
+
|
|
268
|
+
// Run post-add eviction rules for pending txs (inside transaction for atomicity)
|
|
269
|
+
if (acceptedPending.size > 0) {
|
|
270
|
+
const feePayers = Array.from(acceptedPending).map(txHash => this.#indices.getMetadata(txHash)!.feePayer);
|
|
271
|
+
const uniqueFeePayers = new Set<string>(feePayers);
|
|
272
|
+
await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [...uniqueFeePayers]);
|
|
273
|
+
}
|
|
237
274
|
});
|
|
238
275
|
|
|
239
276
|
// Build final accepted list for pending txs (excludes intra-batch evictions)
|
|
@@ -249,37 +286,24 @@ export class TxPoolV2Impl {
|
|
|
249
286
|
this.#instrumentation.recordRejected(rejected.length);
|
|
250
287
|
}
|
|
251
288
|
|
|
252
|
-
// Run post-add eviction rules for pending txs
|
|
253
|
-
if (acceptedPending.size > 0) {
|
|
254
|
-
const feePayers = Array.from(acceptedPending).map(txHash => this.#indices.getMetadata(txHash)!.feePayer);
|
|
255
|
-
const uniqueFeePayers = new Set<string>(feePayers);
|
|
256
|
-
await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [...uniqueFeePayers]);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
289
|
return { accepted, ignored, rejected, ...(errors.size > 0 ? { errors } : {}) };
|
|
260
290
|
}
|
|
261
291
|
|
|
262
|
-
/**
|
|
292
|
+
/** Adds a validated pending tx, running pre-add rules and evicting conflicts. */
|
|
263
293
|
async #tryAddRegularPendingTx(
|
|
264
294
|
tx: Tx,
|
|
295
|
+
precomputedMeta: TxMetaData,
|
|
265
296
|
opts: { source?: string },
|
|
266
297
|
poolAccess: PreAddPoolAccess,
|
|
267
298
|
acceptedPending: Set<string>,
|
|
268
299
|
ignored: TxHash[],
|
|
269
300
|
errors: Map<string, TxPoolRejectionError>,
|
|
270
301
|
preAddContext?: PreAddContext,
|
|
271
|
-
): Promise<{ status: 'accepted' | 'ignored'
|
|
272
|
-
const
|
|
273
|
-
const txHashStr = txHash.toString();
|
|
274
|
-
|
|
275
|
-
// Build metadata and validate using metadata
|
|
276
|
-
const meta = await buildTxMetaData(tx);
|
|
277
|
-
if (!(await this.#validateMeta(meta))) {
|
|
278
|
-
return { status: 'rejected' };
|
|
279
|
-
}
|
|
302
|
+
): Promise<{ status: 'accepted' | 'ignored' }> {
|
|
303
|
+
const txHashStr = tx.getTxHash().toString();
|
|
280
304
|
|
|
281
305
|
// Run pre-add rules
|
|
282
|
-
const preAddResult = await this.#evictionManager.runPreAddRules(
|
|
306
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
|
|
283
307
|
|
|
284
308
|
if (preAddResult.shouldIgnore) {
|
|
285
309
|
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
@@ -316,50 +340,62 @@ export class TxPoolV2Impl {
|
|
|
316
340
|
}
|
|
317
341
|
}
|
|
318
342
|
|
|
343
|
+
// Randomly drop the transaction for testing purposes (report as accepted so it propagates)
|
|
344
|
+
if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
|
|
345
|
+
this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
|
|
346
|
+
return { status: 'accepted' };
|
|
347
|
+
}
|
|
348
|
+
|
|
319
349
|
// Add the transaction
|
|
320
|
-
await this.#addTx(tx, 'pending', opts);
|
|
350
|
+
await this.#addTx(tx, 'pending', opts, precomputedMeta);
|
|
321
351
|
return { status: 'accepted' };
|
|
322
352
|
}
|
|
323
353
|
|
|
324
|
-
async canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'
|
|
354
|
+
async canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'> {
|
|
325
355
|
const txHashStr = tx.getTxHash().toString();
|
|
326
356
|
|
|
327
357
|
// Check if already in pool
|
|
328
358
|
if (this.#indices.has(txHashStr)) {
|
|
359
|
+
this.#log.verbose(`canAddPendingTx: tx ${txHashStr} already in pool`);
|
|
329
360
|
return 'ignored';
|
|
330
361
|
}
|
|
331
362
|
|
|
332
|
-
// Build metadata and
|
|
363
|
+
// Build metadata and check pre-add rules
|
|
333
364
|
const meta = await buildTxMetaData(tx);
|
|
334
|
-
const validationResult = await this.#validateMeta(meta, undefined, 'can add pending');
|
|
335
|
-
if (validationResult !== true) {
|
|
336
|
-
return 'rejected';
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// Use pre-add rules
|
|
340
365
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
341
366
|
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
342
367
|
|
|
343
|
-
|
|
368
|
+
if (preAddResult.shouldIgnore) {
|
|
369
|
+
this.#log.verbose(`canAddPendingTx: tx ${txHashStr} ignored by pre-add rule`, {
|
|
370
|
+
reason: preAddResult.reason?.message ?? 'no reason provided',
|
|
371
|
+
});
|
|
372
|
+
return 'ignored';
|
|
373
|
+
}
|
|
374
|
+
return 'accepted';
|
|
344
375
|
}
|
|
345
376
|
|
|
346
377
|
async addProtectedTxs(txs: Tx[], block: BlockHeader, opts: { source?: string }): Promise<void> {
|
|
347
378
|
const slotNumber = block.globalVariables.slotNumber;
|
|
348
379
|
|
|
380
|
+
// Precompute setup-call allow-list flags outside the store transaction
|
|
381
|
+
const allowedFlags = await Promise.all(txs.map(tx => this.#checkAllowedSetupCalls(tx)));
|
|
382
|
+
|
|
349
383
|
await this.#store.transactionAsync(async () => {
|
|
350
|
-
for (
|
|
384
|
+
for (let i = 0; i < txs.length; i++) {
|
|
385
|
+
const tx = txs[i];
|
|
351
386
|
const txHash = tx.getTxHash();
|
|
352
387
|
const txHashStr = txHash.toString();
|
|
353
388
|
const isNew = !this.#indices.has(txHashStr);
|
|
354
389
|
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
355
390
|
|
|
356
391
|
if (isNew) {
|
|
392
|
+
const meta = await buildTxMetaData(tx, allowedFlags[i]);
|
|
357
393
|
// New tx - add as mined or protected (callback emitted by #addTx)
|
|
358
394
|
if (minedBlockId) {
|
|
359
|
-
await this.#addTx(tx, { mined: minedBlockId }, opts);
|
|
395
|
+
await this.#addTx(tx, { mined: minedBlockId }, opts, meta);
|
|
360
396
|
this.#indices.setProtection(txHashStr, slotNumber);
|
|
361
397
|
} else {
|
|
362
|
-
await this.#addTx(tx, { protected: slotNumber }, opts);
|
|
398
|
+
await this.#addTx(tx, { protected: slotNumber }, opts, meta);
|
|
363
399
|
}
|
|
364
400
|
} else {
|
|
365
401
|
// Existing tx - update protection and mined status
|
|
@@ -379,33 +415,35 @@ export class TxPoolV2Impl {
|
|
|
379
415
|
let softDeletedHits = 0;
|
|
380
416
|
let missingPreviouslyEvicted = 0;
|
|
381
417
|
|
|
382
|
-
|
|
383
|
-
const
|
|
418
|
+
await this.#store.transactionAsync(async () => {
|
|
419
|
+
for (const txHash of txHashes) {
|
|
420
|
+
const txHashStr = txHash.toString();
|
|
384
421
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
422
|
+
if (this.#indices.has(txHashStr)) {
|
|
423
|
+
// Update protection for existing tx
|
|
424
|
+
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
425
|
+
} else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
426
|
+
// Resurrect soft-deleted tx as protected
|
|
427
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
428
|
+
if (buffer) {
|
|
429
|
+
const tx = Tx.fromBuffer(buffer);
|
|
430
|
+
await this.#addTx(tx, { protected: slotNumber });
|
|
431
|
+
softDeletedHits++;
|
|
432
|
+
} else {
|
|
433
|
+
// Data missing despite soft-delete flag — treat as truly missing
|
|
434
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
435
|
+
missing.push(txHash);
|
|
436
|
+
}
|
|
395
437
|
} else {
|
|
396
|
-
//
|
|
438
|
+
// Truly missing — pre-record protection for tx we don't have yet
|
|
397
439
|
this.#indices.setProtection(txHashStr, slotNumber);
|
|
398
440
|
missing.push(txHash);
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
this.#indices.setProtection(txHashStr, slotNumber);
|
|
403
|
-
missing.push(txHash);
|
|
404
|
-
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
405
|
-
missingPreviouslyEvicted++;
|
|
441
|
+
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
442
|
+
missingPreviouslyEvicted++;
|
|
443
|
+
}
|
|
406
444
|
}
|
|
407
445
|
}
|
|
408
|
-
}
|
|
446
|
+
});
|
|
409
447
|
|
|
410
448
|
// Record metrics
|
|
411
449
|
if (softDeletedHits > 0) {
|
|
@@ -466,56 +504,64 @@ export class TxPoolV2Impl {
|
|
|
466
504
|
}
|
|
467
505
|
}
|
|
468
506
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
507
|
+
await this.#store.transactionAsync(async () => {
|
|
508
|
+
// Step 4: Mark txs as mined (only those we have in the pool)
|
|
509
|
+
for (const meta of found) {
|
|
510
|
+
this.#indices.markAsMined(meta, blockId);
|
|
511
|
+
await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
|
|
512
|
+
}
|
|
474
513
|
|
|
475
|
-
|
|
476
|
-
|
|
514
|
+
// Step 5: Run post-event eviction rules (inside transaction for atomicity)
|
|
515
|
+
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
if (found.length > 0) {
|
|
519
|
+
this.#callbacks.onTxsMined(found.map(m => m.txHash));
|
|
520
|
+
}
|
|
477
521
|
|
|
478
522
|
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
479
523
|
}
|
|
480
524
|
|
|
481
525
|
async prepareForSlot(slotNumber: SlotNumber): Promise<void> {
|
|
482
|
-
|
|
483
|
-
|
|
526
|
+
await this.#store.transactionAsync(async () => {
|
|
527
|
+
// Step 0: Clean up slot-deleted txs from previous slots
|
|
528
|
+
await this.#deletedPool.cleanupSlotDeleted(slotNumber);
|
|
484
529
|
|
|
485
|
-
|
|
486
|
-
|
|
530
|
+
// Step 1: Find expired protected txs
|
|
531
|
+
const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
|
|
487
532
|
|
|
488
|
-
|
|
489
|
-
|
|
533
|
+
// Step 2: Clear protection for all expired entries (including those without metadata)
|
|
534
|
+
this.#indices.clearProtection(expiredProtected);
|
|
490
535
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
536
|
+
// Step 3: Filter to only txs that have metadata and are not mined
|
|
537
|
+
const txsToRestore = this.#indices.filterRestorable(expiredProtected);
|
|
538
|
+
if (txsToRestore.length === 0) {
|
|
539
|
+
this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
497
542
|
|
|
498
|
-
|
|
543
|
+
this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
|
|
499
544
|
|
|
500
|
-
|
|
501
|
-
|
|
545
|
+
// Step 4: Validate for pending pool
|
|
546
|
+
const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
|
|
502
547
|
|
|
503
|
-
|
|
504
|
-
|
|
548
|
+
// Step 5: Resolve nullifier conflicts and add winners to pending indices
|
|
549
|
+
const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
505
550
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
551
|
+
// Step 6: Delete invalid txs and evict conflict losers
|
|
552
|
+
await this.#deleteTxsBatch(invalid);
|
|
553
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
509
554
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
555
|
+
// Step 7: Run eviction rules (enforce pool size limit)
|
|
556
|
+
if (added.length > 0) {
|
|
557
|
+
const feePayers = added.map(meta => meta.feePayer);
|
|
558
|
+
const uniqueFeePayers = new Set<string>(feePayers);
|
|
559
|
+
await this.#evictionManager.evictAfterNewTxs(
|
|
560
|
+
added.map(m => m.txHash),
|
|
561
|
+
[...uniqueFeePayers],
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
});
|
|
519
565
|
}
|
|
520
566
|
|
|
521
567
|
async handlePrunedBlocks(latestBlock: L2BlockId, options?: { deleteAllTxs?: boolean }): Promise<void> {
|
|
@@ -528,57 +574,60 @@ export class TxPoolV2Impl {
|
|
|
528
574
|
|
|
529
575
|
this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
|
|
530
576
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
577
|
+
await this.#store.transactionAsync(async () => {
|
|
578
|
+
// Step 2: Mark ALL un-mined txs with their original mined block number
|
|
579
|
+
// This ensures they get soft-deleted if removed later, and only hard-deleted
|
|
580
|
+
// when their original mined block is finalized
|
|
581
|
+
await this.#deletedPool.markFromPrunedBlock(
|
|
582
|
+
txsToUnmine.map(m => ({
|
|
583
|
+
txHash: m.txHash,
|
|
584
|
+
minedAtBlock: BlockNumber(m.minedL2BlockId!.number),
|
|
585
|
+
})),
|
|
586
|
+
);
|
|
540
587
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
588
|
+
// Step 3: Unmine - clear mined status from metadata
|
|
589
|
+
for (const meta of txsToUnmine) {
|
|
590
|
+
this.#indices.markAsUnmined(meta);
|
|
591
|
+
}
|
|
545
592
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
593
|
+
// If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
|
|
594
|
+
if (options?.deleteAllTxs) {
|
|
595
|
+
const allTxHashes = txsToUnmine.map(m => m.txHash);
|
|
596
|
+
await this.#deleteTxsBatch(allTxHashes);
|
|
597
|
+
this.#log.info(
|
|
598
|
+
`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`,
|
|
599
|
+
);
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
555
602
|
|
|
556
|
-
|
|
557
|
-
|
|
603
|
+
// Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
|
|
604
|
+
const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
|
|
558
605
|
|
|
559
|
-
|
|
560
|
-
|
|
606
|
+
// Step 5: Validate for pending pool
|
|
607
|
+
const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
|
|
561
608
|
|
|
562
|
-
|
|
563
|
-
|
|
609
|
+
// Step 6: Resolve nullifier conflicts and add winners to pending indices
|
|
610
|
+
const { toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
564
611
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
612
|
+
// Step 7: Delete invalid txs and evict conflict losers
|
|
613
|
+
await this.#deleteTxsBatch(invalid);
|
|
614
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
568
615
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
616
|
+
this.#log.info(
|
|
617
|
+
`Handled prune to block ${latestBlock.number}: ${valid.length} txs restored to pending, ${invalid.length} invalid, ${toEvict.length} evicted due to nullifier conflicts`,
|
|
618
|
+
{ txHashesRestored: valid.map(m => m.txHash), txHashesInvalid: invalid, txHashesEvicted: toEvict },
|
|
619
|
+
);
|
|
573
620
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
621
|
+
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
622
|
+
// This handles cases like existing pending txs with invalid fee payer balances
|
|
623
|
+
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
624
|
+
});
|
|
577
625
|
}
|
|
578
626
|
|
|
579
627
|
async handleFailedExecution(txHashes: TxHash[]): Promise<void> {
|
|
580
|
-
|
|
581
|
-
|
|
628
|
+
await this.#store.transactionAsync(async () => {
|
|
629
|
+
await this.#deleteTxsBatch(txHashes.map(h => h.toString()));
|
|
630
|
+
});
|
|
582
631
|
|
|
583
632
|
this.#log.info(`Deleted ${txHashes.length} failed txs`, { txHashes: txHashes.map(h => h.toString()) });
|
|
584
633
|
}
|
|
@@ -589,27 +638,29 @@ export class TxPoolV2Impl {
|
|
|
589
638
|
// Step 1: Find mined txs at or before finalized block
|
|
590
639
|
const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
|
|
591
640
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
const
|
|
597
|
-
|
|
598
|
-
|
|
641
|
+
await this.#store.transactionAsync(async () => {
|
|
642
|
+
// Step 2: Collect mined txs for archiving (before deletion)
|
|
643
|
+
const txsToArchive: Tx[] = [];
|
|
644
|
+
if (this.#archive.isEnabled()) {
|
|
645
|
+
for (const txHashStr of minedTxsToFinalize) {
|
|
646
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
647
|
+
if (buffer) {
|
|
648
|
+
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
649
|
+
}
|
|
599
650
|
}
|
|
600
651
|
}
|
|
601
|
-
}
|
|
602
652
|
|
|
603
|
-
|
|
604
|
-
|
|
653
|
+
// Step 3: Delete mined txs from active pool
|
|
654
|
+
await this.#deleteTxsBatch(minedTxsToFinalize);
|
|
605
655
|
|
|
606
|
-
|
|
607
|
-
|
|
656
|
+
// Step 4: Finalize soft-deleted txs
|
|
657
|
+
await this.#deletedPool.finalizeBlock(blockNumber);
|
|
608
658
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
659
|
+
// Step 5: Archive mined txs
|
|
660
|
+
if (txsToArchive.length > 0) {
|
|
661
|
+
await this.#archive.archiveTxs(txsToArchive);
|
|
662
|
+
}
|
|
663
|
+
});
|
|
613
664
|
|
|
614
665
|
if (minedTxsToFinalize.length > 0) {
|
|
615
666
|
this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
|
|
@@ -754,9 +805,10 @@ export class TxPoolV2Impl {
|
|
|
754
805
|
tx: Tx,
|
|
755
806
|
state: 'pending' | { protected: SlotNumber } | { mined: L2BlockId },
|
|
756
807
|
opts: { source?: string } = {},
|
|
808
|
+
precomputedMeta?: TxMetaData,
|
|
757
809
|
): Promise<TxMetaData> {
|
|
758
810
|
const txHashStr = tx.getTxHash().toString();
|
|
759
|
-
const meta = await buildTxMetaData(tx);
|
|
811
|
+
const meta = precomputedMeta ?? (await buildTxMetaData(tx));
|
|
760
812
|
meta.receivedAt = this.#dateProvider.now();
|
|
761
813
|
|
|
762
814
|
await this.#txsDB.set(txHashStr, tx.toBuffer());
|
|
@@ -938,7 +990,8 @@ export class TxPoolV2Impl {
|
|
|
938
990
|
|
|
939
991
|
try {
|
|
940
992
|
const tx = Tx.fromBuffer(buffer);
|
|
941
|
-
const
|
|
993
|
+
const allowedSetupCalls = await this.#checkAllowedSetupCalls(tx);
|
|
994
|
+
const meta = await buildTxMetaData(tx, allowedSetupCalls);
|
|
942
995
|
loaded.push({ tx, meta });
|
|
943
996
|
} catch (err) {
|
|
944
997
|
this.#log.warn(`Failed to deserialize tx ${txHashStr}, deleting`, { err });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Attestation Validation
|
|
2
|
+
|
|
3
|
+
This module validates `CheckpointAttestation` gossipsub messages. Attestations are signatures from committee members endorsing a checkpoint proposal.
|
|
4
|
+
|
|
5
|
+
**Topic**: `checkpoint_attestation` | **Snappy size limit**: 5 KB
|
|
6
|
+
|
|
7
|
+
## Stage 1: AttestationValidator (Gossipsub Validation)
|
|
8
|
+
|
|
9
|
+
| # | Rule | Consequence | Severity | File |
|
|
10
|
+
|---|------|-------------|----------|------|
|
|
11
|
+
| 1 | **Slot timeliness**: `currentSlot` or `nextSlot`. Previous slot within 500ms: IGNORE. Older: REJECT. | REJECT or IGNORE | HighToleranceError | `attestation_validator.ts` |
|
|
12
|
+
| 2 | **Attester signature**: `getSender()` must recover valid address | REJECT | LowToleranceError | same |
|
|
13
|
+
| 3 | **Attester in committee**: recovered address in committee for slot | REJECT | HighToleranceError | same |
|
|
14
|
+
| 4 | **Proposer exists**: `getProposerAttesterAddressInSlot` must return defined | REJECT | HighToleranceError | same |
|
|
15
|
+
| 5 | **Proposer signature**: `getProposer()` must recover valid address | REJECT | LowToleranceError | same |
|
|
16
|
+
| 6 | **Proposer matches expected**: recovered proposer = expected for slot | REJECT | HighToleranceError | same |
|
|
17
|
+
| 7 | **NoCommitteeError**: committee unavailable | REJECT | LowToleranceError | same |
|
|
18
|
+
|
|
19
|
+
**Fisherman mode extension** (`FishermanAttestationValidator`): if a checkpoint proposal for the same archive exists in pool, the attestation's `ConsensusPayload` must `.equals()` the stored proposal's payload. On mismatch: REJECT + LowToleranceError.
|
|
20
|
+
|
|
21
|
+
## Stage 2: Pool Admission
|
|
22
|
+
|
|
23
|
+
| # | Rule | Consequence |
|
|
24
|
+
|---|------|-------------|
|
|
25
|
+
| 8 | Sender recoverable (pool-side) | Silent drop |
|
|
26
|
+
| 9 | Not a duplicate (same slot + proposalId + signer) | IGNORE |
|
|
27
|
+
| 10 | Per-signer cap: `MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER` = 2 | IGNORE |
|
|
28
|
+
|
|
29
|
+
Own attestations added via `addOwnCheckpointAttestations` bypass the per-signer cap.
|
|
30
|
+
|
|
31
|
+
## Stage 3: Equivocation Detection
|
|
32
|
+
|
|
33
|
+
When a signer's attestation count for a slot reaches exactly 2 (different proposals): `duplicateAttestationCallback` fires -> `WANT_TO_SLASH_EVENT` with `OffenseType.DUPLICATE_ATTESTATION`. Attestation still ACCEPTED and rebroadcast. Callback fires once (not again at count 3+).
|
|
34
|
+
|
|
35
|
+
## Validation at L1 Checkpoint Submission (Archiver)
|
|
36
|
+
|
|
37
|
+
| Rule | Consequence | File |
|
|
38
|
+
|------|-------------|------|
|
|
39
|
+
| Each attestation must have recoverable signature (or address-only is allowed but does not count toward quorum) | Checkpoint rejected as invalid | `archiver/src/modules/validation.ts` |
|
|
40
|
+
| Attestation at index `i` must correspond to committee member at index `i` | Checkpoint rejected as invalid | same |
|
|
41
|
+
| Valid attestation count >= floor(committee * 2/3) + 1 | Checkpoint rejected as invalid | same |
|
|
42
|
+
| No committee / escape hatch open | Accepted unconditionally | same |
|
|
43
|
+
|
|
44
|
+
Note: `skipValidateCheckpointAttestations` config flag bypasses all archiver attestation validation.
|
|
45
|
+
|
|
46
|
+
## Gossipsub Topic Scoring
|
|
47
|
+
|
|
48
|
+
P3 enabled with expected messages per slot = `targetCommitteeSize`. Conservative threshold (30% of convergence value). Max P3 penalty = -34 per topic.
|
|
49
|
+
|
|
@@ -23,13 +23,14 @@ export class CheckpointAttestationValidator implements P2PValidator<CheckpointAt
|
|
|
23
23
|
const slotNumber = message.payload.header.slotNumber;
|
|
24
24
|
|
|
25
25
|
try {
|
|
26
|
-
|
|
26
|
+
// Use target slots since proposals target pipeline slots (slot + 1 when pipelining)
|
|
27
|
+
const { targetSlot, nextSlot } = this.epochCache.getTargetAndNextSlot();
|
|
27
28
|
|
|
28
|
-
if (slotNumber !==
|
|
29
|
+
if (slotNumber !== targetSlot && slotNumber !== nextSlot) {
|
|
29
30
|
// Check if message is for previous slot and within clock tolerance
|
|
30
|
-
if (!isWithinClockTolerance(slotNumber,
|
|
31
|
+
if (!isWithinClockTolerance(slotNumber, targetSlot, this.epochCache)) {
|
|
31
32
|
this.logger.warn(
|
|
32
|
-
`Checkpoint attestation slot ${slotNumber} is not current (${
|
|
33
|
+
`Checkpoint attestation slot ${slotNumber} is not current (${targetSlot}) or next (${nextSlot}) slot`,
|
|
33
34
|
);
|
|
34
35
|
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
35
36
|
}
|
|
@@ -36,10 +36,11 @@ export function isWithinClockTolerance(
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// Check how far we are into the current slot (in milliseconds)
|
|
39
|
-
const { ts: slotStartTs, nowMs
|
|
39
|
+
const { ts: slotStartTs, nowMs } = epochCache.getEpochAndSlotNow();
|
|
40
|
+
const targetSlot = epochCache.getTargetSlot();
|
|
40
41
|
|
|
41
|
-
// Sanity check: ensure the epoch cache's
|
|
42
|
-
if (
|
|
42
|
+
// Sanity check: ensure the epoch cache's target slot matches the expected current slot
|
|
43
|
+
if (targetSlot !== currentSlot) {
|
|
43
44
|
return false;
|
|
44
45
|
}
|
|
45
46
|
|