@aztec/p2p 0.0.0-test.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dest/bootstrap/bootstrap.d.ts +38 -0
- package/dest/bootstrap/bootstrap.d.ts.map +1 -0
- package/dest/bootstrap/bootstrap.js +123 -0
- package/dest/client/factory.d.ts +21 -0
- package/dest/client/factory.d.ts.map +1 -0
- package/dest/client/factory.js +37 -0
- package/dest/client/index.d.ts +3 -0
- package/dest/client/index.d.ts.map +1 -0
- package/dest/client/index.js +2 -0
- package/dest/client/p2p_client.d.ts +314 -0
- package/dest/client/p2p_client.d.ts.map +1 -0
- package/dest/client/p2p_client.js +505 -0
- package/dest/config.d.ts +180 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +193 -0
- package/dest/enr/generate-enr.d.ts +9 -0
- package/dest/enr/generate-enr.d.ts.map +1 -0
- package/dest/enr/generate-enr.js +30 -0
- package/dest/enr/index.d.ts +2 -0
- package/dest/enr/index.d.ts.map +1 -0
- package/dest/enr/index.js +1 -0
- package/dest/errors/reqresp.error.d.ts +28 -0
- package/dest/errors/reqresp.error.d.ts.map +1 -0
- package/dest/errors/reqresp.error.js +30 -0
- package/dest/index.d.ts +8 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +7 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +57 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.js +6 -0
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +3 -0
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +195 -0
- package/dest/mem_pools/attestation_pool/index.d.ts +3 -0
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/index.js +2 -0
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +22 -0
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +112 -0
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -0
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +129 -0
- package/dest/mem_pools/attestation_pool/mocks.d.ts +19 -0
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/mocks.js +33 -0
- package/dest/mem_pools/index.d.ts +4 -0
- package/dest/mem_pools/index.d.ts.map +1 -0
- package/dest/mem_pools/index.js +1 -0
- package/dest/mem_pools/instrumentation.d.ts +30 -0
- package/dest/mem_pools/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/instrumentation.js +84 -0
- package/dest/mem_pools/interface.d.ts +11 -0
- package/dest/mem_pools/interface.d.ts.map +1 -0
- package/dest/mem_pools/interface.js +3 -0
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +66 -0
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +245 -0
- package/dest/mem_pools/tx_pool/index.d.ts +4 -0
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/index.js +3 -0
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +56 -0
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +141 -0
- package/dest/mem_pools/tx_pool/priority.d.ts +8 -0
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/priority.js +10 -0
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +66 -0
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/tx_pool.js +3 -0
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +7 -0
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +169 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +8 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.js +19 -0
- package/dest/msg_validators/attestation_validator/index.d.ts +2 -0
- package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/index.js +1 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +8 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +21 -0
- package/dest/msg_validators/block_proposal_validator/index.d.ts +2 -0
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/block_proposal_validator/index.js +1 -0
- package/dest/msg_validators/index.d.ts +4 -0
- package/dest/msg_validators/index.d.ts.map +1 -0
- package/dest/msg_validators/index.js +3 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +7 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +31 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +11 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/block_header_validator.js +26 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +6 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/data_validator.js +107 -0
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +12 -0
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/double_spend_validator.js +41 -0
- package/dest/msg_validators/tx_validator/index.d.ts +7 -0
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/index.js +6 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +10 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.js +44 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +25 -0
- package/dest/services/data_store.d.ts +27 -0
- package/dest/services/data_store.d.ts.map +1 -0
- package/dest/services/data_store.js +188 -0
- package/dest/services/discv5/discV5_service.d.ts +42 -0
- package/dest/services/discv5/discV5_service.d.ts.map +1 -0
- package/dest/services/discv5/discV5_service.js +214 -0
- package/dest/services/dummy_service.d.ts +85 -0
- package/dest/services/dummy_service.d.ts.map +1 -0
- package/dest/services/dummy_service.js +92 -0
- package/dest/services/encoding.d.ts +31 -0
- package/dest/services/encoding.d.ts.map +1 -0
- package/dest/services/encoding.js +66 -0
- package/dest/services/gossipsub/scoring.d.ts +7 -0
- package/dest/services/gossipsub/scoring.d.ts.map +1 -0
- package/dest/services/gossipsub/scoring.js +10 -0
- package/dest/services/index.d.ts +3 -0
- package/dest/services/index.d.ts.map +1 -0
- package/dest/services/index.js +2 -0
- package/dest/services/libp2p/libp2p_service.d.ts +186 -0
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -0
- package/dest/services/libp2p/libp2p_service.js +712 -0
- package/dest/services/peer-manager/metrics.d.ts +12 -0
- package/dest/services/peer-manager/metrics.d.ts.map +1 -0
- package/dest/services/peer-manager/metrics.js +33 -0
- package/dest/services/peer-manager/peer_manager.d.ts +94 -0
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -0
- package/dest/services/peer-manager/peer_manager.js +445 -0
- package/dest/services/peer-manager/peer_scoring.d.ts +28 -0
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -0
- package/dest/services/peer-manager/peer_scoring.js +86 -0
- package/dest/services/reqresp/config.d.ts +16 -0
- package/dest/services/reqresp/config.d.ts.map +1 -0
- package/dest/services/reqresp/config.js +20 -0
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +45 -0
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -0
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +88 -0
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +61 -0
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -0
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +181 -0
- package/dest/services/reqresp/index.d.ts +6 -0
- package/dest/services/reqresp/index.d.ts.map +1 -0
- package/dest/services/reqresp/index.js +4 -0
- package/dest/services/reqresp/interface.d.ts +116 -0
- package/dest/services/reqresp/interface.d.ts.map +1 -0
- package/dest/services/reqresp/interface.js +84 -0
- package/dest/services/reqresp/metrics.d.ts +15 -0
- package/dest/services/reqresp/metrics.d.ts.map +1 -0
- package/dest/services/reqresp/metrics.js +55 -0
- package/dest/services/reqresp/protocols/block.d.ts +4 -0
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block.js +8 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts +51 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/goodbye.js +87 -0
- package/dest/services/reqresp/protocols/index.d.ts +9 -0
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/index.js +7 -0
- package/dest/services/reqresp/protocols/ping.d.ts +9 -0
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/ping.js +7 -0
- package/dest/services/reqresp/protocols/status.d.ts +9 -0
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/status.js +7 -0
- package/dest/services/reqresp/protocols/tx.d.ts +13 -0
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/tx.js +20 -0
- package/dest/services/reqresp/rate-limiter/index.d.ts +2 -0
- package/dest/services/reqresp/rate-limiter/index.d.ts.map +1 -0
- package/dest/services/reqresp/rate-limiter/index.js +1 -0
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +102 -0
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -0
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +184 -0
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +3 -0
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -0
- package/dest/services/reqresp/rate-limiter/rate_limits.js +54 -0
- package/dest/services/reqresp/reqresp.d.ts +166 -0
- package/dest/services/reqresp/reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/reqresp.js +516 -0
- package/dest/services/reqresp/status.d.ts +31 -0
- package/dest/services/reqresp/status.d.ts.map +1 -0
- package/dest/services/reqresp/status.js +51 -0
- package/dest/services/service.d.ts +87 -0
- package/dest/services/service.d.ts.map +1 -0
- package/dest/services/service.js +5 -0
- package/dest/test-helpers/generate-peer-id-private-keys.d.ts +7 -0
- package/dest/test-helpers/generate-peer-id-private-keys.d.ts.map +1 -0
- package/dest/test-helpers/generate-peer-id-private-keys.js +13 -0
- package/dest/test-helpers/get-ports.d.ts +7 -0
- package/dest/test-helpers/get-ports.d.ts.map +1 -0
- package/dest/test-helpers/get-ports.js +8 -0
- package/dest/test-helpers/index.d.ts +6 -0
- package/dest/test-helpers/index.d.ts.map +1 -0
- package/dest/test-helpers/index.js +5 -0
- package/dest/test-helpers/make-enrs.d.ts +16 -0
- package/dest/test-helpers/make-enrs.d.ts.map +1 -0
- package/dest/test-helpers/make-enrs.js +32 -0
- package/dest/test-helpers/make-test-p2p-clients.d.ts +36 -0
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -0
- package/dest/test-helpers/make-test-p2p-clients.js +68 -0
- package/dest/test-helpers/reqresp-nodes.d.ts +66 -0
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -0
- package/dest/test-helpers/reqresp-nodes.js +207 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -0
- package/dest/testbench/p2p_client_testbench_worker.js +132 -0
- package/dest/testbench/parse_log_file.d.ts +2 -0
- package/dest/testbench/parse_log_file.d.ts.map +1 -0
- package/dest/testbench/parse_log_file.js +131 -0
- package/dest/testbench/testbench.d.ts +2 -0
- package/dest/testbench/testbench.d.ts.map +1 -0
- package/dest/testbench/testbench.js +61 -0
- package/dest/testbench/worker_client_manager.d.ts +56 -0
- package/dest/testbench/worker_client_manager.d.ts.map +1 -0
- package/dest/testbench/worker_client_manager.js +266 -0
- package/dest/types/index.d.ts +32 -0
- package/dest/types/index.d.ts.map +1 -0
- package/dest/types/index.js +28 -0
- package/dest/util.d.ts +53 -0
- package/dest/util.d.ts.map +1 -0
- package/dest/util.js +140 -0
- package/dest/versioning.d.ts +12 -0
- package/dest/versioning.d.ts.map +1 -0
- package/dest/versioning.js +33 -0
- package/package.json +127 -0
- package/src/bootstrap/bootstrap.ts +146 -0
- package/src/client/factory.ts +89 -0
- package/src/client/index.ts +2 -0
- package/src/client/p2p_client.ts +754 -0
- package/src/config.ts +371 -0
- package/src/enr/generate-enr.ts +39 -0
- package/src/enr/index.ts +1 -0
- package/src/errors/reqresp.error.ts +35 -0
- package/src/index.ts +7 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +62 -0
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +230 -0
- package/src/mem_pools/attestation_pool/index.ts +2 -0
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +159 -0
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +161 -0
- package/src/mem_pools/attestation_pool/mocks.ts +44 -0
- package/src/mem_pools/index.ts +3 -0
- package/src/mem_pools/instrumentation.ts +126 -0
- package/src/mem_pools/interface.ts +12 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +309 -0
- package/src/mem_pools/tx_pool/index.ts +3 -0
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +174 -0
- package/src/mem_pools/tx_pool/priority.ts +13 -0
- package/src/mem_pools/tx_pool/tx_pool.ts +76 -0
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +130 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +26 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +29 -0
- package/src/msg_validators/block_proposal_validator/index.ts +1 -0
- package/src/msg_validators/index.ts +3 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +32 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +25 -0
- package/src/msg_validators/tx_validator/data_validator.ts +106 -0
- package/src/msg_validators/tx_validator/double_spend_validator.ts +38 -0
- package/src/msg_validators/tx_validator/index.ts +6 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +48 -0
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +18 -0
- package/src/services/data_store.ts +235 -0
- package/src/services/discv5/discV5_service.ts +256 -0
- package/src/services/dummy_service.ts +134 -0
- package/src/services/encoding.ts +79 -0
- package/src/services/gossipsub/scoring.ts +13 -0
- package/src/services/index.ts +2 -0
- package/src/services/libp2p/libp2p_service.ts +871 -0
- package/src/services/peer-manager/metrics.ts +41 -0
- package/src/services/peer-manager/peer_manager.ts +530 -0
- package/src/services/peer-manager/peer_scoring.ts +105 -0
- package/src/services/reqresp/config.ts +35 -0
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +94 -0
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +217 -0
- package/src/services/reqresp/index.ts +4 -0
- package/src/services/reqresp/interface.ts +185 -0
- package/src/services/reqresp/metrics.ts +57 -0
- package/src/services/reqresp/protocols/block.ts +15 -0
- package/src/services/reqresp/protocols/goodbye.ts +101 -0
- package/src/services/reqresp/protocols/index.ts +8 -0
- package/src/services/reqresp/protocols/ping.ts +8 -0
- package/src/services/reqresp/protocols/status.ts +8 -0
- package/src/services/reqresp/protocols/tx.ts +29 -0
- package/src/services/reqresp/rate-limiter/index.ts +1 -0
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +228 -0
- package/src/services/reqresp/rate-limiter/rate_limits.ts +55 -0
- package/src/services/reqresp/reqresp.ts +661 -0
- package/src/services/reqresp/status.ts +59 -0
- package/src/services/service.ts +112 -0
- package/src/test-helpers/generate-peer-id-private-keys.ts +15 -0
- package/src/test-helpers/get-ports.ts +8 -0
- package/src/test-helpers/index.ts +5 -0
- package/src/test-helpers/make-enrs.ts +44 -0
- package/src/test-helpers/make-test-p2p-clients.ts +122 -0
- package/src/test-helpers/reqresp-nodes.ts +289 -0
- package/src/testbench/README.md +20 -0
- package/src/testbench/p2p_client_testbench_worker.ts +152 -0
- package/src/testbench/parse_log_file.ts +175 -0
- package/src/testbench/testbench.ts +66 -0
- package/src/testbench/worker_client_manager.ts +318 -0
- package/src/types/index.ts +36 -0
- package/src/util.ts +196 -0
- package/src/versioning.ts +50 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
5
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
6
|
+
import { PoolInstrumentation, PoolName } from '../instrumentation.js';
|
|
7
|
+
export class KvAttestationPool {
|
|
8
|
+
store;
|
|
9
|
+
log;
|
|
10
|
+
metrics;
|
|
11
|
+
attestations;
|
|
12
|
+
proposalsForSlot;
|
|
13
|
+
attestationsForProposal;
|
|
14
|
+
constructor(store, telemetry = getTelemetryClient(), log = createLogger('aztec:attestation_pool')){
|
|
15
|
+
this.store = store;
|
|
16
|
+
this.log = log;
|
|
17
|
+
this.attestations = store.openMap('attestations');
|
|
18
|
+
this.proposalsForSlot = store.openMultiMap('proposals_for_slot');
|
|
19
|
+
this.attestationsForProposal = store.openMultiMap('attestations_for_proposal');
|
|
20
|
+
this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL);
|
|
21
|
+
}
|
|
22
|
+
getProposalKey(slot, proposalId) {
|
|
23
|
+
const slotStr = typeof slot === 'string' ? slot : new Fr(slot).toString();
|
|
24
|
+
const proposalIdStr = typeof proposalId === 'string' ? proposalId : Buffer.isBuffer(proposalId) ? Fr.fromBuffer(proposalId).toString() : proposalId.toString();
|
|
25
|
+
return `${slotStr}-${proposalIdStr}`;
|
|
26
|
+
}
|
|
27
|
+
getAttestationKey(slot, proposalId, address) {
|
|
28
|
+
return `${this.getProposalKey(slot, proposalId)}-${address}`;
|
|
29
|
+
}
|
|
30
|
+
async addAttestations(attestations) {
|
|
31
|
+
await this.store.transactionAsync(async ()=>{
|
|
32
|
+
for (const attestation of attestations){
|
|
33
|
+
const slotNumber = attestation.payload.header.globalVariables.slotNumber;
|
|
34
|
+
const proposalId = attestation.archive;
|
|
35
|
+
const address = (await attestation.getSender()).toString();
|
|
36
|
+
await this.attestations.set(this.getAttestationKey(slotNumber, proposalId, address), attestation.toBuffer());
|
|
37
|
+
await this.proposalsForSlot.set(slotNumber.toString(), proposalId.toString());
|
|
38
|
+
await this.attestationsForProposal.set(this.getProposalKey(slotNumber, proposalId), this.getAttestationKey(slotNumber, proposalId, address));
|
|
39
|
+
this.log.verbose(`Added attestation for slot ${slotNumber} from ${address}`);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
this.metrics.recordAddedObjects(attestations.length);
|
|
43
|
+
}
|
|
44
|
+
async getAttestationsForSlot(slot, proposalId) {
|
|
45
|
+
const attestationIds = await toArray(this.attestationsForProposal.getValuesAsync(this.getProposalKey(slot, proposalId)));
|
|
46
|
+
const attestations = [];
|
|
47
|
+
// alternatively iterate this.attestaions starting from slot-proposal-EthAddress.zero
|
|
48
|
+
for (const id of attestationIds){
|
|
49
|
+
const buf = await this.attestations.getAsync(id);
|
|
50
|
+
if (!buf) {
|
|
51
|
+
// this should not happen unless we lost writes
|
|
52
|
+
throw new Error('Attestation not found ' + id);
|
|
53
|
+
}
|
|
54
|
+
const attestation = BlockAttestation.fromBuffer(buf);
|
|
55
|
+
attestations.push(attestation);
|
|
56
|
+
}
|
|
57
|
+
return attestations;
|
|
58
|
+
}
|
|
59
|
+
async deleteAttestationsOlderThan(oldestSlot) {
|
|
60
|
+
const olderThan = await toArray(this.proposalsForSlot.keysAsync({
|
|
61
|
+
end: new Fr(oldestSlot).toString()
|
|
62
|
+
}));
|
|
63
|
+
for (const oldSlot of olderThan){
|
|
64
|
+
await this.deleteAttestationsForSlot(BigInt(oldSlot));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async deleteAttestationsForSlot(slot) {
|
|
68
|
+
const slotFr = new Fr(slot);
|
|
69
|
+
let numberOfAttestations = 0;
|
|
70
|
+
await this.store.transactionAsync(async ()=>{
|
|
71
|
+
const proposalIds = await toArray(this.proposalsForSlot.getValuesAsync(slotFr.toString()));
|
|
72
|
+
for (const proposalId of proposalIds){
|
|
73
|
+
const attestations = await toArray(this.attestationsForProposal.getValuesAsync(this.getProposalKey(slotFr, proposalId)));
|
|
74
|
+
numberOfAttestations += attestations.length;
|
|
75
|
+
for (const attestation of attestations){
|
|
76
|
+
await this.attestations.delete(attestation);
|
|
77
|
+
}
|
|
78
|
+
await this.attestationsForProposal.delete(this.getProposalKey(slotFr, proposalId));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
this.log.verbose(`Removed ${numberOfAttestations} attestations for slot ${slot}`);
|
|
82
|
+
this.metrics.recordRemovedObjects(numberOfAttestations);
|
|
83
|
+
}
|
|
84
|
+
async deleteAttestationsForSlotAndProposal(slot, proposalId) {
|
|
85
|
+
let numberOfAttestations = 0;
|
|
86
|
+
await this.store.transactionAsync(async ()=>{
|
|
87
|
+
const slotString = new Fr(slot).toString();
|
|
88
|
+
const attestations = await toArray(this.attestationsForProposal.getValuesAsync(this.getProposalKey(slot, proposalId)));
|
|
89
|
+
numberOfAttestations += attestations.length;
|
|
90
|
+
for (const attestation of attestations){
|
|
91
|
+
await this.attestations.delete(attestation);
|
|
92
|
+
}
|
|
93
|
+
await this.proposalsForSlot.deleteValue(slotString, proposalId);
|
|
94
|
+
await this.attestationsForProposal.delete(this.getProposalKey(slotString, proposalId));
|
|
95
|
+
});
|
|
96
|
+
this.log.verbose(`Removed ${numberOfAttestations} attestations for slot ${slot} and proposal ${proposalId}`);
|
|
97
|
+
this.metrics.recordRemovedObjects(numberOfAttestations);
|
|
98
|
+
}
|
|
99
|
+
async deleteAttestations(attestations) {
|
|
100
|
+
await this.store.transactionAsync(async ()=>{
|
|
101
|
+
for (const attestation of attestations){
|
|
102
|
+
const slotNumber = attestation.payload.header.globalVariables.slotNumber;
|
|
103
|
+
const proposalId = attestation.archive;
|
|
104
|
+
const address = (await attestation.getSender()).toString();
|
|
105
|
+
await this.attestations.delete(this.getAttestationKey(slotNumber, proposalId, address));
|
|
106
|
+
await this.attestationsForProposal.deleteValue(this.getProposalKey(slotNumber, proposalId), this.getAttestationKey(slotNumber, proposalId, address));
|
|
107
|
+
this.log.debug(`Deleted attestation for slot ${slotNumber} from ${address}`);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
this.metrics.recordRemovedObjects(attestations.length);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
2
|
+
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
3
|
+
import type { AttestationPool } from './attestation_pool.js';
|
|
4
|
+
export declare class InMemoryAttestationPool implements AttestationPool {
|
|
5
|
+
#private;
|
|
6
|
+
private log;
|
|
7
|
+
private metrics;
|
|
8
|
+
private attestations;
|
|
9
|
+
constructor(telemetry?: TelemetryClient, log?: import("@aztec/foundation/log").Logger);
|
|
10
|
+
getAttestationsForSlot(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
|
|
11
|
+
addAttestations(attestations: BlockAttestation[]): Promise<void>;
|
|
12
|
+
deleteAttestationsOlderThan(oldestSlot: bigint): Promise<void>;
|
|
13
|
+
deleteAttestationsForSlot(slot: bigint): Promise<void>;
|
|
14
|
+
deleteAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<void>;
|
|
15
|
+
deleteAttestations(attestations: BlockAttestation[]): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=memory_attestation_pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory_attestation_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/memory_attestation_pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAGnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,qBAAa,uBAAwB,YAAW,eAAe;;IAKE,OAAO,CAAC,GAAG;IAJ1E,OAAO,CAAC,OAAO,CAAwC;IAEvD,OAAO,CAAC,YAAY,CAAgG;gBAExG,SAAS,GAAE,eAAsC,EAAU,GAAG,yCAAuC;IAK1G,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAW/E,eAAe,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgChE,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBpE,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWtD,oCAAoC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAe/E,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBjF"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
3
|
+
import { PoolInstrumentation, PoolName } from '../instrumentation.js';
|
|
4
|
+
export class InMemoryAttestationPool {
|
|
5
|
+
log;
|
|
6
|
+
metrics;
|
|
7
|
+
attestations;
|
|
8
|
+
constructor(telemetry = getTelemetryClient(), log = createLogger('p2p:attestation_pool')){
|
|
9
|
+
this.log = log;
|
|
10
|
+
this.attestations = new Map();
|
|
11
|
+
this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL);
|
|
12
|
+
}
|
|
13
|
+
getAttestationsForSlot(slot, proposalId) {
|
|
14
|
+
const slotAttestationMap = this.attestations.get(slot);
|
|
15
|
+
if (slotAttestationMap) {
|
|
16
|
+
const proposalAttestationMap = slotAttestationMap.get(proposalId);
|
|
17
|
+
if (proposalAttestationMap) {
|
|
18
|
+
return Promise.resolve(Array.from(proposalAttestationMap.values()));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return Promise.resolve([]);
|
|
22
|
+
}
|
|
23
|
+
async addAttestations(attestations) {
|
|
24
|
+
for (const attestation of attestations){
|
|
25
|
+
// Perf: order and group by slot before insertion
|
|
26
|
+
const slotNumber = attestation.payload.header.globalVariables.slotNumber;
|
|
27
|
+
const proposalId = attestation.archive.toString();
|
|
28
|
+
const address = await attestation.getSender();
|
|
29
|
+
const slotAttestationMap = getSlotOrDefault(this.attestations, slotNumber.toBigInt());
|
|
30
|
+
const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
|
|
31
|
+
proposalAttestationMap.set(address.toString(), attestation);
|
|
32
|
+
this.log.verbose(`Added attestation for slot ${slotNumber} from ${address}`);
|
|
33
|
+
}
|
|
34
|
+
// TODO: set these to pending or something ????
|
|
35
|
+
this.metrics.recordAddedObjects(attestations.length);
|
|
36
|
+
return Promise.resolve();
|
|
37
|
+
}
|
|
38
|
+
#getNumberOfAttestationsInSlot(slot) {
|
|
39
|
+
let total = 0;
|
|
40
|
+
const slotAttestationMap = getSlotOrDefault(this.attestations, slot);
|
|
41
|
+
if (slotAttestationMap) {
|
|
42
|
+
for (const proposalAttestationMap of slotAttestationMap.values() ?? []){
|
|
43
|
+
total += proposalAttestationMap.size;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return total;
|
|
47
|
+
}
|
|
48
|
+
async deleteAttestationsOlderThan(oldestSlot) {
|
|
49
|
+
const olderThan = [];
|
|
50
|
+
// Entries are iterated in insertion order, so we can break as soon as we find a slot that is older than the oldestSlot.
|
|
51
|
+
// Note: this will only prune correctly if attestations are added in order of rising slot, it is important that we do not allow
|
|
52
|
+
// insertion of attestations that are old. #(https://github.com/AztecProtocol/aztec-packages/issues/10322)
|
|
53
|
+
const slots = this.attestations.keys();
|
|
54
|
+
for (const slot of slots){
|
|
55
|
+
if (slot < oldestSlot) {
|
|
56
|
+
olderThan.push(slot);
|
|
57
|
+
} else {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
for (const oldSlot of olderThan){
|
|
62
|
+
await this.deleteAttestationsForSlot(oldSlot);
|
|
63
|
+
}
|
|
64
|
+
return Promise.resolve();
|
|
65
|
+
}
|
|
66
|
+
deleteAttestationsForSlot(slot) {
|
|
67
|
+
// We count the number of attestations we are removing
|
|
68
|
+
const numberOfAttestations = this.#getNumberOfAttestationsInSlot(slot);
|
|
69
|
+
this.attestations.delete(slot);
|
|
70
|
+
this.log.verbose(`Removed ${numberOfAttestations} attestations for slot ${slot}`);
|
|
71
|
+
this.metrics.recordRemovedObjects(numberOfAttestations);
|
|
72
|
+
return Promise.resolve();
|
|
73
|
+
}
|
|
74
|
+
deleteAttestationsForSlotAndProposal(slot, proposalId) {
|
|
75
|
+
const slotAttestationMap = getSlotOrDefault(this.attestations, slot);
|
|
76
|
+
if (slotAttestationMap) {
|
|
77
|
+
if (slotAttestationMap.has(proposalId)) {
|
|
78
|
+
const numberOfAttestations = slotAttestationMap.get(proposalId)?.size ?? 0;
|
|
79
|
+
slotAttestationMap.delete(proposalId);
|
|
80
|
+
this.log.verbose(`Removed ${numberOfAttestations} attestations for slot ${slot} and proposal ${proposalId}`);
|
|
81
|
+
this.metrics.recordRemovedObjects(numberOfAttestations);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return Promise.resolve();
|
|
85
|
+
}
|
|
86
|
+
async deleteAttestations(attestations) {
|
|
87
|
+
for (const attestation of attestations){
|
|
88
|
+
const slotNumber = attestation.payload.header.globalVariables.slotNumber;
|
|
89
|
+
const slotAttestationMap = this.attestations.get(slotNumber.toBigInt());
|
|
90
|
+
if (slotAttestationMap) {
|
|
91
|
+
const proposalId = attestation.archive.toString();
|
|
92
|
+
const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
|
|
93
|
+
if (proposalAttestationMap) {
|
|
94
|
+
const address = await attestation.getSender();
|
|
95
|
+
proposalAttestationMap.delete(address.toString());
|
|
96
|
+
this.log.debug(`Deleted attestation for slot ${slotNumber} from ${address}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
this.metrics.recordRemovedObjects(attestations.length);
|
|
101
|
+
return Promise.resolve();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get Slot or Default
|
|
106
|
+
*
|
|
107
|
+
* Fetch the slot mapping, if it does not exist, then create a mapping and return it
|
|
108
|
+
* @param map - The map to fetch from
|
|
109
|
+
* @param slot - The slot to fetch
|
|
110
|
+
* @returns The slot mapping
|
|
111
|
+
*/ function getSlotOrDefault(map, slot) {
|
|
112
|
+
if (!map.has(slot)) {
|
|
113
|
+
map.set(slot, new Map());
|
|
114
|
+
}
|
|
115
|
+
return map.get(slot);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get Proposal or Default
|
|
119
|
+
*
|
|
120
|
+
* Fetch the proposal mapping, if it does not exist, then create a mapping and return it
|
|
121
|
+
* @param map - The map to fetch from
|
|
122
|
+
* @param proposalId - The proposal id to fetch
|
|
123
|
+
* @returns The proposal mapping
|
|
124
|
+
*/ function getProposalOrDefault(map, proposalId) {
|
|
125
|
+
if (!map.has(proposalId)) {
|
|
126
|
+
map.set(proposalId, new Map());
|
|
127
|
+
}
|
|
128
|
+
return map.get(proposalId);
|
|
129
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
4
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import { type LocalAccount } from 'viem/accounts';
|
|
6
|
+
/** Generate Account
|
|
7
|
+
*
|
|
8
|
+
* Create a random signer
|
|
9
|
+
* @returns A random viem signer
|
|
10
|
+
*/
|
|
11
|
+
export declare const generateAccount: () => LocalAccount;
|
|
12
|
+
/** Mock Attestation
|
|
13
|
+
*
|
|
14
|
+
* @param signer A viem signer to create a signature
|
|
15
|
+
* @param slot The slot number the attestation is for
|
|
16
|
+
* @returns A Block Attestation
|
|
17
|
+
*/
|
|
18
|
+
export declare const mockAttestation: (signer: Secp256k1Signer, slot?: number, archive?: Fr, txs?: TxHash[]) => Promise<BlockAttestation>;
|
|
19
|
+
//# sourceMappingURL=mocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EACL,gBAAgB,EAIjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,KAAK,YAAY,EAA2C,MAAM,eAAe,CAAC;AAE3F;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAAO,YAGlC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,WAClB,eAAe,SACjB,MAAM,YACH,EAAE,QACN,MAAM,EAAE,KACZ,QAAQ,gBAAgB,CAS1B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BlockAttestation, ConsensusPayload, SignatureDomainSeparator, getHashedSignaturePayloadEthSignedMessage } from '@aztec/stdlib/p2p';
|
|
3
|
+
import { makeHeader } from '@aztec/stdlib/testing';
|
|
4
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
6
|
+
/** Generate Account
|
|
7
|
+
*
|
|
8
|
+
* Create a random signer
|
|
9
|
+
* @returns A random viem signer
|
|
10
|
+
*/ export const generateAccount = ()=>{
|
|
11
|
+
const privateKey = generatePrivateKey();
|
|
12
|
+
return privateKeyToAccount(privateKey);
|
|
13
|
+
};
|
|
14
|
+
/** Mock Attestation
|
|
15
|
+
*
|
|
16
|
+
* @param signer A viem signer to create a signature
|
|
17
|
+
* @param slot The slot number the attestation is for
|
|
18
|
+
* @returns A Block Attestation
|
|
19
|
+
*/ export const mockAttestation = async (signer, slot = 0, archive = Fr.random(), txs = [
|
|
20
|
+
0,
|
|
21
|
+
1,
|
|
22
|
+
2,
|
|
23
|
+
3,
|
|
24
|
+
4,
|
|
25
|
+
5
|
|
26
|
+
].map(()=>TxHash.random()))=>{
|
|
27
|
+
// Use arbitrary numbers for all other than slot
|
|
28
|
+
const header = makeHeader(1, 2, slot);
|
|
29
|
+
const payload = new ConsensusPayload(header, archive, txs);
|
|
30
|
+
const hash = await getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockAttestation);
|
|
31
|
+
const signature = signer.sign(hash);
|
|
32
|
+
return new BlockAttestation(payload, signature);
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mem_pools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Gossipable } from '@aztec/stdlib/p2p';
|
|
2
|
+
import { type LmdbStatsCallback, type TelemetryClient } from '@aztec/telemetry-client';
|
|
3
|
+
export declare enum PoolName {
|
|
4
|
+
TX_POOL = "TxPool",
|
|
5
|
+
ATTESTATION_POOL = "AttestationPool"
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Instrumentation class for the Pools (TxPool, AttestationPool, etc).
|
|
9
|
+
*/
|
|
10
|
+
export declare class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
11
|
+
/** The number of txs in the mempool */
|
|
12
|
+
private objectsInMempool;
|
|
13
|
+
/** Tracks tx size */
|
|
14
|
+
private objectSize;
|
|
15
|
+
private dbMetrics;
|
|
16
|
+
private defaultAttributes;
|
|
17
|
+
constructor(telemetry: TelemetryClient, name: PoolName, dbStats?: LmdbStatsCallback);
|
|
18
|
+
recordSize(poolObject: PoolObject): void;
|
|
19
|
+
/**
|
|
20
|
+
* Updates the metrics with the new objects.
|
|
21
|
+
* @param txs - The objects to record
|
|
22
|
+
*/
|
|
23
|
+
recordAddedObjects(count?: number, status?: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Updates the metrics by removing objects from the mempool.
|
|
26
|
+
* @param count - The number of objects to remove from the mempool
|
|
27
|
+
*/
|
|
28
|
+
recordRemovedObjects(count?: number, status?: string): void;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/mem_pools/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAIL,KAAK,iBAAiB,EAGtB,KAAK,eAAe,EAErB,MAAM,yBAAyB,CAAC;AAEjC,oBAAY,QAAQ;IAClB,OAAO,WAAW;IAClB,gBAAgB,oBAAoB;CACrC;AA4BD;;GAEG;AACH,qBAAa,mBAAmB,CAAC,UAAU,SAAS,UAAU;IAC5D,uCAAuC;IACvC,OAAO,CAAC,gBAAgB,CAAgB;IACxC,qBAAqB;IACrB,OAAO,CAAC,UAAU,CAAY;IAE9B,OAAO,CAAC,SAAS,CAAc;IAE/B,OAAO,CAAC,iBAAiB,CAAC;gBAEd,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,iBAAiB;IAwB5E,UAAU,CAAC,UAAU,EAAE,UAAU;IAIxC;;;OAGG;IACI,kBAAkB,CAAC,KAAK,SAAI,EAAE,MAAM,CAAC,EAAE,MAAM;IAiBpD;;;OAGG;IACI,oBAAoB,CAAC,KAAK,SAAI,EAAE,MAAM,CAAC,EAAE,MAAM;CAgBvD"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Attributes, LmdbMetrics, Metrics } from '@aztec/telemetry-client';
|
|
2
|
+
export var PoolName = /*#__PURE__*/ function(PoolName) {
|
|
3
|
+
PoolName["TX_POOL"] = "TxPool";
|
|
4
|
+
PoolName["ATTESTATION_POOL"] = "AttestationPool";
|
|
5
|
+
return PoolName;
|
|
6
|
+
}({});
|
|
7
|
+
/**
|
|
8
|
+
* Get the metrics labels for a given pool name.
|
|
9
|
+
* They must all have different names, as if duplicates appear, it will brick
|
|
10
|
+
* the metrics instance
|
|
11
|
+
*/ function getMetricsLabels(name) {
|
|
12
|
+
if (name === "TxPool") {
|
|
13
|
+
return {
|
|
14
|
+
objectInMempool: Metrics.MEMPOOL_TX_COUNT,
|
|
15
|
+
objectSize: Metrics.MEMPOOL_TX_SIZE
|
|
16
|
+
};
|
|
17
|
+
} else if (name === "AttestationPool") {
|
|
18
|
+
return {
|
|
19
|
+
objectInMempool: Metrics.MEMPOOL_ATTESTATIONS_COUNT,
|
|
20
|
+
objectSize: Metrics.MEMPOOL_ATTESTATIONS_SIZE
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
throw new Error('Invalid pool type');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Instrumentation class for the Pools (TxPool, AttestationPool, etc).
|
|
27
|
+
*/ export class PoolInstrumentation {
|
|
28
|
+
/** The number of txs in the mempool */ objectsInMempool;
|
|
29
|
+
/** Tracks tx size */ objectSize;
|
|
30
|
+
dbMetrics;
|
|
31
|
+
defaultAttributes;
|
|
32
|
+
constructor(telemetry, name, dbStats){
|
|
33
|
+
const meter = telemetry.getMeter(name);
|
|
34
|
+
this.defaultAttributes = {
|
|
35
|
+
[Attributes.POOL_NAME]: name
|
|
36
|
+
};
|
|
37
|
+
const metricsLabels = getMetricsLabels(name);
|
|
38
|
+
this.objectsInMempool = meter.createUpDownCounter(metricsLabels.objectInMempool, {
|
|
39
|
+
description: 'The current number of transactions in the mempool'
|
|
40
|
+
});
|
|
41
|
+
this.objectSize = meter.createHistogram(metricsLabels.objectSize, {
|
|
42
|
+
unit: 'By',
|
|
43
|
+
description: 'The size of transactions in the mempool'
|
|
44
|
+
});
|
|
45
|
+
this.dbMetrics = new LmdbMetrics(meter, {
|
|
46
|
+
[Attributes.DB_DATA_TYPE]: 'tx-pool'
|
|
47
|
+
}, dbStats);
|
|
48
|
+
}
|
|
49
|
+
recordSize(poolObject) {
|
|
50
|
+
this.objectSize.record(poolObject.getSize());
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Updates the metrics with the new objects.
|
|
54
|
+
* @param txs - The objects to record
|
|
55
|
+
*/ recordAddedObjects(count = 1, status) {
|
|
56
|
+
if (count < 0) {
|
|
57
|
+
throw new Error('Count must be positive');
|
|
58
|
+
}
|
|
59
|
+
if (count === 0) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const attributes = status ? {
|
|
63
|
+
...this.defaultAttributes,
|
|
64
|
+
[Attributes.STATUS]: status
|
|
65
|
+
} : this.defaultAttributes;
|
|
66
|
+
this.objectsInMempool.add(count, attributes);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Updates the metrics by removing objects from the mempool.
|
|
70
|
+
* @param count - The number of objects to remove from the mempool
|
|
71
|
+
*/ recordRemovedObjects(count = 1, status) {
|
|
72
|
+
if (count < 0) {
|
|
73
|
+
throw new Error('Count must be positive');
|
|
74
|
+
}
|
|
75
|
+
if (count === 0) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const attributes = status ? {
|
|
79
|
+
...this.defaultAttributes,
|
|
80
|
+
[Attributes.STATUS]: status
|
|
81
|
+
} : this.defaultAttributes;
|
|
82
|
+
this.objectsInMempool.add(-1 * count, attributes);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
2
|
+
import type { AttestationPool } from './attestation_pool/attestation_pool.js';
|
|
3
|
+
import type { TxPool } from './tx_pool/tx_pool.js';
|
|
4
|
+
/**
|
|
5
|
+
* A interface the combines all mempools
|
|
6
|
+
*/
|
|
7
|
+
export type MemPools<T extends P2PClientType = P2PClientType.Full> = {
|
|
8
|
+
txPool: TxPool;
|
|
9
|
+
attestationPool?: T extends P2PClientType.Full ? AttestationPool : undefined;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/mem_pools/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,CAAC,IAAI,IAAI;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,CAAC,SAAS,aAAa,CAAC,IAAI,GAAG,eAAe,GAAG,SAAS,CAAC;CAC9E,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
2
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
3
|
+
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
4
|
+
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
5
|
+
import type { TxPool } from './tx_pool.js';
|
|
6
|
+
/**
|
|
7
|
+
* KV implementation of the Transaction Pool.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AztecKVTxPool implements TxPool {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* Class constructor for KV TxPool. Initiates our transaction pool as an AztecMap.
|
|
13
|
+
* @param store - A KV store for live txs in the pool.
|
|
14
|
+
* @param archive - A KV store for archived txs.
|
|
15
|
+
* @param telemetry - A telemetry client.
|
|
16
|
+
* @param archivedTxLimit - The number of txs to archive.
|
|
17
|
+
* @param log - A logger.
|
|
18
|
+
*/
|
|
19
|
+
constructor(store: AztecAsyncKVStore, archive: AztecAsyncKVStore, telemetry?: TelemetryClient, archivedTxLimit?: number, log?: Logger);
|
|
20
|
+
markAsMined(txHashes: TxHash[], blockNumber: number): Promise<void>;
|
|
21
|
+
markMinedAsPending(txHashes: TxHash[]): Promise<void>;
|
|
22
|
+
getPendingTxHashes(): Promise<TxHash[]>;
|
|
23
|
+
getMinedTxHashes(): Promise<[TxHash, number][]>;
|
|
24
|
+
getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a transaction exists in the pool and returns it.
|
|
27
|
+
* @param txHash - The generated tx hash.
|
|
28
|
+
* @returns The transaction, if found, 'undefined' otherwise.
|
|
29
|
+
*/
|
|
30
|
+
getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if an archived tx exists and returns it.
|
|
33
|
+
* @param txHash - The tx hash.
|
|
34
|
+
* @returns The transaction metadata, if found, 'undefined' otherwise.
|
|
35
|
+
*/
|
|
36
|
+
getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Adds a list of transactions to the pool. Duplicates are ignored.
|
|
39
|
+
* @param txs - An array of txs to be added to the pool.
|
|
40
|
+
* @returns Empty promise.
|
|
41
|
+
*/
|
|
42
|
+
addTxs(txs: Tx[]): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
45
|
+
* @param txHashes - An array of tx hashes to be removed from the tx pool.
|
|
46
|
+
* @returns Empty promise.
|
|
47
|
+
*/
|
|
48
|
+
deleteTxs(txHashes: TxHash[]): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Gets all the transactions stored in the pool.
|
|
51
|
+
* @returns Array of tx objects in the order they were added to the pool.
|
|
52
|
+
*/
|
|
53
|
+
getAllTxs(): Promise<Tx[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the hashes of all transactions currently in the tx pool.
|
|
56
|
+
* @returns An array of transaction hashes found in the tx pool.
|
|
57
|
+
*/
|
|
58
|
+
getAllTxHashes(): Promise<TxHash[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Archives a list of txs for future reference. The number of archived txs is limited by the specified archivedTxLimit.
|
|
61
|
+
* @param txs - The list of transactions to archive.
|
|
62
|
+
* @returns Empty promise.
|
|
63
|
+
*/
|
|
64
|
+
private archiveTxs;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=aztec_kv_tx_pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aztec_kv_tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/aztec_kv_tx_pool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAG5F,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAInF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;GAEG;AACH,qBAAa,aAAc,YAAW,MAAM;;IA4B1C;;;;;;;OAOG;gBAED,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,iBAAiB,EAC1B,SAAS,GAAE,eAAsC,EACjD,eAAe,GAAE,MAAU,EAC3B,GAAG,SAA8B;IAgB5B,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBnE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB/C,kBAAkB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKvC,gBAAgB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAK/C,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAalF;;;;OAIG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAUjE;;;;OAIG;IACU,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAUzE;;;;OAIG;IACU,MAAM,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA8B7C;;;;OAIG;IACI,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAqCnD;;;OAGG;IACU,SAAS,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;IASvC;;;OAGG;IACU,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKhD;;;;OAIG;YACW,UAAU;CAiCzB"}
|