@aztec/p2p 0.0.1-commit.ef17749e1 → 0.0.1-commit.f103f88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -3
- package/dest/client/factory.d.ts +1 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +23 -10
- package/dest/client/interface.d.ts +9 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +3 -2
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +46 -14
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +17 -6
- package/dest/config.d.ts +111 -95
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +27 -2
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +7 -5
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +11 -8
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
- package/dest/mem_pools/index.d.ts +1 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +7 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +9 -2
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +13 -3
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +19 -5
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +5 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +20 -11
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +4 -2
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +2 -2
- package/dest/msg_validators/clock_tolerance.d.ts +12 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +54 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +19 -11
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +35 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +23 -4
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +36 -10
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +13 -4
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +49 -17
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +21 -1
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +28 -1
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +5 -5
- package/dest/services/dummy_service.d.ts +6 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +6 -1
- package/dest/services/encoding.d.ts +5 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -1
- package/dest/services/gossipsub/topic_score_params.d.ts +13 -2
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +21 -4
- package/dest/services/libp2p/libp2p_service.d.ts +15 -25
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +151 -118
- package/dest/services/peer-manager/peer_manager.d.ts +6 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +37 -10
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +32 -10
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +69 -65
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +3 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +3 -0
- package/dest/services/reqresp/config.d.ts +3 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/interface.d.ts +14 -9
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +10 -11
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +0 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +1 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +1 -3
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
- package/dest/services/reqresp/reqresp.d.ts +4 -2
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +28 -11
- package/dest/services/service.d.ts +5 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +57 -73
- package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +39 -29
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/slow_tx_collection.js +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +3 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.d.ts +6 -5
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +9 -7
- package/dest/test-helpers/mock-pubsub.d.ts +11 -3
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +35 -10
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +1 -2
- package/dest/test-helpers/testbench-utils.d.ts +1 -1
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +23 -3
- package/dest/testbench/p2p_client_testbench_worker.js +66 -15
- package/dest/testbench/worker_client_manager.d.ts +8 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +49 -1
- package/package.json +14 -14
- package/src/client/factory.ts +41 -13
- package/src/client/interface.ts +9 -1
- package/src/client/p2p_client.ts +50 -17
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +18 -8
- package/src/config.ts +48 -3
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +12 -8
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +2 -1
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/interfaces.ts +6 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +19 -3
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +13 -1
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +20 -5
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +21 -9
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +4 -1
- package/src/msg_validators/clock_tolerance.ts +72 -3
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +4 -1
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +4 -1
- package/src/msg_validators/proposal_validator/proposal_validator.ts +17 -10
- package/src/msg_validators/tx_validator/README.md +5 -1
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +42 -1
- package/src/msg_validators/tx_validator/factory.ts +43 -3
- package/src/msg_validators/tx_validator/gas_validator.ts +65 -16
- package/src/msg_validators/tx_validator/phases_validator.ts +31 -1
- package/src/services/data_store.ts +5 -13
- package/src/services/dummy_service.ts +8 -2
- package/src/services/encoding.ts +9 -1
- package/src/services/gossipsub/topic_score_params.ts +36 -4
- package/src/services/libp2p/libp2p_service.ts +150 -134
- package/src/services/peer-manager/peer_manager.ts +43 -10
- package/src/services/peer-manager/peer_scoring.ts +27 -5
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +64 -69
- package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +5 -0
- package/src/services/reqresp/config.ts +2 -2
- package/src/services/reqresp/interface.ts +21 -11
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +1 -3
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
- package/src/services/reqresp/reqresp.ts +37 -12
- package/src/services/service.ts +6 -1
- package/src/services/tx_collection/fast_tx_collection.ts +57 -83
- package/src/services/tx_collection/file_store_tx_source.ts +43 -31
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/slow_tx_collection.ts +1 -1
- package/src/services/tx_collection/tx_collection.ts +3 -5
- package/src/services/tx_collection/tx_source.ts +8 -7
- package/src/test-helpers/mock-pubsub.ts +31 -5
- package/src/test-helpers/reqresp-nodes.ts +2 -2
- package/src/test-helpers/testbench-utils.ts +30 -3
- package/src/testbench/p2p_client_testbench_worker.ts +70 -14
- package/src/testbench/worker_client_manager.ts +55 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
- package/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
- package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { ContractInstancePublishedEvent } from '@aztec/protocol-contracts/instance-registry';
|
|
3
|
+
import { computeContractAddressFromInstance } from '@aztec/stdlib/contract';
|
|
4
|
+
import {
|
|
5
|
+
TX_ERROR_INCORRECT_CONTRACT_ADDRESS,
|
|
6
|
+
TX_ERROR_MALFORMED_CONTRACT_INSTANCE_LOG,
|
|
7
|
+
type Tx,
|
|
8
|
+
type TxValidationResult,
|
|
9
|
+
type TxValidator,
|
|
10
|
+
} from '@aztec/stdlib/tx';
|
|
11
|
+
|
|
12
|
+
/** Validates that contract instance deployment logs contain correct addresses. */
|
|
13
|
+
export class ContractInstanceTxValidator implements TxValidator<Tx> {
|
|
14
|
+
#log: Logger;
|
|
15
|
+
|
|
16
|
+
constructor(bindings?: LoggerBindings) {
|
|
17
|
+
this.#log = createLogger('p2p:tx_validator:contract_instance', bindings);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async validateTx(tx: Tx): Promise<TxValidationResult> {
|
|
21
|
+
const reason = await this.#hasCorrectContractInstanceAddresses(tx);
|
|
22
|
+
return reason ? { result: 'invalid', reason: [reason] } : { result: 'valid' };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async #hasCorrectContractInstanceAddresses(tx: Tx): Promise<string | undefined> {
|
|
26
|
+
const privateLogs = tx.data.getNonEmptyPrivateLogs();
|
|
27
|
+
for (const log of privateLogs) {
|
|
28
|
+
if (!ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let event;
|
|
33
|
+
try {
|
|
34
|
+
event = ContractInstancePublishedEvent.fromLog(log);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to parse contract instance event: ${e}`);
|
|
37
|
+
return TX_ERROR_MALFORMED_CONTRACT_INSTANCE_LOG;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const instance = event.toContractInstance();
|
|
42
|
+
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
43
|
+
if (!computedAddress.equals(instance.address)) {
|
|
44
|
+
this.#log.warn(
|
|
45
|
+
`Rejecting tx ${tx.getTxHash()}: contract instance address mismatch. Claimed ${instance.address}, computed ${computedAddress}`,
|
|
46
|
+
);
|
|
47
|
+
return TX_ERROR_INCORRECT_CONTRACT_ADDRESS;
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to compute contract instance address: ${e}`);
|
|
51
|
+
return TX_ERROR_MALFORMED_CONTRACT_INSTANCE_LOG;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS } from '@aztec/constants';
|
|
2
2
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
4
|
+
import { computeContractClassId } from '@aztec/stdlib/contract';
|
|
3
5
|
import { computeCalldataHash } from '@aztec/stdlib/hash';
|
|
4
6
|
import {
|
|
5
7
|
TX_ERROR_CALLDATA_COUNT_MISMATCH,
|
|
@@ -9,7 +11,9 @@ import {
|
|
|
9
11
|
TX_ERROR_CONTRACT_CLASS_LOG_LENGTH,
|
|
10
12
|
TX_ERROR_CONTRACT_CLASS_LOG_SORTING,
|
|
11
13
|
TX_ERROR_INCORRECT_CALLDATA,
|
|
14
|
+
TX_ERROR_INCORRECT_CONTRACT_CLASS_ID,
|
|
12
15
|
TX_ERROR_INCORRECT_HASH,
|
|
16
|
+
TX_ERROR_MALFORMED_CONTRACT_CLASS_LOG,
|
|
13
17
|
Tx,
|
|
14
18
|
type TxValidationResult,
|
|
15
19
|
type TxValidator,
|
|
@@ -26,7 +30,8 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
26
30
|
const reason =
|
|
27
31
|
(await this.#hasCorrectHash(tx)) ??
|
|
28
32
|
(await this.#hasCorrectCalldata(tx)) ??
|
|
29
|
-
(await this.#hasCorrectContractClassLogs(tx))
|
|
33
|
+
(await this.#hasCorrectContractClassLogs(tx)) ??
|
|
34
|
+
(await this.#hasCorrectContractClassIds(tx));
|
|
30
35
|
return reason ? { result: 'invalid', reason: [reason] } : { result: 'valid' };
|
|
31
36
|
}
|
|
32
37
|
|
|
@@ -127,4 +132,40 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
127
132
|
|
|
128
133
|
return undefined;
|
|
129
134
|
}
|
|
135
|
+
|
|
136
|
+
async #hasCorrectContractClassIds(tx: Tx): Promise<string | undefined> {
|
|
137
|
+
const contractClassLogs = tx.getContractClassLogs();
|
|
138
|
+
for (const log of contractClassLogs) {
|
|
139
|
+
if (!ContractClassPublishedEvent.isContractClassPublishedEvent(log)) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let event;
|
|
144
|
+
try {
|
|
145
|
+
event = ContractClassPublishedEvent.fromLog(log);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to parse contract class event: ${e}`);
|
|
148
|
+
return TX_ERROR_MALFORMED_CONTRACT_CLASS_LOG;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
const { publicBytecodeCommitment } = await event.toContractClassPublicWithBytecodeCommitment();
|
|
153
|
+
const computedClassId = await computeContractClassId({
|
|
154
|
+
artifactHash: event.artifactHash,
|
|
155
|
+
privateFunctionsRoot: event.privateFunctionsRoot,
|
|
156
|
+
publicBytecodeCommitment,
|
|
157
|
+
});
|
|
158
|
+
if (!computedClassId.equals(event.contractClassId)) {
|
|
159
|
+
this.#log.warn(
|
|
160
|
+
`Rejecting tx ${tx.getTxHash()}: contract class id mismatch. Claimed ${event.contractClassId}, computed ${computedClassId}`,
|
|
161
|
+
);
|
|
162
|
+
return TX_ERROR_INCORRECT_CONTRACT_CLASS_ID;
|
|
163
|
+
}
|
|
164
|
+
} catch (e) {
|
|
165
|
+
this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to compute contract class id: ${e}`);
|
|
166
|
+
return TX_ERROR_MALFORMED_CONTRACT_CLASS_LOG;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
130
171
|
}
|
|
@@ -53,12 +53,13 @@ import type { TxMetaData } from '../../mem_pools/tx_pool_v2/tx_metadata.js';
|
|
|
53
53
|
import { AggregateTxValidator } from './aggregate_tx_validator.js';
|
|
54
54
|
import { ArchiveCache } from './archive_cache.js';
|
|
55
55
|
import { type ArchiveSource, BlockHeaderTxValidator } from './block_header_validator.js';
|
|
56
|
+
import { ContractInstanceTxValidator } from './contract_instance_validator.js';
|
|
56
57
|
import { DataTxValidator } from './data_validator.js';
|
|
57
58
|
import { DoubleSpendTxValidator, type NullifierSource } from './double_spend_validator.js';
|
|
58
59
|
import { GasLimitsValidator, GasTxValidator } from './gas_validator.js';
|
|
59
60
|
import { MetadataTxValidator } from './metadata_validator.js';
|
|
60
61
|
import { NullifierCache } from './nullifier_cache.js';
|
|
61
|
-
import { PhasesTxValidator } from './phases_validator.js';
|
|
62
|
+
import { AllowedSetupCallsMetaValidator, PhasesTxValidator } from './phases_validator.js';
|
|
62
63
|
import { SizeTxValidator } from './size_validator.js';
|
|
63
64
|
import { TimestampTxValidator } from './timestamp_validator.js';
|
|
64
65
|
import { TxPermittedValidator } from './tx_permitted_validator.js';
|
|
@@ -97,6 +98,7 @@ export function createFirstStageTxValidationsForGossipedTransactions(
|
|
|
97
98
|
txsPermitted: boolean,
|
|
98
99
|
allowedInSetup: AllowedElement[] = [],
|
|
99
100
|
bindings?: LoggerBindings,
|
|
101
|
+
gasLimitOpts?: { rollupManaLimit?: number; maxBlockL2Gas?: number; maxBlockDAGas?: number },
|
|
100
102
|
): Record<string, TransactionValidator> {
|
|
101
103
|
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
102
104
|
|
|
@@ -158,6 +160,7 @@ export function createFirstStageTxValidationsForGossipedTransactions(
|
|
|
158
160
|
ProtocolContractAddress.FeeJuice,
|
|
159
161
|
gasFees,
|
|
160
162
|
bindings,
|
|
163
|
+
gasLimitOpts,
|
|
161
164
|
),
|
|
162
165
|
severity: PeerErrorSeverity.MidToleranceError,
|
|
163
166
|
},
|
|
@@ -165,6 +168,10 @@ export function createFirstStageTxValidationsForGossipedTransactions(
|
|
|
165
168
|
validator: new DataTxValidator(bindings),
|
|
166
169
|
severity: PeerErrorSeverity.MidToleranceError,
|
|
167
170
|
},
|
|
171
|
+
contractInstanceValidator: {
|
|
172
|
+
validator: new ContractInstanceTxValidator(bindings),
|
|
173
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
174
|
+
},
|
|
168
175
|
};
|
|
169
176
|
}
|
|
170
177
|
|
|
@@ -216,6 +223,7 @@ function createTxValidatorForMinimumTxIntegrityChecks(
|
|
|
216
223
|
),
|
|
217
224
|
new SizeTxValidator(bindings),
|
|
218
225
|
new DataTxValidator(bindings),
|
|
226
|
+
new ContractInstanceTxValidator(bindings),
|
|
219
227
|
new TxProofValidator(verifier, bindings),
|
|
220
228
|
);
|
|
221
229
|
}
|
|
@@ -278,6 +286,9 @@ export function createTxValidatorForAcceptingTxsOverRPC(
|
|
|
278
286
|
timestamp,
|
|
279
287
|
blockNumber,
|
|
280
288
|
txsPermitted,
|
|
289
|
+
rollupManaLimit,
|
|
290
|
+
maxBlockL2Gas,
|
|
291
|
+
maxBlockDAGas,
|
|
281
292
|
}: {
|
|
282
293
|
l1ChainId: number;
|
|
283
294
|
rollupVersion: number;
|
|
@@ -287,6 +298,9 @@ export function createTxValidatorForAcceptingTxsOverRPC(
|
|
|
287
298
|
timestamp: UInt64;
|
|
288
299
|
blockNumber: BlockNumber;
|
|
289
300
|
txsPermitted: boolean;
|
|
301
|
+
rollupManaLimit: number;
|
|
302
|
+
maxBlockL2Gas?: number;
|
|
303
|
+
maxBlockDAGas?: number;
|
|
290
304
|
},
|
|
291
305
|
bindings?: LoggerBindings,
|
|
292
306
|
): TxValidator<Tx> {
|
|
@@ -313,11 +327,16 @@ export function createTxValidatorForAcceptingTxsOverRPC(
|
|
|
313
327
|
new BlockHeaderTxValidator(new ArchiveCache(db), bindings),
|
|
314
328
|
new DoubleSpendTxValidator(new NullifierCache(db), bindings),
|
|
315
329
|
new DataTxValidator(bindings),
|
|
330
|
+
new ContractInstanceTxValidator(bindings),
|
|
316
331
|
];
|
|
317
332
|
|
|
318
333
|
if (!skipFeeEnforcement) {
|
|
319
334
|
validators.push(
|
|
320
|
-
new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees, bindings
|
|
335
|
+
new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees, bindings, {
|
|
336
|
+
rollupManaLimit,
|
|
337
|
+
maxBlockL2Gas,
|
|
338
|
+
maxBlockDAGas,
|
|
339
|
+
}),
|
|
321
340
|
);
|
|
322
341
|
}
|
|
323
342
|
|
|
@@ -403,6 +422,7 @@ export async function createTxValidatorForTransactionsEnteringPendingTxPool(
|
|
|
403
422
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
404
423
|
timestamp: bigint,
|
|
405
424
|
blockNumber: BlockNumber,
|
|
425
|
+
gasLimitOpts: { rollupManaLimit?: number; maxBlockL2Gas?: number; maxBlockDAGas?: number },
|
|
406
426
|
bindings?: LoggerBindings,
|
|
407
427
|
): Promise<TxValidator<TxMetaData>> {
|
|
408
428
|
await worldStateSynchronizer.syncImmediate();
|
|
@@ -419,9 +439,29 @@ export async function createTxValidatorForTransactionsEnteringPendingTxPool(
|
|
|
419
439
|
},
|
|
420
440
|
};
|
|
421
441
|
return new AggregateTxValidator<TxMetaData>(
|
|
422
|
-
new GasLimitsValidator<TxMetaData>(bindings),
|
|
442
|
+
new GasLimitsValidator<TxMetaData>({ ...gasLimitOpts, bindings }),
|
|
423
443
|
new TimestampTxValidator<TxMetaData>({ timestamp, blockNumber }, bindings),
|
|
424
444
|
new DoubleSpendTxValidator<TxMetaData>(nullifierSource, bindings),
|
|
425
445
|
new BlockHeaderTxValidator<TxMetaData>(archiveSource, bindings),
|
|
446
|
+
new AllowedSetupCallsMetaValidator<TxMetaData>(bindings),
|
|
426
447
|
);
|
|
427
448
|
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Creates a function that checks whether a tx's setup-phase calls are on the allow list.
|
|
452
|
+
*
|
|
453
|
+
* Uses the `PhasesTxValidator` on the full Tx. The result is stored as a boolean
|
|
454
|
+
* flag in `TxMetaData.allowedSetupCalls` at receipt time, so the pending pool
|
|
455
|
+
* migration validator can check it without needing the full Tx or its dependencies.
|
|
456
|
+
*/
|
|
457
|
+
export function createCheckAllowedSetupCalls(
|
|
458
|
+
contractDataSource: ContractDataSource,
|
|
459
|
+
setupAllowList: AllowedElement[],
|
|
460
|
+
getTimestamp: () => UInt64,
|
|
461
|
+
): (tx: Tx) => Promise<boolean> {
|
|
462
|
+
return async (tx: Tx) => {
|
|
463
|
+
const validator = new PhasesTxValidator(contractDataSource, setupAllowList, getTimestamp());
|
|
464
|
+
const result = await validator.validateTx(tx);
|
|
465
|
+
return result.result === 'valid';
|
|
466
|
+
};
|
|
467
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT,
|
|
2
3
|
MAX_PROCESSABLE_L2_GAS,
|
|
3
4
|
PRIVATE_TX_L2_GAS_OVERHEAD,
|
|
4
5
|
PUBLIC_TX_L2_GAS_OVERHEAD,
|
|
@@ -49,16 +50,31 @@ export interface HasGasLimitData {
|
|
|
49
50
|
*/
|
|
50
51
|
export class GasLimitsValidator<T extends HasGasLimitData> implements TxValidator<T> {
|
|
51
52
|
#log: Logger;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
#effectiveMaxL2Gas: number;
|
|
54
|
+
#effectiveMaxDAGas: number;
|
|
55
|
+
#rollupManaLimit: number;
|
|
56
|
+
#maxBlockL2Gas: number;
|
|
57
|
+
#maxBlockDAGas: number;
|
|
58
|
+
|
|
59
|
+
constructor(opts?: {
|
|
60
|
+
rollupManaLimit?: number;
|
|
61
|
+
maxBlockL2Gas?: number;
|
|
62
|
+
maxBlockDAGas?: number;
|
|
63
|
+
bindings?: LoggerBindings;
|
|
64
|
+
}) {
|
|
65
|
+
this.#log = createLogger('sequencer:tx_validator:tx_gas', opts?.bindings);
|
|
66
|
+
this.#rollupManaLimit = opts?.rollupManaLimit ?? Infinity;
|
|
67
|
+
this.#maxBlockL2Gas = opts?.maxBlockL2Gas ?? Infinity;
|
|
68
|
+
this.#maxBlockDAGas = opts?.maxBlockDAGas ?? Infinity;
|
|
69
|
+
this.#effectiveMaxL2Gas = Math.min(MAX_PROCESSABLE_L2_GAS, this.#rollupManaLimit, this.#maxBlockL2Gas);
|
|
70
|
+
this.#effectiveMaxDAGas = Math.min(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, this.#maxBlockDAGas);
|
|
55
71
|
}
|
|
56
72
|
|
|
57
73
|
validateTx(tx: T): Promise<TxValidationResult> {
|
|
58
74
|
return Promise.resolve(this.validateGasLimit(tx));
|
|
59
75
|
}
|
|
60
76
|
|
|
61
|
-
/** Checks gas limits are >= fixed minimums and <=
|
|
77
|
+
/** Checks gas limits are >= fixed minimums and <= effective max gas (L2 and DA). */
|
|
62
78
|
validateGasLimit(tx: T): TxValidationResult {
|
|
63
79
|
const gasLimits = tx.data.constants.txContext.gasSettings.gasLimits;
|
|
64
80
|
const minGasLimits = new Gas(
|
|
@@ -71,15 +87,37 @@ export class GasLimitsValidator<T extends HasGasLimitData> implements TxValidato
|
|
|
71
87
|
gasLimits,
|
|
72
88
|
minGasLimits,
|
|
73
89
|
});
|
|
74
|
-
return {
|
|
90
|
+
return {
|
|
91
|
+
result: 'invalid',
|
|
92
|
+
reason: [
|
|
93
|
+
`${TX_ERROR_INSUFFICIENT_GAS_LIMIT} (required=da:${minGasLimits.daGas},l2:${minGasLimits.l2Gas} got=da:${gasLimits.daGas},l2:${gasLimits.l2Gas})`,
|
|
94
|
+
],
|
|
95
|
+
};
|
|
75
96
|
}
|
|
76
97
|
|
|
77
|
-
if (gasLimits.l2Gas >
|
|
78
|
-
this.#log.verbose(`Rejecting transaction due to the gas limit
|
|
98
|
+
if (gasLimits.l2Gas > this.#effectiveMaxL2Gas) {
|
|
99
|
+
this.#log.verbose(`Rejecting transaction due to the L2 gas limit being higher than the effective maximum`, {
|
|
79
100
|
gasLimits,
|
|
80
|
-
|
|
101
|
+
effectiveMaxL2Gas: this.#effectiveMaxL2Gas,
|
|
102
|
+
rollupManaLimit: this.#rollupManaLimit,
|
|
103
|
+
maxBlockL2Gas: this.#maxBlockL2Gas,
|
|
81
104
|
});
|
|
82
|
-
return {
|
|
105
|
+
return {
|
|
106
|
+
result: 'invalid',
|
|
107
|
+
reason: [`${TX_ERROR_GAS_LIMIT_TOO_HIGH} (l2Gas=${gasLimits.l2Gas}, max=${this.#effectiveMaxL2Gas})`],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (gasLimits.daGas > this.#effectiveMaxDAGas) {
|
|
112
|
+
this.#log.verbose(`Rejecting transaction due to the DA gas limit being higher than the effective maximum`, {
|
|
113
|
+
gasLimits,
|
|
114
|
+
effectiveMaxDAGas: this.#effectiveMaxDAGas,
|
|
115
|
+
maxBlockDAGas: this.#maxBlockDAGas,
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
result: 'invalid',
|
|
119
|
+
reason: [`${TX_ERROR_GAS_LIMIT_TOO_HIGH} (daGas=${gasLimits.daGas}, max=${this.#effectiveMaxDAGas})`],
|
|
120
|
+
};
|
|
83
121
|
}
|
|
84
122
|
|
|
85
123
|
return { result: 'valid' };
|
|
@@ -106,37 +144,44 @@ export class GasTxValidator implements TxValidator<Tx> {
|
|
|
106
144
|
#publicDataSource: PublicStateSource;
|
|
107
145
|
#feeJuiceAddress: AztecAddress;
|
|
108
146
|
#gasFees: GasFees;
|
|
147
|
+
#gasLimitOpts?: { rollupManaLimit?: number; maxBlockL2Gas?: number; maxBlockDAGas?: number };
|
|
109
148
|
|
|
110
149
|
constructor(
|
|
111
150
|
publicDataSource: PublicStateSource,
|
|
112
151
|
feeJuiceAddress: AztecAddress,
|
|
113
152
|
gasFees: GasFees,
|
|
114
153
|
private bindings?: LoggerBindings,
|
|
154
|
+
opts?: { rollupManaLimit?: number; maxBlockL2Gas?: number; maxBlockDAGas?: number },
|
|
115
155
|
) {
|
|
116
156
|
this.#log = createLogger('sequencer:tx_validator:tx_gas', bindings);
|
|
117
157
|
this.#publicDataSource = publicDataSource;
|
|
118
158
|
this.#feeJuiceAddress = feeJuiceAddress;
|
|
119
159
|
this.#gasFees = gasFees;
|
|
160
|
+
this.#gasLimitOpts = opts;
|
|
120
161
|
}
|
|
121
162
|
|
|
122
163
|
async validateTx(tx: Tx): Promise<TxValidationResult> {
|
|
123
|
-
const gasLimitValidation = new GasLimitsValidator(
|
|
164
|
+
const gasLimitValidation = new GasLimitsValidator({
|
|
165
|
+
...this.#gasLimitOpts,
|
|
166
|
+
bindings: this.bindings,
|
|
167
|
+
}).validateGasLimit(tx);
|
|
124
168
|
if (gasLimitValidation.result === 'invalid') {
|
|
125
169
|
return Promise.resolve(gasLimitValidation);
|
|
126
170
|
}
|
|
127
|
-
|
|
128
|
-
|
|
171
|
+
const skipReason = this.#getSkipReason(tx);
|
|
172
|
+
if (skipReason) {
|
|
173
|
+
return Promise.resolve({ result: 'skipped', reason: [skipReason] });
|
|
129
174
|
}
|
|
130
175
|
return await this.validateTxFee(tx);
|
|
131
176
|
}
|
|
132
177
|
|
|
133
178
|
/**
|
|
134
|
-
* Check whether the tx's max fees are valid for the current block, and skip if not.
|
|
179
|
+
* Check whether the tx's max fees are valid for the current block, and return a skip reason if not.
|
|
135
180
|
* We skip instead of invalidating since the tx may become eligible later.
|
|
136
181
|
* Note that circuits check max fees even if fee payer is unset, so we
|
|
137
182
|
* keep this validation even if the tx does not pay fees.
|
|
138
183
|
*/
|
|
139
|
-
#
|
|
184
|
+
#getSkipReason(tx: Tx): string | undefined {
|
|
140
185
|
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
141
186
|
|
|
142
187
|
// Skip the tx if its max fees are not enough for the current block's gas fees.
|
|
@@ -149,8 +194,9 @@ export class GasTxValidator implements TxValidator<Tx> {
|
|
|
149
194
|
txMaxFeesPerGas: maxFeesPerGas.toInspect(),
|
|
150
195
|
currentGasFees: this.#gasFees.toInspect(),
|
|
151
196
|
});
|
|
197
|
+
return `${TX_ERROR_INSUFFICIENT_FEE_PER_GAS} (maxFee=da:${maxFeesPerGas.feePerDaGas},l2:${maxFeesPerGas.feePerL2Gas} required=da:${this.#gasFees.feePerDaGas},l2:${this.#gasFees.feePerL2Gas})`;
|
|
152
198
|
}
|
|
153
|
-
return
|
|
199
|
+
return undefined;
|
|
154
200
|
}
|
|
155
201
|
|
|
156
202
|
/**
|
|
@@ -179,7 +225,10 @@ export class GasTxValidator implements TxValidator<Tx> {
|
|
|
179
225
|
balance,
|
|
180
226
|
feeLimit,
|
|
181
227
|
});
|
|
182
|
-
return {
|
|
228
|
+
return {
|
|
229
|
+
result: 'invalid',
|
|
230
|
+
reason: [`${TX_ERROR_INSUFFICIENT_FEE_PAYER_BALANCE} (required=${feeLimit}, available=${balance})`],
|
|
231
|
+
};
|
|
183
232
|
}
|
|
184
233
|
return { result: 'valid' };
|
|
185
234
|
}
|
|
@@ -40,7 +40,7 @@ export class PhasesTxValidator implements TxValidator<Tx> {
|
|
|
40
40
|
// which are needed for public FPC flows, but fail if the account contract hasnt been deployed yet,
|
|
41
41
|
// which is what we're trying to do as part of the current txs.
|
|
42
42
|
// We only need to create/revert checkpoint here because of this addNewContracts call.
|
|
43
|
-
|
|
43
|
+
this.contractsDB.addNewContracts(tx);
|
|
44
44
|
|
|
45
45
|
if (!tx.data.forPublic) {
|
|
46
46
|
this.#log.debug(
|
|
@@ -141,3 +141,33 @@ export class PhasesTxValidator implements TxValidator<Tx> {
|
|
|
141
141
|
return TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
+
|
|
145
|
+
/** Structural interface for the allowed-setup-calls flag check. */
|
|
146
|
+
export interface HasAllowedSetupCallsData {
|
|
147
|
+
txHash: { toString(): string };
|
|
148
|
+
allowedSetupCalls: boolean;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Validates that a transaction's setup-phase calls were allowed at receipt time.
|
|
153
|
+
*
|
|
154
|
+
* Checks the precomputed `allowedSetupCalls` flag on TxMetaData. The flag is
|
|
155
|
+
* computed by running the PhasesTxValidator on the full Tx when it first enters
|
|
156
|
+
* the pool. This lightweight validator is used during pending pool migration to
|
|
157
|
+
* reject txs whose setup calls are not on the allow list.
|
|
158
|
+
*/
|
|
159
|
+
export class AllowedSetupCallsMetaValidator<T extends HasAllowedSetupCallsData> implements TxValidator<T> {
|
|
160
|
+
#log: Logger;
|
|
161
|
+
|
|
162
|
+
constructor(bindings?: LoggerBindings) {
|
|
163
|
+
this.#log = createLogger('sequencer:tx_validator:tx_phases_meta', bindings);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
validateTx(tx: T): Promise<TxValidationResult> {
|
|
167
|
+
if (!tx.allowedSetupCalls) {
|
|
168
|
+
this.#log.verbose(`Rejecting tx ${tx.txHash} because its setup calls are not on the allow list`);
|
|
169
|
+
return Promise.resolve({ result: 'invalid', reason: [TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED] });
|
|
170
|
+
}
|
|
171
|
+
return Promise.resolve({ result: 'valid' });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -28,8 +28,6 @@ export class AztecDatastore implements Datastore {
|
|
|
28
28
|
#memoryDatastore: Map<string, MemoryItem>;
|
|
29
29
|
#dbDatastore: AztecAsyncMap<string, Uint8Array>;
|
|
30
30
|
|
|
31
|
-
#batchOps: BatchOp[] = [];
|
|
32
|
-
|
|
33
31
|
private maxMemoryItems: number;
|
|
34
32
|
|
|
35
33
|
constructor(db: AztecAsyncKVStore, { maxMemoryItems } = { maxMemoryItems: 50 }) {
|
|
@@ -92,23 +90,17 @@ export class AztecDatastore implements Datastore {
|
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
batch(): Batch {
|
|
93
|
+
const ops: BatchOp[] = [];
|
|
95
94
|
return {
|
|
96
95
|
put: (key, value) => {
|
|
97
|
-
|
|
98
|
-
type: 'put',
|
|
99
|
-
key,
|
|
100
|
-
value,
|
|
101
|
-
});
|
|
96
|
+
ops.push({ type: 'put', key, value });
|
|
102
97
|
},
|
|
103
98
|
delete: key => {
|
|
104
|
-
|
|
105
|
-
type: 'del',
|
|
106
|
-
key,
|
|
107
|
-
});
|
|
99
|
+
ops.push({ type: 'del', key });
|
|
108
100
|
},
|
|
109
101
|
commit: async () => {
|
|
110
102
|
await this.#db.transactionAsync(async () => {
|
|
111
|
-
for (const op of
|
|
103
|
+
for (const op of ops) {
|
|
112
104
|
if (op.type === 'put' && op.value) {
|
|
113
105
|
await this.put(op.key, op.value);
|
|
114
106
|
} else if (op.type === 'del') {
|
|
@@ -116,7 +108,7 @@ export class AztecDatastore implements Datastore {
|
|
|
116
108
|
}
|
|
117
109
|
}
|
|
118
110
|
});
|
|
119
|
-
|
|
111
|
+
ops.length = 0;
|
|
120
112
|
},
|
|
121
113
|
};
|
|
122
114
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
2
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type { Gossipable, PeerErrorSeverity, TopicType } from '@aztec/stdlib/p2p';
|
|
3
|
+
import type { CheckpointProposalCore, Gossipable, PeerErrorSeverity, TopicType } from '@aztec/stdlib/p2p';
|
|
4
4
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
6
6
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -86,7 +86,12 @@ export class DummyP2PService implements P2PService {
|
|
|
86
86
|
/**
|
|
87
87
|
* Register a callback into the validator client for when a checkpoint proposal is received
|
|
88
88
|
*/
|
|
89
|
-
public
|
|
89
|
+
public registerValidatorCheckpointReceivedCallback(_callback: P2PCheckpointReceivedCallback) {}
|
|
90
|
+
public registerAllNodesCheckpointReceivedCallback(_callback: P2PCheckpointReceivedCallback) {}
|
|
91
|
+
|
|
92
|
+
public notifyOwnCheckpointProposal(_checkpoint: CheckpointProposalCore): Promise<void> {
|
|
93
|
+
return Promise.resolve();
|
|
94
|
+
}
|
|
90
95
|
|
|
91
96
|
/**
|
|
92
97
|
* Register a callback for when a duplicate proposal is detected
|
|
@@ -282,6 +287,7 @@ export class DummyPeerManager implements PeerManagerInterface {
|
|
|
282
287
|
|
|
283
288
|
export class DummyReqResp implements ReqRespInterface {
|
|
284
289
|
updateConfig(_config: Partial<P2PReqRespConfig>): void {}
|
|
290
|
+
setShouldRejectPeer(): void {}
|
|
285
291
|
start(
|
|
286
292
|
_subProtocolHandlers: ReqRespSubProtocolHandlers,
|
|
287
293
|
_subProtocolValidators: ReqRespSubProtocolValidators,
|
package/src/services/encoding.ts
CHANGED
|
@@ -9,6 +9,14 @@ import { webcrypto } from 'node:crypto';
|
|
|
9
9
|
import { compressSync, uncompressSync } from 'snappy';
|
|
10
10
|
import xxhashFactory from 'xxhash-wasm';
|
|
11
11
|
|
|
12
|
+
/** Thrown when a Snappy-compressed response exceeds the allowed decompressed size. */
|
|
13
|
+
export class OversizedSnappyResponseError extends Error {
|
|
14
|
+
constructor(decompressedSize: number, maxSizeKb: number) {
|
|
15
|
+
super(`Decompressed size ${decompressedSize} exceeds maximum allowed size of ${maxSizeKb}kb`);
|
|
16
|
+
this.name = 'OversizedSnappyResponseError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
12
20
|
// Load WASM
|
|
13
21
|
const xxhash = await xxhashFactory();
|
|
14
22
|
|
|
@@ -86,7 +94,7 @@ export class SnappyTransform implements DataTransform {
|
|
|
86
94
|
const { decompressedSize } = readSnappyPreamble(data);
|
|
87
95
|
if (decompressedSize > maxSizeKb * 1024) {
|
|
88
96
|
this.logger.warn(`Decompressed size ${decompressedSize} exceeds maximum allowed size of ${maxSizeKb}kb`);
|
|
89
|
-
throw new
|
|
97
|
+
throw new OversizedSnappyResponseError(decompressedSize, maxSizeKb);
|
|
90
98
|
}
|
|
91
99
|
|
|
92
100
|
return Buffer.from(uncompressSync(data, { asBuffer: true }));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TopicType, createTopicString } from '@aztec/stdlib/p2p';
|
|
2
|
-
import {
|
|
2
|
+
import { createCheckpointTimingModel } from '@aztec/stdlib/timetable';
|
|
3
3
|
|
|
4
4
|
import { createTopicScoreParams } from '@chainsafe/libp2p-gossipsub/score';
|
|
5
5
|
|
|
@@ -9,12 +9,18 @@ import { createTopicScoreParams } from '@chainsafe/libp2p-gossipsub/score';
|
|
|
9
9
|
export type TopicScoringNetworkParams = {
|
|
10
10
|
/** L2 slot duration in milliseconds */
|
|
11
11
|
slotDurationMs: number;
|
|
12
|
+
/** L1 slot duration in seconds */
|
|
13
|
+
ethereumSlotDuration: number;
|
|
12
14
|
/** Gossipsub heartbeat interval in milliseconds */
|
|
13
15
|
heartbeatIntervalMs: number;
|
|
14
16
|
/** Target committee size (number of validators expected to attest per slot) */
|
|
15
17
|
targetCommitteeSize: number;
|
|
16
18
|
/** Duration per block in milliseconds when building multiple blocks per slot. If undefined, single block mode. */
|
|
17
19
|
blockDurationMs?: number;
|
|
20
|
+
/** Time budget in seconds reserved for L1 publishing. Defaults to ethereumSlotDuration. */
|
|
21
|
+
l1PublishingTime?: number;
|
|
22
|
+
/** One-way proposal/attestation propagation budget in seconds. */
|
|
23
|
+
p2pPropagationTime?: number;
|
|
18
24
|
/** Expected number of block proposals per slot for scoring override. 0 disables scoring, undefined falls back to blocksPerSlot - 1. */
|
|
19
25
|
expectedBlockProposalsPerSlot?: number;
|
|
20
26
|
};
|
|
@@ -25,10 +31,32 @@ export type TopicScoringNetworkParams = {
|
|
|
25
31
|
*
|
|
26
32
|
* @param slotDurationMs - L2 slot duration in milliseconds
|
|
27
33
|
* @param blockDurationMs - Duration per block in milliseconds (undefined = single block mode)
|
|
34
|
+
* @param opts - Shared checkpoint timing inputs used by the sequencer and validators
|
|
28
35
|
* @returns Number of blocks per slot
|
|
29
36
|
*/
|
|
30
|
-
export function calculateBlocksPerSlot(
|
|
31
|
-
|
|
37
|
+
export function calculateBlocksPerSlot(
|
|
38
|
+
slotDurationMs: number,
|
|
39
|
+
blockDurationMs: number | undefined,
|
|
40
|
+
opts?: {
|
|
41
|
+
ethereumSlotDuration: number;
|
|
42
|
+
l1PublishingTime?: number;
|
|
43
|
+
p2pPropagationTime?: number;
|
|
44
|
+
},
|
|
45
|
+
): number {
|
|
46
|
+
if (!opts) {
|
|
47
|
+
return createCheckpointTimingModel({
|
|
48
|
+
aztecSlotDuration: slotDurationMs / 1000,
|
|
49
|
+
blockDuration: blockDurationMs ? blockDurationMs / 1000 : undefined,
|
|
50
|
+
}).calculateMaxBlocksPerSlot();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return createCheckpointTimingModel({
|
|
54
|
+
aztecSlotDuration: slotDurationMs / 1000,
|
|
55
|
+
ethereumSlotDuration: opts.ethereumSlotDuration,
|
|
56
|
+
blockDuration: blockDurationMs ? blockDurationMs / 1000 : undefined,
|
|
57
|
+
l1PublishingTime: opts.l1PublishingTime ?? opts.ethereumSlotDuration,
|
|
58
|
+
p2pPropagationTime: opts.p2pPropagationTime,
|
|
59
|
+
}).calculateMaxBlocksPerSlot();
|
|
32
60
|
}
|
|
33
61
|
|
|
34
62
|
/**
|
|
@@ -279,7 +307,11 @@ export class TopicScoreParamsFactory {
|
|
|
279
307
|
const { slotDurationMs, heartbeatIntervalMs, blockDurationMs } = params;
|
|
280
308
|
|
|
281
309
|
// Compute values that are the same for all topics
|
|
282
|
-
this.blocksPerSlot = calculateBlocksPerSlot(slotDurationMs, blockDurationMs
|
|
310
|
+
this.blocksPerSlot = calculateBlocksPerSlot(slotDurationMs, blockDurationMs, {
|
|
311
|
+
ethereumSlotDuration: params.ethereumSlotDuration,
|
|
312
|
+
l1PublishingTime: params.l1PublishingTime,
|
|
313
|
+
p2pPropagationTime: params.p2pPropagationTime,
|
|
314
|
+
});
|
|
283
315
|
this.heartbeatsPerSlot = slotDurationMs / heartbeatIntervalMs;
|
|
284
316
|
this.invalidDecay = computeDecay(heartbeatIntervalMs, slotDurationMs, INVALID_DECAY_WINDOW_SLOTS);
|
|
285
317
|
|