@aztec/p2p 0.0.1-commit.fcb71a6 → 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/interface.d.ts +18 -5
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +10 -13
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +449 -118
- package/dest/config.js +2 -2
- 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 +237 -263
- 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 +113 -108
- 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 +9 -6
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +16 -12
- package/dest/mem_pools/instrumentation.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +4 -13
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +15 -10
- 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 +91 -50
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +19 -5
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +59 -3
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +79 -5
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +47 -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 +2 -2
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- 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/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 +51 -18
- 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/block_header_validator.d.ts +1 -1
- 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/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 +1 -1
- 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/timestamp_validator.d.ts +1 -1
- 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 +6 -5
- 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 +28 -11
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +711 -152
- package/dest/services/peer-manager/metrics.d.ts +1 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -26
- 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 +0 -10
- 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/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/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/status.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -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/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 +3 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +5 -5
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +6 -19
- package/dest/testbench/p2p_client_testbench_worker.js +30 -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 +16 -16
- package/src/client/interface.ts +19 -4
- package/src/client/p2p_client.ts +82 -132
- package/src/config.ts +2 -2
- package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
- package/src/mem_pools/attestation_pool/mocks.ts +19 -13
- package/src/mem_pools/instrumentation.ts +9 -18
- package/src/mem_pools/tx_pool/README.md +28 -13
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +130 -75
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +66 -5
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +119 -4
- 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_reorg_rule.ts +4 -2
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +36 -21
- 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/block_header_validator.ts +3 -1
- package/src/msg_validators/tx_validator/data_validator.ts +12 -4
- 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 +12 -4
- package/src/msg_validators/tx_validator/size_validator.ts +18 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +3 -1
- package/src/services/dummy_service.ts +6 -0
- package/src/services/encoding.ts +5 -4
- package/src/services/libp2p/instrumentation.ts +19 -73
- package/src/services/libp2p/libp2p_service.ts +351 -115
- package/src/services/peer-manager/metrics.ts +5 -26
- package/src/services/peer-manager/peer_manager.ts +1 -2
- 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/metrics.ts +7 -23
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +9 -0
- package/src/services/reqresp/protocols/status.ts +7 -4
- package/src/services/service.ts +19 -4
- package/src/services/tx_collection/instrumentation.ts +4 -21
- package/src/services/tx_collection/slow_tx_collection.ts +2 -2
- package/src/services/tx_collection/tx_collection.ts +4 -4
- package/src/services/tx_provider.ts +2 -2
- package/src/services/tx_provider_instrumentation.ts +11 -24
- package/src/testbench/p2p_client_testbench_worker.ts +40 -21
- package/src/testbench/worker_client_manager.ts +6 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
- 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/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
- 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,16 @@
|
|
|
1
|
+
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
2
|
+
import type { TxPoolOptions } from '../tx_pool.js';
|
|
3
|
+
import { type EvictionContext, type EvictionResult, type EvictionRule, type TxPoolOperations } from './eviction_strategy.js';
|
|
4
|
+
export declare class FeePayerBalanceEvictionRule implements EvictionRule {
|
|
5
|
+
private worldState;
|
|
6
|
+
readonly name = "FeePayerBalanceEviction";
|
|
7
|
+
readonly reason = "fee_payer_balance";
|
|
8
|
+
private log;
|
|
9
|
+
constructor(worldState: WorldStateSynchronizer);
|
|
10
|
+
evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult>;
|
|
11
|
+
updateConfig(_config: TxPoolOptions): void;
|
|
12
|
+
private evictForFeePayers;
|
|
13
|
+
private getEvictionsForFeePayer;
|
|
14
|
+
private createPublicStateSource;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmVlX3BheWVyX2JhbGFuY2VfZXZpY3Rpb25fcnVsZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL21lbV9wb29scy90eF9wb29sL2V2aWN0aW9uL2ZlZV9wYXllcl9iYWxhbmNlX2V2aWN0aW9uX3J1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUEsT0FBTyxLQUFLLEVBQUUsc0JBQXNCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUk5RSxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDbkQsT0FBTyxFQUNMLEtBQUssZUFBZSxFQUVwQixLQUFLLGNBQWMsRUFDbkIsS0FBSyxZQUFZLEVBRWpCLEtBQUssZ0JBQWdCLEVBQ3RCLE1BQU0sd0JBQXdCLENBQUM7QUFFaEMscUJBQWEsMkJBQTRCLFlBQVcsWUFBWTtJQU1sRCxPQUFPLENBQUMsVUFBVTtJQUw5QixTQUFnQixJQUFJLDZCQUE2QjtJQUNqRCxTQUFnQixNQUFNLHVCQUF1QjtJQUU3QyxPQUFPLENBQUMsR0FBRyxDQUF1RTtJQUVsRixZQUFvQixVQUFVLEVBQUUsc0JBQXNCLEVBQUk7SUFFcEQsS0FBSyxDQUFDLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSxFQUFFLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0E4Q3ZGO0lBRUQsWUFBWSxDQUFDLE9BQU8sRUFBRSxhQUFhLEdBQUcsSUFBSSxDQUFHO1lBRS9CLGlCQUFpQjtZQXNCakIsdUJBQXVCO0lBNERyQyxPQUFPLENBQUMsdUJBQXVCO0NBR2hDIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee_payer_balance_eviction_rule.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAI9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,cAAc,EACnB,KAAK,YAAY,EAEjB,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAEhC,qBAAa,2BAA4B,YAAW,YAAY;IAMlD,OAAO,CAAC,UAAU;IAL9B,SAAgB,IAAI,6BAA6B;IACjD,SAAgB,MAAM,uBAAuB;IAE7C,OAAO,CAAC,GAAG,CAAuE;IAElF,YAAoB,UAAU,EAAE,sBAAsB,EAAI;IAEpD,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CA8CvF;IAED,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAG;YAE/B,iBAAiB;YAsBjB,uBAAuB;IA4DrC,OAAO,CAAC,uBAAuB;CAGhC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
|
+
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
|
+
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
5
|
+
import { EvictionEvent } from './eviction_strategy.js';
|
|
6
|
+
export class FeePayerBalanceEvictionRule {
|
|
7
|
+
worldState;
|
|
8
|
+
name;
|
|
9
|
+
reason;
|
|
10
|
+
log;
|
|
11
|
+
constructor(worldState){
|
|
12
|
+
this.worldState = worldState;
|
|
13
|
+
this.name = 'FeePayerBalanceEviction';
|
|
14
|
+
this.reason = 'fee_payer_balance';
|
|
15
|
+
this.log = createLogger('p2p:mempool:tx_pool:fee_payer_balance_eviction_rule');
|
|
16
|
+
}
|
|
17
|
+
async evict(context, txPool) {
|
|
18
|
+
try {
|
|
19
|
+
if (context.event === EvictionEvent.TXS_ADDED) {
|
|
20
|
+
return await this.evictForFeePayers(context.feePayers, this.worldState.getCommitted(), txPool);
|
|
21
|
+
}
|
|
22
|
+
if (context.event === EvictionEvent.BLOCK_MINED) {
|
|
23
|
+
const blockNumber = context.block.getBlockNumber();
|
|
24
|
+
// Ensure world state is synced to this block before accessing the snapshot.
|
|
25
|
+
// This handles the race where a block is added to the archiver
|
|
26
|
+
// but the world state hasn't synced it yet.
|
|
27
|
+
await this.worldState.syncImmediate(blockNumber);
|
|
28
|
+
return await this.evictForFeePayers(context.feePayers, this.worldState.getSnapshot(blockNumber), txPool);
|
|
29
|
+
}
|
|
30
|
+
// TODO: fix this edge-case
|
|
31
|
+
// This can lead to a race condition if we are catching up in the p2p client.
|
|
32
|
+
// Let's say we have 3 txs for the same fee payer, which get mined in blocks 1, 2, 3.
|
|
33
|
+
// Tx1 consumes fee juice, tx2 increases it, tx3 consumes it again. We see block1 with tx1 first, run this rule, and evict tx3.
|
|
34
|
+
// But tx3 was valid (due to tx2) and mined on block3. And we have just removed from the mempool a tx we needed for proving/reexec.
|
|
35
|
+
//
|
|
36
|
+
// NOTE: this will happen only in case of that lower-priority-fee tx entered in e.g. block 2, and we have higher-priority-fee tx in block 3
|
|
37
|
+
// (simply because that was the timing of these txs). But, in case of higher-priority-fee txs being in block 2, the tx3 won't be evicted
|
|
38
|
+
// -----
|
|
39
|
+
// Proposed fix: evict only if node is synched
|
|
40
|
+
if (context.event === EvictionEvent.CHAIN_PRUNED) {
|
|
41
|
+
// Ensure world state is synced to this block before accessing the snapshot.
|
|
42
|
+
await this.worldState.syncImmediate(context.blockNumber);
|
|
43
|
+
const feePayers = await txPool.getPendingFeePayers();
|
|
44
|
+
return await this.evictForFeePayers(feePayers, this.worldState.getSnapshot(context.blockNumber), txPool);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
reason: this.reason,
|
|
48
|
+
success: true,
|
|
49
|
+
txsEvicted: []
|
|
50
|
+
};
|
|
51
|
+
} catch (err) {
|
|
52
|
+
this.log.error('Failed to evict txs due to fee payer balance', {
|
|
53
|
+
err
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
reason: this.reason,
|
|
57
|
+
success: false,
|
|
58
|
+
txsEvicted: [],
|
|
59
|
+
error: new Error('Failed to evict txs due to fee payer balance', {
|
|
60
|
+
cause: err
|
|
61
|
+
})
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
updateConfig(_config) {}
|
|
66
|
+
async evictForFeePayers(feePayers, db, txPool) {
|
|
67
|
+
const publicStateSource = this.createPublicStateSource(db);
|
|
68
|
+
const txsToEvict = (await Promise.all(feePayers.map((feePayer)=>this.getEvictionsForFeePayer(feePayer, publicStateSource, txPool)))).flat();
|
|
69
|
+
if (txsToEvict.length > 0) {
|
|
70
|
+
await txPool.deleteTxs(txsToEvict);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
reason: this.reason,
|
|
74
|
+
success: true,
|
|
75
|
+
txsEvicted: txsToEvict
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async getEvictionsForFeePayer(feePayer, publicStateSource, txPool) {
|
|
79
|
+
const initialBalance = (await publicStateSource.storageRead(ProtocolContractAddress.FeeJuice, //TODO: cache this LRU-style
|
|
80
|
+
await computeFeePayerBalanceStorageSlot(feePayer))).toBigInt();
|
|
81
|
+
const txs = [];
|
|
82
|
+
for await (const entry of txPool.getFeePayerTxInfos(feePayer)){
|
|
83
|
+
txs.push(entry);
|
|
84
|
+
}
|
|
85
|
+
if (txs.length === 0) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
const txsToEvict = [];
|
|
89
|
+
let balance = initialBalance;
|
|
90
|
+
let hasNonEvictableOverBalance = false;
|
|
91
|
+
// Evaluate balance in priority order so later claims cannot fund earlier spends.
|
|
92
|
+
// This sorts so that higher priority txs come first.
|
|
93
|
+
txs.sort((a, b)=>{
|
|
94
|
+
if (a.priority === b.priority) {
|
|
95
|
+
return a.txHash.toBigInt() >= b.txHash.toBigInt() ? -1 : 1;
|
|
96
|
+
}
|
|
97
|
+
return a.priority > b.priority ? -1 : 1;
|
|
98
|
+
});
|
|
99
|
+
for (const tx of txs){
|
|
100
|
+
const available = balance + tx.claimAmount;
|
|
101
|
+
if (available >= tx.feeLimit) {
|
|
102
|
+
balance = available - tx.feeLimit;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (tx.isEvictable) {
|
|
106
|
+
txsToEvict.push(tx.txHash);
|
|
107
|
+
} else {
|
|
108
|
+
hasNonEvictableOverBalance = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (hasNonEvictableOverBalance) {
|
|
112
|
+
this.log.verbose('Fee payer balance cannot be satisfied due to non-evictable txs', {
|
|
113
|
+
feePayer: feePayer.toString(),
|
|
114
|
+
balance: initialBalance
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return txsToEvict;
|
|
118
|
+
}
|
|
119
|
+
createPublicStateSource(db) {
|
|
120
|
+
return new DatabasePublicStateSource(db);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -9,9 +9,9 @@ import { type EvictionContext, type EvictionResult, type EvictionRule, type TxPo
|
|
|
9
9
|
* - Transactions with an expiration timestamp less than or equal to the mined block timestamp
|
|
10
10
|
*/
|
|
11
11
|
export declare class InvalidTxsAfterMiningRule implements EvictionRule {
|
|
12
|
-
readonly name
|
|
12
|
+
readonly name = "InvalidTxsAfterMining";
|
|
13
13
|
private log;
|
|
14
14
|
evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult>;
|
|
15
15
|
updateConfig(_config: TxPoolOptions): void;
|
|
16
16
|
}
|
|
17
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
17
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW52YWxpZF90eHNfYWZ0ZXJfbWluaW5nX3J1bGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9tZW1fcG9vbHMvdHhfcG9vbC9ldmljdGlvbi9pbnZhbGlkX3R4c19hZnRlcl9taW5pbmdfcnVsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHQSxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDbkQsT0FBTyxFQUNMLEtBQUssZUFBZSxFQUVwQixLQUFLLGNBQWMsRUFDbkIsS0FBSyxZQUFZLEVBQ2pCLEtBQUssZ0JBQWdCLEVBQ3RCLE1BQU0sd0JBQXdCLENBQUM7QUFFaEM7Ozs7Ozs7R0FPRztBQUNILHFCQUFhLHlCQUEwQixZQUFXLFlBQVk7SUFDNUQsU0FBZ0IsSUFBSSwyQkFBMkI7SUFFL0MsT0FBTyxDQUFDLEdBQUcsQ0FBcUU7SUFFMUUsS0FBSyxDQUFDLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSxFQUFFLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0EyRXZGO0lBRUQsWUFBWSxDQUFDLE9BQU8sRUFBRSxhQUFhLEdBQUcsSUFBSSxDQUFHO0NBQzlDIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invalid_txs_after_mining_rule.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;GAOG;AACH,qBAAa,yBAA0B,YAAW,YAAY;IAC5D,SAAgB,IAAI,
|
|
1
|
+
{"version":3,"file":"invalid_txs_after_mining_rule.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;GAOG;AACH,qBAAa,yBAA0B,YAAW,YAAY;IAC5D,SAAgB,IAAI,2BAA2B;IAE/C,OAAO,CAAC,GAAG,CAAqE;IAE1E,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CA2EvF;IAED,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAG;CAC9C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
2
2
|
import type { TxPoolOptions } from '../tx_pool.js';
|
|
3
3
|
import { type EvictionContext, type EvictionResult, type EvictionRule, type TxPoolOperations } from './eviction_strategy.js';
|
|
4
4
|
/**
|
|
@@ -10,10 +10,10 @@ import { type EvictionContext, type EvictionResult, type EvictionRule, type TxPo
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class InvalidTxsAfterReorgRule implements EvictionRule {
|
|
12
12
|
private worldState;
|
|
13
|
-
readonly name
|
|
13
|
+
readonly name = "InvalidTxsAfterReorg";
|
|
14
14
|
private log;
|
|
15
|
-
constructor(worldState:
|
|
15
|
+
constructor(worldState: WorldStateSynchronizer);
|
|
16
16
|
evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult>;
|
|
17
17
|
updateConfig(_config: TxPoolOptions): void;
|
|
18
18
|
}
|
|
19
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW52YWxpZF90eHNfYWZ0ZXJfcmVvcmdfcnVsZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL21lbV9wb29scy90eF9wb29sL2V2aWN0aW9uL2ludmFsaWRfdHhzX2FmdGVyX3Jlb3JnX3J1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0EsT0FBTyxLQUFLLEVBQUUsc0JBQXNCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUk5RSxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDbkQsT0FBTyxFQUNMLEtBQUssZUFBZSxFQUVwQixLQUFLLGNBQWMsRUFDbkIsS0FBSyxZQUFZLEVBQ2pCLEtBQUssZ0JBQWdCLEVBQ3RCLE1BQU0sd0JBQXdCLENBQUM7QUFFaEM7Ozs7OztHQU1HO0FBQ0gscUJBQWEsd0JBQXlCLFlBQVcsWUFBWTtJQUt4QyxPQUFPLENBQUMsVUFBVTtJQUpyQyxTQUFnQixJQUFJLDBCQUEwQjtJQUU5QyxPQUFPLENBQUMsR0FBRyxDQUFvRTtJQUUvRSxZQUEyQixVQUFVLEVBQUUsc0JBQXNCLEVBQUk7SUFFM0QsS0FBSyxDQUFDLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSxFQUFFLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0EyRHZGO0lBRUQsWUFBWSxDQUFDLE9BQU8sRUFBRSxhQUFhLEdBQUcsSUFBSSxDQUFHO0NBQzlDIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invalid_txs_after_reorg_rule.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"invalid_txs_after_reorg_rule.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAI9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAEhC;;;;;;GAMG;AACH,qBAAa,wBAAyB,YAAW,YAAY;IAKxC,OAAO,CAAC,UAAU;IAJrC,SAAgB,IAAI,0BAA0B;IAE9C,OAAO,CAAC,GAAG,CAAoE;IAE/E,YAA2B,UAAU,EAAE,sBAAsB,EAAI;IAE3D,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CA2DvF;IAED,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAG;CAC9C"}
|
|
@@ -33,6 +33,8 @@ import { EvictionEvent } from './eviction_strategy.js';
|
|
|
33
33
|
candidateTxs.forEach(({ blockHash })=>{
|
|
34
34
|
insertIntoSortedArray(uniqueBlockHashes, blockHash, Fr.cmp, false);
|
|
35
35
|
});
|
|
36
|
+
// Ensure world state is synced to this block before accessing the snapshot.
|
|
37
|
+
await this.worldState.syncImmediate(context.blockNumber);
|
|
36
38
|
const db = this.worldState.getSnapshot(context.blockNumber);
|
|
37
39
|
const blocksFromDb = await db.findLeafIndices(MerkleTreeId.ARCHIVE, uniqueBlockHashes);
|
|
38
40
|
// Identify txs whose blockHash is not found in the archive (pruned)
|
|
@@ -10,7 +10,7 @@ export interface LowPriorityEvictionConfig {
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class LowPriorityEvictionRule implements EvictionRule {
|
|
12
12
|
private config;
|
|
13
|
-
readonly name
|
|
13
|
+
readonly name = "LowPriorityEviction";
|
|
14
14
|
private log;
|
|
15
15
|
constructor(config: LowPriorityEvictionConfig);
|
|
16
16
|
evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult>;
|
|
@@ -23,4 +23,4 @@ export declare class LowPriorityEvictionRule implements EvictionRule {
|
|
|
23
23
|
*/
|
|
24
24
|
getConfig(): LowPriorityEvictionConfig;
|
|
25
25
|
}
|
|
26
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
26
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG93X3ByaW9yaXR5X2V2aWN0aW9uX3J1bGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9tZW1fcG9vbHMvdHhfcG9vbC9ldmljdGlvbi9sb3dfcHJpb3JpdHlfZXZpY3Rpb25fcnVsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHQSxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDbkQsT0FBTyxFQUNMLEtBQUssZUFBZSxFQUVwQixLQUFLLGNBQWMsRUFDbkIsS0FBSyxZQUFZLEVBQ2pCLEtBQUssZ0JBQWdCLEVBQ3RCLE1BQU0sd0JBQXdCLENBQUM7QUFFaEMsTUFBTSxXQUFXLHlCQUF5QjtJQUN4QyxzRUFBc0U7SUFDdEUsV0FBVyxFQUFFLE1BQU0sQ0FBQztDQUNyQjtBQUVEOzs7R0FHRztBQUNILHFCQUFhLHVCQUF3QixZQUFXLFlBQVk7SUFLOUMsT0FBTyxDQUFDLE1BQU07SUFKMUIsU0FBZ0IsSUFBSSx5QkFBeUI7SUFFN0MsT0FBTyxDQUFDLEdBQUcsQ0FBa0U7SUFFN0UsWUFBb0IsTUFBTSxFQUFFLHlCQUF5QixFQUFJO0lBRTVDLEtBQUssQ0FBQyxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sRUFBRSxnQkFBZ0IsR0FBRyxPQUFPLENBQUMsY0FBYyxDQUFDLENBNEQ5RjtJQUVEOztPQUVHO0lBQ0gsWUFBWSxDQUFDLE1BQU0sRUFBRSxhQUFhLEdBQUcsSUFBSSxDQUl4QztJQUVEOztPQUVHO0lBQ0gsU0FBUyxJQUFJLHlCQUF5QixDQUVyQztDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"low_priority_eviction_rule.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,yBAAyB;IACxC,sEAAsE;IACtE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,YAAY;IAK9C,OAAO,CAAC,MAAM;IAJ1B,SAAgB,IAAI,
|
|
1
|
+
{"version":3,"file":"low_priority_eviction_rule.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,yBAAyB;IACxC,sEAAsE;IACtE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,YAAY;IAK9C,OAAO,CAAC,MAAM;IAJ1B,SAAgB,IAAI,yBAAyB;IAE7C,OAAO,CAAC,GAAG,CAAkE;IAE7E,YAAoB,MAAM,EAAE,yBAAyB,EAAI;IAE5C,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CA4D9F;IAED;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAIxC;IAED;;OAEG;IACH,SAAS,IAAI,yBAAyB,CAErC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Tx } from '@aztec/stdlib/tx';
|
|
2
|
+
import type { PreAddEvictionResult, PreAddEvictionRule, PreAddPoolAccess } from './eviction_strategy.js';
|
|
3
|
+
/**
|
|
4
|
+
* Pre-add eviction rule that checks for nullifier conflicts between incoming and existing transactions.
|
|
5
|
+
*
|
|
6
|
+
* When an incoming tx shares nullifiers with existing pending txs:
|
|
7
|
+
* - If the incoming tx has strictly higher priority fee, evict all conflicting txs
|
|
8
|
+
* - If any conflicting tx has equal or higher priority fee, reject the incoming tx
|
|
9
|
+
*
|
|
10
|
+
* This prevents nullifier spam attacks where an attacker floods the mempool with
|
|
11
|
+
* transactions spending the same nullifiers.
|
|
12
|
+
*/
|
|
13
|
+
export declare class NullifierConflictPreAddRule implements PreAddEvictionRule {
|
|
14
|
+
readonly name = "NullifierConflictPreAdd";
|
|
15
|
+
private log;
|
|
16
|
+
/**
|
|
17
|
+
* Check if the incoming transaction conflicts with existing transactions via nullifiers.
|
|
18
|
+
*
|
|
19
|
+
* @param tx - The incoming transaction
|
|
20
|
+
* @param poolAccess - Read-only access to pool state
|
|
21
|
+
* @returns Result with rejection status and txs to evict
|
|
22
|
+
*/
|
|
23
|
+
check(tx: Tx, poolAccess: PreAddPoolAccess): Promise<PreAddEvictionResult>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnVsbGlmaWVyX2NvbmZsaWN0X3ByZV9hZGRfcnVsZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL21lbV9wb29scy90eF9wb29sL2V2aWN0aW9uL251bGxpZmllcl9jb25mbGljdF9wcmVfYWRkX3J1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0EsT0FBTyxFQUFFLEtBQUssRUFBRSxFQUFVLE1BQU0sa0JBQWtCLENBQUM7QUFFbkQsT0FBTyxLQUFLLEVBQUUsb0JBQW9CLEVBQUUsa0JBQWtCLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUl6Rzs7Ozs7Ozs7O0dBU0c7QUFDSCxxQkFBYSwyQkFBNEIsWUFBVyxrQkFBa0I7SUFDcEUsU0FBZ0IsSUFBSSw2QkFBNkI7SUFFakQsT0FBTyxDQUFDLEdBQUcsQ0FBdUU7SUFFbEY7Ozs7OztPQU1HO0lBQ0csS0FBSyxDQUFDLEVBQUUsRUFBRSxFQUFFLEVBQUUsVUFBVSxFQUFFLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxvQkFBb0IsQ0FBQyxDQTBDL0U7Q0FDRiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nullifier_conflict_pre_add_rule.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,EAAU,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAIzG;;;;;;;;;GASG;AACH,qBAAa,2BAA4B,YAAW,kBAAkB;IACpE,SAAgB,IAAI,6BAA6B;IAEjD,OAAO,CAAC,GAAG,CAAuE;IAElF;;;;;;OAMG;IACG,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA0C/E;CACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { findIndexInSortedArray, insertIntoSortedArray } from '@aztec/foundation/array';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
const cmpTxHash = (a, b)=>Fr.cmp(a.hash, b.hash);
|
|
5
|
+
/**
|
|
6
|
+
* Pre-add eviction rule that checks for nullifier conflicts between incoming and existing transactions.
|
|
7
|
+
*
|
|
8
|
+
* When an incoming tx shares nullifiers with existing pending txs:
|
|
9
|
+
* - If the incoming tx has strictly higher priority fee, evict all conflicting txs
|
|
10
|
+
* - If any conflicting tx has equal or higher priority fee, reject the incoming tx
|
|
11
|
+
*
|
|
12
|
+
* This prevents nullifier spam attacks where an attacker floods the mempool with
|
|
13
|
+
* transactions spending the same nullifiers.
|
|
14
|
+
*/ export class NullifierConflictPreAddRule {
|
|
15
|
+
name = 'NullifierConflictPreAdd';
|
|
16
|
+
log = createLogger('p2p:mempool:tx_pool:nullifier_conflict_pre_add_rule');
|
|
17
|
+
/**
|
|
18
|
+
* Check if the incoming transaction conflicts with existing transactions via nullifiers.
|
|
19
|
+
*
|
|
20
|
+
* @param tx - The incoming transaction
|
|
21
|
+
* @param poolAccess - Read-only access to pool state
|
|
22
|
+
* @returns Result with rejection status and txs to evict
|
|
23
|
+
*/ async check(tx, poolAccess) {
|
|
24
|
+
const txHash = tx.getTxHash();
|
|
25
|
+
const nullifiers = tx.data.getNonEmptyNullifiers();
|
|
26
|
+
const txHashesToEvict = [];
|
|
27
|
+
const incomingPriority = poolAccess.getTxPriority(tx);
|
|
28
|
+
for (const nullifier of nullifiers){
|
|
29
|
+
const conflictingHash = await poolAccess.getTxHashByNullifier(nullifier);
|
|
30
|
+
if (!conflictingHash || conflictingHash.equals(txHash) || findIndexInSortedArray(txHashesToEvict, conflictingHash, cmpTxHash) !== -1) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
// Get the conflicting tx's priority
|
|
34
|
+
const conflictingTx = await poolAccess.getPendingTxByHash(conflictingHash);
|
|
35
|
+
if (!conflictingTx) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const conflictingPriority = poolAccess.getTxPriority(conflictingTx);
|
|
39
|
+
// If incoming tx has strictly higher priority, mark for eviction
|
|
40
|
+
// Otherwise, reject incoming tx (ties go to existing tx)
|
|
41
|
+
if (incomingPriority > conflictingPriority) {
|
|
42
|
+
insertIntoSortedArray(txHashesToEvict, conflictingHash, cmpTxHash);
|
|
43
|
+
} else {
|
|
44
|
+
this.log.debug(`Rejecting tx ${txHash.toString()}: nullifier conflict with ${conflictingHash.toString()} which has higher or equal fee`);
|
|
45
|
+
return {
|
|
46
|
+
shouldReject: true,
|
|
47
|
+
txHashesToEvict: [],
|
|
48
|
+
reason: `nullifier conflict with ${conflictingHash.toString()}`
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
shouldReject: false,
|
|
54
|
+
txHashesToEvict
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
2
|
import { type Logger } from '@aztec/foundation/log';
|
|
3
|
-
import { type
|
|
4
|
-
export declare class
|
|
3
|
+
import { type CheckpointAttestation, type P2PValidator, type ValidationResult } from '@aztec/stdlib/p2p';
|
|
4
|
+
export declare class CheckpointAttestationValidator implements P2PValidator<CheckpointAttestation> {
|
|
5
5
|
protected epochCache: EpochCacheInterface;
|
|
6
6
|
protected logger: Logger;
|
|
7
7
|
constructor(epochCache: EpochCacheInterface);
|
|
8
|
-
validate(message:
|
|
8
|
+
validate(message: CheckpointAttestation): Promise<ValidationResult>;
|
|
9
9
|
}
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0ZXN0YXRpb25fdmFsaWRhdG9yLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbXNnX3ZhbGlkYXRvcnMvYXR0ZXN0YXRpb25fdmFsaWRhdG9yL2F0dGVzdGF0aW9uX3ZhbGlkYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBRTlELE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUNsRSxPQUFPLEVBQ0wsS0FBSyxxQkFBcUIsRUFDMUIsS0FBSyxZQUFZLEVBRWpCLEtBQUssZ0JBQWdCLEVBQ3RCLE1BQU0sbUJBQW1CLENBQUM7QUFJM0IscUJBQWEsOEJBQStCLFlBQVcsWUFBWSxDQUFDLHFCQUFxQixDQUFDO0lBQ3hGLFNBQVMsQ0FBQyxVQUFVLEVBQUUsbUJBQW1CLENBQUM7SUFDMUMsU0FBUyxDQUFDLE1BQU0sRUFBRSxNQUFNLENBQUM7SUFFekIsWUFBWSxVQUFVLEVBQUUsbUJBQW1CLEVBRzFDO0lBRUssUUFBUSxDQUFDLE9BQU8sRUFBRSxxQkFBcUIsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0E2RHhFO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attestation_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/attestation_validator/attestation_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,
|
|
1
|
+
{"version":3,"file":"attestation_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/attestation_validator/attestation_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EAEjB,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAI3B,qBAAa,8BAA+B,YAAW,YAAY,CAAC,qBAAqB,CAAC;IACxF,SAAS,CAAC,UAAU,EAAE,mBAAmB,CAAC;IAC1C,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IAEzB,YAAY,UAAU,EAAE,mBAAmB,EAG1C;IAEK,QAAQ,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA6DxE;CACF"}
|
|
@@ -1,53 +1,86 @@
|
|
|
1
1
|
import { NoCommitteeError } from '@aztec/ethereum/contracts';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
4
|
-
|
|
4
|
+
import { isWithinClockTolerance } from '../clock_tolerance.js';
|
|
5
|
+
export class CheckpointAttestationValidator {
|
|
5
6
|
epochCache;
|
|
6
7
|
logger;
|
|
7
8
|
constructor(epochCache){
|
|
8
9
|
this.epochCache = epochCache;
|
|
9
|
-
this.logger = createLogger('p2p:attestation-validator');
|
|
10
|
+
this.logger = createLogger('p2p:checkpoint-attestation-validator');
|
|
10
11
|
}
|
|
11
12
|
async validate(message) {
|
|
12
13
|
const slotNumber = message.payload.header.slotNumber;
|
|
13
14
|
try {
|
|
14
|
-
const {
|
|
15
|
+
const { currentSlot, nextSlot } = this.epochCache.getCurrentAndNextSlot();
|
|
15
16
|
if (slotNumber !== currentSlot && slotNumber !== nextSlot) {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
// Check if message is for previous slot and within clock tolerance
|
|
18
|
+
if (!isWithinClockTolerance(slotNumber, currentSlot, this.epochCache)) {
|
|
19
|
+
this.logger.warn(`Checkpoint attestation slot ${slotNumber} is not current (${currentSlot}) or next (${nextSlot}) slot`);
|
|
20
|
+
return {
|
|
21
|
+
result: 'reject',
|
|
22
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
this.logger.debug(`Ignoring checkpoint attestation for previous slot ${slotNumber} within clock tolerance`);
|
|
26
|
+
return {
|
|
27
|
+
result: 'ignore'
|
|
28
|
+
};
|
|
18
29
|
}
|
|
19
30
|
// Verify the signature is valid
|
|
20
31
|
const attester = message.getSender();
|
|
21
32
|
if (attester === undefined) {
|
|
22
|
-
this.logger.warn(`Invalid signature in attestation for slot ${slotNumber}`);
|
|
23
|
-
return
|
|
33
|
+
this.logger.warn(`Invalid signature in checkpoint attestation for slot ${slotNumber}`);
|
|
34
|
+
return {
|
|
35
|
+
result: 'reject',
|
|
36
|
+
severity: PeerErrorSeverity.LowToleranceError
|
|
37
|
+
};
|
|
24
38
|
}
|
|
25
39
|
// Verify the attester is in the committee for this slot
|
|
26
40
|
if (!await this.epochCache.isInCommittee(slotNumber, attester)) {
|
|
27
41
|
this.logger.warn(`Attester ${attester.toString()} is not in committee for slot ${slotNumber}`);
|
|
28
|
-
return
|
|
42
|
+
return {
|
|
43
|
+
result: 'reject',
|
|
44
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
45
|
+
};
|
|
29
46
|
}
|
|
30
|
-
// Verify the proposer signature matches the expected proposer for
|
|
47
|
+
// Verify the proposer signature matches the expected proposer for the attestation's slot
|
|
48
|
+
// We look up the proposer for the specific slot rather than using currentSlot/nextSlot
|
|
49
|
+
// since timing differences could cause mismatches
|
|
31
50
|
const proposer = message.getProposer();
|
|
32
|
-
const expectedProposer = slotNumber
|
|
51
|
+
const expectedProposer = await this.epochCache.getProposerAttesterAddressInSlot(slotNumber);
|
|
33
52
|
if (!expectedProposer) {
|
|
34
53
|
this.logger.warn(`No proposer defined for slot ${slotNumber}`);
|
|
35
|
-
return
|
|
54
|
+
return {
|
|
55
|
+
result: 'reject',
|
|
56
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
57
|
+
};
|
|
36
58
|
}
|
|
37
59
|
if (!proposer) {
|
|
38
|
-
this.logger.warn(`Invalid proposer signature in attestation for slot ${slotNumber}`);
|
|
39
|
-
return
|
|
60
|
+
this.logger.warn(`Invalid proposer signature in checkpoint attestation for slot ${slotNumber}`);
|
|
61
|
+
return {
|
|
62
|
+
result: 'reject',
|
|
63
|
+
severity: PeerErrorSeverity.LowToleranceError
|
|
64
|
+
};
|
|
40
65
|
}
|
|
41
66
|
if (!proposer.equals(expectedProposer)) {
|
|
42
|
-
this.logger.warn(`Proposer signature mismatch in attestation. ` + `Expected ${expectedProposer?.toString() ?? 'none'} but got ${proposer.toString()} for slot ${slotNumber}`);
|
|
43
|
-
return
|
|
67
|
+
this.logger.warn(`Proposer signature mismatch in checkpoint attestation. ` + `Expected ${expectedProposer?.toString() ?? 'none'} but got ${proposer.toString()} for slot ${slotNumber}`);
|
|
68
|
+
return {
|
|
69
|
+
result: 'reject',
|
|
70
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
71
|
+
};
|
|
44
72
|
}
|
|
45
|
-
return
|
|
73
|
+
return {
|
|
74
|
+
result: 'accept'
|
|
75
|
+
};
|
|
46
76
|
} catch (e) {
|
|
47
77
|
// People shouldn't be sending us attestations if the committee doesn't exist
|
|
48
78
|
if (e instanceof NoCommitteeError) {
|
|
49
|
-
this.logger.warn(`No committee exists for attestation for slot ${slotNumber}`);
|
|
50
|
-
return
|
|
79
|
+
this.logger.warn(`No committee exists for checkpoint attestation for slot ${slotNumber}`);
|
|
80
|
+
return {
|
|
81
|
+
result: 'reject',
|
|
82
|
+
severity: PeerErrorSeverity.LowToleranceError
|
|
83
|
+
};
|
|
51
84
|
}
|
|
52
85
|
throw e;
|
|
53
86
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { type
|
|
2
|
+
import { type CheckpointAttestation, type ValidationResult } from '@aztec/stdlib/p2p';
|
|
3
3
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
4
4
|
import type { AttestationPool } from '../../mem_pools/attestation_pool/attestation_pool.js';
|
|
5
|
-
import {
|
|
5
|
+
import { CheckpointAttestationValidator } from './attestation_validator.js';
|
|
6
6
|
/**
|
|
7
7
|
* FishermanAttestationValidator extends the base AttestationValidator to add
|
|
8
8
|
* additional validation for fisherman nodes: verifying that attestations sign
|
|
@@ -11,10 +11,10 @@ import { AttestationValidator } from './attestation_validator.js';
|
|
|
11
11
|
* handled by LibP2PService based on the fishermanMode config to ensure a better
|
|
12
12
|
* view of the network.
|
|
13
13
|
*/
|
|
14
|
-
export declare class FishermanAttestationValidator extends
|
|
14
|
+
export declare class FishermanAttestationValidator extends CheckpointAttestationValidator {
|
|
15
15
|
private attestationPool;
|
|
16
16
|
private invalidAttestationCounter;
|
|
17
17
|
constructor(epochCache: EpochCacheInterface, attestationPool: AttestationPool, telemetryClient: TelemetryClient);
|
|
18
|
-
validate(message:
|
|
18
|
+
validate(message: CheckpointAttestation): Promise<ValidationResult>;
|
|
19
19
|
}
|
|
20
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmlzaGVybWFuX2F0dGVzdGF0aW9uX3ZhbGlkYXRvci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL21zZ192YWxpZGF0b3JzL2F0dGVzdGF0aW9uX3ZhbGlkYXRvci9maXNoZXJtYW5fYXR0ZXN0YXRpb25fdmFsaWRhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDOUQsT0FBTyxFQUFFLEtBQUsscUJBQXFCLEVBQXFCLEtBQUssZ0JBQWdCLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUN6RyxPQUFPLEVBQXVCLEtBQUssZUFBZSxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFcEYsT0FBTyxLQUFLLEVBQUUsZUFBZSxFQUFFLE1BQU0sc0RBQXNELENBQUM7QUFDNUYsT0FBTyxFQUFFLDhCQUE4QixFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFFNUU7Ozs7Ozs7R0FPRztBQUNILHFCQUFhLDZCQUE4QixTQUFRLDhCQUE4QjtJQUs3RSxPQUFPLENBQUMsZUFBZTtJQUp6QixPQUFPLENBQUMseUJBQXlCLENBQUM7SUFFbEMsWUFDRSxVQUFVLEVBQUUsbUJBQW1CLEVBQ3ZCLGVBQWUsRUFBRSxlQUFlLEVBQ3hDLGVBQWUsRUFBRSxlQUFlLEVBT2pDO0lBRWMsUUFBUSxDQUFDLE9BQU8sRUFBRSxxQkFBcUIsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0F3RGpGO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fisherman_attestation_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/attestation_validator/fisherman_attestation_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"fisherman_attestation_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/attestation_validator/fisherman_attestation_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,KAAK,qBAAqB,EAAqB,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACzG,OAAO,EAAuB,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAEpF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAE5E;;;;;;;GAOG;AACH,qBAAa,6BAA8B,SAAQ,8BAA8B;IAK7E,OAAO,CAAC,eAAe;IAJzB,OAAO,CAAC,yBAAyB,CAAC;IAElC,YACE,UAAU,EAAE,mBAAmB,EACvB,eAAe,EAAE,eAAe,EACxC,eAAe,EAAE,eAAe,EAOjC;IAEc,QAAQ,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAwDjF;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
2
|
-
import { Attributes, Metrics
|
|
3
|
-
import {
|
|
2
|
+
import { Attributes, Metrics } from '@aztec/telemetry-client';
|
|
3
|
+
import { CheckpointAttestationValidator } from './attestation_validator.js';
|
|
4
4
|
/**
|
|
5
5
|
* FishermanAttestationValidator extends the base AttestationValidator to add
|
|
6
6
|
* additional validation for fisherman nodes: verifying that attestations sign
|
|
@@ -8,22 +8,19 @@ import { AttestationValidator } from './attestation_validator.js';
|
|
|
8
8
|
* Invalid attestations are rejected (not propagated), but peer penalization is
|
|
9
9
|
* handled by LibP2PService based on the fishermanMode config to ensure a better
|
|
10
10
|
* view of the network.
|
|
11
|
-
*/ export class FishermanAttestationValidator extends
|
|
11
|
+
*/ export class FishermanAttestationValidator extends CheckpointAttestationValidator {
|
|
12
12
|
attestationPool;
|
|
13
13
|
invalidAttestationCounter;
|
|
14
14
|
constructor(epochCache, attestationPool, telemetryClient){
|
|
15
15
|
super(epochCache), this.attestationPool = attestationPool;
|
|
16
16
|
this.logger = this.logger.createChild('[FISHERMAN]');
|
|
17
17
|
const meter = telemetryClient.getMeter('FishermanAttestationValidator');
|
|
18
|
-
this.invalidAttestationCounter = meter.createUpDownCounter(Metrics.VALIDATOR_INVALID_ATTESTATION_RECEIVED_COUNT
|
|
19
|
-
description: 'The number of invalid attestations received',
|
|
20
|
-
valueType: ValueType.INT
|
|
21
|
-
});
|
|
18
|
+
this.invalidAttestationCounter = meter.createUpDownCounter(Metrics.VALIDATOR_INVALID_ATTESTATION_RECEIVED_COUNT);
|
|
22
19
|
}
|
|
23
20
|
async validate(message) {
|
|
24
21
|
// First run the standard validation
|
|
25
22
|
const baseValidationResult = await super.validate(message);
|
|
26
|
-
if (baseValidationResult !==
|
|
23
|
+
if (baseValidationResult.result !== 'accept') {
|
|
27
24
|
// Track base validation failures (invalid signature, wrong committee, etc.)
|
|
28
25
|
this.invalidAttestationCounter.add(1, {
|
|
29
26
|
[Attributes.ERROR_TYPE]: 'base_validation_failed'
|
|
@@ -35,20 +32,22 @@ import { AttestationValidator } from './attestation_validator.js';
|
|
|
35
32
|
const attester = message.getSender();
|
|
36
33
|
const proposer = message.getProposer();
|
|
37
34
|
if (!attester || !proposer) {
|
|
38
|
-
return
|
|
35
|
+
return {
|
|
36
|
+
result: 'accept'
|
|
37
|
+
};
|
|
39
38
|
}
|
|
40
39
|
const proposalId = message.archive.toString();
|
|
41
|
-
const proposal = await this.attestationPool.
|
|
40
|
+
const proposal = await this.attestationPool.getCheckpointProposal(proposalId);
|
|
42
41
|
if (proposal) {
|
|
43
42
|
// Compare the attestation payload with the proposal payload
|
|
44
|
-
if (!message.payload.equals(proposal
|
|
43
|
+
if (!message.payload.equals(proposal)) {
|
|
45
44
|
this.logger.error(`Attestation payload mismatch for slot ${slotNumberBigInt}! ` + `Attester ${attester.toString()} signed different data than the proposal.`, {
|
|
46
45
|
slot: slotNumberBigInt.toString(),
|
|
47
46
|
attester: attester.toString(),
|
|
48
47
|
proposer: proposer.toString(),
|
|
49
48
|
proposalArchive: proposal.archive.toString(),
|
|
50
49
|
attestationArchive: message.archive.toString(),
|
|
51
|
-
proposalHeader: proposal.
|
|
50
|
+
proposalHeader: proposal.checkpointHeader.hash().toString(),
|
|
52
51
|
attestationHeader: message.payload.header.hash().toString()
|
|
53
52
|
});
|
|
54
53
|
// Track invalid attestation metric
|
|
@@ -56,12 +55,17 @@ import { AttestationValidator } from './attestation_validator.js';
|
|
|
56
55
|
[Attributes.ERROR_TYPE]: 'payload_mismatch'
|
|
57
56
|
});
|
|
58
57
|
// Return error to reject the message, but LibP2PService won't penalize in fisherman mode
|
|
59
|
-
return
|
|
58
|
+
return {
|
|
59
|
+
result: 'reject',
|
|
60
|
+
severity: PeerErrorSeverity.LowToleranceError
|
|
61
|
+
};
|
|
60
62
|
}
|
|
61
63
|
} else {
|
|
62
64
|
// We might receive attestations before proposals in some cases
|
|
63
65
|
this.logger.debug(`Received attestation for slot ${slotNumberBigInt} but proposal not found yet. ` + `Proposal ID: ${proposalId}`);
|
|
64
66
|
}
|
|
65
|
-
return
|
|
67
|
+
return {
|
|
68
|
+
result: 'accept'
|
|
69
|
+
};
|
|
66
70
|
}
|
|
67
71
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
/**
|
|
4
|
+
* Maximum clock disparity tolerance for P2P message validation (in milliseconds).
|
|
5
|
+
* Messages for the previous slot are accepted if we're within this many milliseconds
|
|
6
|
+
* of the current slot start. This prevents penalizing peers for messages that
|
|
7
|
+
* were valid when sent but arrived slightly late due to network latency.
|
|
8
|
+
*
|
|
9
|
+
* This follows Ethereum's MAXIMUM_GOSSIP_CLOCK_DISPARITY approach.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS = 500;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a message for the previous slot should be accepted due to clock tolerance.
|
|
14
|
+
*
|
|
15
|
+
* @param messageSlot - The slot number from the received message
|
|
16
|
+
* @param currentSlot - The current slot number
|
|
17
|
+
* @param epochCache - EpochCache to get timing information
|
|
18
|
+
* @returns true if the message is for the previous slot AND we're within the clock tolerance window
|
|
19
|
+
*/
|
|
20
|
+
export declare function isWithinClockTolerance(messageSlot: SlotNumber, currentSlot: SlotNumber, epochCache: EpochCacheInterface): boolean;
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xvY2tfdG9sZXJhbmNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbXNnX3ZhbGlkYXRvcnMvY2xvY2tfdG9sZXJhbmNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDOUQsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRTdEOzs7Ozs7O0dBT0c7QUFDSCxlQUFPLE1BQU0saUNBQWlDLE1BQU0sQ0FBQztBQUVyRDs7Ozs7OztHQU9HO0FBQ0gsd0JBQWdCLHNCQUFzQixDQUNwQyxXQUFXLEVBQUUsVUFBVSxFQUN2QixXQUFXLEVBQUUsVUFBVSxFQUN2QixVQUFVLEVBQUUsbUJBQW1CLEdBQzlCLE9BQU8sQ0F5QlQifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock_tolerance.d.ts","sourceRoot":"","sources":["../../src/msg_validators/clock_tolerance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,MAAM,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,UAAU,EACvB,WAAW,EAAE,UAAU,EACvB,UAAU,EAAE,mBAAmB,GAC9B,OAAO,CAyBT"}
|