@aztec/p2p 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c
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/client/factory.d.ts +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +2 -3
- package/dest/client/interface.d.ts +18 -5
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +16 -19
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +460 -127
- package/dest/config.d.ts +4 -7
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +10 -13
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +61 -42
- 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 +239 -265
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -18
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +114 -109
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -16
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +89 -128
- package/dest/mem_pools/attestation_pool/mocks.d.ts +11 -8
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +17 -13
- package/dest/mem_pools/instrumentation.d.ts +7 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +30 -12
- package/dest/mem_pools/interface.d.ts +3 -4
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +37 -27
- 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 +314 -335
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/mem_pools/tx_pool/index.d.ts +1 -2
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +6 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +11 -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 +30 -24
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +52 -19
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +18 -14
- package/dest/msg_validators/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -0
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
- 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/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 +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
- 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/gas_validator.js +8 -14
- 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 +2 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/size_validator.d.ts +6 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +20 -0
- 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 +3 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/services/dummy_service.d.ts +6 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +3 -0
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -6
- 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 +20 -73
- package/dest/services/libp2p/libp2p_service.d.ts +31 -14
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +722 -168
- package/dest/services/peer-manager/metrics.d.ts +6 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +18 -21
- package/dest/services/peer-manager/peer_manager.d.ts +2 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +4 -12
- 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 +2 -5
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- package/dest/services/reqresp/interface.d.ts +2 -2
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +1 -1
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +5 -21
- 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/bitvector.js +7 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +2 -2
- 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/status.d.ts +5 -4
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +7 -3
- package/dest/services/reqresp/protocols/tx.d.ts +2 -3
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +402 -24
- package/dest/services/service.d.ts +16 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -3
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +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/instrumentation.js +4 -14
- package/dest/services/tx_collection/slow_tx_collection.d.ts +4 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +7 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +4 -2
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +11 -2
- package/dest/services/tx_provider_instrumentation.d.ts +5 -2
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +13 -13
- package/dest/test-helpers/mock-tx-helpers.js +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +31 -17
- package/dest/testbench/worker_client_manager.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -1
- package/package.json +18 -18
- package/src/client/factory.ts +5 -10
- package/src/client/interface.ts +19 -4
- package/src/client/p2p_client.ts +101 -154
- package/src/config.ts +12 -18
- package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -289
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +163 -141
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
- package/src/mem_pools/attestation_pool/mocks.ts +21 -15
- package/src/mem_pools/instrumentation.ts +38 -14
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +367 -371
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/mem_pools/tx_pool/index.ts +0 -1
- package/src/mem_pools/tx_pool/priority.ts +8 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +11 -5
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +23 -17
- package/src/msg_validators/attestation_validator/attestation_validator.ts +37 -22
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +13 -16
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +4 -2
- package/src/msg_validators/tx_validator/data_validator.ts +12 -4
- package/src/msg_validators/tx_validator/factory.ts +3 -2
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +8 -25
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +13 -5
- package/src/msg_validators/tx_validator/size_validator.ts +18 -0
- package/src/msg_validators/tx_validator/test_utils.ts +1 -1
- package/src/msg_validators/tx_validator/timestamp_validator.ts +5 -2
- package/src/services/dummy_service.ts +6 -0
- package/src/services/encoding.ts +6 -5
- package/src/services/libp2p/instrumentation.ts +19 -73
- package/src/services/libp2p/libp2p_service.ts +369 -138
- package/src/services/peer-manager/metrics.ts +22 -21
- package/src/services/peer-manager/peer_manager.ts +5 -4
- package/src/services/peer-manager/peer_scoring.ts +1 -5
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +3 -1
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/interface.ts +1 -1
- package/src/services/reqresp/metrics.ts +7 -23
- 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/bitvector.ts +9 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
- package/src/services/reqresp/protocols/status.ts +16 -12
- package/src/services/reqresp/protocols/tx.ts +1 -2
- package/src/services/service.ts +19 -4
- package/src/services/tx_collection/config.ts +1 -1
- package/src/services/tx_collection/fast_tx_collection.ts +3 -2
- package/src/services/tx_collection/instrumentation.ts +4 -21
- package/src/services/tx_collection/slow_tx_collection.ts +3 -3
- package/src/services/tx_collection/tx_collection.ts +6 -5
- package/src/services/tx_provider.ts +19 -3
- package/src/services/tx_provider_instrumentation.ts +18 -14
- package/src/test-helpers/mock-pubsub.ts +1 -1
- package/src/test-helpers/mock-tx-helpers.ts +1 -1
- package/src/test-helpers/reqresp-nodes.ts +1 -1
- package/src/testbench/p2p_client_testbench_worker.ts +42 -22
- package/src/testbench/worker_client_manager.ts +6 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -80
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -238
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -283
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
package/src/client/factory.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { configureP2PClientAddresses, createLibP2PPeerIdFromPrivateKey, getPeerI
|
|
|
26
26
|
export type P2PClientDeps<T extends P2PClientType> = {
|
|
27
27
|
txPool?: TxPool;
|
|
28
28
|
store?: AztecAsyncKVStore;
|
|
29
|
-
attestationPool?:
|
|
29
|
+
attestationPool?: AttestationPool;
|
|
30
30
|
logger?: Logger;
|
|
31
31
|
txCollectionNodeSources?: TxSource[];
|
|
32
32
|
p2pServiceFactory?: (...args: Parameters<(typeof LibP2PService)['new']>) => Promise<LibP2PService<T>>;
|
|
@@ -73,19 +73,14 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
73
73
|
);
|
|
74
74
|
const l1Constants = await archiver.getL1Constants();
|
|
75
75
|
|
|
76
|
-
const mempools: MemPools
|
|
76
|
+
const mempools: MemPools = {
|
|
77
77
|
txPool:
|
|
78
78
|
deps.txPool ??
|
|
79
79
|
new AztecKVTxPool(store, archive, worldStateSynchronizer, telemetry, {
|
|
80
|
-
|
|
80
|
+
maxPendingTxCount: config.maxPendingTxCount,
|
|
81
81
|
archivedTxLimit: config.archivedTxLimit,
|
|
82
82
|
}),
|
|
83
|
-
attestationPool:
|
|
84
|
-
clientType === P2PClientType.Full
|
|
85
|
-
? ((deps.attestationPool ?? new KvAttestationPool(attestationStore, telemetry)) as T extends P2PClientType.Full
|
|
86
|
-
? AttestationPool
|
|
87
|
-
: undefined)
|
|
88
|
-
: undefined,
|
|
83
|
+
attestationPool: deps.attestationPool ?? new KvAttestationPool(attestationStore, telemetry),
|
|
89
84
|
};
|
|
90
85
|
|
|
91
86
|
const p2pService = await createP2PService<T>(
|
|
@@ -147,7 +142,7 @@ async function createP2PService<T extends P2PClientType>(
|
|
|
147
142
|
epochCache: EpochCacheInterface,
|
|
148
143
|
store: AztecAsyncKVStore,
|
|
149
144
|
peerStore: AztecLMDBStoreV2,
|
|
150
|
-
mempools: MemPools
|
|
145
|
+
mempools: MemPools,
|
|
151
146
|
p2pServiceFactory: P2PClientDeps<T>['p2pServiceFactory'],
|
|
152
147
|
packageVersion: string,
|
|
153
148
|
logger: Logger,
|
package/src/client/interface.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EthAddress, L2BlockId } from '@aztec/stdlib/block';
|
|
2
2
|
import type { P2PApiFull } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlockProposal, CheckpointAttestation, CheckpointProposal, P2PClientType } from '@aztec/stdlib/p2p';
|
|
4
4
|
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
6
6
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
ReqRespSubProtocolHandler,
|
|
14
14
|
ReqRespSubProtocolValidators,
|
|
15
15
|
} from '../services/reqresp/interface.js';
|
|
16
|
-
import type { P2PBlockReceivedCallback } from '../services/service.js';
|
|
16
|
+
import type { P2PBlockReceivedCallback, P2PCheckpointReceivedCallback } from '../services/service.js';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Enum defining the possible states of the p2p client.
|
|
@@ -50,8 +50,15 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
50
50
|
*/
|
|
51
51
|
broadcastProposal(proposal: BlockProposal): Promise<void>;
|
|
52
52
|
|
|
53
|
-
/**
|
|
54
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Broadcasts a checkpoint proposal (last block in a checkpoint) to other peers.
|
|
55
|
+
*
|
|
56
|
+
* @param proposal - the checkpoint proposal
|
|
57
|
+
*/
|
|
58
|
+
broadcastCheckpointProposal(proposal: CheckpointProposal): Promise<void>;
|
|
59
|
+
|
|
60
|
+
/** Broadcasts checkpoint attestations to other peers. */
|
|
61
|
+
broadcastCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void>;
|
|
55
62
|
|
|
56
63
|
/**
|
|
57
64
|
* Registers a callback from the validator client that determines how to behave when
|
|
@@ -63,6 +70,14 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
63
70
|
// ^ This pattern is not my favorite (md)
|
|
64
71
|
registerBlockProposalHandler(callback: P2PBlockReceivedCallback): void;
|
|
65
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Registers a callback from the validator client that determines how to behave when
|
|
75
|
+
* foreign checkpoint proposals are received
|
|
76
|
+
*
|
|
77
|
+
* @param handler - A function taking a received checkpoint proposal and producing attestations
|
|
78
|
+
*/
|
|
79
|
+
registerCheckpointProposalHandler(callback: P2PCheckpointReceivedCallback): void;
|
|
80
|
+
|
|
66
81
|
/**
|
|
67
82
|
* Request a list of transactions from another peer by their tx hashes.
|
|
68
83
|
* @param txHashes - Hashes of the txs to query.
|
package/src/client/p2p_client.ts
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
import type { AztecAsyncKVStore,
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
L2BlockSource,
|
|
5
|
+
import type { AztecAsyncKVStore, AztecAsyncSingleton } from '@aztec/kv-store';
|
|
6
|
+
import { L2TipsKVStore } from '@aztec/kv-store/stores';
|
|
7
|
+
import {
|
|
8
|
+
type EthAddress,
|
|
9
|
+
type L2Block,
|
|
10
|
+
type L2BlockSource,
|
|
11
11
|
L2BlockStream,
|
|
12
|
-
L2BlockStreamEvent,
|
|
13
|
-
L2Tips,
|
|
14
|
-
|
|
12
|
+
type L2BlockStreamEvent,
|
|
13
|
+
type L2Tips,
|
|
14
|
+
type L2TipsStore,
|
|
15
15
|
} from '@aztec/stdlib/block';
|
|
16
16
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
17
17
|
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
18
18
|
import { type PeerInfo, tryStop } from '@aztec/stdlib/interfaces/server';
|
|
19
|
-
import { BlockAttestation, type BlockProposal, type P2PClientType } from '@aztec/stdlib/p2p';
|
|
20
|
-
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
21
19
|
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} from '@aztec/telemetry-client';
|
|
20
|
+
type BlockProposal,
|
|
21
|
+
CheckpointAttestation,
|
|
22
|
+
type CheckpointProposal,
|
|
23
|
+
type P2PClientType,
|
|
24
|
+
} from '@aztec/stdlib/p2p';
|
|
25
|
+
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
26
|
+
import { Attributes, type TelemetryClient, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
29
27
|
|
|
30
28
|
import type { PeerId } from '@libp2p/interface';
|
|
31
29
|
import type { ENR } from '@nethermindeth/enr';
|
|
@@ -41,7 +39,7 @@ import {
|
|
|
41
39
|
type ReqRespSubProtocolValidators,
|
|
42
40
|
} from '../services/reqresp/interface.js';
|
|
43
41
|
import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
|
|
44
|
-
import type { P2PBlockReceivedCallback, P2PService } from '../services/service.js';
|
|
42
|
+
import type { P2PBlockReceivedCallback, P2PCheckpointReceivedCallback, P2PService } from '../services/service.js';
|
|
45
43
|
import { TxCollection } from '../services/tx_collection/tx_collection.js';
|
|
46
44
|
import { TxProvider } from '../services/tx_provider.js';
|
|
47
45
|
import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
|
|
@@ -63,14 +61,11 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
63
61
|
private provenBlockNumberAtStart = -1;
|
|
64
62
|
private finalizedBlockNumberAtStart = -1;
|
|
65
63
|
|
|
66
|
-
private
|
|
67
|
-
private synchedLatestBlockNumber: AztecAsyncSingleton<number>;
|
|
68
|
-
private synchedProvenBlockNumber: AztecAsyncSingleton<number>;
|
|
69
|
-
private synchedFinalizedBlockNumber: AztecAsyncSingleton<number>;
|
|
64
|
+
private l2Tips: L2TipsStore;
|
|
70
65
|
private synchedLatestSlot: AztecAsyncSingleton<bigint>;
|
|
71
66
|
|
|
72
67
|
private txPool: TxPool;
|
|
73
|
-
private attestationPool:
|
|
68
|
+
private attestationPool: AttestationPool;
|
|
74
69
|
|
|
75
70
|
private config: P2PConfig;
|
|
76
71
|
|
|
@@ -92,7 +87,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
92
87
|
_clientType: T,
|
|
93
88
|
private store: AztecAsyncKVStore,
|
|
94
89
|
private l2BlockSource: L2BlockSource & ContractDataSource,
|
|
95
|
-
mempools: MemPools
|
|
90
|
+
mempools: MemPools,
|
|
96
91
|
private p2pService: P2PService,
|
|
97
92
|
private txCollection: TxCollection,
|
|
98
93
|
config: Partial<P2PConfig> = {},
|
|
@@ -104,7 +99,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
104
99
|
|
|
105
100
|
this.config = { ...getP2PDefaultConfig(), ...config };
|
|
106
101
|
this.txPool = mempools.txPool;
|
|
107
|
-
this.attestationPool = mempools.attestationPool
|
|
102
|
+
this.attestationPool = mempools.attestationPool;
|
|
108
103
|
|
|
109
104
|
this.txProvider = new TxProvider(
|
|
110
105
|
this.txCollection,
|
|
@@ -115,7 +110,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
115
110
|
);
|
|
116
111
|
|
|
117
112
|
// Default to collecting all txs when we see a valid proposal
|
|
118
|
-
// This can be overridden by the validator client to
|
|
113
|
+
// This can be overridden by the validator client to validate, and it will call getTxsForBlockProposal on its own
|
|
114
|
+
// Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
119
115
|
// TODO(palla/txs): We should not trigger a request for txs on a proposal before fully validating it. We need to bring
|
|
120
116
|
// validator-client code into here so we can validate a proposal is reasonable.
|
|
121
117
|
this.registerBlockProposalHandler(async (block, sender) => {
|
|
@@ -124,21 +120,17 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
124
120
|
const constants = this.txCollection.getConstants();
|
|
125
121
|
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
|
|
126
122
|
const deadline = new Date(nextSlotTimestampSeconds * 1000);
|
|
127
|
-
const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.
|
|
123
|
+
const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.blockHeader.lastArchive.root);
|
|
128
124
|
if (!parentBlock) {
|
|
129
125
|
this.log.debug(`Cannot collect txs for proposal as parent block not found`);
|
|
130
|
-
return;
|
|
126
|
+
return false;
|
|
131
127
|
}
|
|
132
|
-
const blockNumber = parentBlock.getBlockNumber() + 1;
|
|
128
|
+
const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
|
|
133
129
|
await this.txProvider.getTxsForBlockProposal(block, blockNumber, { pinnedPeer: sender, deadline });
|
|
134
|
-
return
|
|
130
|
+
return true;
|
|
135
131
|
});
|
|
136
132
|
|
|
137
|
-
|
|
138
|
-
this.synchedBlockHashes = store.openMap('p2p_pool_block_hashes');
|
|
139
|
-
this.synchedLatestBlockNumber = store.openSingleton('p2p_pool_last_l2_block');
|
|
140
|
-
this.synchedProvenBlockNumber = store.openSingleton('p2p_pool_last_proven_l2_block');
|
|
141
|
-
this.synchedFinalizedBlockNumber = store.openSingleton('p2p_pool_last_finalized_l2_block');
|
|
133
|
+
this.l2Tips = new L2TipsKVStore(store, 'p2p_client');
|
|
142
134
|
this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
|
|
143
135
|
}
|
|
144
136
|
|
|
@@ -163,8 +155,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
163
155
|
return Promise.resolve(this.p2pService.getPeers(includePending));
|
|
164
156
|
}
|
|
165
157
|
|
|
166
|
-
public getL2BlockHash(number:
|
|
167
|
-
return this.
|
|
158
|
+
public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
|
|
159
|
+
return this.l2Tips.getL2BlockHash(number);
|
|
168
160
|
}
|
|
169
161
|
|
|
170
162
|
public updateP2PConfig(config: Partial<P2PConfig>): Promise<void> {
|
|
@@ -173,82 +165,45 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
173
165
|
return Promise.resolve();
|
|
174
166
|
}
|
|
175
167
|
|
|
176
|
-
public
|
|
177
|
-
|
|
178
|
-
let latestBlockHash: string | undefined;
|
|
179
|
-
|
|
180
|
-
const provenBlockNumber = await this.getSyncedProvenBlockNum();
|
|
181
|
-
let provenBlockHash: string | undefined;
|
|
182
|
-
|
|
183
|
-
const finalizedBlockNumber = await this.getSyncedFinalizedBlockNum();
|
|
184
|
-
let finalizedBlockHash: string | undefined;
|
|
185
|
-
|
|
186
|
-
if (latestBlockNumber > 0) {
|
|
187
|
-
latestBlockHash = await this.synchedBlockHashes.getAsync(latestBlockNumber);
|
|
188
|
-
if (typeof latestBlockHash === 'undefined') {
|
|
189
|
-
throw new Error(`Block hash for latest block ${latestBlockNumber} not found in p2p client`);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (provenBlockNumber > 0) {
|
|
194
|
-
provenBlockHash = await this.synchedBlockHashes.getAsync(provenBlockNumber);
|
|
195
|
-
if (typeof provenBlockHash === 'undefined') {
|
|
196
|
-
throw new Error(`Block hash for proven block ${provenBlockNumber} not found in p2p client`);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (finalizedBlockNumber > 0) {
|
|
201
|
-
finalizedBlockHash = await this.synchedBlockHashes.getAsync(finalizedBlockNumber);
|
|
202
|
-
if (typeof finalizedBlockHash === 'undefined') {
|
|
203
|
-
throw new Error(`Block hash for finalized block ${finalizedBlockNumber} not found in p2p client`);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
latest: { hash: latestBlockHash!, number: latestBlockNumber },
|
|
209
|
-
proven: { hash: provenBlockHash!, number: provenBlockNumber },
|
|
210
|
-
finalized: { hash: finalizedBlockHash!, number: finalizedBlockNumber },
|
|
211
|
-
};
|
|
168
|
+
public getL2Tips(): Promise<L2Tips> {
|
|
169
|
+
return this.l2Tips.getL2Tips();
|
|
212
170
|
}
|
|
213
171
|
|
|
214
172
|
public async handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
|
|
215
173
|
this.log.debug(`Handling block stream event ${event.type}`);
|
|
174
|
+
|
|
216
175
|
switch (event.type) {
|
|
217
176
|
case 'blocks-added':
|
|
218
177
|
await this.handleLatestL2Blocks(event.blocks);
|
|
219
178
|
break;
|
|
220
179
|
case 'chain-finalized': {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const from = (await this.getSyncedFinalizedBlockNum()) + 1;
|
|
180
|
+
const oldFinalizedBlockNum = await this.getSyncedFinalizedBlockNum();
|
|
181
|
+
const from = BlockNumber(oldFinalizedBlockNum + 1);
|
|
224
182
|
const limit = event.block.number - from + 1;
|
|
225
183
|
if (limit > 0) {
|
|
226
|
-
|
|
184
|
+
const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
|
|
185
|
+
await this.handleFinalizedL2Blocks(oldBlocks);
|
|
227
186
|
}
|
|
228
187
|
break;
|
|
229
188
|
}
|
|
230
|
-
case 'chain-proven':
|
|
231
|
-
await this.setBlockHash(event.block);
|
|
189
|
+
case 'chain-proven':
|
|
232
190
|
this.txCollection.stopCollectingForBlocksUpTo(event.block.number);
|
|
233
|
-
await this.synchedProvenBlockNumber.set(event.block.number);
|
|
234
191
|
break;
|
|
235
|
-
}
|
|
236
192
|
case 'chain-pruned':
|
|
237
|
-
await this.setBlockHash(event.block);
|
|
238
193
|
this.txCollection.stopCollectingForBlocksAfter(event.block.number);
|
|
239
194
|
await this.handlePruneL2Blocks(event.block.number);
|
|
240
195
|
break;
|
|
196
|
+
case 'chain-checkpointed':
|
|
197
|
+
break;
|
|
241
198
|
default: {
|
|
242
199
|
const _: never = event;
|
|
243
200
|
break;
|
|
244
201
|
}
|
|
245
202
|
}
|
|
246
|
-
}
|
|
247
203
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
204
|
+
// Pass the event through to our l2 tips store
|
|
205
|
+
await this.l2Tips.handleBlockStreamEvent(event);
|
|
206
|
+
await this.startServiceIfSynched();
|
|
252
207
|
}
|
|
253
208
|
|
|
254
209
|
#assertIsReady() {
|
|
@@ -272,20 +227,17 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
272
227
|
|
|
273
228
|
// get the current latest block numbers
|
|
274
229
|
const latestBlockNumbers = await this.l2BlockSource.getL2Tips();
|
|
275
|
-
this.latestBlockNumberAtStart = latestBlockNumbers.
|
|
276
|
-
this.provenBlockNumberAtStart = latestBlockNumbers.proven.number;
|
|
277
|
-
this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.number;
|
|
230
|
+
this.latestBlockNumberAtStart = latestBlockNumbers.proposed.number;
|
|
231
|
+
this.provenBlockNumberAtStart = latestBlockNumbers.proven.block.number;
|
|
232
|
+
this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.block.number;
|
|
278
233
|
|
|
279
234
|
const syncedLatestBlock = (await this.getSyncedLatestBlockNum()) + 1;
|
|
280
235
|
const syncedProvenBlock = (await this.getSyncedProvenBlockNum()) + 1;
|
|
281
236
|
const syncedFinalizedBlock = (await this.getSyncedFinalizedBlockNum()) + 1;
|
|
282
237
|
|
|
283
|
-
if (
|
|
284
|
-
(await this.txPool.isEmpty()) &&
|
|
285
|
-
(this.attestationPool === undefined || (await this.attestationPool?.isEmpty()))
|
|
286
|
-
) {
|
|
238
|
+
if ((await this.txPool.isEmpty()) && (await this.attestationPool.isEmpty())) {
|
|
287
239
|
// if mempools are empty, we don't care about syncing prior blocks
|
|
288
|
-
this.initBlockStream(this.latestBlockNumberAtStart);
|
|
240
|
+
this.initBlockStream(BlockNumber(this.latestBlockNumberAtStart));
|
|
289
241
|
this.setCurrentState(P2PClientState.RUNNING);
|
|
290
242
|
this.syncPromise = Promise.resolve();
|
|
291
243
|
await this.p2pService.start();
|
|
@@ -333,15 +285,13 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
333
285
|
return this.p2pService.addReqRespSubProtocol(subProtocol, handler, validator);
|
|
334
286
|
}
|
|
335
287
|
|
|
336
|
-
private initBlockStream(startingBlock?:
|
|
288
|
+
private initBlockStream(startingBlock?: BlockNumber) {
|
|
337
289
|
if (!this.blockStream) {
|
|
338
290
|
const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
|
|
339
|
-
this.blockStream = new
|
|
291
|
+
this.blockStream = new L2BlockStream(
|
|
340
292
|
this.l2BlockSource,
|
|
341
293
|
this,
|
|
342
294
|
this,
|
|
343
|
-
this.telemetry.getTracer('P2PL2BlockStream'),
|
|
344
|
-
'P2PL2BlockStream',
|
|
345
295
|
createLogger(`${this.log.module}:l2-block-stream`),
|
|
346
296
|
{ batchSize, pollIntervalMS, startingBlock },
|
|
347
297
|
);
|
|
@@ -381,25 +331,32 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
381
331
|
return this.p2pService.propagate(proposal);
|
|
382
332
|
}
|
|
383
333
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
334
|
+
@trackSpan('p2pClient.broadcastCheckpointProposal', async proposal => ({
|
|
335
|
+
[Attributes.SLOT_NUMBER]: proposal.slotNumber,
|
|
336
|
+
[Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
|
|
337
|
+
[Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
|
|
338
|
+
}))
|
|
339
|
+
public broadcastCheckpointProposal(proposal: CheckpointProposal): Promise<void> {
|
|
340
|
+
this.log.verbose(`Broadcasting checkpoint proposal for slot ${proposal.slotNumber} to peers`);
|
|
341
|
+
return this.p2pService.propagate(proposal);
|
|
387
342
|
}
|
|
388
343
|
|
|
389
|
-
public async
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
? this.attestationPool?.getAttestationsForSlotAndProposal(slot, proposalId)
|
|
393
|
-
: this.attestationPool?.getAttestationsForSlot(slot))) ?? []
|
|
394
|
-
);
|
|
344
|
+
public async broadcastCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
|
|
345
|
+
this.log.verbose(`Broadcasting ${attestations.length} checkpoint attestations to peers`);
|
|
346
|
+
await Promise.all(attestations.map(att => this.p2pService.propagate(att)));
|
|
395
347
|
}
|
|
396
348
|
|
|
397
|
-
public
|
|
398
|
-
|
|
349
|
+
public async getCheckpointAttestationsForSlot(
|
|
350
|
+
slot: SlotNumber,
|
|
351
|
+
proposalId?: string,
|
|
352
|
+
): Promise<CheckpointAttestation[]> {
|
|
353
|
+
return await (proposalId
|
|
354
|
+
? this.attestationPool.getCheckpointAttestationsForSlotAndProposal(slot, proposalId)
|
|
355
|
+
: this.attestationPool.getCheckpointAttestationsForSlot(slot));
|
|
399
356
|
}
|
|
400
357
|
|
|
401
|
-
public
|
|
402
|
-
return this.attestationPool
|
|
358
|
+
public addCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
|
|
359
|
+
return this.attestationPool.addCheckpointAttestations(attestations);
|
|
403
360
|
}
|
|
404
361
|
|
|
405
362
|
// REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
@@ -408,6 +365,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
408
365
|
this.p2pService.registerBlockReceivedCallback(handler);
|
|
409
366
|
}
|
|
410
367
|
|
|
368
|
+
public registerCheckpointProposalHandler(handler: P2PCheckpointReceivedCallback): void {
|
|
369
|
+
this.p2pService.registerCheckpointReceivedCallback(handler);
|
|
370
|
+
}
|
|
371
|
+
|
|
411
372
|
/**
|
|
412
373
|
* Uses the batched Request Response protocol to request a set of transactions from the network.
|
|
413
374
|
*/
|
|
@@ -649,20 +610,23 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
649
610
|
* Public function to check the latest block number that the P2P client is synced to.
|
|
650
611
|
* @returns Block number of latest L2 Block we've synced with.
|
|
651
612
|
*/
|
|
652
|
-
public async getSyncedLatestBlockNum(): Promise<
|
|
653
|
-
|
|
613
|
+
public async getSyncedLatestBlockNum(): Promise<BlockNumber> {
|
|
614
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
615
|
+
return tips.proposed.number;
|
|
654
616
|
}
|
|
655
617
|
|
|
656
618
|
/**
|
|
657
619
|
* Public function to check the latest proven block number that the P2P client is synced to.
|
|
658
620
|
* @returns Block number of latest proven L2 Block we've synced with.
|
|
659
621
|
*/
|
|
660
|
-
public async getSyncedProvenBlockNum(): Promise<
|
|
661
|
-
|
|
622
|
+
public async getSyncedProvenBlockNum(): Promise<BlockNumber> {
|
|
623
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
624
|
+
return tips.proven.block.number;
|
|
662
625
|
}
|
|
663
626
|
|
|
664
|
-
public async getSyncedFinalizedBlockNum(): Promise<
|
|
665
|
-
|
|
627
|
+
public async getSyncedFinalizedBlockNum(): Promise<BlockNumber> {
|
|
628
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
629
|
+
return tips.finalized.block.number;
|
|
666
630
|
}
|
|
667
631
|
|
|
668
632
|
/** Returns latest L2 slot for which we have seen an L2 block. */
|
|
@@ -678,7 +642,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
678
642
|
const blockNumber = await this.getSyncedLatestBlockNum();
|
|
679
643
|
const blockHash =
|
|
680
644
|
blockNumber === 0
|
|
681
|
-
?
|
|
645
|
+
? GENESIS_BLOCK_HEADER_HASH.toString()
|
|
682
646
|
: await this.l2BlockSource
|
|
683
647
|
.getBlockHeader(blockNumber)
|
|
684
648
|
.then(header => header?.hash())
|
|
@@ -686,8 +650,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
686
650
|
|
|
687
651
|
return {
|
|
688
652
|
state: this.currentState,
|
|
689
|
-
syncedToL2Block: { number: blockNumber, hash: blockHash },
|
|
690
|
-
}
|
|
653
|
+
syncedToL2Block: { number: blockNumber, hash: blockHash! },
|
|
654
|
+
};
|
|
691
655
|
}
|
|
692
656
|
|
|
693
657
|
/**
|
|
@@ -698,7 +662,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
698
662
|
private async markTxsAsMinedFromBlocks(blocks: L2Block[]): Promise<void> {
|
|
699
663
|
for (const block of blocks) {
|
|
700
664
|
const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
|
|
701
|
-
await this.txPool.markAsMined(txHashes, block.
|
|
665
|
+
await this.txPool.markAsMined(txHashes, block.header);
|
|
702
666
|
}
|
|
703
667
|
}
|
|
704
668
|
|
|
@@ -707,29 +671,18 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
707
671
|
* @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
|
|
708
672
|
* @returns Empty promise.
|
|
709
673
|
*/
|
|
710
|
-
private async handleLatestL2Blocks(blocks:
|
|
674
|
+
private async handleLatestL2Blocks(blocks: L2Block[]): Promise<void> {
|
|
711
675
|
if (!blocks.length) {
|
|
712
676
|
return Promise.resolve();
|
|
713
677
|
}
|
|
714
678
|
|
|
715
|
-
await this.markTxsAsMinedFromBlocks(blocks
|
|
716
|
-
await this.
|
|
717
|
-
|
|
718
|
-
const lastBlock = blocks.at(-1)!.block;
|
|
679
|
+
await this.markTxsAsMinedFromBlocks(blocks);
|
|
680
|
+
await this.txPool.clearNonEvictableTxs();
|
|
681
|
+
await this.startCollectingMissingTxs(blocks);
|
|
719
682
|
|
|
720
|
-
|
|
721
|
-
blocks.map(async block =>
|
|
722
|
-
this.setBlockHash({
|
|
723
|
-
number: block.block.number,
|
|
724
|
-
hash: await block.block.hash().then(h => h.toString()),
|
|
725
|
-
}),
|
|
726
|
-
),
|
|
727
|
-
);
|
|
728
|
-
|
|
729
|
-
await this.synchedLatestBlockNumber.set(lastBlock.number);
|
|
683
|
+
const lastBlock = blocks.at(-1)!;
|
|
730
684
|
await this.synchedLatestSlot.set(BigInt(lastBlock.header.getSlot()));
|
|
731
685
|
this.log.verbose(`Synched to latest block ${lastBlock.number}`);
|
|
732
|
-
await this.startServiceIfSynched();
|
|
733
686
|
}
|
|
734
687
|
|
|
735
688
|
/** Request txs for unproven blocks so the prover node has more chances to get them. */
|
|
@@ -780,19 +733,16 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
780
733
|
await this.txPool.deleteTxs(txHashes, { permanently: true });
|
|
781
734
|
await this.txPool.cleanupDeletedMinedTxs(lastBlockNum);
|
|
782
735
|
|
|
783
|
-
await this.attestationPool
|
|
736
|
+
await this.attestationPool.deleteCheckpointAttestationsOlderThan(lastBlockSlot);
|
|
784
737
|
|
|
785
|
-
await this.synchedFinalizedBlockNumber.set(lastBlockNum);
|
|
786
738
|
this.log.debug(`Synched to finalized block ${lastBlockNum} at slot ${lastBlockSlot}`);
|
|
787
|
-
|
|
788
|
-
await this.startServiceIfSynched();
|
|
789
739
|
}
|
|
790
740
|
|
|
791
741
|
/**
|
|
792
742
|
* Updates the tx pool after a chain prune.
|
|
793
743
|
* @param latestBlock - The block number the chain was pruned to.
|
|
794
744
|
*/
|
|
795
|
-
private async handlePruneL2Blocks(latestBlock:
|
|
745
|
+
private async handlePruneL2Blocks(latestBlock: BlockNumber): Promise<void> {
|
|
796
746
|
const txsToDelete = new Map<string, TxHash>();
|
|
797
747
|
const minedTxs = await this.txPool.getMinedTxHashes();
|
|
798
748
|
|
|
@@ -831,21 +781,18 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
831
781
|
this.log.info(`Deleting ${minedTxsFromReorg.length} mined txs from reorg`);
|
|
832
782
|
await this.txPool.deleteTxs(minedTxsFromReorg);
|
|
833
783
|
} else {
|
|
834
|
-
this.
|
|
835
|
-
await this.txPool.markMinedAsPending(minedTxsFromReorg);
|
|
784
|
+
await this.txPool.markMinedAsPending(minedTxsFromReorg, latestBlock);
|
|
836
785
|
}
|
|
837
|
-
|
|
838
|
-
await this.synchedLatestBlockNumber.set(latestBlock);
|
|
839
|
-
// no need to update block hashes, as they will be updated as new blocks are added
|
|
840
786
|
}
|
|
841
787
|
|
|
842
788
|
private async startServiceIfSynched() {
|
|
843
789
|
if (this.currentState !== P2PClientState.SYNCHING) {
|
|
844
790
|
return;
|
|
845
791
|
}
|
|
846
|
-
const
|
|
847
|
-
const
|
|
848
|
-
const
|
|
792
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
793
|
+
const syncedFinalizedBlock = tips.finalized.block.number;
|
|
794
|
+
const syncedProvenBlock = tips.proven.block.number;
|
|
795
|
+
const syncedLatestBlock = tips.proposed.number;
|
|
849
796
|
|
|
850
797
|
if (
|
|
851
798
|
syncedLatestBlock >= this.latestBlockNumberAtStart &&
|
package/src/config.ts
CHANGED
|
@@ -2,16 +2,16 @@ import {
|
|
|
2
2
|
type ConfigMappingsType,
|
|
3
3
|
SecretValue,
|
|
4
4
|
booleanConfigHelper,
|
|
5
|
-
floatConfigHelper,
|
|
6
5
|
getConfigFromMappings,
|
|
7
6
|
getDefaultConfig,
|
|
8
7
|
numberConfigHelper,
|
|
8
|
+
percentageConfigHelper,
|
|
9
9
|
pickConfigMappings,
|
|
10
10
|
secretStringConfigHelper,
|
|
11
11
|
} from '@aztec/foundation/config';
|
|
12
|
-
import { Fr } from '@aztec/foundation/
|
|
12
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
13
|
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
|
|
14
|
-
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
14
|
+
import { FunctionSelector } from '@aztec/stdlib/abi/function-selector';
|
|
15
15
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
16
16
|
import { type AllowedElement, type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';
|
|
17
17
|
|
|
@@ -133,11 +133,8 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig, TxCollectionCo
|
|
|
133
133
|
/** Which calls are allowed in the public setup phase of a tx. */
|
|
134
134
|
txPublicSetupAllowList: AllowedElement[];
|
|
135
135
|
|
|
136
|
-
/** The maximum
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/** If the pool is full, it will still accept a few more txs until it reached maxTxPoolOverspillFactor * maxTxPoolSize. Then it will evict */
|
|
140
|
-
txPoolOverflowFactor: number;
|
|
136
|
+
/** The maximum number of pending txs before evicting lower priority txs. */
|
|
137
|
+
maxPendingTxCount: number;
|
|
141
138
|
|
|
142
139
|
/** The node's seen message ID cache size */
|
|
143
140
|
seenMessageCacheSize: number;
|
|
@@ -375,15 +372,12 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
|
375
372
|
printDefault: () =>
|
|
376
373
|
'AuthRegistry, FeeJuice.increase_public_balance, Token.increase_public_balance, FPC.prepare_fee',
|
|
377
374
|
},
|
|
378
|
-
|
|
379
|
-
env: '
|
|
380
|
-
description: 'The maximum
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
env: 'P2P_TX_POOL_OVERFLOW_FACTOR',
|
|
385
|
-
description: 'How much the tx pool can overflow before it starts evicting txs. Must be greater than 1',
|
|
386
|
-
...floatConfigHelper(1.1), // 10% overflow
|
|
375
|
+
maxPendingTxCount: {
|
|
376
|
+
env: 'P2P_MAX_PENDING_TX_COUNT',
|
|
377
|
+
description: 'The maximum number of pending txs before evicting lower priority txs.',
|
|
378
|
+
// Worst case scenario: Uncompressed public/private tx is ~ 156kb
|
|
379
|
+
// This implies we are using ~156MB of memory for pending pool
|
|
380
|
+
...numberConfigHelper(1_000),
|
|
387
381
|
},
|
|
388
382
|
seenMessageCacheSize: {
|
|
389
383
|
env: 'P2P_SEEN_MSG_CACHE_SIZE',
|
|
@@ -413,7 +407,7 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
|
413
407
|
dropTransactionsProbability: {
|
|
414
408
|
env: 'P2P_DROP_TX_CHANCE',
|
|
415
409
|
description: 'The probability that a transaction is discarded (0 - 1). - For testing purposes only',
|
|
416
|
-
...
|
|
410
|
+
...percentageConfigHelper(0),
|
|
417
411
|
},
|
|
418
412
|
disableTransactions: {
|
|
419
413
|
env: 'TRANSACTIONS_DISABLED',
|