@aztec/p2p 0.0.1-commit.29c6b1a3 → 0.0.1-commit.2e2504e2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts +4 -3
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +4 -4
- package/dest/client/factory.d.ts +1 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +8 -5
- package/dest/client/p2p_client.d.ts +4 -2
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +15 -4
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +1 -1
- package/dest/config.d.ts +8 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -1
- package/dest/mem_pools/instrumentation.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +2 -2
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts +5 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/index.js +4 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +193 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +71 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +94 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +150 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +1041 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +7 -2
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +5 -4
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +4 -3
- package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +4 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +4 -3
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +12 -12
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +3 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
- package/dest/msg_validators/tx_validator/size_validator.d.ts +3 -1
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/size_validator.js +4 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +10 -6
- package/dest/services/discv5/discV5_service.js +1 -1
- package/dest/services/index.d.ts +2 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +1 -0
- package/dest/services/libp2p/instrumentation.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +14 -3
- package/dest/services/libp2p/libp2p_service.d.ts +1 -1
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +10 -10
- package/dest/services/peer-manager/metrics.d.ts +2 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +20 -5
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +8 -2
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +2 -2
- package/dest/services/reqresp/metrics.d.ts +6 -5
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +17 -5
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +2 -2
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +6 -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 +14 -14
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +9 -2
- package/dest/services/tx_file_store/config.d.ts +18 -0
- package/dest/services/tx_file_store/config.d.ts.map +1 -0
- package/dest/services/tx_file_store/config.js +26 -0
- package/dest/services/tx_file_store/index.d.ts +4 -0
- package/dest/services/tx_file_store/index.d.ts.map +1 -0
- package/dest/services/tx_file_store/index.js +3 -0
- package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
- package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_file_store/instrumentation.js +29 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
- package/dest/services/tx_file_store/tx_file_store.js +149 -0
- package/dest/services/tx_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +5 -5
- package/dest/test-helpers/testbench-utils.d.ts +3 -1
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +2 -1
- package/dest/testbench/p2p_client_testbench_worker.js +1 -1
- package/package.json +14 -14
- package/src/bootstrap/bootstrap.ts +7 -4
- package/src/client/factory.ts +9 -9
- package/src/client/p2p_client.ts +14 -2
- package/src/client/test/tx_proposal_collector/README.md +4 -4
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +1 -1
- package/src/config.ts +8 -1
- package/src/mem_pools/instrumentation.ts +2 -1
- package/src/mem_pools/tx_pool_v2/README.md +188 -0
- package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
- package/src/mem_pools/tx_pool_v2/index.ts +11 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +225 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +160 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +209 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1265 -0
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +8 -2
- package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
- package/src/msg_validators/tx_validator/block_header_validator.ts +7 -8
- package/src/msg_validators/tx_validator/data_validator.ts +6 -2
- package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
- package/src/msg_validators/tx_validator/factory.ts +46 -30
- package/src/msg_validators/tx_validator/gas_validator.ts +9 -3
- package/src/msg_validators/tx_validator/metadata_validator.ts +6 -3
- package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
- package/src/msg_validators/tx_validator/size_validator.ts +6 -2
- package/src/msg_validators/tx_validator/timestamp_validator.ts +6 -3
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
- package/src/services/data_store.ts +10 -7
- package/src/services/discv5/discV5_service.ts +1 -1
- package/src/services/index.ts +1 -0
- package/src/services/libp2p/instrumentation.ts +15 -2
- package/src/services/libp2p/libp2p_service.ts +20 -16
- package/src/services/peer-manager/metrics.ts +21 -4
- package/src/services/peer-manager/peer_scoring.ts +4 -1
- package/src/services/reqresp/batch-tx-requester/README.md +7 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +2 -2
- package/src/services/reqresp/metrics.ts +34 -9
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +2 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +10 -10
- package/src/services/tx_collection/instrumentation.ts +11 -2
- package/src/services/tx_file_store/config.ts +43 -0
- package/src/services/tx_file_store/index.ts +3 -0
- package/src/services/tx_file_store/instrumentation.ts +36 -0
- package/src/services/tx_file_store/tx_file_store.ts +173 -0
- package/src/services/tx_provider_instrumentation.ts +11 -5
- package/src/test-helpers/testbench-utils.ts +2 -0
- package/src/testbench/p2p_client_testbench_worker.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
3
3
|
import type { P2PBootstrapApi } from '@aztec/stdlib/interfaces/server';
|
|
4
4
|
import { OtelMetricsAdapter, type TelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -18,12 +18,15 @@ import { convertToMultiaddr, getPeerIdPrivateKey, getPublicIp } from '../util.js
|
|
|
18
18
|
export class BootstrapNode implements P2PBootstrapApi {
|
|
19
19
|
private node?: Discv5EventEmitter = undefined;
|
|
20
20
|
private peerId?: PeerId;
|
|
21
|
+
private logger: Logger;
|
|
21
22
|
|
|
22
23
|
constructor(
|
|
23
24
|
private store: AztecAsyncKVStore,
|
|
24
25
|
private telemetry: TelemetryClient,
|
|
25
|
-
|
|
26
|
-
) {
|
|
26
|
+
bindings?: LoggerBindings,
|
|
27
|
+
) {
|
|
28
|
+
this.logger = createLogger('p2p:bootstrap', bindings);
|
|
29
|
+
}
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* Starts the bootstrap node.
|
|
@@ -65,7 +68,7 @@ export class BootstrapNode implements P2PBootstrapApi {
|
|
|
65
68
|
|
|
66
69
|
this.logger.debug(`Starting bootstrap node ${peerId} listening on ${listenAddrUdp.toString()}`);
|
|
67
70
|
|
|
68
|
-
const metricsRegistry = new OtelMetricsAdapter(this.telemetry);
|
|
71
|
+
const metricsRegistry = new OtelMetricsAdapter(this.telemetry, this.logger.getBindings());
|
|
69
72
|
this.node = Discv5.create({
|
|
70
73
|
enr: ourEnr,
|
|
71
74
|
peerId,
|
package/src/client/factory.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { DummyP2PService } from '../services/dummy_service.js';
|
|
|
21
21
|
import { LibP2PService } from '../services/index.js';
|
|
22
22
|
import { TxCollection } from '../services/tx_collection/tx_collection.js';
|
|
23
23
|
import { type TxSource, createNodeRpcTxSources } from '../services/tx_collection/tx_source.js';
|
|
24
|
+
import { TxFileStore } from '../services/tx_file_store/tx_file_store.js';
|
|
24
25
|
import { configureP2PClientAddresses, createLibP2PPeerIdFromPrivateKey, getPeerIdPrivateKey } from '../util.js';
|
|
25
26
|
|
|
26
27
|
export type P2PClientDeps<T extends P2PClientType> = {
|
|
@@ -62,15 +63,11 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
62
63
|
);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
1,
|
|
71
|
-
config,
|
|
72
|
-
createLogger('p2p-attestation:lmdb-v2'),
|
|
73
|
-
);
|
|
66
|
+
const bindings = logger.getBindings();
|
|
67
|
+
const store = deps.store ?? (await createStore(P2P_STORE_NAME, 2, config, bindings));
|
|
68
|
+
const archive = await createStore(P2P_ARCHIVE_STORE_NAME, 1, config, bindings);
|
|
69
|
+
const peerStore = await createStore(P2P_PEER_STORE_NAME, 1, config, bindings);
|
|
70
|
+
const attestationStore = await createStore(P2P_ATTESTATION_STORE_NAME, 1, config, bindings);
|
|
74
71
|
const l1Constants = await archiver.getL1Constants();
|
|
75
72
|
|
|
76
73
|
const mempools: MemPools = {
|
|
@@ -120,6 +117,8 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
120
117
|
logger.createChild('tx-collection'),
|
|
121
118
|
);
|
|
122
119
|
|
|
120
|
+
const txFileStore = await TxFileStore.create(mempools.txPool, config, logger.createChild('tx-file-store'), telemetry);
|
|
121
|
+
|
|
123
122
|
return new P2PClient(
|
|
124
123
|
clientType,
|
|
125
124
|
store,
|
|
@@ -127,6 +126,7 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
127
126
|
mempools,
|
|
128
127
|
p2pService,
|
|
129
128
|
txCollection,
|
|
129
|
+
txFileStore,
|
|
130
130
|
config,
|
|
131
131
|
dateProvider,
|
|
132
132
|
telemetry,
|
package/src/client/p2p_client.ts
CHANGED
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
|
|
42
42
|
import type { P2PBlockReceivedCallback, P2PCheckpointReceivedCallback, P2PService } from '../services/service.js';
|
|
43
43
|
import { TxCollection } from '../services/tx_collection/tx_collection.js';
|
|
44
|
+
import type { TxFileStore } from '../services/tx_file_store/tx_file_store.js';
|
|
44
45
|
import { TxProvider } from '../services/tx_provider.js';
|
|
45
46
|
import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
|
|
46
47
|
|
|
@@ -90,6 +91,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
90
91
|
mempools: MemPools,
|
|
91
92
|
private p2pService: P2PService,
|
|
92
93
|
private txCollection: TxCollection,
|
|
94
|
+
private txFileStore: TxFileStore | undefined,
|
|
93
95
|
config: Partial<P2PConfig> = {},
|
|
94
96
|
private _dateProvider: DateProvider = new DateProvider(),
|
|
95
97
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
@@ -274,6 +276,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
274
276
|
|
|
275
277
|
this.blockStream!.start();
|
|
276
278
|
await this.txCollection.start();
|
|
279
|
+
this.txFileStore?.start();
|
|
277
280
|
return this.syncPromise;
|
|
278
281
|
}
|
|
279
282
|
|
|
@@ -306,6 +309,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
306
309
|
this.log.debug('Stopping p2p client...');
|
|
307
310
|
await tryStop(this.txCollection);
|
|
308
311
|
this.log.debug('Stopped tx collection service');
|
|
312
|
+
await this.txFileStore?.stop();
|
|
313
|
+
this.log.debug('Stopped tx file store');
|
|
309
314
|
await this.p2pService.stop();
|
|
310
315
|
this.log.debug('Stopped p2p service');
|
|
311
316
|
await this.blockStream?.stop();
|
|
@@ -326,8 +331,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
326
331
|
[Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
|
|
327
332
|
[Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
|
|
328
333
|
}))
|
|
329
|
-
public broadcastProposal(proposal: BlockProposal): Promise<void> {
|
|
334
|
+
public async broadcastProposal(proposal: BlockProposal): Promise<void> {
|
|
330
335
|
this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber} to peers`);
|
|
336
|
+
// Store our own proposal so we can respond to req/resp requests for it
|
|
337
|
+
await this.attestationPool.addBlockProposal(proposal);
|
|
331
338
|
return this.p2pService.propagate(proposal);
|
|
332
339
|
}
|
|
333
340
|
|
|
@@ -336,8 +343,13 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
336
343
|
[Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
|
|
337
344
|
[Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
|
|
338
345
|
}))
|
|
339
|
-
public broadcastCheckpointProposal(proposal: CheckpointProposal): Promise<void> {
|
|
346
|
+
public async broadcastCheckpointProposal(proposal: CheckpointProposal): Promise<void> {
|
|
340
347
|
this.log.verbose(`Broadcasting checkpoint proposal for slot ${proposal.slotNumber} to peers`);
|
|
348
|
+
const blockProposal = proposal.getBlockProposal();
|
|
349
|
+
if (blockProposal) {
|
|
350
|
+
// Store our own last-block proposal so we can respond to req/resp requests for it.
|
|
351
|
+
await this.attestationPool.addBlockProposal(blockProposal);
|
|
352
|
+
}
|
|
341
353
|
return this.p2pService.propagate(proposal);
|
|
342
354
|
}
|
|
343
355
|
|
|
@@ -24,7 +24,7 @@ The benchmark runs a small simulated network on localhost:
|
|
|
24
24
|
```
|
|
25
25
|
┌─────────────────────────────────────────────────────────────────────┐
|
|
26
26
|
│ Test Process (Driver) │
|
|
27
|
-
│ p2p_client.
|
|
27
|
+
│ p2p_client.proposal_tx_collector.bench.test.ts │
|
|
28
28
|
│ ┌─────────────────────────────────────────────────────────────┐ │
|
|
29
29
|
│ │ WorkerClientManager │ │
|
|
30
30
|
│ │ (src/testbench/worker_client_manager.ts) │ │
|
|
@@ -127,13 +127,13 @@ From the p2p package:
|
|
|
127
127
|
|
|
128
128
|
```bash
|
|
129
129
|
cd yarn-project/p2p
|
|
130
|
-
yarn test src/client/test/tx_proposal_collector/p2p_client.
|
|
130
|
+
yarn test src/client/test/tx_proposal_collector/p2p_client.proposal_tx_collector.bench.test.ts
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
Or from repo root:
|
|
134
134
|
|
|
135
135
|
```bash
|
|
136
|
-
yarn test p2p_client.
|
|
136
|
+
yarn test p2p_client.proposal_tx_collector.bench.test.ts
|
|
137
137
|
```
|
|
138
138
|
|
|
139
139
|
The benchmark is intentionally long due to spawning many processes and running multiple cases.
|
|
@@ -207,7 +207,7 @@ This benchmark does **not** measure:
|
|
|
207
207
|
|
|
208
208
|
| File | Purpose |
|
|
209
209
|
|------|---------|
|
|
210
|
-
| `p2p_client.
|
|
210
|
+
| `p2p_client.proposal_tx_collector.bench.test.ts` | Test suite (cases, distributions, output formatting) |
|
|
211
211
|
| `proposal_tx_collector_worker.ts` | Collector-specific worker implementation |
|
|
212
212
|
| `proposal_tx_collector_worker_protocol.ts` | IPC message types and serialization |
|
|
213
213
|
| `src/testbench/worker_client_manager.ts` | Worker process manager (forking, IPC, orchestration) |
|
|
@@ -104,7 +104,7 @@ async function startClient(config: P2PConfig, clientIndex: number) {
|
|
|
104
104
|
const worldState = createMockWorldStateSynchronizer();
|
|
105
105
|
const l2BlockSource = new MockL2BlockSource();
|
|
106
106
|
const proofVerifier = new AlwaysTrueCircuitVerifier();
|
|
107
|
-
kvStore = await openTmpStore(`proposal-bench-${clientIndex}
|
|
107
|
+
kvStore = await openTmpStore(`proposal-bench-${clientIndex}`, true, BENCHMARK_CONSTANTS.KV_STORE_MAP_SIZE_KB);
|
|
108
108
|
logger = createLogger(`p2p:proposal-bench:${clientIndex}`);
|
|
109
109
|
|
|
110
110
|
const telemetry = getTelemetryClient();
|
package/src/config.ts
CHANGED
|
@@ -21,11 +21,17 @@ import {
|
|
|
21
21
|
} from './services/reqresp/batch-tx-requester/config.js';
|
|
22
22
|
import { type P2PReqRespConfig, p2pReqRespConfigMappings } from './services/reqresp/config.js';
|
|
23
23
|
import { type TxCollectionConfig, txCollectionConfigMappings } from './services/tx_collection/config.js';
|
|
24
|
+
import { type TxFileStoreConfig, txFileStoreConfigMappings } from './services/tx_file_store/config.js';
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* P2P client configuration values.
|
|
27
28
|
*/
|
|
28
|
-
export interface P2PConfig
|
|
29
|
+
export interface P2PConfig
|
|
30
|
+
extends P2PReqRespConfig,
|
|
31
|
+
BatchTxRequesterConfig,
|
|
32
|
+
ChainConfig,
|
|
33
|
+
TxCollectionConfig,
|
|
34
|
+
TxFileStoreConfig {
|
|
29
35
|
/** A flag dictating whether the P2P subsystem should be enabled. */
|
|
30
36
|
p2pEnabled: boolean;
|
|
31
37
|
|
|
@@ -439,6 +445,7 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
|
439
445
|
...batchTxRequesterConfigMappings,
|
|
440
446
|
...chainConfigMappings,
|
|
441
447
|
...txCollectionConfigMappings,
|
|
448
|
+
...txFileStoreConfigMappings,
|
|
442
449
|
};
|
|
443
450
|
|
|
444
451
|
/**
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type ObservableGauge,
|
|
13
13
|
type TelemetryClient,
|
|
14
14
|
type UpDownCounter,
|
|
15
|
+
createUpDownCounterWithDefault,
|
|
15
16
|
} from '@aztec/telemetry-client';
|
|
16
17
|
|
|
17
18
|
export enum PoolName {
|
|
@@ -97,7 +98,7 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
97
98
|
dbStats,
|
|
98
99
|
);
|
|
99
100
|
|
|
100
|
-
this.addObjectCounter = this.meter
|
|
101
|
+
this.addObjectCounter = createUpDownCounterWithDefault(this.meter, metricsLabels.itemsAdded);
|
|
101
102
|
|
|
102
103
|
this.minedDelay = this.meter.createHistogram(metricsLabels.itemMinedDelay);
|
|
103
104
|
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# TxPoolV2
|
|
2
|
+
|
|
3
|
+
Transaction pool implementation with explicit state management and pluggable eviction rules.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
TxPoolV2 manages transactions through a state machine with clear transitions:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
addPendingTxs()
|
|
11
|
+
│
|
|
12
|
+
▼
|
|
13
|
+
┌─────────────────────────────────────┐
|
|
14
|
+
│ PENDING │◄──────────────────┐
|
|
15
|
+
│ (awaiting block inclusion) │ │
|
|
16
|
+
└─────────────────────────────────────┘ │
|
|
17
|
+
│ │
|
|
18
|
+
│ protectTxs() / addProtectedTxs() │
|
|
19
|
+
▼ │
|
|
20
|
+
┌─────────────────────────────────────┐ │
|
|
21
|
+
│ PROTECTED │───────────────────┘
|
|
22
|
+
│ (in a block proposal) │ prepareForSlot()
|
|
23
|
+
└─────────────────────────────────────┘ (slot passed without mining)
|
|
24
|
+
│ │
|
|
25
|
+
│ handleMinedBlock() │
|
|
26
|
+
▼ │
|
|
27
|
+
┌─────────────────────────────────────┐ │
|
|
28
|
+
│ MINED │───────────────────┘
|
|
29
|
+
│ (included in a block) │ handlePrunedBlocks()
|
|
30
|
+
└─────────────────────────────────────┘ (reorg)
|
|
31
|
+
│
|
|
32
|
+
│ handleFinalizedBlock()
|
|
33
|
+
▼
|
|
34
|
+
┌─────────────────────────────────────┐
|
|
35
|
+
│ DELETED │
|
|
36
|
+
│ (optionally archived) │
|
|
37
|
+
└─────────────────────────────────────┘
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Key Components
|
|
41
|
+
|
|
42
|
+
### TxPoolV2 (`tx_pool_v2.ts`)
|
|
43
|
+
|
|
44
|
+
The public API wrapper that serializes all operations through a queue to prevent race conditions. Delegates to `TxPoolV2Impl` for actual logic.
|
|
45
|
+
|
|
46
|
+
### TxPoolV2Impl (`tx_pool_v2_impl.ts`)
|
|
47
|
+
|
|
48
|
+
Core implementation containing:
|
|
49
|
+
- KV store persistence for transactions and metadata
|
|
50
|
+
- In-memory indices for fast lookups (by nullifier, fee payer, priority)
|
|
51
|
+
- State transition logic
|
|
52
|
+
- Pre-add rule execution
|
|
53
|
+
- Post-event eviction rule execution
|
|
54
|
+
|
|
55
|
+
### TxMetaData (`tx_metadata.ts`)
|
|
56
|
+
|
|
57
|
+
Lightweight metadata stored alongside each transaction:
|
|
58
|
+
- `txHash`: Transaction identifier
|
|
59
|
+
- `state`: Current state (pending, protected, mined)
|
|
60
|
+
- `priorityFee`: For priority ordering
|
|
61
|
+
- `feePayer`: For balance-based eviction
|
|
62
|
+
- `nullifiers`: For conflict detection
|
|
63
|
+
- `estimatedTxFee`: For balance calculations
|
|
64
|
+
- `blockId`: Block info when mined
|
|
65
|
+
- `protectedSlot`: Slot number when protected
|
|
66
|
+
|
|
67
|
+
## Eviction Rules
|
|
68
|
+
|
|
69
|
+
The pool uses a pluggable rule system for managing transactions.
|
|
70
|
+
|
|
71
|
+
### Pre-Add Rules
|
|
72
|
+
|
|
73
|
+
Checked before adding a transaction to the pending pool:
|
|
74
|
+
|
|
75
|
+
| Rule | Purpose |
|
|
76
|
+
|------|---------|
|
|
77
|
+
| `NullifierConflictRule` | Handles transactions with conflicting nullifiers. Higher priority tx wins. |
|
|
78
|
+
| `FeePayerBalancePreAddRule` | Ensures fee payer has sufficient balance for all their pending txs. |
|
|
79
|
+
| `LowPriorityPreAddRule` | Rejects txs when pool is full and new tx has lowest priority. |
|
|
80
|
+
|
|
81
|
+
### Post-Event Eviction Rules
|
|
82
|
+
|
|
83
|
+
Run after events to clean up the pool:
|
|
84
|
+
|
|
85
|
+
| Rule | Trigger | Purpose |
|
|
86
|
+
|------|---------|---------|
|
|
87
|
+
| `LowPriorityEvictionRule` | `txs_added` | Evicts lowest priority txs when pool exceeds limit. |
|
|
88
|
+
| `FeePayerBalanceEvictionRule` | `block_mined` | Evicts txs when fee payer balance decreases. |
|
|
89
|
+
| `InvalidTxsAfterMiningRule` | `block_mined` | Evicts pending txs with nullifiers that were just mined. |
|
|
90
|
+
| `InvalidTxsAfterReorgRule` | `chain_pruned` | Evicts txs with invalid anchor blocks after reorg. |
|
|
91
|
+
|
|
92
|
+
## Usage
|
|
93
|
+
|
|
94
|
+
### Creating a Pool
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { AztecKVTxPoolV2 } from './tx_pool_v2.js';
|
|
98
|
+
|
|
99
|
+
const pool = new AztecKVTxPoolV2(txStore, archiveStore, {
|
|
100
|
+
l2BlockSource: archiver,
|
|
101
|
+
worldStateSynchronizer: worldState,
|
|
102
|
+
pendingTxValidator: validator,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
await pool.start();
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Adding Transactions
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// Add to pending pool (validates and runs pre-add rules)
|
|
112
|
+
const result = await pool.addPendingTxs(txs, { source: 'gossip' });
|
|
113
|
+
// result: { accepted: TxHash[], ignored: TxHash[], rejected: TxHash[] }
|
|
114
|
+
|
|
115
|
+
// Check without modifying pool
|
|
116
|
+
const canAdd = await pool.canAddPendingTx(tx);
|
|
117
|
+
// canAdd: 'accepted' | 'ignored' | 'rejected'
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Block Building Flow
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// 1. Proposer protects txs for their block
|
|
124
|
+
await pool.protectTxs(selectedTxHashes, blockHeader);
|
|
125
|
+
|
|
126
|
+
// 2. On successful mining
|
|
127
|
+
await pool.handleMinedBlock(minedTxHashes, blockHeader);
|
|
128
|
+
|
|
129
|
+
// 3. If slot passes without mining
|
|
130
|
+
await pool.prepareForSlot(nextSlotNumber);
|
|
131
|
+
|
|
132
|
+
// 4. On finalization
|
|
133
|
+
await pool.handleFinalizedBlock(finalizedBlockHeader);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Handling Reorgs
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
// When blocks are pruned, un-mine affected transactions
|
|
140
|
+
await pool.handlePrunedBlocks(latestValidBlockId);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Configuration
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
await pool.updateConfig({
|
|
147
|
+
maxPendingTxCount: 10000, // 0 = unlimited
|
|
148
|
+
archivedTxLimit: 1000, // 0 = disabled
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Return Values
|
|
153
|
+
|
|
154
|
+
### AddTxsResult
|
|
155
|
+
|
|
156
|
+
When adding pending transactions, each tx is categorized:
|
|
157
|
+
|
|
158
|
+
| Status | Meaning |
|
|
159
|
+
|--------|---------|
|
|
160
|
+
| `accepted` | Successfully added to the pool |
|
|
161
|
+
| `ignored` | Valid but not added (duplicate, lost nullifier conflict, insufficient balance) |
|
|
162
|
+
| `rejected` | Failed validation (invalid proof, expired, etc.) |
|
|
163
|
+
|
|
164
|
+
## Archive
|
|
165
|
+
|
|
166
|
+
Finalized transactions can optionally be archived for historical queries:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
const archivedTx = await pool.getArchivedTxByHash(txHash);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The archive uses FIFO eviction when `archivedTxLimit` is reached.
|
|
173
|
+
|
|
174
|
+
## Testing
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Unit tests (131 tests)
|
|
178
|
+
yarn test src/mem_pools/tx_pool_v2/tx_pool_v2.test.ts
|
|
179
|
+
|
|
180
|
+
# Compatibility tests (25 tests)
|
|
181
|
+
yarn test src/mem_pools/tx_pool_v2/tx_pool_v2.compat.test.ts
|
|
182
|
+
|
|
183
|
+
# Eviction rule tests
|
|
184
|
+
yarn test src/mem_pools/tx_pool_v2/eviction/
|
|
185
|
+
|
|
186
|
+
# Benchmarks
|
|
187
|
+
yarn test src/mem_pools/tx_pool_v2/tx_pool_v2_bench.test.ts
|
|
188
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TxArchive } from './tx_archive.js';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
3
|
+
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
4
|
+
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Manages archived transactions with FIFO eviction.
|
|
8
|
+
* Archived transactions have their proofs stripped to save space.
|
|
9
|
+
*/
|
|
10
|
+
export class TxArchive {
|
|
11
|
+
#store: AztecAsyncKVStore;
|
|
12
|
+
#txs: AztecAsyncMap<string, Buffer>;
|
|
13
|
+
#indices: AztecAsyncMap<number, string>;
|
|
14
|
+
#limit: number;
|
|
15
|
+
#log: Logger;
|
|
16
|
+
|
|
17
|
+
constructor(store: AztecAsyncKVStore, limit: number, log?: Logger) {
|
|
18
|
+
this.#store = store;
|
|
19
|
+
this.#txs = store.openMap('archivedTxs');
|
|
20
|
+
this.#indices = store.openMap('archivedTxIndices');
|
|
21
|
+
this.#limit = limit;
|
|
22
|
+
this.#log = log ?? createLogger('p2p:tx_pool_v2:archive');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Updates the maximum number of archived transactions.
|
|
27
|
+
*/
|
|
28
|
+
updateLimit(limit: number): void {
|
|
29
|
+
this.#limit = limit;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Gets the current archive limit.
|
|
34
|
+
*/
|
|
35
|
+
getLimit(): number {
|
|
36
|
+
return this.#limit;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Checks if archiving is enabled.
|
|
41
|
+
*/
|
|
42
|
+
isEnabled(): boolean {
|
|
43
|
+
return this.#limit > 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Archives transactions, stripping their proofs.
|
|
48
|
+
* Evicts oldest transactions if the limit is exceeded.
|
|
49
|
+
*/
|
|
50
|
+
async archiveTxs(txs: Tx[]): Promise<void> {
|
|
51
|
+
if (!this.isEnabled() || txs.length === 0) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
await this.#store.transactionAsync(async () => {
|
|
57
|
+
// Get current head and tail indices
|
|
58
|
+
let headIdx = await this.getHeadIndex();
|
|
59
|
+
let tailIdx = await this.getTailIndex();
|
|
60
|
+
|
|
61
|
+
for (const tx of txs) {
|
|
62
|
+
// Evict oldest entries if at capacity
|
|
63
|
+
while (headIdx - tailIdx >= this.#limit) {
|
|
64
|
+
const txHashToEvict = await this.#indices.getAsync(tailIdx);
|
|
65
|
+
if (txHashToEvict) {
|
|
66
|
+
await this.#txs.delete(txHashToEvict);
|
|
67
|
+
await this.#indices.delete(tailIdx);
|
|
68
|
+
}
|
|
69
|
+
tailIdx++;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Archive the transaction with stripped proof
|
|
73
|
+
const archivedTx = this.stripProof(tx);
|
|
74
|
+
const txHash = tx.getTxHash().toString();
|
|
75
|
+
await this.#txs.set(txHash, archivedTx.toBuffer());
|
|
76
|
+
await this.#indices.set(headIdx, txHash);
|
|
77
|
+
headIdx++;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.#log.debug(`Archived ${txs.length} txs, total: ${headIdx - tailIdx}`);
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
this.#log.error('Error archiving transactions', { error });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves an archived transaction by its hash.
|
|
89
|
+
*/
|
|
90
|
+
async getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
91
|
+
const buffer = await this.#txs.getAsync(txHash.toString());
|
|
92
|
+
return buffer ? Tx.fromBuffer(buffer) : undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Gets the current count of archived transactions.
|
|
97
|
+
*/
|
|
98
|
+
async getCount(): Promise<number> {
|
|
99
|
+
const head = await this.getHeadIndex();
|
|
100
|
+
const tail = await this.getTailIndex();
|
|
101
|
+
return head - tail;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Strips the proof from a transaction for archival.
|
|
106
|
+
*/
|
|
107
|
+
private stripProof(tx: Tx): Tx {
|
|
108
|
+
return new Tx(tx.txHash, tx.data, ChonkProof.empty(), tx.contractClassLogFields, tx.publicFunctionCalldata);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private async getHeadIndex(): Promise<number> {
|
|
112
|
+
const entry = await this.#indices.entriesAsync({ limit: 1, reverse: true }).next();
|
|
113
|
+
return (entry.value?.[0] ?? -1) + 1;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private async getTailIndex(): Promise<number> {
|
|
117
|
+
const entry = await this.#indices.entriesAsync({ limit: 1 }).next();
|
|
118
|
+
return entry.value?.[0] ?? 0;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
4
|
+
|
|
5
|
+
import type { TxMetaData } from '../tx_metadata.js';
|
|
6
|
+
import {
|
|
7
|
+
type EvictionConfig,
|
|
8
|
+
type EvictionContext,
|
|
9
|
+
EvictionEvent,
|
|
10
|
+
type EvictionRule,
|
|
11
|
+
type PoolOperations,
|
|
12
|
+
type PreAddPoolAccess,
|
|
13
|
+
type PreAddResult,
|
|
14
|
+
type PreAddRule,
|
|
15
|
+
} from './interfaces.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Manages eviction rules for the transaction pool.
|
|
19
|
+
* Coordinates pre-add rules (run during addPendingTxs) and post-event rules (run after events).
|
|
20
|
+
*/
|
|
21
|
+
export class EvictionManager {
|
|
22
|
+
private preAddRules: PreAddRule[] = [];
|
|
23
|
+
private postEventRules: EvictionRule[] = [];
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
private pool: PoolOperations,
|
|
27
|
+
private log: Logger,
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Registers a pre-add rule that runs during transaction addition.
|
|
32
|
+
*/
|
|
33
|
+
registerPreAddRule(rule: PreAddRule): void {
|
|
34
|
+
this.preAddRules.push(rule);
|
|
35
|
+
this.log.debug(`Registered pre-add rule: ${rule.name}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Registers a post-event eviction rule that runs after events.
|
|
40
|
+
*/
|
|
41
|
+
registerRule(rule: EvictionRule): void {
|
|
42
|
+
this.postEventRules.push(rule);
|
|
43
|
+
this.log.debug(`Registered eviction rule: ${rule.name}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Runs all pre-add rules for an incoming transaction.
|
|
48
|
+
* Returns combined result of all rules.
|
|
49
|
+
*/
|
|
50
|
+
async runPreAddRules(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
|
|
51
|
+
const allTxHashesToEvict: string[] = [];
|
|
52
|
+
|
|
53
|
+
for (const rule of this.preAddRules) {
|
|
54
|
+
try {
|
|
55
|
+
const result = await rule.check(incomingMeta, poolAccess);
|
|
56
|
+
|
|
57
|
+
if (result.shouldIgnore) {
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Collect txs to evict from all rules
|
|
62
|
+
for (const txHash of result.txHashesToEvict) {
|
|
63
|
+
if (!allTxHashesToEvict.includes(txHash)) {
|
|
64
|
+
allTxHashesToEvict.push(txHash);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} catch (err) {
|
|
68
|
+
this.log.error(`Error running pre-add rule ${rule.name}`, { err, txHash: incomingMeta.txHash });
|
|
69
|
+
// On error, ignore the transaction to be safe
|
|
70
|
+
return {
|
|
71
|
+
shouldIgnore: true,
|
|
72
|
+
txHashesToEvict: [],
|
|
73
|
+
reason: `pre-add rule ${rule.name} error: ${err}`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
shouldIgnore: false,
|
|
80
|
+
txHashesToEvict: allTxHashesToEvict,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Runs post-event eviction after new transactions are added.
|
|
86
|
+
*/
|
|
87
|
+
async evictAfterNewTxs(newTxHashes: string[], feePayers: string[]): Promise<void> {
|
|
88
|
+
const context: EvictionContext = {
|
|
89
|
+
event: EvictionEvent.TXS_ADDED,
|
|
90
|
+
newTxHashes,
|
|
91
|
+
feePayers,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
await this.runPostEventRules(context);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Runs post-event eviction after a block is mined.
|
|
99
|
+
*/
|
|
100
|
+
async evictAfterNewBlock(block: BlockHeader, newNullifiers: string[], feePayers: string[]): Promise<void> {
|
|
101
|
+
const context: EvictionContext = {
|
|
102
|
+
event: EvictionEvent.BLOCK_MINED,
|
|
103
|
+
block,
|
|
104
|
+
newNullifiers,
|
|
105
|
+
feePayers,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
await this.runPostEventRules(context);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Runs post-event eviction after a chain prune (reorg).
|
|
113
|
+
*/
|
|
114
|
+
async evictAfterChainPrune(blockNumber: BlockNumber): Promise<void> {
|
|
115
|
+
const context: EvictionContext = {
|
|
116
|
+
event: EvictionEvent.CHAIN_PRUNED,
|
|
117
|
+
blockNumber,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
await this.runPostEventRules(context);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Updates configuration for all rules.
|
|
125
|
+
*/
|
|
126
|
+
updateConfig(config: EvictionConfig): void {
|
|
127
|
+
for (const rule of this.preAddRules) {
|
|
128
|
+
rule.updateConfig?.(config);
|
|
129
|
+
}
|
|
130
|
+
for (const rule of this.postEventRules) {
|
|
131
|
+
rule.updateConfig?.(config);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private async runPostEventRules(context: EvictionContext): Promise<void> {
|
|
136
|
+
for (const rule of this.postEventRules) {
|
|
137
|
+
try {
|
|
138
|
+
const result = await rule.evict(context, this.pool);
|
|
139
|
+
if (!result.success) {
|
|
140
|
+
this.log.warn(`Eviction rule ${rule.name} failed`, { error: result.error });
|
|
141
|
+
}
|
|
142
|
+
} catch (err) {
|
|
143
|
+
this.log.error(`Error running eviction rule ${rule.name}`, { err });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|