@aztec/p2p 0.0.1-commit.f295ac2 → 0.0.1-commit.fc805bf
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/bootstrap/bootstrap.d.ts +4 -3
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +4 -4
- package/dest/client/factory.d.ts +1 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +6 -5
- package/dest/client/p2p_client.d.ts +1 -1
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +9 -2
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +305 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
- package/dest/config.d.ts +8 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -0
- 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 +2 -2
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +3 -3
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +3 -2
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +3 -2
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +8 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +3 -3
- 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/msg_validators/attestation_validator/attestation_validator.d.ts +3 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +41 -10
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
- 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 -6
- 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/proposal_validator/proposal_validator.d.ts +3 -3
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +55 -31
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +3 -3
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +93 -64
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +5 -4
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +3 -2
- package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +4 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +8 -3
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +21 -11
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +3 -2
- 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 +3 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
- package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +23 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
- 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 +10 -6
- package/dest/services/discv5/discV5_service.js +1 -1
- package/dest/services/dummy_service.d.ts +13 -1
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +39 -0
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +2 -3
- 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 +14 -3
- package/dest/services/libp2p/libp2p_service.d.ts +13 -7
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +60 -51
- package/dest/services/peer-manager/metrics.d.ts +2 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +20 -5
- 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 +8 -2
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
- package/dest/services/reqresp/interface.d.ts +5 -3
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +2 -2
- package/dest/services/reqresp/metrics.d.ts +6 -5
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +17 -5
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +5 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +16 -3
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +18 -6
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +43 -13
- package/dest/services/reqresp/reqresp.d.ts +6 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +58 -22
- package/dest/services/service.d.ts +4 -1
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +4 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +9 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +6 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +16 -5
- package/dest/services/tx_collection/index.d.ts +2 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -0
- 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 +9 -2
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
- package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
- 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 +8 -8
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +5 -5
- 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 +5 -5
- package/dest/test-helpers/index.d.ts +3 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +2 -0
- package/dest/test-helpers/test_tx_provider.d.ts +40 -0
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
- package/dest/test-helpers/test_tx_provider.js +41 -0
- package/dest/test-helpers/testbench-utils.d.ts +158 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +297 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +212 -133
- package/dest/testbench/worker_client_manager.d.ts +51 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +226 -44
- package/package.json +14 -14
- package/src/bootstrap/bootstrap.ts +7 -4
- package/src/client/factory.ts +6 -10
- package/src/client/p2p_client.ts +14 -7
- package/src/client/test/tx_proposal_collector/README.md +227 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
- package/src/config.ts +6 -1
- package/src/mem_pools/instrumentation.ts +2 -1
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +2 -2
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +2 -1
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +2 -1
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +10 -7
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
- package/src/msg_validators/attestation_validator/attestation_validator.ts +26 -14
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +14 -8
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +31 -31
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +91 -67
- package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
- package/src/msg_validators/tx_validator/block_header_validator.ts +6 -5
- package/src/msg_validators/tx_validator/data_validator.ts +6 -2
- package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
- package/src/msg_validators/tx_validator/factory.ts +64 -23
- package/src/msg_validators/tx_validator/gas_validator.ts +9 -3
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +6 -3
- package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
- package/src/msg_validators/tx_validator/size_validator.ts +22 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +6 -3
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
- package/src/services/data_store.ts +10 -7
- package/src/services/discv5/discV5_service.ts +1 -1
- package/src/services/dummy_service.ts +45 -0
- package/src/services/encoding.ts +2 -3
- package/src/services/libp2p/instrumentation.ts +15 -2
- package/src/services/libp2p/libp2p_service.ts +99 -73
- package/src/services/peer-manager/metrics.ts +21 -4
- package/src/services/peer-manager/peer_scoring.ts +4 -1
- package/src/services/reqresp/batch-tx-requester/README.md +305 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +16 -0
- package/src/services/reqresp/interface.ts +5 -2
- package/src/services/reqresp/metrics.ts +34 -9
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +7 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +18 -4
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +51 -9
- package/src/services/reqresp/reqresp.ts +66 -19
- package/src/services/service.ts +4 -0
- package/src/services/tx_collection/config.ts +15 -1
- package/src/services/tx_collection/fast_tx_collection.ts +36 -13
- package/src/services/tx_collection/index.ts +5 -0
- package/src/services/tx_collection/instrumentation.ts +11 -2
- package/src/services/tx_collection/proposal_tx_collector.ts +114 -0
- package/src/services/tx_collection/slow_tx_collection.ts +2 -2
- package/src/services/tx_collection/tx_collection.ts +8 -8
- package/src/services/tx_provider.ts +2 -2
- package/src/services/tx_provider_instrumentation.ts +11 -5
- package/src/test-helpers/index.ts +2 -0
- package/src/test-helpers/test_tx_provider.ts +64 -0
- package/src/test-helpers/testbench-utils.ts +374 -0
- package/src/testbench/p2p_client_testbench_worker.ts +321 -126
- package/src/testbench/worker_client_manager.ts +304 -47
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
@@ -24,7 +25,7 @@ export type EvictionContext =
|
|
|
24
25
|
}
|
|
25
26
|
| {
|
|
26
27
|
event: typeof EvictionEvent.CHAIN_PRUNED;
|
|
27
|
-
blockNumber:
|
|
28
|
+
blockNumber: BlockNumber;
|
|
28
29
|
}
|
|
29
30
|
| {
|
|
30
31
|
event: typeof EvictionEvent.BLOCK_MINED;
|
|
@@ -2,7 +2,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
2
2
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
3
|
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import type {
|
|
5
|
+
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
6
6
|
import { DatabasePublicStateSource, type MerkleTreeReadOperations } from '@aztec/stdlib/trees';
|
|
7
7
|
import type { TxHash } from '@aztec/stdlib/tx';
|
|
8
8
|
|
|
@@ -22,7 +22,7 @@ export class FeePayerBalanceEvictionRule implements EvictionRule {
|
|
|
22
22
|
|
|
23
23
|
private log = createLogger('p2p:mempool:tx_pool:fee_payer_balance_eviction_rule');
|
|
24
24
|
|
|
25
|
-
constructor(private worldState:
|
|
25
|
+
constructor(private worldState: WorldStateSynchronizer) {}
|
|
26
26
|
|
|
27
27
|
async evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult> {
|
|
28
28
|
try {
|
|
@@ -31,11 +31,12 @@ export class FeePayerBalanceEvictionRule implements EvictionRule {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
if (context.event === EvictionEvent.BLOCK_MINED) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
34
|
+
const blockNumber = context.block.getBlockNumber();
|
|
35
|
+
// Ensure world state is synced to this block before accessing the snapshot.
|
|
36
|
+
// This handles the race where a block is added to the archiver
|
|
37
|
+
// but the world state hasn't synced it yet.
|
|
38
|
+
await this.worldState.syncImmediate(blockNumber);
|
|
39
|
+
return await this.evictForFeePayers(context.feePayers, this.worldState.getSnapshot(blockNumber), txPool);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
// TODO: fix this edge-case
|
|
@@ -49,6 +50,8 @@ export class FeePayerBalanceEvictionRule implements EvictionRule {
|
|
|
49
50
|
// -----
|
|
50
51
|
// Proposed fix: evict only if node is synched
|
|
51
52
|
if (context.event === EvictionEvent.CHAIN_PRUNED) {
|
|
53
|
+
// Ensure world state is synced to this block before accessing the snapshot.
|
|
54
|
+
await this.worldState.syncImmediate(context.blockNumber);
|
|
52
55
|
const feePayers = await txPool.getPendingFeePayers();
|
|
53
56
|
return await this.evictForFeePayers(feePayers, this.worldState.getSnapshot(context.blockNumber), txPool);
|
|
54
57
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { findIndexInSortedArray, insertIntoSortedArray } from '@aztec/foundation/array';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import type {
|
|
4
|
+
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
5
5
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
6
|
import type { TxHash } from '@aztec/stdlib/tx';
|
|
7
7
|
|
|
@@ -26,7 +26,7 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
|
|
|
26
26
|
|
|
27
27
|
private log = createLogger('p2p:mempool:tx_pool:invalid_txs_after_reorg_rule');
|
|
28
28
|
|
|
29
|
-
public constructor(private worldState:
|
|
29
|
+
public constructor(private worldState: WorldStateSynchronizer) {}
|
|
30
30
|
|
|
31
31
|
async evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult> {
|
|
32
32
|
if (context.event !== EvictionEvent.CHAIN_PRUNED) {
|
|
@@ -46,6 +46,8 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
|
|
|
46
46
|
insertIntoSortedArray(uniqueBlockHashes, blockHash, Fr.cmp, false);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
+
// Ensure world state is synced to this block before accessing the snapshot.
|
|
50
|
+
await this.worldState.syncImmediate(context.blockNumber);
|
|
49
51
|
const db = this.worldState.getSnapshot(context.blockNumber);
|
|
50
52
|
const blocksFromDb = await db.findLeafIndices(MerkleTreeId.ARCHIVE, uniqueBlockHashes);
|
|
51
53
|
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
2
|
import { NoCommitteeError } from '@aztec/ethereum/contracts';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type CheckpointAttestation,
|
|
6
|
+
type P2PValidator,
|
|
7
|
+
PeerErrorSeverity,
|
|
8
|
+
type ValidationResult,
|
|
9
|
+
} from '@aztec/stdlib/p2p';
|
|
10
|
+
|
|
11
|
+
import { isWithinClockTolerance } from '../clock_tolerance.js';
|
|
5
12
|
|
|
6
13
|
export class CheckpointAttestationValidator implements P2PValidator<CheckpointAttestation> {
|
|
7
14
|
protected epochCache: EpochCacheInterface;
|
|
@@ -12,30 +19,35 @@ export class CheckpointAttestationValidator implements P2PValidator<CheckpointAt
|
|
|
12
19
|
this.logger = createLogger('p2p:checkpoint-attestation-validator');
|
|
13
20
|
}
|
|
14
21
|
|
|
15
|
-
async validate(message: CheckpointAttestation): Promise<
|
|
22
|
+
async validate(message: CheckpointAttestation): Promise<ValidationResult> {
|
|
16
23
|
const slotNumber = message.payload.header.slotNumber;
|
|
17
24
|
|
|
18
25
|
try {
|
|
19
|
-
const { currentSlot, nextSlot } =
|
|
26
|
+
const { currentSlot, nextSlot } = this.epochCache.getCurrentAndNextSlot();
|
|
20
27
|
|
|
21
28
|
if (slotNumber !== currentSlot && slotNumber !== nextSlot) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
// Check if message is for previous slot and within clock tolerance
|
|
30
|
+
if (!isWithinClockTolerance(slotNumber, currentSlot, this.epochCache)) {
|
|
31
|
+
this.logger.warn(
|
|
32
|
+
`Checkpoint attestation slot ${slotNumber} is not current (${currentSlot}) or next (${nextSlot}) slot`,
|
|
33
|
+
);
|
|
34
|
+
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
35
|
+
}
|
|
36
|
+
this.logger.debug(`Ignoring checkpoint attestation for previous slot ${slotNumber} within clock tolerance`);
|
|
37
|
+
return { result: 'ignore' };
|
|
26
38
|
}
|
|
27
39
|
|
|
28
40
|
// Verify the signature is valid
|
|
29
41
|
const attester = message.getSender();
|
|
30
42
|
if (attester === undefined) {
|
|
31
43
|
this.logger.warn(`Invalid signature in checkpoint attestation for slot ${slotNumber}`);
|
|
32
|
-
return PeerErrorSeverity.LowToleranceError;
|
|
44
|
+
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
33
45
|
}
|
|
34
46
|
|
|
35
47
|
// Verify the attester is in the committee for this slot
|
|
36
48
|
if (!(await this.epochCache.isInCommittee(slotNumber, attester))) {
|
|
37
49
|
this.logger.warn(`Attester ${attester.toString()} is not in committee for slot ${slotNumber}`);
|
|
38
|
-
return PeerErrorSeverity.HighToleranceError;
|
|
50
|
+
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
39
51
|
}
|
|
40
52
|
|
|
41
53
|
// Verify the proposer signature matches the expected proposer for the attestation's slot
|
|
@@ -45,26 +57,26 @@ export class CheckpointAttestationValidator implements P2PValidator<CheckpointAt
|
|
|
45
57
|
const expectedProposer = await this.epochCache.getProposerAttesterAddressInSlot(slotNumber);
|
|
46
58
|
if (!expectedProposer) {
|
|
47
59
|
this.logger.warn(`No proposer defined for slot ${slotNumber}`);
|
|
48
|
-
return PeerErrorSeverity.HighToleranceError;
|
|
60
|
+
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
49
61
|
}
|
|
50
62
|
if (!proposer) {
|
|
51
63
|
this.logger.warn(`Invalid proposer signature in checkpoint attestation for slot ${slotNumber}`);
|
|
52
|
-
return PeerErrorSeverity.LowToleranceError;
|
|
64
|
+
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
53
65
|
}
|
|
54
66
|
if (!proposer.equals(expectedProposer)) {
|
|
55
67
|
this.logger.warn(
|
|
56
68
|
`Proposer signature mismatch in checkpoint attestation. ` +
|
|
57
69
|
`Expected ${expectedProposer?.toString() ?? 'none'} but got ${proposer.toString()} for slot ${slotNumber}`,
|
|
58
70
|
);
|
|
59
|
-
return PeerErrorSeverity.HighToleranceError;
|
|
71
|
+
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
60
72
|
}
|
|
61
73
|
|
|
62
|
-
return
|
|
74
|
+
return { result: 'accept' };
|
|
63
75
|
} catch (e) {
|
|
64
76
|
// People shouldn't be sending us attestations if the committee doesn't exist
|
|
65
77
|
if (e instanceof NoCommitteeError) {
|
|
66
78
|
this.logger.warn(`No committee exists for checkpoint attestation for slot ${slotNumber}`);
|
|
67
|
-
return PeerErrorSeverity.LowToleranceError;
|
|
79
|
+
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
68
80
|
}
|
|
69
81
|
throw e;
|
|
70
82
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { type CheckpointAttestation, PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
3
|
-
import { Attributes, Metrics, type TelemetryClient } from '@aztec/telemetry-client';
|
|
2
|
+
import { type CheckpointAttestation, PeerErrorSeverity, type ValidationResult } from '@aztec/stdlib/p2p';
|
|
3
|
+
import { Attributes, Metrics, type TelemetryClient, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
|
|
4
4
|
|
|
5
5
|
import type { AttestationPool } from '../../mem_pools/attestation_pool/attestation_pool.js';
|
|
6
6
|
import { CheckpointAttestationValidator } from './attestation_validator.js';
|
|
@@ -25,13 +25,19 @@ export class FishermanAttestationValidator extends CheckpointAttestationValidato
|
|
|
25
25
|
this.logger = this.logger.createChild('[FISHERMAN]');
|
|
26
26
|
|
|
27
27
|
const meter = telemetryClient.getMeter('FishermanAttestationValidator');
|
|
28
|
-
this.invalidAttestationCounter =
|
|
28
|
+
this.invalidAttestationCounter = createUpDownCounterWithDefault(
|
|
29
|
+
meter,
|
|
30
|
+
Metrics.VALIDATOR_INVALID_ATTESTATION_RECEIVED_COUNT,
|
|
31
|
+
{
|
|
32
|
+
[Attributes.ERROR_TYPE]: ['base_validation_failed', 'payload_mismatch'],
|
|
33
|
+
},
|
|
34
|
+
);
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
override async validate(message: CheckpointAttestation): Promise<
|
|
37
|
+
override async validate(message: CheckpointAttestation): Promise<ValidationResult> {
|
|
32
38
|
// First run the standard validation
|
|
33
39
|
const baseValidationResult = await super.validate(message);
|
|
34
|
-
if (baseValidationResult !==
|
|
40
|
+
if (baseValidationResult.result !== 'accept') {
|
|
35
41
|
// Track base validation failures (invalid signature, wrong committee, etc.)
|
|
36
42
|
this.invalidAttestationCounter.add(1, {
|
|
37
43
|
[Attributes.ERROR_TYPE]: 'base_validation_failed',
|
|
@@ -45,7 +51,7 @@ export class FishermanAttestationValidator extends CheckpointAttestationValidato
|
|
|
45
51
|
const proposer = message.getProposer();
|
|
46
52
|
|
|
47
53
|
if (!attester || !proposer) {
|
|
48
|
-
return
|
|
54
|
+
return { result: 'accept' };
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
const proposalId = message.archive.toString();
|
|
@@ -74,7 +80,7 @@ export class FishermanAttestationValidator extends CheckpointAttestationValidato
|
|
|
74
80
|
});
|
|
75
81
|
|
|
76
82
|
// Return error to reject the message, but LibP2PService won't penalize in fisherman mode
|
|
77
|
-
return PeerErrorSeverity.LowToleranceError;
|
|
83
|
+
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
78
84
|
}
|
|
79
85
|
} else {
|
|
80
86
|
// We might receive attestations before proposals in some cases
|
|
@@ -83,6 +89,6 @@ export class FishermanAttestationValidator extends CheckpointAttestationValidato
|
|
|
83
89
|
);
|
|
84
90
|
}
|
|
85
91
|
|
|
86
|
-
return
|
|
92
|
+
return { result: 'accept' };
|
|
87
93
|
}
|
|
88
94
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Maximum clock disparity tolerance for P2P message validation (in milliseconds).
|
|
6
|
+
* Messages for the previous slot are accepted if we're within this many milliseconds
|
|
7
|
+
* of the current slot start. This prevents penalizing peers for messages that
|
|
8
|
+
* were valid when sent but arrived slightly late due to network latency.
|
|
9
|
+
*
|
|
10
|
+
* This follows Ethereum's MAXIMUM_GOSSIP_CLOCK_DISPARITY approach.
|
|
11
|
+
*/
|
|
12
|
+
export const MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS = 500;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a message for the previous slot should be accepted due to clock tolerance.
|
|
16
|
+
*
|
|
17
|
+
* @param messageSlot - The slot number from the received message
|
|
18
|
+
* @param currentSlot - The current slot number
|
|
19
|
+
* @param epochCache - EpochCache to get timing information
|
|
20
|
+
* @returns true if the message is for the previous slot AND we're within the clock tolerance window
|
|
21
|
+
*/
|
|
22
|
+
export function isWithinClockTolerance(
|
|
23
|
+
messageSlot: SlotNumber,
|
|
24
|
+
currentSlot: SlotNumber,
|
|
25
|
+
epochCache: EpochCacheInterface,
|
|
26
|
+
): boolean {
|
|
27
|
+
// Guard against slot 0 edge case (genesis)
|
|
28
|
+
if (currentSlot === SlotNumber.ZERO) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Only apply tolerance to messages for the previous slot
|
|
33
|
+
const previousSlot = SlotNumber(currentSlot - 1);
|
|
34
|
+
if (messageSlot !== previousSlot) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Check how far we are into the current slot (in milliseconds)
|
|
39
|
+
const { ts: slotStartTs, nowMs, slot } = epochCache.getEpochAndSlotNow();
|
|
40
|
+
|
|
41
|
+
// Sanity check: ensure the epoch cache's current slot matches the expected current slot
|
|
42
|
+
if (slot !== currentSlot) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ts is in seconds, convert to ms; nowMs is already in milliseconds
|
|
47
|
+
const slotStartMs = slotStartTs * 1000n;
|
|
48
|
+
const elapsedMs = Number(nowMs - slotStartMs);
|
|
49
|
+
|
|
50
|
+
return elapsedMs < MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS;
|
|
51
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
2
|
import { NoCommitteeError } from '@aztec/ethereum/contracts';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { BlockProposal, CheckpointProposal, PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
4
|
+
import { BlockProposal, CheckpointProposal, PeerErrorSeverity, type ValidationResult } from '@aztec/stdlib/p2p';
|
|
5
|
+
|
|
6
|
+
import { isWithinClockTolerance } from '../clock_tolerance.js';
|
|
5
7
|
|
|
6
8
|
export abstract class ProposalValidator<TProposal extends BlockProposal | CheckpointProposal> {
|
|
7
9
|
protected epochCache: EpochCacheInterface;
|
|
@@ -14,22 +16,35 @@ export abstract class ProposalValidator<TProposal extends BlockProposal | Checkp
|
|
|
14
16
|
this.logger = createLogger(loggerName);
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
public async validate(proposal: TProposal): Promise<
|
|
19
|
+
public async validate(proposal: TProposal): Promise<ValidationResult> {
|
|
18
20
|
try {
|
|
21
|
+
// Slot check
|
|
22
|
+
const { currentSlot, nextSlot } = this.epochCache.getCurrentAndNextSlot();
|
|
23
|
+
const slotNumber = proposal.slotNumber;
|
|
24
|
+
if (slotNumber !== currentSlot && slotNumber !== nextSlot) {
|
|
25
|
+
// Check if message is for previous slot and within clock tolerance
|
|
26
|
+
if (!isWithinClockTolerance(slotNumber, currentSlot, this.epochCache)) {
|
|
27
|
+
this.logger.warn(`Penalizing peer for invalid slot number ${slotNumber}`, { currentSlot, nextSlot });
|
|
28
|
+
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
29
|
+
}
|
|
30
|
+
this.logger.verbose(`Ignoring proposal for previous slot ${slotNumber} within clock tolerance`);
|
|
31
|
+
return { result: 'ignore' };
|
|
32
|
+
}
|
|
33
|
+
|
|
19
34
|
// Signature validity
|
|
20
35
|
const proposer = proposal.getSender();
|
|
21
36
|
if (!proposer) {
|
|
22
|
-
this.logger.
|
|
23
|
-
return PeerErrorSeverity.MidToleranceError;
|
|
37
|
+
this.logger.warn(`Penalizing peer for proposal with invalid signature`);
|
|
38
|
+
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
24
39
|
}
|
|
25
40
|
|
|
26
41
|
// Transactions permitted check
|
|
27
42
|
const embeddedTxCount = proposal.txs?.length ?? 0;
|
|
28
43
|
if (!this.txsPermitted && (proposal.txHashes.length > 0 || embeddedTxCount > 0)) {
|
|
29
|
-
this.logger.
|
|
44
|
+
this.logger.warn(
|
|
30
45
|
`Penalizing peer for proposal with ${proposal.txHashes.length} transaction(s) when transactions are not permitted`,
|
|
31
46
|
);
|
|
32
|
-
return PeerErrorSeverity.MidToleranceError;
|
|
47
|
+
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
33
48
|
}
|
|
34
49
|
|
|
35
50
|
// Embedded txs must be listed in txHashes
|
|
@@ -44,32 +59,17 @@ export abstract class ProposalValidator<TProposal extends BlockProposal | Checkp
|
|
|
44
59
|
txHashesLength: proposal.txHashes.length,
|
|
45
60
|
missingTxHashes,
|
|
46
61
|
});
|
|
47
|
-
return PeerErrorSeverity.MidToleranceError;
|
|
62
|
+
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
48
63
|
}
|
|
49
64
|
|
|
50
|
-
//
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.logger.debug(`Penalizing peer for invalid slot number ${slotNumber}`, { currentSlot, nextSlot });
|
|
56
|
-
return PeerErrorSeverity.HighToleranceError;
|
|
57
|
-
}
|
|
58
|
-
if (slotNumber === currentSlot && currentProposer !== undefined && !proposer.equals(currentProposer)) {
|
|
59
|
-
this.logger.debug(`Penalizing peer for invalid proposer for current slot ${slotNumber}`, {
|
|
60
|
-
currentProposer,
|
|
61
|
-
nextProposer,
|
|
62
|
-
proposer: proposer.toString(),
|
|
63
|
-
});
|
|
64
|
-
return PeerErrorSeverity.MidToleranceError;
|
|
65
|
-
}
|
|
66
|
-
if (slotNumber === nextSlot && nextProposer !== undefined && !proposer.equals(nextProposer)) {
|
|
67
|
-
this.logger.debug(`Penalizing peer for invalid proposer for next slot ${slotNumber}`, {
|
|
68
|
-
currentProposer,
|
|
69
|
-
nextProposer,
|
|
65
|
+
// Proposer check
|
|
66
|
+
const expectedProposer = await this.epochCache.getProposerAttesterAddressInSlot(slotNumber);
|
|
67
|
+
if (expectedProposer !== undefined && !proposer.equals(expectedProposer)) {
|
|
68
|
+
this.logger.warn(`Penalizing peer for invalid proposer for current slot ${slotNumber}`, {
|
|
69
|
+
expectedProposer,
|
|
70
70
|
proposer: proposer.toString(),
|
|
71
71
|
});
|
|
72
|
-
return PeerErrorSeverity.MidToleranceError;
|
|
72
|
+
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
// Validate tx hashes for all txs embedded in the proposal
|
|
@@ -78,13 +78,13 @@ export abstract class ProposalValidator<TProposal extends BlockProposal | Checkp
|
|
|
78
78
|
proposer,
|
|
79
79
|
slotNumber,
|
|
80
80
|
});
|
|
81
|
-
return PeerErrorSeverity.LowToleranceError;
|
|
81
|
+
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
return
|
|
84
|
+
return { result: 'accept' };
|
|
85
85
|
} catch (e) {
|
|
86
86
|
if (e instanceof NoCommitteeError) {
|
|
87
|
-
return PeerErrorSeverity.LowToleranceError;
|
|
87
|
+
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
88
88
|
}
|
|
89
89
|
throw e;
|
|
90
90
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
2
|
import type { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
3
3
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type BlockProposal,
|
|
6
|
+
type CheckpointProposal,
|
|
7
|
+
PeerErrorSeverity,
|
|
8
|
+
type ValidationResult,
|
|
9
|
+
} from '@aztec/stdlib/p2p';
|
|
5
10
|
import type { TxHash } from '@aztec/stdlib/tx';
|
|
6
11
|
|
|
7
12
|
import type { MockProxy } from 'jest-mock-extended';
|
|
@@ -10,7 +15,7 @@ export interface ProposalValidatorTestParams<TProposal extends BlockProposal | C
|
|
|
10
15
|
validatorFactory: (
|
|
11
16
|
epochCache: EpochCacheInterface,
|
|
12
17
|
opts: { txsPermitted: boolean },
|
|
13
|
-
) => { validate: (proposal: TProposal) => Promise<
|
|
18
|
+
) => { validate: (proposal: TProposal) => Promise<ValidationResult> };
|
|
14
19
|
makeProposal: (options?: any) => Promise<TProposal>;
|
|
15
20
|
makeHeader: (epochNumber: number | bigint, slotNumber: number | bigint, blockNumber: number | bigint) => any;
|
|
16
21
|
getSigner: () => Secp256k1Signer;
|
|
@@ -29,24 +34,75 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
|
|
|
29
34
|
|
|
30
35
|
describe('shared proposal validation logic', () => {
|
|
31
36
|
let epochCache: MockProxy<EpochCacheInterface>;
|
|
32
|
-
let validator: { validate: (proposal: TProposal) => Promise<
|
|
37
|
+
let validator: { validate: (proposal: TProposal) => Promise<ValidationResult> };
|
|
38
|
+
const previousSlot = getSlot(99);
|
|
39
|
+
const currentSlot = getSlot(100);
|
|
40
|
+
const nextSlot = getSlot(101);
|
|
41
|
+
|
|
42
|
+
function mockGetProposer(currentProposer: EthAddress, nextProposer: EthAddress, previousProposer?: EthAddress) {
|
|
43
|
+
epochCache.getProposerAttesterAddressInSlot.mockImplementation(slot => {
|
|
44
|
+
if (slot === currentSlot) {
|
|
45
|
+
return Promise.resolve(currentProposer);
|
|
46
|
+
}
|
|
47
|
+
if (slot === nextSlot) {
|
|
48
|
+
return Promise.resolve(nextProposer);
|
|
49
|
+
}
|
|
50
|
+
if (slot === previousSlot && previousProposer) {
|
|
51
|
+
return Promise.resolve(previousProposer);
|
|
52
|
+
}
|
|
53
|
+
throw new Error('Unexpected argument');
|
|
54
|
+
});
|
|
55
|
+
}
|
|
33
56
|
|
|
34
57
|
beforeEach(() => {
|
|
35
58
|
epochCache = epochCacheMock();
|
|
36
59
|
validator = validatorFactory(epochCache, { txsPermitted: true });
|
|
60
|
+
epochCache.getCurrentAndNextSlot.mockReturnValue({
|
|
61
|
+
currentSlot: currentSlot,
|
|
62
|
+
nextSlot: nextSlot,
|
|
63
|
+
});
|
|
37
64
|
});
|
|
38
65
|
|
|
39
|
-
it('returns high tolerance error if slot number is not current or next slot', async () => {
|
|
40
|
-
const header = makeHeader(1,
|
|
66
|
+
it('returns high tolerance error if slot number is not current or next slot (outside clock tolerance)', async () => {
|
|
67
|
+
const header = makeHeader(1, 99, 99);
|
|
41
68
|
const mockProposal = await makeProposal({ blockHeader: header, lastBlockHeader: header });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
69
|
+
|
|
70
|
+
// Mock getEpochAndSlotNow to return time OUTSIDE clock tolerance (1000ms elapsed)
|
|
71
|
+
epochCache.getEpochAndSlotNow.mockReturnValue({
|
|
72
|
+
epoch: 1 as any,
|
|
73
|
+
slot: currentSlot,
|
|
74
|
+
ts: 1000n, // slot started at 1000 seconds
|
|
75
|
+
nowMs: 1001000n, // 1000ms elapsed, outside 500ms tolerance
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
epochCache.getProposerAttesterAddressInSlot.mockResolvedValue(getAddress());
|
|
79
|
+
const result = await validator.validate(mockProposal);
|
|
80
|
+
expect(result).toEqual({ result: 'reject', severity: PeerErrorSeverity.HighToleranceError });
|
|
81
|
+
|
|
82
|
+
// Should not try to resolve proposers if base validation fails
|
|
83
|
+
expect(epochCache.getProposerAttesterAddressInSlot).not.toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('returns ignore if previous slot proposal is within clock tolerance', async () => {
|
|
87
|
+
const previousProposer = getSigner();
|
|
88
|
+
const header = makeHeader(1, 99, 99);
|
|
89
|
+
const mockProposal = await makeProposal({
|
|
90
|
+
blockHeader: header,
|
|
91
|
+
lastBlockHeader: header,
|
|
92
|
+
signer: previousProposer,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Mock getEpochAndSlotNow to return time WITHIN clock tolerance (100ms elapsed)
|
|
96
|
+
epochCache.getEpochAndSlotNow.mockReturnValue({
|
|
97
|
+
epoch: 1 as any,
|
|
98
|
+
slot: currentSlot,
|
|
99
|
+
ts: 1000n, // slot started at 1000 seconds
|
|
100
|
+
nowMs: 1000100n, // 100ms elapsed, within 500ms tolerance
|
|
47
101
|
});
|
|
102
|
+
|
|
103
|
+
mockGetProposer(getAddress(), getAddress(), getAddress(previousProposer));
|
|
48
104
|
const result = await validator.validate(mockProposal);
|
|
49
|
-
expect(result).
|
|
105
|
+
expect(result).toEqual({ result: 'ignore' });
|
|
50
106
|
});
|
|
51
107
|
|
|
52
108
|
it('returns mid tolerance error if proposer is not current proposer for current slot', async () => {
|
|
@@ -59,14 +115,10 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
|
|
|
59
115
|
lastBlockHeader: header,
|
|
60
116
|
signer: invalidProposer,
|
|
61
117
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
nextSlot: getSlot(101),
|
|
65
|
-
currentProposer: getAddress(currentProposer),
|
|
66
|
-
nextProposer: getAddress(nextProposer),
|
|
67
|
-
});
|
|
118
|
+
|
|
119
|
+
mockGetProposer(getAddress(currentProposer), getAddress(nextProposer));
|
|
68
120
|
const result = await validator.validate(mockProposal);
|
|
69
|
-
expect(result).
|
|
121
|
+
expect(result).toEqual({ result: 'reject', severity: PeerErrorSeverity.MidToleranceError });
|
|
70
122
|
});
|
|
71
123
|
|
|
72
124
|
it('returns mid tolerance error if proposer is not next proposer for next slot', async () => {
|
|
@@ -79,14 +131,10 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
|
|
|
79
131
|
lastBlockHeader: header,
|
|
80
132
|
signer: invalidProposer,
|
|
81
133
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
nextSlot: getSlot(101),
|
|
85
|
-
currentProposer: getAddress(currentProposer),
|
|
86
|
-
nextProposer: getAddress(nextProposer),
|
|
87
|
-
});
|
|
134
|
+
|
|
135
|
+
mockGetProposer(getAddress(currentProposer), getAddress(nextProposer));
|
|
88
136
|
const result = await validator.validate(mockProposal);
|
|
89
|
-
expect(result).
|
|
137
|
+
expect(result).toEqual({ result: 'reject', severity: PeerErrorSeverity.MidToleranceError });
|
|
90
138
|
});
|
|
91
139
|
|
|
92
140
|
it('returns mid tolerance error if proposer is current proposer but proposal is for next slot', async () => {
|
|
@@ -98,14 +146,10 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
|
|
|
98
146
|
lastBlockHeader: header,
|
|
99
147
|
signer: currentProposer,
|
|
100
148
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
nextSlot: getSlot(101),
|
|
104
|
-
currentProposer: getAddress(currentProposer),
|
|
105
|
-
nextProposer: getAddress(nextProposer),
|
|
106
|
-
});
|
|
149
|
+
|
|
150
|
+
mockGetProposer(getAddress(currentProposer), getAddress(nextProposer));
|
|
107
151
|
const result = await validator.validate(mockProposal);
|
|
108
|
-
expect(result).
|
|
152
|
+
expect(result).toEqual({ result: 'reject', severity: PeerErrorSeverity.MidToleranceError });
|
|
109
153
|
});
|
|
110
154
|
|
|
111
155
|
it('returns undefined if proposal is valid for current slot and proposer', async () => {
|
|
@@ -117,14 +161,10 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
|
|
|
117
161
|
lastBlockHeader: header,
|
|
118
162
|
signer: currentProposer,
|
|
119
163
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
nextSlot: getSlot(101),
|
|
123
|
-
currentProposer: getAddress(currentProposer),
|
|
124
|
-
nextProposer: getAddress(nextProposer),
|
|
125
|
-
});
|
|
164
|
+
|
|
165
|
+
mockGetProposer(getAddress(currentProposer), getAddress(nextProposer));
|
|
126
166
|
const result = await validator.validate(mockProposal);
|
|
127
|
-
expect(result).
|
|
167
|
+
expect(result).toEqual({ result: 'accept' });
|
|
128
168
|
});
|
|
129
169
|
|
|
130
170
|
it('returns undefined if proposal is valid for next slot and proposer', async () => {
|
|
@@ -132,14 +172,10 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
|
|
|
132
172
|
const nextProposer = getSigner();
|
|
133
173
|
const header = makeHeader(1, 101, 101);
|
|
134
174
|
const mockProposal = await makeProposal({ blockHeader: header, lastBlockHeader: header, signer: nextProposer });
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
nextSlot: getSlot(101),
|
|
138
|
-
currentProposer: getAddress(currentProposer),
|
|
139
|
-
nextProposer: getAddress(nextProposer),
|
|
140
|
-
});
|
|
175
|
+
|
|
176
|
+
mockGetProposer(getAddress(currentProposer), getAddress(nextProposer));
|
|
141
177
|
const result = await validator.validate(mockProposal);
|
|
142
|
-
expect(result).
|
|
178
|
+
expect(result).toEqual({ result: 'accept' });
|
|
143
179
|
});
|
|
144
180
|
|
|
145
181
|
describe('transaction permission validation', () => {
|
|
@@ -153,14 +189,10 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
|
|
|
153
189
|
signer: currentProposer,
|
|
154
190
|
txHashes: getTxHashes(2),
|
|
155
191
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
nextSlot: getSlot(101),
|
|
159
|
-
currentProposer: getAddress(currentProposer),
|
|
160
|
-
nextProposer: getAddress(),
|
|
161
|
-
});
|
|
192
|
+
|
|
193
|
+
mockGetProposer(getAddress(currentProposer), getAddress());
|
|
162
194
|
const result = await validatorWithTxsDisabled.validate(mockProposal);
|
|
163
|
-
expect(result).
|
|
195
|
+
expect(result).toEqual({ result: 'reject', severity: PeerErrorSeverity.MidToleranceError });
|
|
164
196
|
});
|
|
165
197
|
|
|
166
198
|
it('returns undefined if txs not permitted but proposal has no txHashes', async () => {
|
|
@@ -173,14 +205,10 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
|
|
|
173
205
|
signer: currentProposer,
|
|
174
206
|
txHashes: getTxHashes(0),
|
|
175
207
|
});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
nextSlot: getSlot(101),
|
|
179
|
-
currentProposer: getAddress(currentProposer),
|
|
180
|
-
nextProposer: getAddress(),
|
|
181
|
-
});
|
|
208
|
+
|
|
209
|
+
mockGetProposer(getAddress(currentProposer), getAddress());
|
|
182
210
|
const result = await validatorWithTxsDisabled.validate(mockProposal);
|
|
183
|
-
expect(result).
|
|
211
|
+
expect(result).toEqual({ result: 'accept' });
|
|
184
212
|
});
|
|
185
213
|
|
|
186
214
|
it('returns undefined if txs permitted and proposal contains txHashes', async () => {
|
|
@@ -192,14 +220,10 @@ export function sharedProposalValidatorTests<TProposal extends BlockProposal | C
|
|
|
192
220
|
signer: currentProposer,
|
|
193
221
|
txHashes: getTxHashes(2),
|
|
194
222
|
});
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
nextSlot: getSlot(101),
|
|
198
|
-
currentProposer: getAddress(currentProposer),
|
|
199
|
-
nextProposer: getAddress(),
|
|
200
|
-
});
|
|
223
|
+
|
|
224
|
+
mockGetProposer(getAddress(currentProposer), getAddress());
|
|
201
225
|
const result = await validator.validate(mockProposal);
|
|
202
|
-
expect(result).
|
|
226
|
+
expect(result).toEqual({ result: 'accept' });
|
|
203
227
|
});
|
|
204
228
|
});
|
|
205
229
|
});
|