@aztec/p2p 3.0.0-canary.a9708bd → 3.0.0-devnet.2-patch.1
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 +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +14 -4
- package/dest/client/factory.d.ts +2 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +8 -3
- package/dest/client/index.d.ts +1 -1
- package/dest/client/interface.d.ts +8 -6
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +11 -34
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +68 -46
- package/dest/config.d.ts +65 -56
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +21 -5
- package/dest/enr/generate-enr.d.ts +2 -2
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +1 -1
- package/dest/enr/index.d.ts +1 -1
- package/dest/errors/attestation-pool.error.d.ts +7 -0
- package/dest/errors/attestation-pool.error.d.ts.map +1 -0
- package/dest/errors/attestation-pool.error.js +12 -0
- package/dest/errors/reqresp.error.d.ts +1 -1
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +43 -6
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +72 -46
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +15 -6
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +73 -18
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +13 -6
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +69 -11
- package/dest/mem_pools/attestation_pool/mocks.d.ts +226 -5
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +9 -7
- package/dest/mem_pools/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +3 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +11 -2
- package/dest/mem_pools/interface.d.ts +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +17 -40
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +103 -44
- package/dest/mem_pools/tx_pool/index.d.ts +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +19 -6
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +88 -9
- package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +21 -6
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +132 -7
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +32 -5
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
- package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
- package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/index.js +1 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +5 -2
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +56 -9
- package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
- package/dest/msg_validators/index.d.ts +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +1 -1
- package/dest/msg_validators/tx_validator/factory.d.ts +4 -3
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +11 -5
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/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 -6
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +6 -24
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -1
- package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +13 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.d.ts +3 -3
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +2 -2
- package/dest/services/dummy_service.d.ts +2 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/encoding.d.ts +25 -4
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +74 -6
- package/dest/services/gossipsub/scoring.d.ts +1 -1
- package/dest/services/index.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +9 -2
- package/dest/services/libp2p/libp2p_service.d.ts +29 -69
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +375 -133
- package/dest/services/peer-manager/interface.d.ts +1 -1
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +11 -0
- package/dest/services/peer-manager/peer_manager.d.ts +1 -32
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +27 -12
- 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 +40 -2
- package/dest/services/reqresp/config.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/index.d.ts +1 -1
- package/dest/services/reqresp/interface.d.ts +2 -11
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +1 -18
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.d.ts +2 -2
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.js +2 -2
- package/dest/services/reqresp/protocols/block.d.ts +1 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +4 -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 +1 -1
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +1 -1
- package/dest/services/reqresp/protocols/goodbye.d.ts +1 -1
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -1
- package/dest/services/reqresp/protocols/ping.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +6 -5
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -3
- package/dest/services/reqresp/protocols/tx.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +2 -2
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts +1 -41
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +14 -10
- package/dest/services/reqresp/status.d.ts +2 -2
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/service.d.ts +2 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -9
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +6 -1
- package/dest/services/tx_collection/index.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -7
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +2 -1
- package/dest/services/tx_collection/tx_collection.d.ts +12 -11
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +3 -2
- package/dest/services/tx_collection/tx_collection_sink.d.ts +3 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +34 -4
- package/dest/services/tx_collection/tx_source.d.ts +1 -1
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +2 -2
- package/dest/services/tx_provider.d.ts +5 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +8 -4
- package/dest/services/tx_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +1 -1
- package/dest/test-helpers/make-enrs.d.ts +1 -1
- package/dest/test-helpers/make-enrs.js +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts +2 -2
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +4 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
- package/dest/test-helpers/mock-tx-helpers.js +19 -0
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +4 -3
- package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +16 -9
- package/dest/testbench/parse_log_file.d.ts +1 -1
- package/dest/testbench/testbench.d.ts +1 -1
- package/dest/testbench/testbench.js +2 -2
- package/dest/testbench/worker_client_manager.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/types/index.d.ts +1 -1
- package/dest/util.d.ts +2 -1
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +11 -2
- package/dest/versioning.d.ts +2 -2
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +2 -2
- package/package.json +21 -21
- package/src/bootstrap/bootstrap.ts +15 -4
- package/src/client/factory.ts +17 -3
- package/src/client/interface.ts +8 -5
- package/src/client/p2p_client.ts +88 -74
- package/src/config.ts +33 -6
- package/src/enr/generate-enr.ts +1 -1
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +46 -5
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +89 -48
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +107 -24
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +98 -19
- package/src/mem_pools/attestation_pool/mocks.ts +11 -8
- package/src/mem_pools/instrumentation.ts +13 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +116 -48
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +98 -12
- package/src/mem_pools/tx_pool/tx_pool.ts +20 -5
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +115 -7
- package/src/msg_validators/attestation_validator/attestation_validator.ts +41 -6
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +63 -18
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
- package/src/msg_validators/tx_validator/double_spend_validator.ts +1 -1
- package/src/msg_validators/tx_validator/factory.ts +13 -6
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +8 -42
- package/src/msg_validators/tx_validator/phases_validator.ts +3 -1
- package/src/msg_validators/tx_validator/test_utils.ts +1 -1
- package/src/msg_validators/tx_validator/timestamp_validator.ts +47 -0
- package/src/services/discv5/discV5_service.ts +2 -2
- package/src/services/dummy_service.ts +1 -1
- package/src/services/encoding.ts +81 -6
- package/src/services/libp2p/instrumentation.ts +10 -1
- package/src/services/libp2p/libp2p_service.ts +427 -157
- package/src/services/peer-manager/metrics.ts +10 -0
- package/src/services/peer-manager/peer_manager.ts +22 -14
- package/src/services/peer-manager/peer_scoring.ts +46 -3
- package/src/services/reqresp/interface.ts +1 -22
- package/src/services/reqresp/protocols/auth.ts +2 -2
- package/src/services/reqresp/protocols/block.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
- package/src/services/reqresp/protocols/status.ts +9 -8
- package/src/services/reqresp/reqresp.ts +15 -11
- package/src/services/service.ts +1 -1
- package/src/services/tx_collection/fast_tx_collection.ts +8 -5
- package/src/services/tx_collection/slow_tx_collection.ts +7 -6
- package/src/services/tx_collection/tx_collection.ts +12 -10
- package/src/services/tx_collection/tx_collection_sink.ts +34 -3
- package/src/services/tx_collection/tx_source.ts +2 -2
- package/src/services/tx_provider.ts +9 -7
- package/src/test-helpers/make-enrs.ts +1 -1
- package/src/test-helpers/mock-tx-helpers.ts +24 -0
- package/src/test-helpers/reqresp-nodes.ts +3 -2
- package/src/testbench/p2p_client_testbench_worker.ts +12 -5
- package/src/testbench/testbench.ts +2 -2
- package/src/util.ts +12 -2
- package/src/versioning.ts +3 -3
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
|
|
3
4
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
4
5
|
|
|
5
6
|
import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
|
|
6
7
|
import type { AttestationPool } from './attestation_pool.js';
|
|
8
|
+
import { ATTESTATION_CAP_BUFFER, MAX_PROPOSALS_PER_SLOT } from './kv_attestation_pool.js';
|
|
7
9
|
|
|
8
10
|
export class InMemoryAttestationPool implements AttestationPool {
|
|
9
11
|
private metrics: PoolInstrumentation<BlockAttestation>;
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
14
|
+
private attestations: Map<
|
|
15
|
+
/*slot=*/ SlotNumber,
|
|
16
|
+
Map</*proposalId*/ string, Map</*address=*/ string, BlockAttestation>>
|
|
17
|
+
>;
|
|
12
18
|
private proposals: Map<string, BlockProposal>;
|
|
13
19
|
|
|
14
20
|
constructor(
|
|
@@ -30,7 +36,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
30
36
|
return Promise.resolve(this.attestations.size === 0);
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
public getAttestationsForSlot(slot:
|
|
39
|
+
public getAttestationsForSlot(slot: SlotNumber): Promise<BlockAttestation[]> {
|
|
34
40
|
return Promise.resolve(
|
|
35
41
|
Array.from(this.attestations.get(slot)?.values() ?? []).flatMap(proposalAttestationMap =>
|
|
36
42
|
Array.from(proposalAttestationMap.values()),
|
|
@@ -38,7 +44,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
38
44
|
);
|
|
39
45
|
}
|
|
40
46
|
|
|
41
|
-
public getAttestationsForSlotAndProposal(slot:
|
|
47
|
+
public getAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<BlockAttestation[]> {
|
|
42
48
|
const slotAttestationMap = this.attestations.get(slot);
|
|
43
49
|
if (slotAttestationMap) {
|
|
44
50
|
const proposalAttestationMap = slotAttestationMap.get(proposalId);
|
|
@@ -55,16 +61,26 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
55
61
|
const slotNumber = attestation.payload.header.slotNumber;
|
|
56
62
|
|
|
57
63
|
const proposalId = attestation.archive.toString();
|
|
58
|
-
const
|
|
64
|
+
const sender = attestation.getSender();
|
|
59
65
|
|
|
60
|
-
|
|
66
|
+
// Skip attestations with invalid signatures
|
|
67
|
+
if (!sender) {
|
|
68
|
+
this.log.warn(`Skipping attestation with invalid signature for slot ${slotNumber}`, {
|
|
69
|
+
signature: attestation.signature.toString(),
|
|
70
|
+
slotNumber,
|
|
71
|
+
proposalId,
|
|
72
|
+
});
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const slotAttestationMap = getSlotOrDefault(this.attestations, slotNumber);
|
|
61
77
|
const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
|
|
62
|
-
proposalAttestationMap.set(
|
|
78
|
+
proposalAttestationMap.set(sender.toString(), attestation);
|
|
63
79
|
|
|
64
|
-
this.log.verbose(`Added attestation for slot ${slotNumber
|
|
80
|
+
this.log.verbose(`Added attestation for slot ${slotNumber} from ${sender}`, {
|
|
65
81
|
signature: attestation.signature.toString(),
|
|
66
82
|
slotNumber,
|
|
67
|
-
address,
|
|
83
|
+
address: sender,
|
|
68
84
|
proposalId,
|
|
69
85
|
});
|
|
70
86
|
}
|
|
@@ -72,7 +88,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
72
88
|
return Promise.resolve();
|
|
73
89
|
}
|
|
74
90
|
|
|
75
|
-
#getNumberOfAttestationsInSlot(slot:
|
|
91
|
+
#getNumberOfAttestationsInSlot(slot: SlotNumber): number {
|
|
76
92
|
let total = 0;
|
|
77
93
|
const slotAttestationMap = getSlotOrDefault(this.attestations, slot);
|
|
78
94
|
|
|
@@ -84,7 +100,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
84
100
|
return total;
|
|
85
101
|
}
|
|
86
102
|
|
|
87
|
-
public async deleteAttestationsOlderThan(oldestSlot:
|
|
103
|
+
public async deleteAttestationsOlderThan(oldestSlot: SlotNumber): Promise<void> {
|
|
88
104
|
const olderThan = [];
|
|
89
105
|
|
|
90
106
|
// Entries are iterated in insertion order, so we can break as soon as we find a slot that is older than the oldestSlot.
|
|
@@ -105,7 +121,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
105
121
|
return Promise.resolve();
|
|
106
122
|
}
|
|
107
123
|
|
|
108
|
-
public deleteAttestationsForSlot(slot:
|
|
124
|
+
public deleteAttestationsForSlot(slot: SlotNumber): Promise<void> {
|
|
109
125
|
// We count the number of attestations we are removing
|
|
110
126
|
const numberOfAttestations = this.#getNumberOfAttestationsInSlot(slot);
|
|
111
127
|
const proposalIdsToDelete = this.attestations.get(slot)?.keys();
|
|
@@ -123,7 +139,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
123
139
|
return Promise.resolve();
|
|
124
140
|
}
|
|
125
141
|
|
|
126
|
-
public deleteAttestationsForSlotAndProposal(slot:
|
|
142
|
+
public deleteAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<void> {
|
|
127
143
|
const slotAttestationMap = getSlotOrDefault(this.attestations, slot);
|
|
128
144
|
if (slotAttestationMap) {
|
|
129
145
|
if (slotAttestationMap.has(proposalId)) {
|
|
@@ -142,24 +158,54 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
142
158
|
public deleteAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
143
159
|
for (const attestation of attestations) {
|
|
144
160
|
const slotNumber = attestation.payload.header.slotNumber;
|
|
145
|
-
const slotAttestationMap = this.attestations.get(slotNumber
|
|
161
|
+
const slotAttestationMap = this.attestations.get(slotNumber);
|
|
146
162
|
if (slotAttestationMap) {
|
|
147
163
|
const proposalId = attestation.archive.toString();
|
|
148
164
|
const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
|
|
149
165
|
if (proposalAttestationMap) {
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
166
|
+
const sender = attestation.getSender();
|
|
167
|
+
|
|
168
|
+
// Skip attestations with invalid signatures
|
|
169
|
+
if (!sender) {
|
|
170
|
+
this.log.warn(`Skipping deletion of attestation with invalid signature for slot ${slotNumber}`);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
proposalAttestationMap.delete(sender.toString());
|
|
175
|
+
this.log.debug(`Deleted attestation for slot ${slotNumber} from ${sender}`);
|
|
153
176
|
}
|
|
154
177
|
}
|
|
155
178
|
}
|
|
156
179
|
return Promise.resolve();
|
|
157
180
|
}
|
|
158
181
|
|
|
182
|
+
public hasAttestation(attestation: BlockAttestation): Promise<boolean> {
|
|
183
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
184
|
+
const proposalId = attestation.archive.toString();
|
|
185
|
+
const sender = attestation.getSender();
|
|
186
|
+
|
|
187
|
+
// Attestations with invalid signatures are never in the pool
|
|
188
|
+
if (!sender) {
|
|
189
|
+
return Promise.resolve(false);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const slotAttestationMap = this.attestations.get(slotNumber);
|
|
193
|
+
if (!slotAttestationMap) {
|
|
194
|
+
return Promise.resolve(false);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const proposalAttestationMap = slotAttestationMap.get(proposalId);
|
|
198
|
+
if (!proposalAttestationMap) {
|
|
199
|
+
return Promise.resolve(false);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return Promise.resolve(proposalAttestationMap.has(sender.toString()));
|
|
203
|
+
}
|
|
204
|
+
|
|
159
205
|
public addBlockProposal(blockProposal: BlockProposal): Promise<void> {
|
|
160
206
|
// We initialize slot-proposal mapping if it does not exist
|
|
161
207
|
// This is important to ensure we can delete this proposal if there were not attestations for it
|
|
162
|
-
const slotProposalMapping = getSlotOrDefault(this.attestations, blockProposal.slotNumber
|
|
208
|
+
const slotProposalMapping = getSlotOrDefault(this.attestations, blockProposal.slotNumber);
|
|
163
209
|
slotProposalMapping.set(blockProposal.payload.archive.toString(), new Map<string, BlockAttestation>());
|
|
164
210
|
|
|
165
211
|
this.proposals.set(blockProposal.payload.archive.toString(), blockProposal);
|
|
@@ -169,6 +215,38 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
169
215
|
public getBlockProposal(id: string): Promise<BlockProposal | undefined> {
|
|
170
216
|
return Promise.resolve(this.proposals.get(id));
|
|
171
217
|
}
|
|
218
|
+
|
|
219
|
+
public hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean> {
|
|
220
|
+
const id = typeof idOrProposal === 'string' ? idOrProposal : idOrProposal.payload.archive.toString();
|
|
221
|
+
return Promise.resolve(this.proposals.has(id));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public hasReachedProposalCap(slot: SlotNumber): Promise<boolean> {
|
|
225
|
+
const slotAttestationMap = this.attestations.get(slot);
|
|
226
|
+
const proposalCount = slotAttestationMap?.size ?? 0;
|
|
227
|
+
return Promise.resolve(proposalCount >= MAX_PROPOSALS_PER_SLOT);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public hasReachedAttestationCap(slot: SlotNumber, proposalId: string, committeeSize: number): Promise<boolean> {
|
|
231
|
+
const limit = committeeSize + ATTESTATION_CAP_BUFFER;
|
|
232
|
+
const count = this.attestations.get(slot)?.get(proposalId)?.size ?? 0;
|
|
233
|
+
return Promise.resolve(limit <= 0 || count >= limit);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public async canAddProposal(block: BlockProposal): Promise<boolean> {
|
|
237
|
+
return this.proposals.has(block.archive.toString()) || !(await this.hasReachedProposalCap(block.slotNumber));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public async canAddAttestation(attestation: BlockAttestation, committeeSize: number): Promise<boolean> {
|
|
241
|
+
const sender = attestation.getSender();
|
|
242
|
+
const slot = attestation.payload.header.slotNumber;
|
|
243
|
+
const pid = attestation.archive.toString();
|
|
244
|
+
return (
|
|
245
|
+
!!sender &&
|
|
246
|
+
((this.attestations.get(slot)?.get(pid)?.has(sender.toString()) ?? false) ||
|
|
247
|
+
!(await this.hasReachedAttestationCap(slot, pid, committeeSize)))
|
|
248
|
+
);
|
|
249
|
+
}
|
|
172
250
|
}
|
|
173
251
|
|
|
174
252
|
/**
|
|
@@ -180,8 +258,9 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
180
258
|
* @returns The slot mapping
|
|
181
259
|
*/
|
|
182
260
|
function getSlotOrDefault(
|
|
183
|
-
|
|
184
|
-
|
|
261
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
262
|
+
map: Map<SlotNumber, Map<string, Map<string, BlockAttestation>>>,
|
|
263
|
+
slot: SlotNumber,
|
|
185
264
|
): Map<string, Map<string, BlockAttestation>> {
|
|
186
265
|
if (!map.has(slot)) {
|
|
187
266
|
map.set(slot, new Map<string, Map<string, BlockAttestation>>());
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import {
|
|
4
4
|
BlockAttestation,
|
|
5
5
|
ConsensusPayload,
|
|
6
6
|
SignatureDomainSeparator,
|
|
7
7
|
getHashedSignaturePayloadEthSignedMessage,
|
|
8
8
|
} from '@aztec/stdlib/p2p';
|
|
9
|
-
import {
|
|
9
|
+
import { makeL2BlockHeader } from '@aztec/stdlib/testing';
|
|
10
10
|
|
|
11
11
|
import { type LocalAccount, generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
12
12
|
|
|
@@ -32,11 +32,14 @@ export const mockAttestation = (
|
|
|
32
32
|
archive: Fr = Fr.random(),
|
|
33
33
|
): BlockAttestation => {
|
|
34
34
|
// Use arbitrary numbers for all other than slot
|
|
35
|
-
const header =
|
|
36
|
-
const payload = new ConsensusPayload(header.
|
|
35
|
+
const header = makeL2BlockHeader(1, 2, slot);
|
|
36
|
+
const payload = new ConsensusPayload(header.toCheckpointHeader(), archive);
|
|
37
37
|
|
|
38
|
-
const
|
|
39
|
-
const
|
|
38
|
+
const attestationHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockAttestation);
|
|
39
|
+
const attestationSignature = signer.sign(attestationHash);
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
const proposalHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockProposal);
|
|
42
|
+
const proposerSignature = signer.sign(proposalHash);
|
|
43
|
+
|
|
44
|
+
return new BlockAttestation(payload, attestationSignature, proposerSignature);
|
|
42
45
|
};
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type MetricsType,
|
|
11
11
|
type ObservableGauge,
|
|
12
12
|
type TelemetryClient,
|
|
13
|
+
type UpDownCounter,
|
|
13
14
|
} from '@aztec/telemetry-client';
|
|
14
15
|
|
|
15
16
|
export enum PoolName {
|
|
@@ -20,6 +21,7 @@ export enum PoolName {
|
|
|
20
21
|
type MetricsLabels = {
|
|
21
22
|
objectInMempool: MetricsType;
|
|
22
23
|
objectSize: MetricsType;
|
|
24
|
+
itemsAdded: MetricsType;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
/**
|
|
@@ -32,11 +34,13 @@ function getMetricsLabels(name: PoolName): MetricsLabels {
|
|
|
32
34
|
return {
|
|
33
35
|
objectInMempool: Metrics.MEMPOOL_TX_COUNT,
|
|
34
36
|
objectSize: Metrics.MEMPOOL_TX_SIZE,
|
|
37
|
+
itemsAdded: Metrics.MEMPOOL_TX_ADDED_COUNT,
|
|
35
38
|
};
|
|
36
39
|
} else if (name === PoolName.ATTESTATION_POOL) {
|
|
37
40
|
return {
|
|
38
41
|
objectInMempool: Metrics.MEMPOOL_ATTESTATIONS_COUNT,
|
|
39
42
|
objectSize: Metrics.MEMPOOL_ATTESTATIONS_SIZE,
|
|
43
|
+
itemsAdded: Metrics.MEMPOOL_ATTESTATIONS_ADDED_COUNT,
|
|
40
44
|
};
|
|
41
45
|
}
|
|
42
46
|
|
|
@@ -53,6 +57,7 @@ export type PoolStatsCallback = () => Promise<{
|
|
|
53
57
|
export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
54
58
|
/** The number of txs in the mempool */
|
|
55
59
|
private objectsInMempool: ObservableGauge;
|
|
60
|
+
private addObjectCounter: UpDownCounter;
|
|
56
61
|
/** Tracks tx size */
|
|
57
62
|
private objectSize: Histogram;
|
|
58
63
|
|
|
@@ -89,6 +94,10 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
89
94
|
dbStats,
|
|
90
95
|
);
|
|
91
96
|
|
|
97
|
+
this.addObjectCounter = this.meter.createUpDownCounter(metricsLabels.itemsAdded, {
|
|
98
|
+
description: 'The number of transactions added to the mempool',
|
|
99
|
+
});
|
|
100
|
+
|
|
92
101
|
this.meter.addBatchObservableCallback(this.observeStats, [this.objectsInMempool]);
|
|
93
102
|
}
|
|
94
103
|
|
|
@@ -96,6 +105,10 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
96
105
|
this.objectSize.record(poolObject.getSize());
|
|
97
106
|
}
|
|
98
107
|
|
|
108
|
+
public incrementAddedObjects(count: number) {
|
|
109
|
+
this.addObjectCounter.add(count);
|
|
110
|
+
}
|
|
111
|
+
|
|
99
112
|
private observeStats = async (observer: BatchObservableResult) => {
|
|
100
113
|
const { itemCount } = await this.poolStats();
|
|
101
114
|
if (typeof itemCount === 'number') {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
3
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
@@ -6,7 +7,7 @@ import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap, AztecAsyncSi
|
|
|
6
7
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
7
8
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
8
9
|
import type { MerkleTreeReadOperations, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
9
|
-
import {
|
|
10
|
+
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
10
11
|
import type { TxAddedToPoolStats } from '@aztec/stdlib/stats';
|
|
11
12
|
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
12
13
|
import { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
@@ -37,7 +38,7 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
37
38
|
txPoolOverflowFactor: number = 1;
|
|
38
39
|
|
|
39
40
|
/** Index from tx hash to the block number in which they were mined, filtered by mined txs. */
|
|
40
|
-
#minedTxHashToBlock: AztecAsyncMap<string,
|
|
41
|
+
#minedTxHashToBlock: AztecAsyncMap<string, BlockNumber>;
|
|
41
42
|
|
|
42
43
|
/** Index from tx priority (stored as hex) to its tx hash, filtered by pending txs. */
|
|
43
44
|
#pendingTxPriorityToHash: AztecAsyncMultiMap<string, string>;
|
|
@@ -48,6 +49,12 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
48
49
|
/** Index from tx hash to its header hash, filtered by pending txs. */
|
|
49
50
|
#pendingTxHashToHeaderHash: AztecAsyncMap<string, string>;
|
|
50
51
|
|
|
52
|
+
/** Map from tx hash to the block number it was originally mined in (for soft-deleted txs). */
|
|
53
|
+
#deletedMinedTxHashes: AztecAsyncMap<string, BlockNumber>;
|
|
54
|
+
|
|
55
|
+
/** MultiMap from block number to deleted mined tx hashes for efficient cleanup. */
|
|
56
|
+
#blockToDeletedMinedTxHash: AztecAsyncMultiMap<BlockNumber, string>;
|
|
57
|
+
|
|
51
58
|
/** The cumulative tx size in bytes that the pending txs in the pool take up. */
|
|
52
59
|
#pendingTxSize: AztecAsyncSingleton<number>;
|
|
53
60
|
|
|
@@ -103,6 +110,8 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
103
110
|
this.#pendingTxHashToSize = store.openMap('pendingTxHashToSize');
|
|
104
111
|
this.#pendingTxHashToHeaderHash = store.openMap('pendingTxHashToHeaderHash');
|
|
105
112
|
this.#pendingTxSize = store.openSingleton('pendingTxSize');
|
|
113
|
+
this.#deletedMinedTxHashes = store.openMap('deletedMinedTxHashes');
|
|
114
|
+
this.#blockToDeletedMinedTxHash = store.openMultiMap('blockToDeletedMinedTxHash');
|
|
106
115
|
|
|
107
116
|
this.#pendingTxs = new Map<string, Tx>();
|
|
108
117
|
this.#nonEvictableTxs = new Set<string>();
|
|
@@ -152,6 +161,17 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
152
161
|
let pendingTxSize = (await this.#pendingTxSize.getAsync()) ?? 0;
|
|
153
162
|
for (const hash of txHashes) {
|
|
154
163
|
const key = hash.toString();
|
|
164
|
+
|
|
165
|
+
// If this tx was previously soft-deleted, remove it from the deleted sets
|
|
166
|
+
if (await this.#deletedMinedTxHashes.hasAsync(key)) {
|
|
167
|
+
const originalBlock = await this.#deletedMinedTxHashes.getAsync(key);
|
|
168
|
+
await this.#deletedMinedTxHashes.delete(key);
|
|
169
|
+
// Remove from block-to-hash mapping
|
|
170
|
+
if (originalBlock !== undefined) {
|
|
171
|
+
await this.#blockToDeletedMinedTxHash.deleteValue(originalBlock, key);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
155
175
|
await this.#minedTxHashToBlock.set(key, blockHeader.globalVariables.blockNumber);
|
|
156
176
|
|
|
157
177
|
const tx = await this.getPendingTxByHash(hash);
|
|
@@ -200,10 +220,10 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
200
220
|
|
|
201
221
|
public async getPendingTxHashes(): Promise<TxHash[]> {
|
|
202
222
|
const vals = await toArray(this.#pendingTxPriorityToHash.valuesAsync({ reverse: true }));
|
|
203
|
-
return vals.map(
|
|
223
|
+
return vals.map(TxHash.fromString);
|
|
204
224
|
}
|
|
205
225
|
|
|
206
|
-
public async getMinedTxHashes(): Promise<[TxHash,
|
|
226
|
+
public async getMinedTxHashes(): Promise<[TxHash, BlockNumber][]> {
|
|
207
227
|
const vals = await toArray(this.#minedTxHashToBlock.entriesAsync());
|
|
208
228
|
return vals.map(([txHash, blockNumber]) => [TxHash.fromString(txHash), blockNumber]);
|
|
209
229
|
}
|
|
@@ -216,11 +236,17 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
216
236
|
return (await this.#minedTxHashToBlock.sizeAsync()) ?? 0;
|
|
217
237
|
}
|
|
218
238
|
|
|
219
|
-
public async getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
|
|
239
|
+
public async getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | 'deleted' | undefined> {
|
|
220
240
|
const key = txHash.toString();
|
|
221
|
-
const [isMined, isKnown] = await Promise.all([
|
|
222
|
-
|
|
223
|
-
|
|
241
|
+
const [isMined, isKnown, isDeleted] = await Promise.all([
|
|
242
|
+
this.#minedTxHashToBlock.hasAsync(key),
|
|
243
|
+
this.#txs.hasAsync(key),
|
|
244
|
+
this.#deletedMinedTxHashes.hasAsync(key),
|
|
245
|
+
]);
|
|
246
|
+
|
|
247
|
+
if (isDeleted) {
|
|
248
|
+
return 'deleted';
|
|
249
|
+
} else if (isMined) {
|
|
224
250
|
return 'mined';
|
|
225
251
|
} else if (isKnown) {
|
|
226
252
|
return 'pending';
|
|
@@ -236,30 +262,23 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
236
262
|
*/
|
|
237
263
|
public async getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
238
264
|
const buffer = await this.#txs.getAsync(txHash.toString());
|
|
239
|
-
|
|
240
|
-
const tx = Tx.fromBuffer(buffer);
|
|
241
|
-
tx.setTxHash(txHash);
|
|
242
|
-
return tx;
|
|
243
|
-
}
|
|
244
|
-
return undefined;
|
|
265
|
+
return buffer ? Tx.fromBuffer(buffer) : undefined;
|
|
245
266
|
}
|
|
246
267
|
|
|
247
268
|
async getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
248
269
|
const txs = await Promise.all(txHashes.map(txHash => this.#txs.getAsync(txHash.toString())));
|
|
249
|
-
return txs.map((buffer
|
|
250
|
-
if (buffer) {
|
|
251
|
-
const tx = Tx.fromBuffer(buffer);
|
|
252
|
-
tx.setTxHash(txHashes[index]);
|
|
253
|
-
return tx;
|
|
254
|
-
}
|
|
255
|
-
return undefined;
|
|
256
|
-
});
|
|
270
|
+
return txs.map(buffer => (buffer ? Tx.fromBuffer(buffer) : undefined));
|
|
257
271
|
}
|
|
258
272
|
|
|
259
273
|
async hasTxs(txHashes: TxHash[]): Promise<boolean[]> {
|
|
260
274
|
return await Promise.all(txHashes.map(txHash => this.#txs.hasAsync(txHash.toString())));
|
|
261
275
|
}
|
|
262
276
|
|
|
277
|
+
async hasTx(txHash: TxHash): Promise<boolean> {
|
|
278
|
+
const result = await this.hasTxs([txHash]);
|
|
279
|
+
return result[0];
|
|
280
|
+
}
|
|
281
|
+
|
|
263
282
|
/**
|
|
264
283
|
* Checks if an archived tx exists and returns it.
|
|
265
284
|
* @param txHash - The tx hash.
|
|
@@ -267,12 +286,7 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
267
286
|
*/
|
|
268
287
|
public async getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
269
288
|
const buffer = await this.#archivedTxs.getAsync(txHash.toString());
|
|
270
|
-
|
|
271
|
-
const tx = Tx.fromBuffer(buffer);
|
|
272
|
-
tx.setTxHash(txHash);
|
|
273
|
-
return tx;
|
|
274
|
-
}
|
|
275
|
-
return undefined;
|
|
289
|
+
return buffer ? Tx.fromBuffer(buffer) : undefined;
|
|
276
290
|
}
|
|
277
291
|
|
|
278
292
|
/**
|
|
@@ -322,10 +336,11 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
322
336
|
|
|
323
337
|
/**
|
|
324
338
|
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
325
|
-
*
|
|
339
|
+
* Mined transactions are soft-deleted with a timestamp, pending transactions are permanently deleted.
|
|
340
|
+
* @param txHashes - An array of tx hashes to be deleted from the tx pool.
|
|
326
341
|
* @returns Empty promise.
|
|
327
342
|
*/
|
|
328
|
-
public deleteTxs(txHashes: TxHash[], eviction =
|
|
343
|
+
public deleteTxs(txHashes: TxHash[], opts: { eviction?: boolean; permanently?: boolean } = {}): Promise<void> {
|
|
329
344
|
if (txHashes.length === 0) {
|
|
330
345
|
return Promise.resolve();
|
|
331
346
|
}
|
|
@@ -337,18 +352,33 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
337
352
|
const tx = await this.getTxByHash(hash);
|
|
338
353
|
|
|
339
354
|
if (tx) {
|
|
340
|
-
const
|
|
341
|
-
|
|
355
|
+
const minedBlockNumber = await this.#minedTxHashToBlock.getAsync(key);
|
|
356
|
+
|
|
357
|
+
if (minedBlockNumber !== undefined) {
|
|
358
|
+
await this.#minedTxHashToBlock.delete(key);
|
|
359
|
+
if (opts.permanently) {
|
|
360
|
+
// Permanently delete mined transactions if specified
|
|
361
|
+
this.#log.trace(`Deleting mined tx ${key} from pool`);
|
|
362
|
+
await this.#txs.delete(key);
|
|
363
|
+
} else {
|
|
364
|
+
// Soft-delete mined transactions: remove from mined set but keep in storage
|
|
365
|
+
this.#log.trace(`Soft-deleting mined tx ${key} from pool`);
|
|
366
|
+
await this.#deletedMinedTxHashes.set(key, minedBlockNumber);
|
|
367
|
+
await this.#blockToDeletedMinedTxHash.set(minedBlockNumber, key);
|
|
368
|
+
}
|
|
369
|
+
} else {
|
|
370
|
+
// Permanently delete pending transactions
|
|
371
|
+
this.#log.trace(`Deleting pending tx ${key} from pool`);
|
|
342
372
|
pendingTxSize -= tx.getSize();
|
|
343
373
|
await this.removePendingTxIndices(tx, key);
|
|
374
|
+
await this.#txs.delete(key);
|
|
344
375
|
}
|
|
345
376
|
|
|
346
|
-
if (!eviction && this.#archivedTxLimit) {
|
|
377
|
+
if (!opts.eviction && this.#archivedTxLimit) {
|
|
347
378
|
deletedTxs.push(tx);
|
|
348
379
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
await this.#minedTxHashToBlock.delete(key);
|
|
380
|
+
} else {
|
|
381
|
+
this.#log.trace(`Skipping deletion of missing tx ${key} from pool`);
|
|
352
382
|
}
|
|
353
383
|
}
|
|
354
384
|
|
|
@@ -363,12 +393,8 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
363
393
|
* @returns Array of tx objects in the order they were added to the pool.
|
|
364
394
|
*/
|
|
365
395
|
public async getAllTxs(): Promise<Tx[]> {
|
|
366
|
-
const vals = await toArray(this.#txs.
|
|
367
|
-
return vals.map(
|
|
368
|
-
const tx = Tx.fromBuffer(buffer);
|
|
369
|
-
tx.setTxHash(TxHash.fromString(hash));
|
|
370
|
-
return tx;
|
|
371
|
-
});
|
|
396
|
+
const vals = await toArray(this.#txs.valuesAsync());
|
|
397
|
+
return vals.map(buffer => Tx.fromBuffer(buffer));
|
|
372
398
|
}
|
|
373
399
|
|
|
374
400
|
/**
|
|
@@ -402,6 +428,8 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
402
428
|
assert(archivedTxLimit >= 0, 'archivedTxLimit must be greater or equal to 0');
|
|
403
429
|
this.#archivedTxLimit = archivedTxLimit;
|
|
404
430
|
}
|
|
431
|
+
|
|
432
|
+
// deletedMinedCleanupThresholdMs is no longer used in block-based cleanup
|
|
405
433
|
}
|
|
406
434
|
|
|
407
435
|
public markTxsAsNonEvictable(txHashes: TxHash[]): Promise<void> {
|
|
@@ -409,6 +437,46 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
409
437
|
return Promise.resolve();
|
|
410
438
|
}
|
|
411
439
|
|
|
440
|
+
/**
|
|
441
|
+
* Permanently deletes deleted mined transactions from blocks up to and including the specified block number.
|
|
442
|
+
* @param blockNumber - Block number threshold. Deleted mined txs from this block or earlier will be permanently deleted.
|
|
443
|
+
* @returns The number of transactions permanently deleted.
|
|
444
|
+
*/
|
|
445
|
+
public async cleanupDeletedMinedTxs(blockNumber: BlockNumber): Promise<number> {
|
|
446
|
+
let deletedCount = 0;
|
|
447
|
+
const txHashesToDelete: string[] = [];
|
|
448
|
+
const blocksToDelete: BlockNumber[] = [];
|
|
449
|
+
|
|
450
|
+
await this.#store.transactionAsync(async () => {
|
|
451
|
+
// Iterate through all entries and check block numbers
|
|
452
|
+
for await (const [block, txHash] of this.#blockToDeletedMinedTxHash.entriesAsync()) {
|
|
453
|
+
if (block <= blockNumber) {
|
|
454
|
+
// Permanently delete the transaction
|
|
455
|
+
await this.#txs.delete(txHash);
|
|
456
|
+
await this.#deletedMinedTxHashes.delete(txHash);
|
|
457
|
+
txHashesToDelete.push(txHash);
|
|
458
|
+
if (!blocksToDelete.includes(block)) {
|
|
459
|
+
blocksToDelete.push(block);
|
|
460
|
+
}
|
|
461
|
+
deletedCount++;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Clean up block-to-hash mapping - delete all values for each block
|
|
466
|
+
for (const block of blocksToDelete) {
|
|
467
|
+
const txHashesForBlock = await toArray(this.#blockToDeletedMinedTxHash.getValuesAsync(block));
|
|
468
|
+
for (const txHash of txHashesForBlock) {
|
|
469
|
+
await this.#blockToDeletedMinedTxHash.deleteValue(block, txHash);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
if (deletedCount > 0) {
|
|
475
|
+
this.#log.debug(`Permanently deleted ${deletedCount} deleted mined txs from blocks up to ${blockNumber}`);
|
|
476
|
+
}
|
|
477
|
+
return deletedCount;
|
|
478
|
+
}
|
|
479
|
+
|
|
412
480
|
/**
|
|
413
481
|
* Creates a GasTxValidator instance.
|
|
414
482
|
* @param db - DB for the validator to use
|
|
@@ -484,7 +552,7 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
484
552
|
const archivedTx: Tx = new Tx(
|
|
485
553
|
tx.txHash,
|
|
486
554
|
tx.data,
|
|
487
|
-
|
|
555
|
+
ChonkProof.empty(),
|
|
488
556
|
tx.contractClassLogFields,
|
|
489
557
|
tx.publicFunctionCalldata,
|
|
490
558
|
);
|
|
@@ -546,7 +614,7 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
546
614
|
}
|
|
547
615
|
|
|
548
616
|
if (txsToEvict.length > 0) {
|
|
549
|
-
await this.deleteTxs(txsToEvict, true);
|
|
617
|
+
await this.deleteTxs(txsToEvict, { eviction: true });
|
|
550
618
|
}
|
|
551
619
|
return {
|
|
552
620
|
numLowPriorityTxsEvicted: txsToEvict.length,
|
|
@@ -620,7 +688,7 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
620
688
|
}
|
|
621
689
|
|
|
622
690
|
if (txsToEvict.length > 0) {
|
|
623
|
-
await this.deleteTxs(txsToEvict, true);
|
|
691
|
+
await this.deleteTxs(txsToEvict, { eviction: true });
|
|
624
692
|
}
|
|
625
693
|
return txsToEvict.length;
|
|
626
694
|
}
|
|
@@ -663,7 +731,7 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
663
731
|
}
|
|
664
732
|
|
|
665
733
|
if (txsToEvict.length > 0) {
|
|
666
|
-
await this.deleteTxs(txsToEvict, true);
|
|
734
|
+
await this.deleteTxs(txsToEvict, { eviction: true });
|
|
667
735
|
}
|
|
668
736
|
return txsToEvict.length;
|
|
669
737
|
}
|
|
@@ -671,7 +739,7 @@ export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<
|
|
|
671
739
|
private async addPendingTxIndices(tx: Tx, txHash: string): Promise<void> {
|
|
672
740
|
await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), txHash);
|
|
673
741
|
await this.#pendingTxHashToSize.set(txHash, tx.getSize());
|
|
674
|
-
await this.#pendingTxHashToHeaderHash.set(txHash, (await tx.data.constants.
|
|
742
|
+
await this.#pendingTxHashToHeaderHash.set(txHash, (await tx.data.constants.anchorBlockHeader.hash()).toString());
|
|
675
743
|
}
|
|
676
744
|
|
|
677
745
|
private async removePendingTxIndices(tx: Tx, txHash: string): Promise<void> {
|