@aztec/p2p 0.0.1-commit.c7c42ec → 0.0.1-commit.f295ac2
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/interface.d.ts +18 -5
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +10 -13
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +449 -118
- package/dest/config.js +2 -2
- 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 +237 -263
- 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 +113 -108
- 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 +9 -6
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +16 -12
- 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 +4 -13
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +13 -8
- 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 +91 -50
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +17 -4
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +59 -3
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +77 -4
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +47 -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 +115 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- 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/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 +12 -10
- 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 +7 -10
- 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/{block_proposal_validator/block_proposal_validator.js → proposal_validator/proposal_validator.js} +19 -21
- 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 +183 -0
- 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/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/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +1 -1
- 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 +4 -2
- 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 +27 -10
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +696 -137
- package/dest/services/peer-manager/metrics.d.ts +1 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -26
- 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 +0 -10
- 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 +3 -3
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +2 -2
- package/dest/services/reqresp/metrics.d.ts +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/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/status.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -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/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_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +6 -19
- package/dest/testbench/p2p_client_testbench_worker.js +27 -12
- 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 +16 -16
- package/src/client/interface.ts +19 -4
- package/src/client/p2p_client.ts +78 -128
- package/src/config.ts +2 -2
- package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
- package/src/mem_pools/attestation_pool/mocks.ts +19 -13
- package/src/mem_pools/instrumentation.ts +9 -18
- package/src/mem_pools/tx_pool/README.md +28 -13
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +128 -73
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +64 -4
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +117 -3
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +159 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +16 -13
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +9 -12
- 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/{block_proposal_validator/block_proposal_validator.ts → proposal_validator/proposal_validator.ts} +23 -28
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +206 -0
- package/src/msg_validators/tx_validator/data_validator.ts +12 -4
- 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/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/timestamp_validator.ts +3 -1
- package/src/services/dummy_service.ts +6 -0
- package/src/services/encoding.ts +3 -1
- package/src/services/libp2p/instrumentation.ts +19 -73
- package/src/services/libp2p/libp2p_service.ts +326 -102
- package/src/services/peer-manager/metrics.ts +5 -26
- package/src/services/peer-manager/peer_manager.ts +1 -2
- 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 +2 -2
- package/src/services/reqresp/metrics.ts +7 -23
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +9 -0
- package/src/services/reqresp/protocols/status.ts +7 -4
- package/src/services/service.ts +19 -4
- package/src/services/tx_collection/instrumentation.ts +4 -21
- package/src/services/tx_provider_instrumentation.ts +11 -24
- package/src/testbench/p2p_client_testbench_worker.ts +35 -12
- package/src/testbench/worker_client_manager.ts +6 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
- 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/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/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Used when running testbench commands
|
|
5
5
|
*/ import { MockL2BlockSource } from '@aztec/archiver/test';
|
|
6
6
|
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
7
|
+
import { SecretValue } from '@aztec/foundation/config';
|
|
7
8
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
9
|
import { createLogger } from '@aztec/foundation/log';
|
|
9
10
|
import { sleep } from '@aztec/foundation/sleep';
|
|
@@ -46,19 +47,23 @@ function mockTxPool() {
|
|
|
46
47
|
function mockAttestationPool() {
|
|
47
48
|
return {
|
|
48
49
|
isEmpty: ()=>Promise.resolve(false),
|
|
49
|
-
addAttestations: ()=>Promise.resolve(),
|
|
50
|
-
deleteAttestations: ()=>Promise.resolve(),
|
|
51
|
-
deleteAttestationsOlderThan: ()=>Promise.resolve(),
|
|
52
|
-
deleteAttestationsForSlot: ()=>Promise.resolve(),
|
|
53
|
-
deleteAttestationsForSlotAndProposal: ()=>Promise.resolve(),
|
|
54
|
-
getAttestationsForSlot: ()=>Promise.resolve([]),
|
|
55
|
-
getAttestationsForSlotAndProposal: ()=>Promise.resolve([]),
|
|
56
50
|
addBlockProposal: ()=>Promise.resolve(),
|
|
57
51
|
getBlockProposal: ()=>Promise.resolve(undefined),
|
|
58
52
|
hasBlockProposal: ()=>Promise.resolve(false),
|
|
59
|
-
hasAttestation: ()=>Promise.resolve(false),
|
|
60
53
|
canAddProposal: ()=>Promise.resolve(true),
|
|
61
|
-
|
|
54
|
+
// Checkpoint attestation methods
|
|
55
|
+
addCheckpointProposal: ()=>Promise.resolve(),
|
|
56
|
+
getCheckpointProposal: ()=>Promise.resolve(undefined),
|
|
57
|
+
hasCheckpointProposal: ()=>Promise.resolve(false),
|
|
58
|
+
addCheckpointAttestations: ()=>Promise.resolve(),
|
|
59
|
+
getCheckpointAttestationsForSlot: ()=>Promise.resolve([]),
|
|
60
|
+
getCheckpointAttestationsForSlotAndProposal: ()=>Promise.resolve([]),
|
|
61
|
+
deleteCheckpointAttestationsOlderThan: ()=>Promise.resolve(),
|
|
62
|
+
hasReachedCheckpointProposalCap: ()=>Promise.resolve(false),
|
|
63
|
+
hasReachedCheckpointAttestationCap: ()=>Promise.resolve(false),
|
|
64
|
+
canAddCheckpointProposal: ()=>Promise.resolve(true),
|
|
65
|
+
canAddCheckpointAttestation: ()=>Promise.resolve(true),
|
|
66
|
+
hasCheckpointAttestation: ()=>Promise.resolve(false)
|
|
62
67
|
};
|
|
63
68
|
}
|
|
64
69
|
function mockEpochCache() {
|
|
@@ -66,7 +71,8 @@ function mockEpochCache() {
|
|
|
66
71
|
getCommittee: ()=>Promise.resolve({
|
|
67
72
|
committee: [],
|
|
68
73
|
seed: 1n,
|
|
69
|
-
epoch: EpochNumber.ZERO
|
|
74
|
+
epoch: EpochNumber.ZERO,
|
|
75
|
+
isEscapeHatchOpen: false
|
|
70
76
|
}),
|
|
71
77
|
getProposerIndexEncoding: ()=>'0x',
|
|
72
78
|
getEpochAndSlotNow: ()=>({
|
|
@@ -81,6 +87,7 @@ function mockEpochCache() {
|
|
|
81
87
|
currentSlot: SlotNumber.ZERO,
|
|
82
88
|
nextSlot: SlotNumber.ZERO
|
|
83
89
|
}),
|
|
90
|
+
getProposerAttesterAddressInSlot: ()=>Promise.resolve(undefined),
|
|
84
91
|
getEpochAndSlotInNextL1Slot: ()=>({
|
|
85
92
|
epoch: EpochNumber.ZERO,
|
|
86
93
|
slot: SlotNumber.ZERO,
|
|
@@ -144,9 +151,16 @@ class TestLibP2PService extends LibP2PService {
|
|
|
144
151
|
}
|
|
145
152
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
146
153
|
process.on('message', async (msg)=>{
|
|
147
|
-
|
|
154
|
+
// Note: peerIdPrivateKey comes as a raw string (not SecretValue) because
|
|
155
|
+
// SecretValue's private fields can't be serialized via IPC
|
|
156
|
+
const { type, config: rawConfig, clientIndex } = msg;
|
|
148
157
|
try {
|
|
149
158
|
if (type === 'START') {
|
|
159
|
+
// Re-wrap the peerIdPrivateKey with SecretValue
|
|
160
|
+
const config = {
|
|
161
|
+
...rawConfig,
|
|
162
|
+
peerIdPrivateKey: rawConfig.peerIdPrivateKey ? new SecretValue(rawConfig.peerIdPrivateKey) : undefined
|
|
163
|
+
};
|
|
150
164
|
const txPool = mockTxPool();
|
|
151
165
|
const attestationPool = mockAttestationPool();
|
|
152
166
|
const epochCache = mockEpochCache();
|
|
@@ -164,7 +178,8 @@ process.on('message', async (msg)=>{
|
|
|
164
178
|
};
|
|
165
179
|
const client = await createP2PClient(P2PClientType.Full, config, l2BlockSource, proofVerifier, worldState, epochCache, 'test-p2p-bench-worker', undefined, telemetry, deps);
|
|
166
180
|
// Create test service with validation disabled
|
|
167
|
-
|
|
181
|
+
// Note: Parameter order must match LibP2PService constructor
|
|
182
|
+
const testService = new TestLibP2PService(P2PClientType.Full, config, client.p2pService.node, client.p2pService.peerDiscoveryService, client.p2pService.reqresp, client.p2pService.peerManager, client.p2pService.mempools, client.p2pService.archiver, epochCache, proofVerifier, worldState, telemetry, logger, true);
|
|
168
183
|
// Replace the existing p2pService with our test version
|
|
169
184
|
client.p2pService = testService;
|
|
170
185
|
await client.start();
|
|
@@ -48,4 +48,4 @@ declare class WorkerClientManager {
|
|
|
48
48
|
cleanup(): Promise<void>;
|
|
49
49
|
}
|
|
50
50
|
export { WorkerClientManager, testChainConfig };
|
|
51
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
51
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ya2VyX2NsaWVudF9tYW5hZ2VyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGVzdGJlbmNoL3dvcmtlcl9jbGllbnRfbWFuYWdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUVwRCxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUV4RCxPQUFPLEVBQUUsS0FBSyxZQUFZLEVBQVEsTUFBTSxlQUFlLENBQUM7QUFJeEQsT0FBTyxFQUFFLEtBQUssU0FBUyxFQUF1QixNQUFNLGNBQWMsQ0FBQztBQVFuRSxRQUFBLE1BQU0sZUFBZSxFQUFFLFdBTXRCLENBQUM7QUFFRixjQUFNLG1CQUFtQjtJQUNoQixTQUFTLEVBQUUsWUFBWSxFQUFFLENBQU07SUFDL0IsaUJBQWlCLEVBQUUsTUFBTSxFQUFFLENBQU07SUFDakMsUUFBUSxFQUFFLE1BQU0sRUFBRSxDQUFNO0lBQ3hCLEtBQUssRUFBRSxNQUFNLEVBQUUsQ0FBTTtJQUM1QixPQUFPLENBQUMsU0FBUyxDQUFxQjtJQUN0QyxPQUFPLENBQUMsTUFBTSxDQUFTO0lBQ3ZCLE9BQU8sQ0FBQyx1QkFBdUIsQ0FBZ0I7SUFFL0MsWUFBWSxNQUFNLEVBQUUsTUFBTSxFQUFFLFNBQVMsRUFBRSxPQUFPLENBQUMsU0FBUyxDQUFDLEVBR3hEO0lBRUQsT0FBTyxTQUtOO0lBRUQ7O09BRUc7SUFDSCxPQUFPLENBQUMsa0JBQWtCO0lBaUIxQjs7T0FFRztJQUNILE9BQU8sQ0FBQyxrQkFBa0I7SUF5RDFCOzs7Ozs7T0FNRztJQUNHLGlCQUFpQixDQUFDLGVBQWUsRUFBRSxNQUFNLHFCQXlDOUM7SUFFRCw0QkFBNEIsU0FFM0I7SUFFRCxrQ0FBa0MsV0FFakM7SUFFRDs7Ozs7T0FLRztJQUNHLFVBQVUsQ0FBQyxXQUFXLEVBQUUsTUFBTSxFQUFFLE9BQU8sRUFBRSxNQUFNLGlCQTRDcEQ7SUFFRDs7T0FFRztJQUNILE9BQU8sQ0FBQyxnQkFBZ0I7SUFzQ3hCOztPQUVHO0lBQ0csT0FBTyxrQkFnQ1o7Q0FDRjtBQUVELE9BQU8sRUFBRSxtQkFBbUIsRUFBRSxlQUFlLEVBQUUsQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker_client_manager.d.ts","sourceRoot":"","sources":["../../src/testbench/worker_client_manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,KAAK,YAAY,EAAQ,MAAM,eAAe,CAAC;AAIxD,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,cAAc,CAAC;AAQnE,QAAA,MAAM,eAAe,EAAE,WAMtB,CAAC;AAEF,cAAM,mBAAmB;IAChB,SAAS,EAAE,YAAY,EAAE,CAAM;IAC/B,iBAAiB,EAAE,MAAM,EAAE,CAAM;IACjC,QAAQ,EAAE,MAAM,EAAE,CAAM;IACxB,KAAK,EAAE,MAAM,EAAE,CAAM;IAC5B,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,uBAAuB,CAAgB;IAE/C,YAAY,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,EAGxD;IAED,OAAO,SAKN;IAED;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAiB1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;
|
|
1
|
+
{"version":3,"file":"worker_client_manager.d.ts","sourceRoot":"","sources":["../../src/testbench/worker_client_manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,KAAK,YAAY,EAAQ,MAAM,eAAe,CAAC;AAIxD,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,cAAc,CAAC;AAQnE,QAAA,MAAM,eAAe,EAAE,WAMtB,CAAC;AAEF,cAAM,mBAAmB;IAChB,SAAS,EAAE,YAAY,EAAE,CAAM;IAC/B,iBAAiB,EAAE,MAAM,EAAE,CAAM;IACjC,QAAQ,EAAE,MAAM,EAAE,CAAM;IACxB,KAAK,EAAE,MAAM,EAAE,CAAM;IAC5B,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,uBAAuB,CAAgB;IAE/C,YAAY,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,EAGxD;IAED,OAAO,SAKN;IAED;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAiB1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAyD1B;;;;;;OAMG;IACG,iBAAiB,CAAC,eAAe,EAAE,MAAM,qBAyC9C;IAED,4BAA4B,SAE3B;IAED,kCAAkC,WAEjC;IAED;;;;;OAKG;IACG,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBA4CpD;IAED;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAsCxB;;OAEG;IACG,OAAO,kBAgCZ;CACF;AAED,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -55,9 +55,14 @@ class WorkerClientManager {
|
|
|
55
55
|
* Spawns a worker process and returns a promise that resolves when the worker is ready
|
|
56
56
|
*/ spawnWorkerProcess(config, clientIndex) {
|
|
57
57
|
const childProcess = fork(workerPath);
|
|
58
|
+
// Extract the raw peerIdPrivateKey value since SecretValue can't be serialized via IPC
|
|
59
|
+
const serializedConfig = {
|
|
60
|
+
...config,
|
|
61
|
+
peerIdPrivateKey: config.peerIdPrivateKey?.getValue()
|
|
62
|
+
};
|
|
58
63
|
childProcess.send({
|
|
59
64
|
type: 'START',
|
|
60
|
-
config,
|
|
65
|
+
config: serializedConfig,
|
|
61
66
|
clientIndex
|
|
62
67
|
});
|
|
63
68
|
// Handle unexpected child process exit
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/p2p",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.f295ac2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
25
25
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
|
|
26
26
|
"start": "node ./dest",
|
|
27
|
-
"start:dev": "concurrently -k \"
|
|
27
|
+
"start:dev": "concurrently -k \"../scripts/tsc.sh --watch\" \"nodemon --watch dest --exec yarn start\""
|
|
28
28
|
},
|
|
29
29
|
"inherits": [
|
|
30
30
|
"../package.common.json"
|
|
@@ -67,17 +67,17 @@
|
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@aztec/constants": "0.0.1-commit.
|
|
71
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
72
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
73
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
74
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
75
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
76
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
77
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
78
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
79
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
80
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
70
|
+
"@aztec/constants": "0.0.1-commit.f295ac2",
|
|
71
|
+
"@aztec/epoch-cache": "0.0.1-commit.f295ac2",
|
|
72
|
+
"@aztec/ethereum": "0.0.1-commit.f295ac2",
|
|
73
|
+
"@aztec/foundation": "0.0.1-commit.f295ac2",
|
|
74
|
+
"@aztec/kv-store": "0.0.1-commit.f295ac2",
|
|
75
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.f295ac2",
|
|
76
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.f295ac2",
|
|
77
|
+
"@aztec/protocol-contracts": "0.0.1-commit.f295ac2",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.f295ac2",
|
|
79
|
+
"@aztec/stdlib": "0.0.1-commit.f295ac2",
|
|
80
|
+
"@aztec/telemetry-client": "0.0.1-commit.f295ac2",
|
|
81
81
|
"@chainsafe/libp2p-gossipsub": "13.0.0",
|
|
82
82
|
"@chainsafe/libp2p-noise": "^15.0.0",
|
|
83
83
|
"@chainsafe/libp2p-yamux": "^6.0.2",
|
|
@@ -104,12 +104,12 @@
|
|
|
104
104
|
"xxhash-wasm": "^1.1.0"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
108
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
107
|
+
"@aztec/archiver": "0.0.1-commit.f295ac2",
|
|
108
|
+
"@aztec/world-state": "0.0.1-commit.f295ac2",
|
|
109
109
|
"@jest/globals": "^30.0.0",
|
|
110
110
|
"@types/jest": "^30.0.0",
|
|
111
111
|
"@types/node": "^22.15.17",
|
|
112
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
112
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
113
113
|
"get-port": "^7.1.0",
|
|
114
114
|
"it-drain": "^3.0.5",
|
|
115
115
|
"it-length": "^3.0.6",
|
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,30 +1,29 @@
|
|
|
1
|
-
import { GENESIS_BLOCK_HEADER_HASH
|
|
1
|
+
import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
|
|
2
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
|
-
L2BlockNew,
|
|
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 L2BlockNew,
|
|
10
|
+
type L2BlockSource,
|
|
11
11
|
L2BlockStream,
|
|
12
|
-
L2BlockStreamEvent,
|
|
13
|
-
L2Tips,
|
|
12
|
+
type L2BlockStreamEvent,
|
|
13
|
+
type L2Tips,
|
|
14
|
+
type L2TipsStore,
|
|
14
15
|
} from '@aztec/stdlib/block';
|
|
15
16
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
16
17
|
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
17
18
|
import { type PeerInfo, tryStop } from '@aztec/stdlib/interfaces/server';
|
|
18
|
-
import { BlockAttestation, type BlockProposal, type P2PClientType } from '@aztec/stdlib/p2p';
|
|
19
|
-
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
20
19
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} 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';
|
|
28
27
|
|
|
29
28
|
import type { PeerId } from '@libp2p/interface';
|
|
30
29
|
import type { ENR } from '@nethermindeth/enr';
|
|
@@ -40,7 +39,7 @@ import {
|
|
|
40
39
|
type ReqRespSubProtocolValidators,
|
|
41
40
|
} from '../services/reqresp/interface.js';
|
|
42
41
|
import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
|
|
43
|
-
import type { P2PBlockReceivedCallback, P2PService } from '../services/service.js';
|
|
42
|
+
import type { P2PBlockReceivedCallback, P2PCheckpointReceivedCallback, P2PService } from '../services/service.js';
|
|
44
43
|
import { TxCollection } from '../services/tx_collection/tx_collection.js';
|
|
45
44
|
import { TxProvider } from '../services/tx_provider.js';
|
|
46
45
|
import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
|
|
@@ -62,10 +61,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
62
61
|
private provenBlockNumberAtStart = -1;
|
|
63
62
|
private finalizedBlockNumberAtStart = -1;
|
|
64
63
|
|
|
65
|
-
private
|
|
66
|
-
private synchedLatestBlockNumber: AztecAsyncSingleton<BlockNumber>;
|
|
67
|
-
private synchedProvenBlockNumber: AztecAsyncSingleton<BlockNumber>;
|
|
68
|
-
private synchedFinalizedBlockNumber: AztecAsyncSingleton<BlockNumber>;
|
|
64
|
+
private l2Tips: L2TipsStore;
|
|
69
65
|
private synchedLatestSlot: AztecAsyncSingleton<bigint>;
|
|
70
66
|
|
|
71
67
|
private txPool: TxPool;
|
|
@@ -114,7 +110,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
114
110
|
);
|
|
115
111
|
|
|
116
112
|
// Default to collecting all txs when we see a valid proposal
|
|
117
|
-
// 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.
|
|
118
115
|
// TODO(palla/txs): We should not trigger a request for txs on a proposal before fully validating it. We need to bring
|
|
119
116
|
// validator-client code into here so we can validate a proposal is reasonable.
|
|
120
117
|
this.registerBlockProposalHandler(async (block, sender) => {
|
|
@@ -123,21 +120,17 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
123
120
|
const constants = this.txCollection.getConstants();
|
|
124
121
|
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
|
|
125
122
|
const deadline = new Date(nextSlotTimestampSeconds * 1000);
|
|
126
|
-
const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.
|
|
123
|
+
const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.blockHeader.lastArchive.root);
|
|
127
124
|
if (!parentBlock) {
|
|
128
125
|
this.log.debug(`Cannot collect txs for proposal as parent block not found`);
|
|
129
|
-
return;
|
|
126
|
+
return false;
|
|
130
127
|
}
|
|
131
128
|
const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
|
|
132
129
|
await this.txProvider.getTxsForBlockProposal(block, blockNumber, { pinnedPeer: sender, deadline });
|
|
133
|
-
return
|
|
130
|
+
return true;
|
|
134
131
|
});
|
|
135
132
|
|
|
136
|
-
|
|
137
|
-
this.synchedBlockHashes = store.openMap('p2p_pool_block_hashes');
|
|
138
|
-
this.synchedLatestBlockNumber = store.openSingleton('p2p_pool_last_l2_block');
|
|
139
|
-
this.synchedProvenBlockNumber = store.openSingleton('p2p_pool_last_proven_l2_block');
|
|
140
|
-
this.synchedFinalizedBlockNumber = store.openSingleton('p2p_pool_last_finalized_l2_block');
|
|
133
|
+
this.l2Tips = new L2TipsKVStore(store, 'p2p_client');
|
|
141
134
|
this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
|
|
142
135
|
}
|
|
143
136
|
|
|
@@ -163,7 +156,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
163
156
|
}
|
|
164
157
|
|
|
165
158
|
public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
|
|
166
|
-
return this.
|
|
159
|
+
return this.l2Tips.getL2BlockHash(number);
|
|
167
160
|
}
|
|
168
161
|
|
|
169
162
|
public updateP2PConfig(config: Partial<P2PConfig>): Promise<void> {
|
|
@@ -172,85 +165,45 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
172
165
|
return Promise.resolve();
|
|
173
166
|
}
|
|
174
167
|
|
|
175
|
-
public
|
|
176
|
-
|
|
177
|
-
let latestBlockHash: string | undefined;
|
|
178
|
-
|
|
179
|
-
const provenBlockNumber = await this.getSyncedProvenBlockNum();
|
|
180
|
-
let provenBlockHash: string | undefined;
|
|
181
|
-
|
|
182
|
-
const finalizedBlockNumber = await this.getSyncedFinalizedBlockNum();
|
|
183
|
-
let finalizedBlockHash: string | undefined;
|
|
184
|
-
|
|
185
|
-
if (latestBlockNumber > 0) {
|
|
186
|
-
latestBlockHash = await this.synchedBlockHashes.getAsync(latestBlockNumber);
|
|
187
|
-
if (typeof latestBlockHash === 'undefined') {
|
|
188
|
-
throw new Error(`Block hash for latest block ${latestBlockNumber} not found in p2p client`);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (provenBlockNumber > 0) {
|
|
193
|
-
provenBlockHash = await this.synchedBlockHashes.getAsync(provenBlockNumber);
|
|
194
|
-
if (typeof provenBlockHash === 'undefined') {
|
|
195
|
-
throw new Error(`Block hash for proven block ${provenBlockNumber} not found in p2p client`);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (finalizedBlockNumber > 0) {
|
|
200
|
-
finalizedBlockHash = await this.synchedBlockHashes.getAsync(finalizedBlockNumber);
|
|
201
|
-
if (typeof finalizedBlockHash === 'undefined') {
|
|
202
|
-
throw new Error(`Block hash for finalized block ${finalizedBlockNumber} not found in p2p client`);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const genesisHash = GENESIS_BLOCK_HEADER_HASH.toString();
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
latest: { hash: latestBlockHash ?? genesisHash, number: latestBlockNumber },
|
|
210
|
-
proven: { hash: provenBlockHash ?? genesisHash, number: provenBlockNumber },
|
|
211
|
-
finalized: { hash: finalizedBlockHash ?? genesisHash, number: finalizedBlockNumber },
|
|
212
|
-
};
|
|
168
|
+
public getL2Tips(): Promise<L2Tips> {
|
|
169
|
+
return this.l2Tips.getL2Tips();
|
|
213
170
|
}
|
|
214
171
|
|
|
215
172
|
public async handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
|
|
216
173
|
this.log.debug(`Handling block stream event ${event.type}`);
|
|
174
|
+
|
|
217
175
|
switch (event.type) {
|
|
218
176
|
case 'blocks-added':
|
|
219
|
-
await this.handleLatestL2Blocks(event.blocks
|
|
177
|
+
await this.handleLatestL2Blocks(event.blocks);
|
|
220
178
|
break;
|
|
221
179
|
case 'chain-finalized': {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const from = BlockNumber((await this.getSyncedFinalizedBlockNum()) + 1);
|
|
180
|
+
const oldFinalizedBlockNum = await this.getSyncedFinalizedBlockNum();
|
|
181
|
+
const from = BlockNumber(oldFinalizedBlockNum + 1);
|
|
225
182
|
const limit = event.block.number - from + 1;
|
|
226
183
|
if (limit > 0) {
|
|
227
184
|
const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
|
|
228
|
-
await this.handleFinalizedL2Blocks(oldBlocks
|
|
185
|
+
await this.handleFinalizedL2Blocks(oldBlocks);
|
|
229
186
|
}
|
|
230
187
|
break;
|
|
231
188
|
}
|
|
232
|
-
case 'chain-proven':
|
|
233
|
-
await this.setBlockHash(event.block);
|
|
189
|
+
case 'chain-proven':
|
|
234
190
|
this.txCollection.stopCollectingForBlocksUpTo(event.block.number);
|
|
235
|
-
await this.synchedProvenBlockNumber.set(event.block.number);
|
|
236
191
|
break;
|
|
237
|
-
}
|
|
238
192
|
case 'chain-pruned':
|
|
239
|
-
await this.setBlockHash(event.block);
|
|
240
193
|
this.txCollection.stopCollectingForBlocksAfter(event.block.number);
|
|
241
194
|
await this.handlePruneL2Blocks(event.block.number);
|
|
242
195
|
break;
|
|
196
|
+
case 'chain-checkpointed':
|
|
197
|
+
break;
|
|
243
198
|
default: {
|
|
244
199
|
const _: never = event;
|
|
245
200
|
break;
|
|
246
201
|
}
|
|
247
202
|
}
|
|
248
|
-
}
|
|
249
203
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
204
|
+
// Pass the event through to our l2 tips store
|
|
205
|
+
await this.l2Tips.handleBlockStreamEvent(event);
|
|
206
|
+
await this.startServiceIfSynched();
|
|
254
207
|
}
|
|
255
208
|
|
|
256
209
|
#assertIsReady() {
|
|
@@ -274,9 +227,9 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
274
227
|
|
|
275
228
|
// get the current latest block numbers
|
|
276
229
|
const latestBlockNumbers = await this.l2BlockSource.getL2Tips();
|
|
277
|
-
this.latestBlockNumberAtStart = latestBlockNumbers.
|
|
278
|
-
this.provenBlockNumberAtStart = latestBlockNumbers.proven.number;
|
|
279
|
-
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;
|
|
280
233
|
|
|
281
234
|
const syncedLatestBlock = (await this.getSyncedLatestBlockNum()) + 1;
|
|
282
235
|
const syncedProvenBlock = (await this.getSyncedProvenBlockNum()) + 1;
|
|
@@ -335,12 +288,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
335
288
|
private initBlockStream(startingBlock?: BlockNumber) {
|
|
336
289
|
if (!this.blockStream) {
|
|
337
290
|
const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
|
|
338
|
-
this.blockStream = new
|
|
291
|
+
this.blockStream = new L2BlockStream(
|
|
339
292
|
this.l2BlockSource,
|
|
340
293
|
this,
|
|
341
294
|
this,
|
|
342
|
-
this.telemetry.getTracer('P2PL2BlockStream'),
|
|
343
|
-
'P2PL2BlockStream',
|
|
344
295
|
createLogger(`${this.log.module}:l2-block-stream`),
|
|
345
296
|
{ batchSize, pollIntervalMS, startingBlock },
|
|
346
297
|
);
|
|
@@ -380,23 +331,32 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
380
331
|
return this.p2pService.propagate(proposal);
|
|
381
332
|
}
|
|
382
333
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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);
|
|
386
342
|
}
|
|
387
343
|
|
|
388
|
-
public async
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
: this.attestationPool.getAttestationsForSlot(slot));
|
|
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)));
|
|
392
347
|
}
|
|
393
348
|
|
|
394
|
-
public
|
|
395
|
-
|
|
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));
|
|
396
356
|
}
|
|
397
357
|
|
|
398
|
-
public
|
|
399
|
-
return this.attestationPool.
|
|
358
|
+
public addCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
|
|
359
|
+
return this.attestationPool.addCheckpointAttestations(attestations);
|
|
400
360
|
}
|
|
401
361
|
|
|
402
362
|
// REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
@@ -405,6 +365,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
405
365
|
this.p2pService.registerBlockReceivedCallback(handler);
|
|
406
366
|
}
|
|
407
367
|
|
|
368
|
+
public registerCheckpointProposalHandler(handler: P2PCheckpointReceivedCallback): void {
|
|
369
|
+
this.p2pService.registerCheckpointReceivedCallback(handler);
|
|
370
|
+
}
|
|
371
|
+
|
|
408
372
|
/**
|
|
409
373
|
* Uses the batched Request Response protocol to request a set of transactions from the network.
|
|
410
374
|
*/
|
|
@@ -647,7 +611,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
647
611
|
* @returns Block number of latest L2 Block we've synced with.
|
|
648
612
|
*/
|
|
649
613
|
public async getSyncedLatestBlockNum(): Promise<BlockNumber> {
|
|
650
|
-
|
|
614
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
615
|
+
return tips.proposed.number;
|
|
651
616
|
}
|
|
652
617
|
|
|
653
618
|
/**
|
|
@@ -655,11 +620,13 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
655
620
|
* @returns Block number of latest proven L2 Block we've synced with.
|
|
656
621
|
*/
|
|
657
622
|
public async getSyncedProvenBlockNum(): Promise<BlockNumber> {
|
|
658
|
-
|
|
623
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
624
|
+
return tips.proven.block.number;
|
|
659
625
|
}
|
|
660
626
|
|
|
661
627
|
public async getSyncedFinalizedBlockNum(): Promise<BlockNumber> {
|
|
662
|
-
|
|
628
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
629
|
+
return tips.finalized.block.number;
|
|
663
630
|
}
|
|
664
631
|
|
|
665
632
|
/** Returns latest L2 slot for which we have seen an L2 block. */
|
|
@@ -714,20 +681,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
714
681
|
await this.startCollectingMissingTxs(blocks);
|
|
715
682
|
|
|
716
683
|
const lastBlock = blocks.at(-1)!;
|
|
717
|
-
|
|
718
|
-
await Promise.all(
|
|
719
|
-
blocks.map(async block =>
|
|
720
|
-
this.setBlockHash({
|
|
721
|
-
number: block.number,
|
|
722
|
-
hash: await block.hash().then(h => h.toString()),
|
|
723
|
-
}),
|
|
724
|
-
),
|
|
725
|
-
);
|
|
726
|
-
|
|
727
|
-
await this.synchedLatestBlockNumber.set(lastBlock.number);
|
|
728
684
|
await this.synchedLatestSlot.set(BigInt(lastBlock.header.getSlot()));
|
|
729
685
|
this.log.verbose(`Synched to latest block ${lastBlock.number}`);
|
|
730
|
-
await this.startServiceIfSynched();
|
|
731
686
|
}
|
|
732
687
|
|
|
733
688
|
/** Request txs for unproven blocks so the prover node has more chances to get them. */
|
|
@@ -778,12 +733,9 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
778
733
|
await this.txPool.deleteTxs(txHashes, { permanently: true });
|
|
779
734
|
await this.txPool.cleanupDeletedMinedTxs(lastBlockNum);
|
|
780
735
|
|
|
781
|
-
await this.attestationPool.
|
|
736
|
+
await this.attestationPool.deleteCheckpointAttestationsOlderThan(lastBlockSlot);
|
|
782
737
|
|
|
783
|
-
await this.synchedFinalizedBlockNumber.set(lastBlockNum);
|
|
784
738
|
this.log.debug(`Synched to finalized block ${lastBlockNum} at slot ${lastBlockSlot}`);
|
|
785
|
-
|
|
786
|
-
await this.startServiceIfSynched();
|
|
787
739
|
}
|
|
788
740
|
|
|
789
741
|
/**
|
|
@@ -831,18 +783,16 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
831
783
|
} else {
|
|
832
784
|
await this.txPool.markMinedAsPending(minedTxsFromReorg, latestBlock);
|
|
833
785
|
}
|
|
834
|
-
|
|
835
|
-
await this.synchedLatestBlockNumber.set(latestBlock);
|
|
836
|
-
// no need to update block hashes, as they will be updated as new blocks are added
|
|
837
786
|
}
|
|
838
787
|
|
|
839
788
|
private async startServiceIfSynched() {
|
|
840
789
|
if (this.currentState !== P2PClientState.SYNCHING) {
|
|
841
790
|
return;
|
|
842
791
|
}
|
|
843
|
-
const
|
|
844
|
-
const
|
|
845
|
-
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;
|
|
846
796
|
|
|
847
797
|
if (
|
|
848
798
|
syncedLatestBlock >= this.latestBlockNumberAtStart &&
|
package/src/config.ts
CHANGED
|
@@ -2,10 +2,10 @@ 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';
|
|
@@ -407,7 +407,7 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
|
407
407
|
dropTransactionsProbability: {
|
|
408
408
|
env: 'P2P_DROP_TX_CHANCE',
|
|
409
409
|
description: 'The probability that a transaction is discarded (0 - 1). - For testing purposes only',
|
|
410
|
-
...
|
|
410
|
+
...percentageConfigHelper(0),
|
|
411
411
|
},
|
|
412
412
|
disableTransactions: {
|
|
413
413
|
env: 'TRANSACTIONS_DISABLED',
|