@aztec/p2p 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c
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 +2 -3
- package/dest/client/interface.d.ts +18 -5
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +16 -19
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +460 -127
- package/dest/config.d.ts +4 -7
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +10 -13
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +61 -42
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +239 -265
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -18
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +114 -109
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -16
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +89 -128
- package/dest/mem_pools/attestation_pool/mocks.d.ts +11 -8
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +17 -13
- package/dest/mem_pools/instrumentation.d.ts +7 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +30 -12
- package/dest/mem_pools/interface.d.ts +3 -4
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +37 -27
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +314 -335
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/mem_pools/tx_pool/index.d.ts +1 -2
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +6 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +11 -6
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- 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 +30 -24
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +52 -19
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +18 -14
- package/dest/msg_validators/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -0
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- 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/factory.d.ts +4 -3
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
- 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 +8 -14
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/size_validator.d.ts +6 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +20 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/services/dummy_service.d.ts +6 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +3 -0
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -6
- package/dest/services/libp2p/instrumentation.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +20 -73
- package/dest/services/libp2p/libp2p_service.d.ts +31 -14
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +722 -168
- package/dest/services/peer-manager/metrics.d.ts +6 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +18 -21
- package/dest/services/peer-manager/peer_manager.d.ts +2 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +4 -12
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +2 -5
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- package/dest/services/reqresp/interface.d.ts +2 -2
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +1 -1
- 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 +5 -21
- package/dest/services/reqresp/protocols/auth.d.ts +2 -2
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.js +2 -2
- package/dest/services/reqresp/protocols/block.d.ts +1 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +7 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +2 -2
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +5 -4
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +7 -3
- package/dest/services/reqresp/protocols/tx.d.ts +2 -3
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +402 -24
- package/dest/services/service.d.ts +16 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -3
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +4 -14
- package/dest/services/tx_collection/slow_tx_collection.d.ts +4 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +7 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +4 -2
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +11 -2
- package/dest/services/tx_provider_instrumentation.d.ts +5 -2
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +13 -13
- package/dest/test-helpers/mock-tx-helpers.js +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +31 -17
- package/dest/testbench/worker_client_manager.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -1
- package/package.json +18 -18
- package/src/client/factory.ts +5 -10
- package/src/client/interface.ts +19 -4
- package/src/client/p2p_client.ts +101 -154
- package/src/config.ts +12 -18
- package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -289
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +163 -141
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
- package/src/mem_pools/attestation_pool/mocks.ts +21 -15
- package/src/mem_pools/instrumentation.ts +38 -14
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +367 -371
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/mem_pools/tx_pool/index.ts +0 -1
- package/src/mem_pools/tx_pool/priority.ts +8 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +11 -5
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +23 -17
- package/src/msg_validators/attestation_validator/attestation_validator.ts +37 -22
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +13 -16
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +4 -2
- package/src/msg_validators/tx_validator/data_validator.ts +12 -4
- package/src/msg_validators/tx_validator/factory.ts +3 -2
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +8 -25
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +13 -5
- package/src/msg_validators/tx_validator/size_validator.ts +18 -0
- package/src/msg_validators/tx_validator/test_utils.ts +1 -1
- package/src/msg_validators/tx_validator/timestamp_validator.ts +5 -2
- package/src/services/dummy_service.ts +6 -0
- package/src/services/encoding.ts +6 -5
- package/src/services/libp2p/instrumentation.ts +19 -73
- package/src/services/libp2p/libp2p_service.ts +369 -138
- package/src/services/peer-manager/metrics.ts +22 -21
- package/src/services/peer-manager/peer_manager.ts +5 -4
- package/src/services/peer-manager/peer_scoring.ts +1 -5
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +3 -1
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/interface.ts +1 -1
- package/src/services/reqresp/metrics.ts +7 -23
- package/src/services/reqresp/protocols/auth.ts +2 -2
- package/src/services/reqresp/protocols/block.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +9 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
- package/src/services/reqresp/protocols/status.ts +16 -12
- package/src/services/reqresp/protocols/tx.ts +1 -2
- package/src/services/service.ts +19 -4
- package/src/services/tx_collection/config.ts +1 -1
- package/src/services/tx_collection/fast_tx_collection.ts +3 -2
- package/src/services/tx_collection/instrumentation.ts +4 -21
- package/src/services/tx_collection/slow_tx_collection.ts +3 -3
- package/src/services/tx_collection/tx_collection.ts +6 -5
- package/src/services/tx_provider.ts +19 -3
- package/src/services/tx_provider_instrumentation.ts +18 -14
- package/src/test-helpers/mock-pubsub.ts +1 -1
- package/src/test-helpers/mock-tx-helpers.ts +1 -1
- package/src/test-helpers/reqresp-nodes.ts +1 -1
- package/src/testbench/p2p_client_testbench_worker.ts +42 -22
- package/src/testbench/worker_client_manager.ts +6 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -80
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -238
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -283
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import type { TxHash } from '@aztec/stdlib/tx';
|
|
3
|
+
|
|
4
|
+
import type { TxPoolOptions } from '../tx_pool.js';
|
|
5
|
+
import {
|
|
6
|
+
type EvictionContext,
|
|
7
|
+
EvictionEvent,
|
|
8
|
+
type EvictionResult,
|
|
9
|
+
type EvictionRule,
|
|
10
|
+
type TxPoolOperations,
|
|
11
|
+
} from './eviction_strategy.js';
|
|
12
|
+
|
|
13
|
+
export interface LowPriorityEvictionConfig {
|
|
14
|
+
/** Maximum number of pending transactions before eviction kicks in */
|
|
15
|
+
maxPoolSize: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Eviction rule that removes low-priority transactions when the number of pending transactions exceeds configured limits.
|
|
20
|
+
* Only triggers on TXS_ADDED events and respects non-evictable transactions.
|
|
21
|
+
*/
|
|
22
|
+
export class LowPriorityEvictionRule implements EvictionRule {
|
|
23
|
+
public readonly name = 'LowPriorityEviction';
|
|
24
|
+
|
|
25
|
+
private log = createLogger('p2p:mempool:tx_pool:low_priority_eviction_rule');
|
|
26
|
+
|
|
27
|
+
constructor(private config: LowPriorityEvictionConfig) {}
|
|
28
|
+
|
|
29
|
+
public async evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult> {
|
|
30
|
+
if (context.event !== EvictionEvent.TXS_ADDED) {
|
|
31
|
+
return {
|
|
32
|
+
reason: 'low_priority',
|
|
33
|
+
success: true,
|
|
34
|
+
txsEvicted: [],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (this.config.maxPoolSize === 0) {
|
|
39
|
+
return {
|
|
40
|
+
reason: 'low_priority',
|
|
41
|
+
success: true,
|
|
42
|
+
txsEvicted: [],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const currentTxCount = await txPool.getPendingTxCount();
|
|
48
|
+
const maxCount = this.config.maxPoolSize;
|
|
49
|
+
|
|
50
|
+
if (currentTxCount <= maxCount) {
|
|
51
|
+
this.log.trace(`Not evicting low priority txs. Pending tx count below limit ${currentTxCount} <= ${maxCount}`);
|
|
52
|
+
return {
|
|
53
|
+
reason: 'low_priority',
|
|
54
|
+
success: true,
|
|
55
|
+
txsEvicted: [],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.log.verbose(`Evicting low priority txs. Pending tx count above limit: ${currentTxCount} > ${maxCount}`);
|
|
60
|
+
const numberToEvict = currentTxCount - maxCount;
|
|
61
|
+
const txsToEvict: TxHash[] = await txPool.getLowestPriorityEvictable(numberToEvict);
|
|
62
|
+
|
|
63
|
+
if (txsToEvict.length > 0) {
|
|
64
|
+
await txPool.deleteTxs(txsToEvict);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const numNewTxsEvicted = context.newTxs.filter(newTxHash =>
|
|
68
|
+
txsToEvict.some(evictedTx => evictedTx.equals(newTxHash)),
|
|
69
|
+
).length;
|
|
70
|
+
|
|
71
|
+
this.log.verbose(`Evicted ${txsToEvict.length} low priority txs, including ${numNewTxsEvicted} newly added txs`, {
|
|
72
|
+
txsEvicted: txsToEvict,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
reason: 'low_priority',
|
|
77
|
+
success: true,
|
|
78
|
+
txsEvicted: txsToEvict,
|
|
79
|
+
};
|
|
80
|
+
} catch (err) {
|
|
81
|
+
this.log.error('Failed to evict low priority transactions', { err });
|
|
82
|
+
return {
|
|
83
|
+
reason: 'low_priority',
|
|
84
|
+
success: false,
|
|
85
|
+
txsEvicted: [],
|
|
86
|
+
error: new Error('Failed to evict low priority txs', { cause: err }),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Updates the configuration for this eviction rule
|
|
93
|
+
*/
|
|
94
|
+
updateConfig(config: TxPoolOptions): void {
|
|
95
|
+
if (config.maxPendingTxCount !== undefined) {
|
|
96
|
+
this.config.maxPoolSize = config.maxPendingTxCount;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Gets the current configuration
|
|
102
|
+
*/
|
|
103
|
+
getConfig(): LowPriorityEvictionConfig {
|
|
104
|
+
return { ...this.config };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { findIndexInSortedArray, insertIntoSortedArray } from '@aztec/foundation/array';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
import type { PreAddEvictionResult, PreAddEvictionRule, PreAddPoolAccess } from './eviction_strategy.js';
|
|
7
|
+
|
|
8
|
+
const cmpTxHash = (a: TxHash, b: TxHash) => Fr.cmp(a.hash, b.hash);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Pre-add eviction rule that checks for nullifier conflicts between incoming and existing transactions.
|
|
12
|
+
*
|
|
13
|
+
* When an incoming tx shares nullifiers with existing pending txs:
|
|
14
|
+
* - If the incoming tx has strictly higher priority fee, evict all conflicting txs
|
|
15
|
+
* - If any conflicting tx has equal or higher priority fee, reject the incoming tx
|
|
16
|
+
*
|
|
17
|
+
* This prevents nullifier spam attacks where an attacker floods the mempool with
|
|
18
|
+
* transactions spending the same nullifiers.
|
|
19
|
+
*/
|
|
20
|
+
export class NullifierConflictPreAddRule implements PreAddEvictionRule {
|
|
21
|
+
public readonly name = 'NullifierConflictPreAdd';
|
|
22
|
+
|
|
23
|
+
private log = createLogger('p2p:mempool:tx_pool:nullifier_conflict_pre_add_rule');
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Check if the incoming transaction conflicts with existing transactions via nullifiers.
|
|
27
|
+
*
|
|
28
|
+
* @param tx - The incoming transaction
|
|
29
|
+
* @param poolAccess - Read-only access to pool state
|
|
30
|
+
* @returns Result with rejection status and txs to evict
|
|
31
|
+
*/
|
|
32
|
+
async check(tx: Tx, poolAccess: PreAddPoolAccess): Promise<PreAddEvictionResult> {
|
|
33
|
+
const txHash = tx.getTxHash();
|
|
34
|
+
const nullifiers = tx.data.getNonEmptyNullifiers();
|
|
35
|
+
const txHashesToEvict: TxHash[] = [];
|
|
36
|
+
const incomingPriority = poolAccess.getTxPriority(tx);
|
|
37
|
+
|
|
38
|
+
for (const nullifier of nullifiers) {
|
|
39
|
+
const conflictingHash = await poolAccess.getTxHashByNullifier(nullifier);
|
|
40
|
+
|
|
41
|
+
if (
|
|
42
|
+
!conflictingHash ||
|
|
43
|
+
conflictingHash.equals(txHash) ||
|
|
44
|
+
findIndexInSortedArray(txHashesToEvict, conflictingHash, cmpTxHash) !== -1
|
|
45
|
+
) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Get the conflicting tx's priority
|
|
50
|
+
const conflictingTx = await poolAccess.getPendingTxByHash(conflictingHash);
|
|
51
|
+
if (!conflictingTx) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const conflictingPriority = poolAccess.getTxPriority(conflictingTx);
|
|
56
|
+
|
|
57
|
+
// If incoming tx has strictly higher priority, mark for eviction
|
|
58
|
+
// Otherwise, reject incoming tx (ties go to existing tx)
|
|
59
|
+
if (incomingPriority > conflictingPriority) {
|
|
60
|
+
insertIntoSortedArray(txHashesToEvict, conflictingHash, cmpTxHash);
|
|
61
|
+
} else {
|
|
62
|
+
this.log.debug(
|
|
63
|
+
`Rejecting tx ${txHash.toString()}: nullifier conflict with ${conflictingHash.toString()} which has higher or equal fee`,
|
|
64
|
+
);
|
|
65
|
+
return {
|
|
66
|
+
shouldReject: true,
|
|
67
|
+
txHashesToEvict: [],
|
|
68
|
+
reason: `nullifier conflict with ${conflictingHash.toString()}`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return { shouldReject: false, txHashesToEvict };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -7,7 +7,14 @@ import type { Tx } from '@aztec/stdlib/tx';
|
|
|
7
7
|
* We currently use the sum of the priority fees for the tx for this value, represented as hex.
|
|
8
8
|
*/
|
|
9
9
|
export function getPendingTxPriority(tx: Tx): string {
|
|
10
|
+
return Buffer32.fromBigInt(getTxPriorityFee(tx)).toString();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns the priority of a tx.
|
|
15
|
+
*/
|
|
16
|
+
export function getTxPriorityFee(tx: Tx): bigint {
|
|
10
17
|
const priorityFees = tx.getGasSettings().maxPriorityFeesPerGas;
|
|
11
18
|
const totalFees = priorityFees.feePerDaGas + priorityFees.feePerL2Gas;
|
|
12
|
-
return
|
|
19
|
+
return totalFees;
|
|
13
20
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
2
3
|
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
3
4
|
|
|
4
5
|
export type TxPoolOptions = {
|
|
5
|
-
|
|
6
|
-
txPoolOverflowFactor?: number;
|
|
6
|
+
maxPendingTxCount?: number;
|
|
7
7
|
archivedTxLimit?: number;
|
|
8
8
|
};
|
|
9
9
|
|
|
@@ -68,8 +68,9 @@ export interface TxPool extends TypedEventEmitter<TxPoolEvents> {
|
|
|
68
68
|
* Moves mined txs back to the pending set in the case of a reorg.
|
|
69
69
|
* Note: txs not known by this peer will be ignored.
|
|
70
70
|
* @param txHashes - Hashes of the txs to flag as pending.
|
|
71
|
+
* @param latestBlock - The block number the chain was pruned to.
|
|
71
72
|
*/
|
|
72
|
-
markMinedAsPending(txHashes: TxHash[]): Promise<void>;
|
|
73
|
+
markMinedAsPending(txHashes: TxHash[], latestBlock: BlockNumber): Promise<void>;
|
|
73
74
|
|
|
74
75
|
/**
|
|
75
76
|
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
@@ -102,7 +103,7 @@ export interface TxPool extends TypedEventEmitter<TxPoolEvents> {
|
|
|
102
103
|
* Gets the hashes of mined transactions currently in the tx pool.
|
|
103
104
|
* @returns An array of mined transaction hashes found in the tx pool.
|
|
104
105
|
*/
|
|
105
|
-
getMinedTxHashes(): Promise<[tx: TxHash, blockNumber:
|
|
106
|
+
getMinedTxHashes(): Promise<[tx: TxHash, blockNumber: BlockNumber][]>;
|
|
106
107
|
|
|
107
108
|
/**
|
|
108
109
|
* Returns whether the given tx hash is flagged as pending, mined, or deleted.
|
|
@@ -126,10 +127,15 @@ export interface TxPool extends TypedEventEmitter<TxPoolEvents> {
|
|
|
126
127
|
*/
|
|
127
128
|
markTxsAsNonEvictable(txHashes: TxHash[]): Promise<void>;
|
|
128
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Clears collection of non-evictable transactions in the pool
|
|
132
|
+
*/
|
|
133
|
+
clearNonEvictableTxs(): Promise<void>;
|
|
134
|
+
|
|
129
135
|
/**
|
|
130
136
|
* Permanently deletes deleted mined transactions from blocks up to and including the specified block number.
|
|
131
137
|
* @param blockNumber - Block number threshold. Deleted mined txs from this block or earlier will be permanently deleted.
|
|
132
138
|
* @returns The number of transactions permanently deleted.
|
|
133
139
|
*/
|
|
134
|
-
cleanupDeletedMinedTxs(blockNumber:
|
|
140
|
+
cleanupDeletedMinedTxs(blockNumber: BlockNumber): Promise<number>;
|
|
135
141
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { unfreeze } from '@aztec/foundation/types';
|
|
2
3
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
3
4
|
import { mockTx } from '@aztec/stdlib/testing';
|
|
@@ -13,7 +14,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
13
14
|
let pool: TxPool;
|
|
14
15
|
|
|
15
16
|
const minedBlockHeader = BlockHeader.empty({
|
|
16
|
-
globalVariables: GlobalVariables.empty({ blockNumber: 1, timestamp: 0n }),
|
|
17
|
+
globalVariables: GlobalVariables.empty({ blockNumber: BlockNumber(1), timestamp: 0n }),
|
|
17
18
|
});
|
|
18
19
|
|
|
19
20
|
beforeEach(() => {
|
|
@@ -25,7 +26,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
it('adds txs to the pool as pending', async () => {
|
|
28
|
-
const tx1 = await mockTx();
|
|
29
|
+
const tx1 = await mockTx(1);
|
|
29
30
|
|
|
30
31
|
await pool.addTxs([tx1]);
|
|
31
32
|
const poolTx = await pool.getTxByHash(tx1.getTxHash());
|
|
@@ -36,9 +37,9 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
it('emits txs-added event with new txs', async () => {
|
|
39
|
-
const tx1 = await mockTx(); // existing and pending
|
|
40
|
-
const tx2 = await mockTx(); // mined but not known
|
|
41
|
-
const tx3 = await mockTx(); // brand new
|
|
40
|
+
const tx1 = await mockTx(1); // existing and pending
|
|
41
|
+
const tx2 = await mockTx(2); // mined but not known
|
|
42
|
+
const tx3 = await mockTx(3); // brand new
|
|
42
43
|
|
|
43
44
|
await pool.addTxs([tx1]);
|
|
44
45
|
await pool.markAsMined([tx2.getTxHash()], minedBlockHeader);
|
|
@@ -51,10 +52,11 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
51
52
|
await pool.addTxs([tx1, tx2, tx3]);
|
|
52
53
|
expect(txsFromEvent).toBeDefined();
|
|
53
54
|
expect(txsFromEvent).toHaveLength(2);
|
|
54
|
-
|
|
55
|
+
const eventHashes = txsFromEvent!.map(tx => tx.getTxHash());
|
|
56
|
+
expect(eventHashes).toEqual(expect.arrayContaining([tx2.getTxHash(), tx3.getTxHash()]));
|
|
55
57
|
});
|
|
56
58
|
|
|
57
|
-
it('
|
|
59
|
+
it('removes txs from the pool', async () => {
|
|
58
60
|
const pendingTx = await mockTx(1);
|
|
59
61
|
const minedTx = await mockTx(2);
|
|
60
62
|
|
|
@@ -82,7 +84,8 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
82
84
|
await pool.addTxs([tx1, tx2]);
|
|
83
85
|
await pool.markAsMined([tx1.getTxHash()], minedBlockHeader);
|
|
84
86
|
|
|
85
|
-
await
|
|
87
|
+
const retrievedTx = await pool.getTxByHash(tx1.getTxHash());
|
|
88
|
+
expect(retrievedTx?.getTxHash()).toEqual(tx1.getTxHash());
|
|
86
89
|
await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('mined');
|
|
87
90
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([[tx1.getTxHash(), 1]]);
|
|
88
91
|
await expect(pool.getPendingTxHashes()).resolves.toEqual([tx2.getTxHash()]);
|
|
@@ -96,7 +99,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
96
99
|
await pool.addTxs([tx1, tx2]);
|
|
97
100
|
await pool.markAsMined([tx1.getTxHash()], minedBlockHeader);
|
|
98
101
|
|
|
99
|
-
await pool.markMinedAsPending([tx1.getTxHash()]);
|
|
102
|
+
await pool.markMinedAsPending([tx1.getTxHash()], BlockNumber(1));
|
|
100
103
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
101
104
|
const pending = await pool.getPendingTxHashes();
|
|
102
105
|
expect(pending).toHaveLength(2);
|
|
@@ -120,7 +123,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
120
123
|
);
|
|
121
124
|
|
|
122
125
|
// reorg: both txs should now become available again
|
|
123
|
-
await pool.markMinedAsPending([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee]);
|
|
126
|
+
await pool.markMinedAsPending([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee], BlockNumber(1));
|
|
124
127
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
125
128
|
await expect(pool.getPendingTxHashes()).resolves.toEqual([tx1.getTxHash()]); // tx2 is not in the pool
|
|
126
129
|
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
@@ -135,7 +138,8 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
135
138
|
|
|
136
139
|
const poolTxs = await pool.getAllTxs();
|
|
137
140
|
expect(poolTxs).toHaveLength(3);
|
|
138
|
-
|
|
141
|
+
const poolHashes = poolTxs.map(tx => tx.getTxHash());
|
|
142
|
+
expect(poolHashes).toEqual(expect.arrayContaining([tx1.getTxHash(), tx2.getTxHash(), tx3.getTxHash()]));
|
|
139
143
|
await expect(pool.getPendingTxCount()).resolves.toEqual(3);
|
|
140
144
|
});
|
|
141
145
|
|
|
@@ -162,17 +166,19 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
162
166
|
|
|
163
167
|
const requestedTxs = await pool.getTxsByHash([tx1.getTxHash(), tx3.getTxHash()]);
|
|
164
168
|
expect(requestedTxs).toHaveLength(2);
|
|
165
|
-
|
|
169
|
+
const requestedHashes = requestedTxs.map(tx => tx!.getTxHash());
|
|
170
|
+
expect(requestedHashes).toEqual(expect.arrayContaining([tx1.getTxHash(), tx3.getTxHash()]));
|
|
166
171
|
});
|
|
167
172
|
|
|
168
173
|
it('returns a large number of transactions by their hash', async () => {
|
|
169
|
-
const numTxs =
|
|
174
|
+
const numTxs = 1_000;
|
|
170
175
|
const txs = await Promise.all(Array.from({ length: numTxs }, (_, i) => mockTx(i)));
|
|
171
176
|
const hashes = txs.map(tx => tx.getTxHash());
|
|
172
177
|
await pool.addTxs(txs);
|
|
173
178
|
const requestedTxs = await pool.getTxsByHash(hashes);
|
|
174
179
|
expect(requestedTxs).toHaveLength(numTxs);
|
|
175
|
-
|
|
180
|
+
const requestedHashes = requestedTxs.map(tx => tx!.getTxHash());
|
|
181
|
+
expect(requestedHashes).toEqual(expect.arrayContaining(hashes));
|
|
176
182
|
});
|
|
177
183
|
|
|
178
184
|
it('returns whether or not txs exist', async () => {
|
|
@@ -261,7 +267,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
261
267
|
await pool.deleteTxs([txs[0].getTxHash(), txs[1].getTxHash()]);
|
|
262
268
|
|
|
263
269
|
// Clean up deleted mined txs from block 1 and earlier
|
|
264
|
-
const deletedCount = await pool.cleanupDeletedMinedTxs(1);
|
|
270
|
+
const deletedCount = await pool.cleanupDeletedMinedTxs(BlockNumber(1));
|
|
265
271
|
|
|
266
272
|
// Verify old transactions are permanently deleted
|
|
267
273
|
expect(deletedCount).toBe(2);
|
|
@@ -276,7 +282,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
276
282
|
|
|
277
283
|
// Mark as mined in block 2
|
|
278
284
|
const laterBlockHeader = BlockHeader.empty({
|
|
279
|
-
globalVariables: GlobalVariables.empty({ blockNumber: 2, timestamp: 0n }),
|
|
285
|
+
globalVariables: GlobalVariables.empty({ blockNumber: BlockNumber(2), timestamp: 0n }),
|
|
280
286
|
});
|
|
281
287
|
await pool.markAsMined([txs[0].getTxHash()], laterBlockHeader);
|
|
282
288
|
|
|
@@ -284,7 +290,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
284
290
|
await pool.deleteTxs([txs[0].getTxHash()]);
|
|
285
291
|
|
|
286
292
|
// Try to clean up with block 1 (before the mined block)
|
|
287
|
-
const deletedCount = await pool.cleanupDeletedMinedTxs(1);
|
|
293
|
+
const deletedCount = await pool.cleanupDeletedMinedTxs(BlockNumber(1));
|
|
288
294
|
|
|
289
295
|
// Verify no transactions were cleaned up
|
|
290
296
|
expect(deletedCount).toBe(0);
|
|
@@ -1,67 +1,82 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { NoCommitteeError } from '@aztec/ethereum';
|
|
2
|
+
import { NoCommitteeError } from '@aztec/ethereum/contracts';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type CheckpointAttestation,
|
|
6
|
+
type P2PValidator,
|
|
7
|
+
PeerErrorSeverity,
|
|
8
|
+
type ValidationResult,
|
|
9
|
+
} from '@aztec/stdlib/p2p';
|
|
5
10
|
|
|
6
|
-
|
|
11
|
+
import { isWithinClockTolerance } from '../clock_tolerance.js';
|
|
12
|
+
|
|
13
|
+
export class CheckpointAttestationValidator implements P2PValidator<CheckpointAttestation> {
|
|
7
14
|
protected epochCache: EpochCacheInterface;
|
|
8
15
|
protected logger: Logger;
|
|
9
16
|
|
|
10
17
|
constructor(epochCache: EpochCacheInterface) {
|
|
11
18
|
this.epochCache = epochCache;
|
|
12
|
-
this.logger = createLogger('p2p:attestation-validator');
|
|
19
|
+
this.logger = createLogger('p2p:checkpoint-attestation-validator');
|
|
13
20
|
}
|
|
14
21
|
|
|
15
|
-
async validate(message:
|
|
22
|
+
async validate(message: CheckpointAttestation): Promise<ValidationResult> {
|
|
16
23
|
const slotNumber = message.payload.header.slotNumber;
|
|
17
24
|
|
|
18
25
|
try {
|
|
19
|
-
const {
|
|
20
|
-
await this.epochCache.getProposerAttesterAddressInCurrentOrNextSlot();
|
|
26
|
+
const { currentSlot, nextSlot } = this.epochCache.getCurrentAndNextSlot();
|
|
21
27
|
|
|
22
28
|
if (slotNumber !== currentSlot && slotNumber !== nextSlot) {
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
// Check if message is for previous slot and within clock tolerance
|
|
30
|
+
if (!isWithinClockTolerance(slotNumber, currentSlot, this.epochCache)) {
|
|
31
|
+
this.logger.warn(
|
|
32
|
+
`Checkpoint attestation slot ${slotNumber} is not current (${currentSlot}) or next (${nextSlot}) slot`,
|
|
33
|
+
);
|
|
34
|
+
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
35
|
+
}
|
|
36
|
+
this.logger.debug(`Ignoring checkpoint attestation for previous slot ${slotNumber} within clock tolerance`);
|
|
37
|
+
return { result: 'ignore' };
|
|
25
38
|
}
|
|
26
39
|
|
|
27
40
|
// Verify the signature is valid
|
|
28
41
|
const attester = message.getSender();
|
|
29
42
|
if (attester === undefined) {
|
|
30
|
-
this.logger.warn(`Invalid signature in attestation for slot ${slotNumber}`);
|
|
31
|
-
return PeerErrorSeverity.LowToleranceError;
|
|
43
|
+
this.logger.warn(`Invalid signature in checkpoint attestation for slot ${slotNumber}`);
|
|
44
|
+
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
32
45
|
}
|
|
33
46
|
|
|
34
47
|
// Verify the attester is in the committee for this slot
|
|
35
48
|
if (!(await this.epochCache.isInCommittee(slotNumber, attester))) {
|
|
36
49
|
this.logger.warn(`Attester ${attester.toString()} is not in committee for slot ${slotNumber}`);
|
|
37
|
-
return PeerErrorSeverity.HighToleranceError;
|
|
50
|
+
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
38
51
|
}
|
|
39
52
|
|
|
40
|
-
// Verify the proposer signature matches the expected proposer for
|
|
53
|
+
// Verify the proposer signature matches the expected proposer for the attestation's slot
|
|
54
|
+
// We look up the proposer for the specific slot rather than using currentSlot/nextSlot
|
|
55
|
+
// since timing differences could cause mismatches
|
|
41
56
|
const proposer = message.getProposer();
|
|
42
|
-
const expectedProposer = slotNumber
|
|
57
|
+
const expectedProposer = await this.epochCache.getProposerAttesterAddressInSlot(slotNumber);
|
|
43
58
|
if (!expectedProposer) {
|
|
44
59
|
this.logger.warn(`No proposer defined for slot ${slotNumber}`);
|
|
45
|
-
return PeerErrorSeverity.HighToleranceError;
|
|
60
|
+
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
46
61
|
}
|
|
47
62
|
if (!proposer) {
|
|
48
|
-
this.logger.warn(`Invalid proposer signature in attestation for slot ${slotNumber}`);
|
|
49
|
-
return PeerErrorSeverity.LowToleranceError;
|
|
63
|
+
this.logger.warn(`Invalid proposer signature in checkpoint attestation for slot ${slotNumber}`);
|
|
64
|
+
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
50
65
|
}
|
|
51
66
|
if (!proposer.equals(expectedProposer)) {
|
|
52
67
|
this.logger.warn(
|
|
53
|
-
`Proposer signature mismatch in attestation. ` +
|
|
68
|
+
`Proposer signature mismatch in checkpoint attestation. ` +
|
|
54
69
|
`Expected ${expectedProposer?.toString() ?? 'none'} but got ${proposer.toString()} for slot ${slotNumber}`,
|
|
55
70
|
);
|
|
56
|
-
return PeerErrorSeverity.HighToleranceError;
|
|
71
|
+
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
57
72
|
}
|
|
58
73
|
|
|
59
|
-
return
|
|
74
|
+
return { result: 'accept' };
|
|
60
75
|
} catch (e) {
|
|
61
76
|
// People shouldn't be sending us attestations if the committee doesn't exist
|
|
62
77
|
if (e instanceof NoCommitteeError) {
|
|
63
|
-
this.logger.warn(`No committee exists for attestation for slot ${slotNumber}`);
|
|
64
|
-
return PeerErrorSeverity.LowToleranceError;
|
|
78
|
+
this.logger.warn(`No committee exists for checkpoint attestation for slot ${slotNumber}`);
|
|
79
|
+
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
65
80
|
}
|
|
66
81
|
throw e;
|
|
67
82
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { type
|
|
3
|
-
import { Attributes, Metrics, type TelemetryClient
|
|
2
|
+
import { type CheckpointAttestation, PeerErrorSeverity, type ValidationResult } from '@aztec/stdlib/p2p';
|
|
3
|
+
import { Attributes, Metrics, type TelemetryClient } from '@aztec/telemetry-client';
|
|
4
4
|
|
|
5
5
|
import type { AttestationPool } from '../../mem_pools/attestation_pool/attestation_pool.js';
|
|
6
|
-
import {
|
|
6
|
+
import { CheckpointAttestationValidator } from './attestation_validator.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* FishermanAttestationValidator extends the base AttestationValidator to add
|
|
@@ -13,7 +13,7 @@ import { AttestationValidator } from './attestation_validator.js';
|
|
|
13
13
|
* handled by LibP2PService based on the fishermanMode config to ensure a better
|
|
14
14
|
* view of the network.
|
|
15
15
|
*/
|
|
16
|
-
export class FishermanAttestationValidator extends
|
|
16
|
+
export class FishermanAttestationValidator extends CheckpointAttestationValidator {
|
|
17
17
|
private invalidAttestationCounter;
|
|
18
18
|
|
|
19
19
|
constructor(
|
|
@@ -25,16 +25,13 @@ export class FishermanAttestationValidator extends AttestationValidator {
|
|
|
25
25
|
this.logger = this.logger.createChild('[FISHERMAN]');
|
|
26
26
|
|
|
27
27
|
const meter = telemetryClient.getMeter('FishermanAttestationValidator');
|
|
28
|
-
this.invalidAttestationCounter = meter.createUpDownCounter(Metrics.VALIDATOR_INVALID_ATTESTATION_RECEIVED_COUNT
|
|
29
|
-
description: 'The number of invalid attestations received',
|
|
30
|
-
valueType: ValueType.INT,
|
|
31
|
-
});
|
|
28
|
+
this.invalidAttestationCounter = meter.createUpDownCounter(Metrics.VALIDATOR_INVALID_ATTESTATION_RECEIVED_COUNT);
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
override async validate(message:
|
|
31
|
+
override async validate(message: CheckpointAttestation): Promise<ValidationResult> {
|
|
35
32
|
// First run the standard validation
|
|
36
33
|
const baseValidationResult = await super.validate(message);
|
|
37
|
-
if (baseValidationResult !==
|
|
34
|
+
if (baseValidationResult.result !== 'accept') {
|
|
38
35
|
// Track base validation failures (invalid signature, wrong committee, etc.)
|
|
39
36
|
this.invalidAttestationCounter.add(1, {
|
|
40
37
|
[Attributes.ERROR_TYPE]: 'base_validation_failed',
|
|
@@ -48,15 +45,15 @@ export class FishermanAttestationValidator extends AttestationValidator {
|
|
|
48
45
|
const proposer = message.getProposer();
|
|
49
46
|
|
|
50
47
|
if (!attester || !proposer) {
|
|
51
|
-
return
|
|
48
|
+
return { result: 'accept' };
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
const proposalId = message.archive.toString();
|
|
55
|
-
const proposal = await this.attestationPool.
|
|
52
|
+
const proposal = await this.attestationPool.getCheckpointProposal(proposalId);
|
|
56
53
|
|
|
57
54
|
if (proposal) {
|
|
58
55
|
// Compare the attestation payload with the proposal payload
|
|
59
|
-
if (!message.payload.equals(proposal
|
|
56
|
+
if (!message.payload.equals(proposal)) {
|
|
60
57
|
this.logger.error(
|
|
61
58
|
`Attestation payload mismatch for slot ${slotNumberBigInt}! ` +
|
|
62
59
|
`Attester ${attester.toString()} signed different data than the proposal.`,
|
|
@@ -66,7 +63,7 @@ export class FishermanAttestationValidator extends AttestationValidator {
|
|
|
66
63
|
proposer: proposer.toString(),
|
|
67
64
|
proposalArchive: proposal.archive.toString(),
|
|
68
65
|
attestationArchive: message.archive.toString(),
|
|
69
|
-
proposalHeader: proposal.
|
|
66
|
+
proposalHeader: proposal.checkpointHeader.hash().toString(),
|
|
70
67
|
attestationHeader: message.payload.header.hash().toString(),
|
|
71
68
|
},
|
|
72
69
|
);
|
|
@@ -77,7 +74,7 @@ export class FishermanAttestationValidator extends AttestationValidator {
|
|
|
77
74
|
});
|
|
78
75
|
|
|
79
76
|
// Return error to reject the message, but LibP2PService won't penalize in fisherman mode
|
|
80
|
-
return PeerErrorSeverity.LowToleranceError;
|
|
77
|
+
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
81
78
|
}
|
|
82
79
|
} else {
|
|
83
80
|
// We might receive attestations before proposals in some cases
|
|
@@ -86,6 +83,6 @@ export class FishermanAttestationValidator extends AttestationValidator {
|
|
|
86
83
|
);
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
return
|
|
86
|
+
return { result: 'accept' };
|
|
90
87
|
}
|
|
91
88
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Maximum clock disparity tolerance for P2P message validation (in milliseconds).
|
|
6
|
+
* Messages for the previous slot are accepted if we're within this many milliseconds
|
|
7
|
+
* of the current slot start. This prevents penalizing peers for messages that
|
|
8
|
+
* were valid when sent but arrived slightly late due to network latency.
|
|
9
|
+
*
|
|
10
|
+
* This follows Ethereum's MAXIMUM_GOSSIP_CLOCK_DISPARITY approach.
|
|
11
|
+
*/
|
|
12
|
+
export const MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS = 500;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a message for the previous slot should be accepted due to clock tolerance.
|
|
16
|
+
*
|
|
17
|
+
* @param messageSlot - The slot number from the received message
|
|
18
|
+
* @param currentSlot - The current slot number
|
|
19
|
+
* @param epochCache - EpochCache to get timing information
|
|
20
|
+
* @returns true if the message is for the previous slot AND we're within the clock tolerance window
|
|
21
|
+
*/
|
|
22
|
+
export function isWithinClockTolerance(
|
|
23
|
+
messageSlot: SlotNumber,
|
|
24
|
+
currentSlot: SlotNumber,
|
|
25
|
+
epochCache: EpochCacheInterface,
|
|
26
|
+
): boolean {
|
|
27
|
+
// Guard against slot 0 edge case (genesis)
|
|
28
|
+
if (currentSlot === SlotNumber.ZERO) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Only apply tolerance to messages for the previous slot
|
|
33
|
+
const previousSlot = SlotNumber(currentSlot - 1);
|
|
34
|
+
if (messageSlot !== previousSlot) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Check how far we are into the current slot (in milliseconds)
|
|
39
|
+
const { ts: slotStartTs, nowMs, slot } = epochCache.getEpochAndSlotNow();
|
|
40
|
+
|
|
41
|
+
// Sanity check: ensure the epoch cache's current slot matches the expected current slot
|
|
42
|
+
if (slot !== currentSlot) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ts is in seconds, convert to ms; nowMs is already in milliseconds
|
|
47
|
+
const slotStartMs = slotStartTs * 1000n;
|
|
48
|
+
const elapsedMs = Number(nowMs - slotStartMs);
|
|
49
|
+
|
|
50
|
+
return elapsedMs < MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS;
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
+
import type { BlockProposal, P2PValidator } from '@aztec/stdlib/p2p';
|
|
3
|
+
|
|
4
|
+
import { ProposalValidator } from '../proposal_validator/proposal_validator.js';
|
|
5
|
+
|
|
6
|
+
export class BlockProposalValidator extends ProposalValidator<BlockProposal> implements P2PValidator<BlockProposal> {
|
|
7
|
+
constructor(epochCache: EpochCacheInterface, opts: { txsPermitted: boolean }) {
|
|
8
|
+
super(epochCache, opts, 'p2p:block_proposal_validator');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
+
import type { CheckpointProposal, P2PValidator } from '@aztec/stdlib/p2p';
|
|
3
|
+
|
|
4
|
+
import { ProposalValidator } from '../proposal_validator/proposal_validator.js';
|
|
5
|
+
|
|
6
|
+
export class CheckpointProposalValidator
|
|
7
|
+
extends ProposalValidator<CheckpointProposal>
|
|
8
|
+
implements P2PValidator<CheckpointProposal>
|
|
9
|
+
{
|
|
10
|
+
constructor(epochCache: EpochCacheInterface, opts: { txsPermitted: boolean }) {
|
|
11
|
+
super(epochCache, opts, 'p2p:checkpoint_proposal_validator');
|
|
12
|
+
}
|
|
13
|
+
}
|