@aztec/p2p 0.0.1-commit.8c0b8ff → 0.0.1-commit.8cb2d04d8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/factory.d.ts +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +1 -0
- package/dest/client/interface.d.ts +9 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +3 -2
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +30 -8
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +17 -6
- package/dest/config.d.ts +107 -103
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +17 -12
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +7 -5
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +16 -9
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
- package/dest/mem_pools/index.d.ts +1 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.d.ts +4 -2
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +16 -14
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +7 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +5 -6
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +6 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +26 -43
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +2 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +18 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +5 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +20 -11
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +4 -2
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +2 -2
- package/dest/msg_validators/clock_tolerance.d.ts +12 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +54 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +19 -11
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +11 -9
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +5 -5
- package/dest/services/dummy_service.d.ts +6 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +6 -1
- package/dest/services/gossipsub/topic_score_params.d.ts +13 -2
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +21 -4
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +14 -0
- package/dest/services/libp2p/libp2p_service.d.ts +15 -25
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +150 -115
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- package/dest/services/peer-manager/peer_manager.d.ts +6 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +39 -11
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +32 -10
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +82 -101
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
- package/dest/services/reqresp/config.d.ts +3 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/interface.d.ts +14 -9
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +10 -11
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +0 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +1 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +1 -3
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
- package/dest/services/reqresp/reqresp.d.ts +4 -2
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +13 -3
- package/dest/services/service.d.ts +5 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +57 -73
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/slow_tx_collection.js +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +3 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +11 -3
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +35 -10
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +1 -2
- package/dest/test-helpers/testbench-utils.d.ts +1 -1
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +21 -2
- package/dest/testbench/p2p_client_testbench_worker.js +66 -15
- package/dest/testbench/worker_client_manager.d.ts +8 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +51 -2
- package/dest/util.d.ts +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +2 -1
- package/src/client/interface.ts +9 -1
- package/src/client/p2p_client.ts +34 -9
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -9
- package/src/config.ts +29 -17
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +17 -12
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/instrumentation.ts +17 -13
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/interfaces.ts +7 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +12 -6
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +3 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +19 -1
- package/src/msg_validators/attestation_validator/README.md +1 -1
- package/src/msg_validators/attestation_validator/attestation_validator.ts +21 -9
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +4 -1
- package/src/msg_validators/clock_tolerance.ts +72 -3
- package/src/msg_validators/proposal_validator/README.md +4 -4
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +4 -1
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +4 -1
- package/src/msg_validators/proposal_validator/proposal_validator.ts +17 -10
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/gas_validator.ts +25 -9
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/services/data_store.ts +5 -13
- package/src/services/dummy_service.ts +8 -2
- package/src/services/gossipsub/topic_score_params.ts +36 -4
- package/src/services/libp2p/instrumentation.ts +14 -0
- package/src/services/libp2p/libp2p_service.ts +146 -130
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +45 -11
- package/src/services/peer-manager/peer_scoring.ts +27 -5
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +78 -111
- package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
- package/src/services/reqresp/config.ts +2 -2
- package/src/services/reqresp/interface.ts +21 -11
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +1 -3
- package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
- package/src/services/reqresp/reqresp.ts +21 -2
- package/src/services/service.ts +6 -1
- package/src/services/tx_collection/fast_tx_collection.ts +57 -83
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/slow_tx_collection.ts +1 -1
- package/src/services/tx_collection/tx_collection.ts +3 -5
- package/src/test-helpers/make-test-p2p-clients.ts +1 -1
- package/src/test-helpers/mock-pubsub.ts +31 -5
- package/src/test-helpers/reqresp-nodes.ts +3 -3
- package/src/test-helpers/testbench-utils.ts +29 -3
- package/src/testbench/p2p_client_testbench_worker.ts +71 -15
- package/src/testbench/worker_client_manager.ts +57 -2
- package/src/util.ts +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -123
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -402
- package/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
- package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -163
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -321
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
|
@@ -73,7 +73,7 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
73
73
|
private defaultAttributes;
|
|
74
74
|
private meter: Meter;
|
|
75
75
|
|
|
76
|
-
private
|
|
76
|
+
private mempoolItemAddedTimestamp: Map<bigint | string, number> = new Map<bigint | string, number>();
|
|
77
77
|
|
|
78
78
|
constructor(
|
|
79
79
|
telemetry: TelemetryClient,
|
|
@@ -114,22 +114,26 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
public transactionsAdded(transactions: Tx[]) {
|
|
117
|
-
|
|
118
|
-
for (const transaction of transactions) {
|
|
119
|
-
this.txAddedTimestamp.set(transaction.txHash.toBigInt(), timestamp);
|
|
120
|
-
}
|
|
117
|
+
transactions.forEach(tx => this.trackMempoolItemAdded(tx.txHash.toBigInt()));
|
|
121
118
|
}
|
|
122
119
|
|
|
123
120
|
public transactionsRemoved(hashes: Iterable<bigint> | Iterable<string>) {
|
|
124
|
-
const timestamp = Date.now();
|
|
125
121
|
for (const hash of hashes) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
122
|
+
this.trackMempoolItemRemoved(BigInt(hash));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public trackMempoolItemAdded(key: bigint | string): void {
|
|
127
|
+
this.mempoolItemAddedTimestamp.set(key, Date.now());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public trackMempoolItemRemoved(key: bigint | string): void {
|
|
131
|
+
const timestamp = Date.now();
|
|
132
|
+
const addedAt = this.mempoolItemAddedTimestamp.get(key);
|
|
133
|
+
if (addedAt !== undefined) {
|
|
134
|
+
this.mempoolItemAddedTimestamp.delete(key);
|
|
135
|
+
if (addedAt < timestamp) {
|
|
136
|
+
this.minedDelay.record(timestamp - addedAt);
|
|
133
137
|
}
|
|
134
138
|
}
|
|
135
139
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
3
3
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
4
4
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
5
5
|
|
|
@@ -33,14 +33,14 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
|
|
|
33
33
|
const pendingTxs = pool.getPendingTxs();
|
|
34
34
|
|
|
35
35
|
// Deduplicate block hashes to reduce redundant DB lookups
|
|
36
|
-
const uniqueBlockHashes = new Map<string,
|
|
36
|
+
const uniqueBlockHashes = new Map<string, BlockHash>();
|
|
37
37
|
const txsByBlockHash = new Map<string, string[]>();
|
|
38
38
|
|
|
39
39
|
for (const meta of pendingTxs) {
|
|
40
40
|
const blockHashStr = meta.anchorBlockHeaderHash;
|
|
41
41
|
if (!txsByBlockHash.has(blockHashStr)) {
|
|
42
42
|
txsByBlockHash.set(blockHashStr, []);
|
|
43
|
-
uniqueBlockHashes.set(blockHashStr,
|
|
43
|
+
uniqueBlockHashes.set(blockHashStr, BlockHash.fromString(blockHashStr));
|
|
44
44
|
}
|
|
45
45
|
txsByBlockHash.get(blockHashStr)!.push(meta.txHash);
|
|
46
46
|
}
|
|
@@ -44,6 +44,8 @@ export type TxPoolV2Config = {
|
|
|
44
44
|
minTxPoolAgeMs: number;
|
|
45
45
|
/** Maximum number of evicted tx hashes to remember for metrics tracking */
|
|
46
46
|
evictedTxCacheSize: number;
|
|
47
|
+
/** The probability (0-1) that a transaction is discarded. 0 disables dropping. For testing purposes only. */
|
|
48
|
+
dropTransactionsProbability: number;
|
|
47
49
|
/** Minimum percentage fee increase required to replace an existing tx via RPC (0 = no bump). */
|
|
48
50
|
priceBumpPercentage: bigint;
|
|
49
51
|
};
|
|
@@ -56,6 +58,7 @@ export const DEFAULT_TX_POOL_V2_CONFIG: TxPoolV2Config = {
|
|
|
56
58
|
archivedTxLimit: 0, // 0 = disabled
|
|
57
59
|
minTxPoolAgeMs: 2_000,
|
|
58
60
|
evictedTxCacheSize: 10_000,
|
|
61
|
+
dropTransactionsProbability: 0,
|
|
59
62
|
priceBumpPercentage: 10n,
|
|
60
63
|
};
|
|
61
64
|
|
|
@@ -157,10 +160,10 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
|
|
|
157
160
|
handleMinedBlock(block: L2Block): Promise<void>;
|
|
158
161
|
|
|
159
162
|
/**
|
|
160
|
-
* Prepares the pool for a new slot
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
163
|
+
* Prepares the pool for a new slot by unprotecting transactions from earlier
|
|
164
|
+
* slots and re-validating them before returning to pending state.
|
|
165
|
+
* @param slotNumber - The pipeline slot we are building for (i.e. the slot
|
|
166
|
+
* the resulting blocks will target on L1).
|
|
164
167
|
*/
|
|
165
168
|
prepareForSlot(slotNumber: SlotNumber): Promise<void>;
|
|
166
169
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { minBigint } from '@aztec/foundation/bigint';
|
|
1
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
@@ -6,7 +7,6 @@ import { Gas } from '@aztec/stdlib/gas';
|
|
|
6
7
|
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
7
8
|
|
|
8
9
|
import { getFeePayerBalanceDelta } from '../../msg_validators/tx_validator/fee_payer_balance.js';
|
|
9
|
-
import { getTxPriorityFee } from '../tx_pool/priority.js';
|
|
10
10
|
import { type PreAddResult, TxPoolRejectionCode } from './eviction/interfaces.js';
|
|
11
11
|
|
|
12
12
|
/** Validator-compatible data interface, mirroring the subset of PrivateKernelTailCircuitPublicInputs used by validators. */
|
|
@@ -166,13 +166,13 @@ export function txHashFromBigInt(value: bigint): string {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/** Minimal fields required for priority comparison. */
|
|
169
|
-
type PriorityComparable = Pick<TxMetaData, 'txHashBigInt' | 'priorityFee'>;
|
|
169
|
+
export type PriorityComparable = Pick<TxMetaData, 'txHash' | 'txHashBigInt' | 'priorityFee'>;
|
|
170
170
|
|
|
171
171
|
/**
|
|
172
172
|
* Compares two priority fees in ascending order.
|
|
173
173
|
* Returns negative if a < b, positive if a > b, 0 if equal.
|
|
174
174
|
*/
|
|
175
|
-
export function compareFee(a: bigint, b: bigint):
|
|
175
|
+
export function compareFee(a: bigint, b: bigint): -1 | 0 | 1 {
|
|
176
176
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
177
177
|
}
|
|
178
178
|
|
|
@@ -181,7 +181,7 @@ export function compareFee(a: bigint, b: bigint): number {
|
|
|
181
181
|
* Uses field element comparison for deterministic ordering.
|
|
182
182
|
* Returns negative if a < b, positive if a > b, 0 if equal.
|
|
183
183
|
*/
|
|
184
|
-
export function compareTxHash(a: bigint, b: bigint):
|
|
184
|
+
export function compareTxHash(a: bigint, b: bigint): -1 | 0 | 1 {
|
|
185
185
|
return Fr.cmpAsBigInt(a, b);
|
|
186
186
|
}
|
|
187
187
|
|
|
@@ -190,7 +190,7 @@ export function compareTxHash(a: bigint, b: bigint): number {
|
|
|
190
190
|
* Returns negative if a < b, positive if a > b, 0 if equal.
|
|
191
191
|
* Use with sort() for ascending order, or negate/reverse for descending.
|
|
192
192
|
*/
|
|
193
|
-
export function comparePriority(a: PriorityComparable, b: PriorityComparable):
|
|
193
|
+
export function comparePriority(a: PriorityComparable, b: PriorityComparable): -1 | 0 | 1 {
|
|
194
194
|
const feeComparison = compareFee(a.priorityFee, b.priorityFee);
|
|
195
195
|
if (feeComparison !== 0) {
|
|
196
196
|
return feeComparison;
|
|
@@ -291,7 +291,7 @@ export function stubTxMetaValidationData(overrides: { expirationTimestamp?: bigi
|
|
|
291
291
|
expirationTimestamp: overrides.expirationTimestamp ?? 0n,
|
|
292
292
|
constants: {
|
|
293
293
|
anchorBlockHeader: {
|
|
294
|
-
hash: () => Promise.resolve(
|
|
294
|
+
hash: () => Promise.resolve(BlockHash.ZERO),
|
|
295
295
|
globalVariables: { blockNumber: BlockNumber(0) },
|
|
296
296
|
},
|
|
297
297
|
txContext: {
|
|
@@ -335,3 +335,9 @@ export function stubTxMetaData(
|
|
|
335
335
|
data: stubTxMetaValidationData({ expirationTimestamp }),
|
|
336
336
|
};
|
|
337
337
|
}
|
|
338
|
+
|
|
339
|
+
/** Returns the priority fee for a tx, based on the L2 priority fee capped by the max fee per gas. */
|
|
340
|
+
function getTxPriorityFee(tx: Tx): bigint {
|
|
341
|
+
const { maxPriorityFeesPerGas: priorityFees, maxFeesPerGas } = tx.getGasSettings();
|
|
342
|
+
return minBigint(maxFeesPerGas.feePerL2Gas, priorityFees.feePerL2Gas);
|
|
343
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { insertIntoSortedArray, removeFromSortedArray } from '@aztec/foundation/array';
|
|
1
2
|
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import type { L2BlockId } from '@aztec/stdlib/block';
|
|
3
4
|
|
|
4
|
-
import { type
|
|
5
|
+
import { type PriorityComparable, type TxMetaData, type TxState, comparePriority } from './tx_metadata.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Manages in-memory indices for the transaction pool.
|
|
@@ -22,8 +23,8 @@ export class TxPoolIndices {
|
|
|
22
23
|
#nullifierToTxHash: Map<string, string> = new Map();
|
|
23
24
|
/** Fee payer to txHashes index (pending txs only) */
|
|
24
25
|
#feePayerToTxHashes: Map<string, Set<string>> = new Map();
|
|
25
|
-
/** Pending
|
|
26
|
-
#pendingByPriority:
|
|
26
|
+
/** Pending transactions sorted ascending by priority fee, ties broken by txHash */
|
|
27
|
+
#pendingByPriority: PriorityComparable[] = [];
|
|
27
28
|
/** Protected transactions: txHash -> slotNumber */
|
|
28
29
|
#protectedTransactions: Map<string, SlotNumber> = new Map();
|
|
29
30
|
|
|
@@ -73,20 +74,14 @@ export class TxPoolIndices {
|
|
|
73
74
|
* @param order - 'desc' for highest priority first, 'asc' for lowest priority first
|
|
74
75
|
*/
|
|
75
76
|
*iteratePendingByPriority(order: 'asc' | 'desc', filter?: (hash: string) => boolean): Generator<string> {
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const sortedHashes = [...hashesAtFee].sort(hashCompareFn);
|
|
85
|
-
for (const hashBigInt of sortedHashes) {
|
|
86
|
-
const hash = txHashFromBigInt(hashBigInt);
|
|
87
|
-
if (filter === undefined || filter(hash)) {
|
|
88
|
-
yield hash;
|
|
89
|
-
}
|
|
77
|
+
const arr = this.#pendingByPriority;
|
|
78
|
+
const start = order === 'asc' ? 0 : arr.length - 1;
|
|
79
|
+
const step = order === 'asc' ? 1 : -1;
|
|
80
|
+
const inBounds = order === 'asc' ? (i: number) => i < arr.length : (i: number) => i >= 0;
|
|
81
|
+
|
|
82
|
+
for (let i = start; inBounds(i); i += step) {
|
|
83
|
+
if (filter === undefined || filter(arr[i].txHash)) {
|
|
84
|
+
yield arr[i].txHash;
|
|
90
85
|
}
|
|
91
86
|
}
|
|
92
87
|
}
|
|
@@ -227,11 +222,7 @@ export class TxPoolIndices {
|
|
|
227
222
|
|
|
228
223
|
/** Gets the count of pending transactions */
|
|
229
224
|
getPendingTxCount(): number {
|
|
230
|
-
|
|
231
|
-
for (const hashes of this.#pendingByPriority.values()) {
|
|
232
|
-
count += hashes.size;
|
|
233
|
-
}
|
|
234
|
-
return count;
|
|
225
|
+
return this.#pendingByPriority.length;
|
|
235
226
|
}
|
|
236
227
|
|
|
237
228
|
/** Gets the lowest priority pending transaction hashes (up to limit) */
|
|
@@ -264,12 +255,10 @@ export class TxPoolIndices {
|
|
|
264
255
|
/** Gets all pending transactions */
|
|
265
256
|
getPendingTxs(): TxMetaData[] {
|
|
266
257
|
const result: TxMetaData[] = [];
|
|
267
|
-
for (const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
result.push(meta);
|
|
272
|
-
}
|
|
258
|
+
for (const entry of this.#pendingByPriority) {
|
|
259
|
+
const meta = this.#metadata.get(entry.txHash);
|
|
260
|
+
if (meta) {
|
|
261
|
+
result.push(meta);
|
|
273
262
|
}
|
|
274
263
|
}
|
|
275
264
|
return result;
|
|
@@ -408,13 +397,12 @@ export class TxPoolIndices {
|
|
|
408
397
|
}
|
|
409
398
|
feePayerSet.add(meta.txHash);
|
|
410
399
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
prioritySet.add(meta.txHashBigInt);
|
|
400
|
+
insertIntoSortedArray(
|
|
401
|
+
this.#pendingByPriority,
|
|
402
|
+
{ txHash: meta.txHash, priorityFee: meta.priorityFee, txHashBigInt: meta.txHashBigInt },
|
|
403
|
+
comparePriority,
|
|
404
|
+
false,
|
|
405
|
+
);
|
|
418
406
|
}
|
|
419
407
|
|
|
420
408
|
#removeFromPendingIndices(meta: TxMetaData): void {
|
|
@@ -432,13 +420,11 @@ export class TxPoolIndices {
|
|
|
432
420
|
}
|
|
433
421
|
}
|
|
434
422
|
|
|
435
|
-
// Remove from priority
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
}
|
|
423
|
+
// Remove from priority array
|
|
424
|
+
removeFromSortedArray(
|
|
425
|
+
this.#pendingByPriority,
|
|
426
|
+
{ txHash: meta.txHash, priorityFee: meta.priorityFee, txHashBigInt: meta.txHashBigInt },
|
|
427
|
+
comparePriority,
|
|
428
|
+
);
|
|
443
429
|
}
|
|
444
430
|
}
|
|
@@ -65,6 +65,9 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
|
|
|
65
65
|
const hashes = txHashes.map(h => (typeof h === 'string' ? TxHash.fromString(h) : TxHash.fromBigInt(h)));
|
|
66
66
|
this.emit('txs-removed', { txHashes: hashes });
|
|
67
67
|
},
|
|
68
|
+
onTxsMined: (txHashes: string[]) => {
|
|
69
|
+
this.#metrics?.transactionsRemoved(txHashes);
|
|
70
|
+
},
|
|
68
71
|
};
|
|
69
72
|
|
|
70
73
|
// Create the implementation
|
|
@@ -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
|
/**
|
|
@@ -339,6 +340,12 @@ export class TxPoolV2Impl {
|
|
|
339
340
|
}
|
|
340
341
|
}
|
|
341
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
|
+
|
|
342
349
|
// Add the transaction
|
|
343
350
|
await this.#addTx(tx, 'pending', opts, precomputedMeta);
|
|
344
351
|
return { status: 'accepted' };
|
|
@@ -349,6 +356,7 @@ export class TxPoolV2Impl {
|
|
|
349
356
|
|
|
350
357
|
// Check if already in pool
|
|
351
358
|
if (this.#indices.has(txHashStr)) {
|
|
359
|
+
this.#log.verbose(`canAddPendingTx: tx ${txHashStr} already in pool`);
|
|
352
360
|
return 'ignored';
|
|
353
361
|
}
|
|
354
362
|
|
|
@@ -357,7 +365,13 @@ export class TxPoolV2Impl {
|
|
|
357
365
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
358
366
|
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
359
367
|
|
|
360
|
-
|
|
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';
|
|
361
375
|
}
|
|
362
376
|
|
|
363
377
|
async addProtectedTxs(txs: Tx[], block: BlockHeader, opts: { source?: string }): Promise<void> {
|
|
@@ -501,6 +515,10 @@ export class TxPoolV2Impl {
|
|
|
501
515
|
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
502
516
|
});
|
|
503
517
|
|
|
518
|
+
if (found.length > 0) {
|
|
519
|
+
this.#callbacks.onTxsMined(found.map(m => m.txHash));
|
|
520
|
+
}
|
|
521
|
+
|
|
504
522
|
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
505
523
|
}
|
|
506
524
|
|
|
@@ -24,7 +24,7 @@ This module validates `CheckpointAttestation` gossipsub messages. Attestations a
|
|
|
24
24
|
|---|------|-------------|
|
|
25
25
|
| 8 | Sender recoverable (pool-side) | Silent drop |
|
|
26
26
|
| 9 | Not a duplicate (same slot + proposalId + signer) | IGNORE |
|
|
27
|
-
| 10 | Per-signer cap: `MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER` =
|
|
27
|
+
| 10 | Per-signer cap: `MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER` = 2 | IGNORE |
|
|
28
28
|
|
|
29
29
|
Own attestations added via `addOwnCheckpointAttestations` bypass the per-signer cap.
|
|
30
30
|
|
|
@@ -8,14 +8,21 @@ import {
|
|
|
8
8
|
type ValidationResult,
|
|
9
9
|
} from '@aztec/stdlib/p2p';
|
|
10
10
|
|
|
11
|
-
import { isWithinClockTolerance } from '../clock_tolerance.js';
|
|
11
|
+
import { PipeliningWindow, isWithinClockTolerance } from '../clock_tolerance.js';
|
|
12
12
|
|
|
13
13
|
export class CheckpointAttestationValidator implements P2PValidator<CheckpointAttestation> {
|
|
14
14
|
protected epochCache: EpochCacheInterface;
|
|
15
15
|
protected logger: Logger;
|
|
16
|
+
private readonly pipeliningWindow: PipeliningWindow;
|
|
16
17
|
|
|
17
|
-
constructor(
|
|
18
|
+
constructor(
|
|
19
|
+
epochCache: EpochCacheInterface,
|
|
20
|
+
opts: {
|
|
21
|
+
l1PublishingTime?: number;
|
|
22
|
+
},
|
|
23
|
+
) {
|
|
18
24
|
this.epochCache = epochCache;
|
|
25
|
+
this.pipeliningWindow = new PipeliningWindow(epochCache, { l1PublishingTime: opts.l1PublishingTime });
|
|
19
26
|
this.logger = createLogger('p2p:checkpoint-attestation-validator');
|
|
20
27
|
}
|
|
21
28
|
|
|
@@ -23,18 +30,23 @@ export class CheckpointAttestationValidator implements P2PValidator<CheckpointAt
|
|
|
23
30
|
const slotNumber = message.payload.header.slotNumber;
|
|
24
31
|
|
|
25
32
|
try {
|
|
26
|
-
|
|
33
|
+
// Use target slots since proposals target pipeline slots (slot + 1 when pipelining).
|
|
34
|
+
const { targetSlot, nextSlot } = this.epochCache.getTargetAndNextSlot();
|
|
27
35
|
|
|
28
|
-
if (slotNumber !==
|
|
29
|
-
//
|
|
30
|
-
|
|
36
|
+
if (slotNumber !== targetSlot && slotNumber !== nextSlot) {
|
|
37
|
+
// When pipelining, accept attestations for the current slot (built in the previous slot)
|
|
38
|
+
// until the target slot reaches its L1 publish cutoff.
|
|
39
|
+
if (this.pipeliningWindow.acceptsAttestation(slotNumber)) {
|
|
40
|
+
// Fall through to remaining validation (signature, committee, etc.)
|
|
41
|
+
} else if (!isWithinClockTolerance(slotNumber, targetSlot, this.epochCache)) {
|
|
31
42
|
this.logger.warn(
|
|
32
|
-
`Checkpoint attestation slot ${slotNumber} is not current (${
|
|
43
|
+
`Checkpoint attestation slot ${slotNumber} is not current (${targetSlot}) or next (${nextSlot}) slot`,
|
|
33
44
|
);
|
|
34
45
|
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
46
|
+
} else {
|
|
47
|
+
this.logger.debug(`Ignoring checkpoint attestation for previous slot ${slotNumber} within clock tolerance`);
|
|
48
|
+
return { result: 'ignore' };
|
|
35
49
|
}
|
|
36
|
-
this.logger.debug(`Ignoring checkpoint attestation for previous slot ${slotNumber} within clock tolerance`);
|
|
37
|
-
return { result: 'ignore' };
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
// Verify the signature is valid
|
|
@@ -20,8 +20,11 @@ export class FishermanAttestationValidator extends CheckpointAttestationValidato
|
|
|
20
20
|
epochCache: EpochCacheInterface,
|
|
21
21
|
private attestationPool: AttestationPoolApi,
|
|
22
22
|
telemetryClient: TelemetryClient,
|
|
23
|
+
opts: {
|
|
24
|
+
l1PublishingTime?: number;
|
|
25
|
+
} = {},
|
|
23
26
|
) {
|
|
24
|
-
super(epochCache);
|
|
27
|
+
super(epochCache, opts);
|
|
25
28
|
this.logger = this.logger.createChild('[FISHERMAN]');
|
|
26
29
|
|
|
27
30
|
const meter = telemetryClient.getMeter('FishermanAttestationValidator');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
2
|
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { DEFAULT_P2P_PROPAGATION_TIME, createPipelinedCheckpointTimingModel } from '@aztec/stdlib/timetable';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Maximum clock disparity tolerance for P2P message validation (in milliseconds).
|
|
@@ -36,10 +37,11 @@ export function isWithinClockTolerance(
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
// Check how far we are into the current slot (in milliseconds)
|
|
39
|
-
const { ts: slotStartTs, nowMs
|
|
40
|
+
const { ts: slotStartTs, nowMs } = epochCache.getEpochAndSlotNow();
|
|
41
|
+
const targetSlot = epochCache.getTargetSlot();
|
|
40
42
|
|
|
41
|
-
// Sanity check: ensure the epoch cache's
|
|
42
|
-
if (
|
|
43
|
+
// Sanity check: ensure the epoch cache's target slot matches the expected current slot
|
|
44
|
+
if (targetSlot !== currentSlot) {
|
|
43
45
|
return false;
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -49,3 +51,70 @@ export function isWithinClockTolerance(
|
|
|
49
51
|
|
|
50
52
|
return elapsedMs < MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS;
|
|
51
53
|
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a message should be accepted under the pipelining grace period.
|
|
57
|
+
*
|
|
58
|
+
* When pipelining is enabled, `targetSlot = slotNow + 1`. A proposal built in slot N-1
|
|
59
|
+
* for slot N arrives when validators are in slot N, so their `targetSlot = N+1`.
|
|
60
|
+
* This function accepts proposals for the current wallclock slot if we're within the
|
|
61
|
+
* first `windowSeconds` seconds of the slot (the pipelining grace period). - see stdlib/timetable/index.ts
|
|
62
|
+
*
|
|
63
|
+
* @param messageSlot - The slot number from the received message
|
|
64
|
+
* @param epochCache - EpochCache to get timing and pipelining state
|
|
65
|
+
* @param windowSeconds - The window grace period allowed for attestations into the next slot
|
|
66
|
+
* @returns true if pipelining is enabled, the message is for the current slot, and we're within the grace period
|
|
67
|
+
*/
|
|
68
|
+
function isWithinPipeliningWindow(
|
|
69
|
+
messageSlot: SlotNumber,
|
|
70
|
+
epochCache: EpochCacheInterface,
|
|
71
|
+
windowSeconds: number,
|
|
72
|
+
): boolean {
|
|
73
|
+
if (!epochCache.isProposerPipeliningEnabled()) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const currentSlot = epochCache.getSlotNow();
|
|
78
|
+
if (messageSlot !== currentSlot) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { ts: slotStartTs, nowMs } = epochCache.getEpochAndSlotNow();
|
|
83
|
+
const slotStartMs = slotStartTs * 1000n;
|
|
84
|
+
const elapsedMs = Number(nowMs - slotStartMs);
|
|
85
|
+
const windowMs = windowSeconds * 1000 + MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS;
|
|
86
|
+
|
|
87
|
+
return elapsedMs < windowMs;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export class PipeliningWindow {
|
|
91
|
+
private readonly proposalWindowIntoTargetSlot: number;
|
|
92
|
+
private readonly attestationWindowIntoTargetSlot: number;
|
|
93
|
+
|
|
94
|
+
constructor(
|
|
95
|
+
private readonly epochCache: EpochCacheInterface,
|
|
96
|
+
opts: {
|
|
97
|
+
p2pPropagationTime?: number;
|
|
98
|
+
l1PublishingTime?: number;
|
|
99
|
+
} = {},
|
|
100
|
+
) {
|
|
101
|
+
const l1Constants = epochCache.getL1Constants();
|
|
102
|
+
const checkpointTiming = createPipelinedCheckpointTimingModel({
|
|
103
|
+
aztecSlotDuration: l1Constants.slotDuration,
|
|
104
|
+
ethereumSlotDuration: l1Constants.ethereumSlotDuration,
|
|
105
|
+
l1PublishingTime: opts.l1PublishingTime ?? l1Constants.ethereumSlotDuration,
|
|
106
|
+
p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
this.proposalWindowIntoTargetSlot = checkpointTiming.proposalWindowIntoTargetSlot;
|
|
110
|
+
this.attestationWindowIntoTargetSlot = checkpointTiming.attestationWindowIntoTargetSlot;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public acceptsProposal(messageSlot: SlotNumber): boolean {
|
|
114
|
+
return isWithinPipeliningWindow(messageSlot, this.epochCache, this.proposalWindowIntoTargetSlot);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public acceptsAttestation(messageSlot: SlotNumber): boolean {
|
|
118
|
+
return isWithinPipeliningWindow(messageSlot, this.epochCache, this.attestationWindowIntoTargetSlot);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -28,7 +28,7 @@ Deserialization guards: `BlockProposal.fromBuffer` and `SignedTxs.fromBuffer` bo
|
|
|
28
28
|
| # | Rule | Consequence |
|
|
29
29
|
|---|------|-------------|
|
|
30
30
|
| 9 | **Duplicate**: same archive root already stored | IGNORE (no penalty) |
|
|
31
|
-
| 10 | **Per-position cap**: max
|
|
31
|
+
| 10 | **Per-position cap**: max 2 proposals per (slot, indexWithinCheckpoint) | REJECT + HighToleranceError |
|
|
32
32
|
| 11 | **Equivocation**: >1 distinct proposal for same (slot, index) | ACCEPT (rebroadcast for detection). At count=2: `duplicateProposalCallback` fires -> slash event (`OffenseType.DUPLICATE_PROPOSAL`, configured via `slashDuplicateProposalPenalty`) |
|
|
33
33
|
|
|
34
34
|
### Stage 3: Validator-Client Processing (BlockProposalHandler)
|
|
@@ -53,7 +53,7 @@ Only runs on validator nodes. Non-validator nodes use a default handler that tri
|
|
|
53
53
|
|
|
54
54
|
**Escape hatch**: during escape hatch periods (`isEscapeHatchOpenAtSlot`), re-execution and slashing are both disabled, and the proposal is rejected locally.
|
|
55
55
|
|
|
56
|
-
**Conditional re-execution**: rules 22-24 only run when at least one condition is true: `fishermanMode` enabled, `slashBroadcastedInvalidBlockPenalty > 0
|
|
56
|
+
**Conditional re-execution**: rules 22-24 only run when at least one condition is true: `fishermanMode` enabled, `slashBroadcastedInvalidBlockPenalty > 0`, committee membership, `alwaysReexecuteBlockProposals`, or `blobClient.canUpload()`.
|
|
57
57
|
|
|
58
58
|
**Slashing**: only `state_mismatch` and `failed_txs` trigger on-chain slashing (`OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL`, gated by `slashBroadcastedInvalidBlockPenalty > 0`). Unknown errors during re-execution do NOT slash.
|
|
59
59
|
|
|
@@ -84,7 +84,7 @@ The checkpoint's embedded `lastBlock` is extracted via `getBlockProposal()` and
|
|
|
84
84
|
| Rule | Consequence | File |
|
|
85
85
|
|------|-------------|------|
|
|
86
86
|
| Block proposal must pass `BlockProposalValidator.validate()` | If REJECT: entire checkpoint REJECTED | `libp2p_service.ts` |
|
|
87
|
-
| Block proposal must not exceed per-position cap (
|
|
87
|
+
| Block proposal must not exceed per-position cap (2) | Checkpoint REJECTED + HighToleranceError | same |
|
|
88
88
|
| Block equivocation detected (>1 proposals for same slot+index) | Checkpoint REJECTED (block itself is ACCEPT for re-broadcast) | same |
|
|
89
89
|
|
|
90
90
|
### Stage 3: Mempool (Attestation Pool)
|
|
@@ -92,7 +92,7 @@ The checkpoint's embedded `lastBlock` is extracted via `getBlockProposal()` and
|
|
|
92
92
|
| Rule | Consequence | File |
|
|
93
93
|
|------|-------------|------|
|
|
94
94
|
| Duplicate (same archive ID) | IGNORE (no penalty). Embedded block still processed if valid. | `attestation_pool.ts` |
|
|
95
|
-
| Per-slot cap: `MAX_CHECKPOINT_PROPOSALS_PER_SLOT` =
|
|
95
|
+
| Per-slot cap: `MAX_CHECKPOINT_PROPOSALS_PER_SLOT` = 2 | REJECT + HighToleranceError. Embedded block still processed. | same |
|
|
96
96
|
|
|
97
97
|
### Stage 4: Equivocation Detection
|
|
98
98
|
|
|
@@ -6,7 +6,10 @@ import { ProposalValidator } from '../proposal_validator/proposal_validator.js';
|
|
|
6
6
|
export class BlockProposalValidator implements P2PValidator<BlockProposal> {
|
|
7
7
|
private proposalValidator: ProposalValidator;
|
|
8
8
|
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(
|
|
10
|
+
epochCache: EpochCacheInterface,
|
|
11
|
+
opts: { txsPermitted: boolean; maxTxsPerBlock?: number; p2pPropagationTime?: number },
|
|
12
|
+
) {
|
|
10
13
|
this.proposalValidator = new ProposalValidator(epochCache, opts, 'p2p:block_proposal_validator');
|
|
11
14
|
}
|
|
12
15
|
|
|
@@ -6,7 +6,10 @@ import { ProposalValidator } from '../proposal_validator/proposal_validator.js';
|
|
|
6
6
|
export class CheckpointProposalValidator implements P2PValidator<CheckpointProposal> {
|
|
7
7
|
private proposalValidator: ProposalValidator;
|
|
8
8
|
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(
|
|
10
|
+
epochCache: EpochCacheInterface,
|
|
11
|
+
opts: { txsPermitted: boolean; maxTxsPerBlock?: number; p2pPropagationTime?: number },
|
|
12
|
+
) {
|
|
10
13
|
this.proposalValidator = new ProposalValidator(epochCache, opts, 'p2p:checkpoint_proposal_validator');
|
|
11
14
|
}
|
|
12
15
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
type ValidationResult,
|
|
9
9
|
} from '@aztec/stdlib/p2p';
|
|
10
10
|
|
|
11
|
-
import { isWithinClockTolerance } from '../clock_tolerance.js';
|
|
11
|
+
import { PipeliningWindow, isWithinClockTolerance } from '../clock_tolerance.js';
|
|
12
12
|
|
|
13
13
|
/** Validates header-level and tx-level fields of block and checkpoint proposals. */
|
|
14
14
|
export class ProposalValidator {
|
|
@@ -16,32 +16,39 @@ export class ProposalValidator {
|
|
|
16
16
|
private logger: Logger;
|
|
17
17
|
private txsPermitted: boolean;
|
|
18
18
|
private maxTxsPerBlock?: number;
|
|
19
|
+
private pipeliningWindow: PipeliningWindow;
|
|
19
20
|
|
|
20
21
|
constructor(
|
|
21
22
|
epochCache: EpochCacheInterface,
|
|
22
|
-
opts: { txsPermitted: boolean; maxTxsPerBlock?: number },
|
|
23
|
+
opts: { txsPermitted: boolean; maxTxsPerBlock?: number; p2pPropagationTime?: number },
|
|
23
24
|
loggerName: string,
|
|
24
25
|
) {
|
|
25
26
|
this.epochCache = epochCache;
|
|
26
27
|
this.txsPermitted = opts.txsPermitted;
|
|
27
28
|
this.maxTxsPerBlock = opts.maxTxsPerBlock;
|
|
29
|
+
this.pipeliningWindow = new PipeliningWindow(epochCache, { p2pPropagationTime: opts.p2pPropagationTime });
|
|
28
30
|
this.logger = createLogger(loggerName);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/** Validates header-level fields: slot, signature, and proposer. */
|
|
32
34
|
public async validate(proposal: BlockProposal | CheckpointProposalCore): Promise<ValidationResult> {
|
|
33
35
|
try {
|
|
34
|
-
// Slot check
|
|
35
|
-
const {
|
|
36
|
+
// Slot check: use target slots since proposals target pipeline slots (slot + 1 when pipelining).
|
|
37
|
+
const { targetSlot, nextSlot } = this.epochCache.getTargetAndNextSlot();
|
|
38
|
+
|
|
36
39
|
const slotNumber = proposal.slotNumber;
|
|
37
|
-
if (slotNumber !==
|
|
38
|
-
//
|
|
39
|
-
if
|
|
40
|
-
|
|
40
|
+
if (slotNumber !== targetSlot && slotNumber !== nextSlot) {
|
|
41
|
+
// When pipelining, accept proposals for the current slot (built in the previous slot)
|
|
42
|
+
// if they're still within the shared proposal acceptance window.
|
|
43
|
+
if (this.pipeliningWindow.acceptsProposal(slotNumber)) {
|
|
44
|
+
// Fall through to remaining validation (signature, proposer, etc.)
|
|
45
|
+
} else if (!isWithinClockTolerance(slotNumber, targetSlot, this.epochCache)) {
|
|
46
|
+
this.logger.warn(`Penalizing peer for invalid slot number ${slotNumber}`, { targetSlot, nextSlot });
|
|
41
47
|
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
48
|
+
} else {
|
|
49
|
+
this.logger.verbose(`Ignoring proposal for previous slot ${slotNumber} within clock tolerance`);
|
|
50
|
+
return { result: 'ignore' };
|
|
42
51
|
}
|
|
43
|
-
this.logger.verbose(`Ignoring proposal for previous slot ${slotNumber} within clock tolerance`);
|
|
44
|
-
return { result: 'ignore' };
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
// Signature validity
|