@aztec/p2p 3.0.0-devnet.2 → 3.0.0-devnet.2-patch.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/client/factory.d.ts +1 -1
- package/dest/client/index.d.ts +1 -1
- package/dest/client/interface.d.ts +4 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +8 -26
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +31 -24
- package/dest/config.d.ts +60 -54
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +12 -2
- package/dest/enr/generate-enr.d.ts +1 -1
- package/dest/enr/index.d.ts +1 -1
- package/dest/errors/attestation-pool.error.d.ts +7 -0
- package/dest/errors/attestation-pool.error.d.ts.map +1 -0
- package/dest/errors/attestation-pool.error.js +12 -0
- package/dest/errors/reqresp.error.d.ts +1 -1
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +43 -6
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +67 -34
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +15 -6
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +57 -18
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +13 -6
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +51 -7
- package/dest/mem_pools/attestation_pool/mocks.d.ts +226 -5
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +2 -2
- package/dest/mem_pools/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +3 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +11 -2
- package/dest/mem_pools/interface.d.ts +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +5 -38
- 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 +9 -3
- package/dest/mem_pools/tx_pool/index.d.ts +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +5 -3
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +7 -0
- package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +10 -3
- 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 +5 -4
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +12 -12
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
- package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
- package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/index.js +1 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +22 -10
- package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
- package/dest/msg_validators/index.d.ts +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/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/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.d.ts +1 -1
- 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/phases_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -1
- package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.d.ts +1 -1
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/dummy_service.d.ts +1 -1
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/encoding.d.ts +25 -4
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +74 -6
- package/dest/services/gossipsub/scoring.d.ts +1 -1
- package/dest/services/index.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +9 -2
- package/dest/services/libp2p/libp2p_service.d.ts +25 -74
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +308 -84
- package/dest/services/peer-manager/interface.d.ts +1 -1
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +11 -0
- package/dest/services/peer-manager/peer_manager.d.ts +1 -32
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +4 -2
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +40 -2
- package/dest/services/reqresp/config.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/index.d.ts +1 -1
- package/dest/services/reqresp/interface.d.ts +2 -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/protocols/auth.d.ts +2 -2
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.js +2 -2
- package/dest/services/reqresp/protocols/block.d.ts +1 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +4 -6
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +1 -1
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +1 -1
- package/dest/services/reqresp/protocols/goodbye.d.ts +1 -1
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -1
- package/dest/services/reqresp/protocols/ping.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +6 -5
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -3
- package/dest/services/reqresp/protocols/tx.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +2 -2
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts +1 -41
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +2 -2
- package/dest/services/reqresp/status.d.ts +2 -2
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/service.d.ts +1 -1
- package/dest/services/tx_collection/config.d.ts +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -9
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/index.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -7
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +2 -1
- package/dest/services/tx_collection/tx_collection.d.ts +11 -11
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.d.ts +3 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.d.ts +1 -1
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +5 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +1 -1
- package/dest/test-helpers/make-enrs.d.ts +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts +2 -2
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +4 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-tx-helpers.d.ts +2 -2
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -1
- package/dest/test-helpers/mock-tx-helpers.js +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +14 -8
- package/dest/testbench/parse_log_file.d.ts +1 -1
- package/dest/testbench/testbench.d.ts +1 -1
- package/dest/testbench/testbench.js +2 -2
- package/dest/testbench/worker_client_manager.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/types/index.d.ts +1 -1
- package/dest/util.d.ts +2 -1
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +11 -2
- package/dest/versioning.d.ts +1 -1
- package/package.json +19 -18
- package/src/client/interface.ts +4 -1
- package/src/client/p2p_client.ts +51 -43
- package/src/config.ts +19 -2
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +46 -5
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +84 -34
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +87 -24
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +77 -15
- package/src/mem_pools/attestation_pool/mocks.ts +3 -3
- package/src/mem_pools/instrumentation.ts +13 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +15 -9
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +13 -6
- package/src/mem_pools/tx_pool/tx_pool.ts +10 -2
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +5 -4
- package/src/msg_validators/attestation_validator/attestation_validator.ts +14 -16
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +26 -10
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +1 -1
- package/src/msg_validators/tx_validator/factory.ts +3 -2
- package/src/msg_validators/tx_validator/metadata_validator.ts +1 -1
- package/src/msg_validators/tx_validator/phases_validator.ts +3 -1
- package/src/msg_validators/tx_validator/test_utils.ts +1 -1
- package/src/msg_validators/tx_validator/timestamp_validator.ts +2 -1
- package/src/services/encoding.ts +81 -6
- package/src/services/libp2p/instrumentation.ts +10 -1
- package/src/services/libp2p/libp2p_service.ts +334 -91
- package/src/services/peer-manager/metrics.ts +10 -0
- package/src/services/peer-manager/peer_manager.ts +4 -2
- package/src/services/peer-manager/peer_scoring.ts +46 -3
- package/src/services/reqresp/interface.ts +1 -1
- package/src/services/reqresp/protocols/auth.ts +2 -2
- package/src/services/reqresp/protocols/block.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
- package/src/services/reqresp/protocols/status.ts +9 -8
- package/src/services/reqresp/reqresp.ts +2 -2
- package/src/services/tx_collection/fast_tx_collection.ts +3 -2
- package/src/services/tx_collection/slow_tx_collection.ts +7 -6
- package/src/services/tx_collection/tx_collection.ts +10 -9
- package/src/services/tx_provider.ts +4 -3
- package/src/test-helpers/mock-tx-helpers.ts +1 -1
- package/src/testbench/p2p_client_testbench_worker.ts +11 -5
- package/src/testbench/testbench.ts +2 -2
- package/src/util.ts +12 -2
package/src/client/p2p_client.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
1
|
+
import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
5
|
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncSingleton } from '@aztec/kv-store';
|
|
5
6
|
import type {
|
|
6
7
|
EthAddress,
|
|
7
|
-
L2Block,
|
|
8
8
|
L2BlockId,
|
|
9
|
+
L2BlockNew,
|
|
9
10
|
L2BlockSource,
|
|
10
11
|
L2BlockStream,
|
|
11
12
|
L2BlockStreamEvent,
|
|
12
13
|
L2Tips,
|
|
13
|
-
PublishedL2Block,
|
|
14
14
|
} from '@aztec/stdlib/block';
|
|
15
15
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
16
16
|
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
@@ -62,10 +62,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
62
62
|
private provenBlockNumberAtStart = -1;
|
|
63
63
|
private finalizedBlockNumberAtStart = -1;
|
|
64
64
|
|
|
65
|
-
private synchedBlockHashes: AztecAsyncMap<
|
|
66
|
-
private synchedLatestBlockNumber: AztecAsyncSingleton<
|
|
67
|
-
private synchedProvenBlockNumber: AztecAsyncSingleton<
|
|
68
|
-
private synchedFinalizedBlockNumber: AztecAsyncSingleton<
|
|
65
|
+
private synchedBlockHashes: AztecAsyncMap<BlockNumber, string>;
|
|
66
|
+
private synchedLatestBlockNumber: AztecAsyncSingleton<BlockNumber>;
|
|
67
|
+
private synchedProvenBlockNumber: AztecAsyncSingleton<BlockNumber>;
|
|
68
|
+
private synchedFinalizedBlockNumber: AztecAsyncSingleton<BlockNumber>;
|
|
69
69
|
private synchedLatestSlot: AztecAsyncSingleton<bigint>;
|
|
70
70
|
|
|
71
71
|
private txPool: TxPool;
|
|
@@ -121,14 +121,14 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
121
121
|
this.log.debug(`Received block proposal from ${sender.toString()}`);
|
|
122
122
|
// TODO(palla/txs): Need to subtract validatorReexecuteDeadlineMs from this deadline (see ValidatorClient.getReexecutionDeadline)
|
|
123
123
|
const constants = this.txCollection.getConstants();
|
|
124
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(block.slotNumber
|
|
124
|
+
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
|
|
125
125
|
const deadline = new Date(nextSlotTimestampSeconds * 1000);
|
|
126
126
|
const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.payload.header.lastArchiveRoot);
|
|
127
127
|
if (!parentBlock) {
|
|
128
128
|
this.log.debug(`Cannot collect txs for proposal as parent block not found`);
|
|
129
129
|
return;
|
|
130
130
|
}
|
|
131
|
-
const blockNumber = parentBlock.getBlockNumber() + 1;
|
|
131
|
+
const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
|
|
132
132
|
await this.txProvider.getTxsForBlockProposal(block, blockNumber, { pinnedPeer: sender, deadline });
|
|
133
133
|
return undefined;
|
|
134
134
|
});
|
|
@@ -162,7 +162,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
162
162
|
return Promise.resolve(this.p2pService.getPeers(includePending));
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
public getL2BlockHash(number:
|
|
165
|
+
public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
|
|
166
166
|
return this.synchedBlockHashes.getAsync(number);
|
|
167
167
|
}
|
|
168
168
|
|
|
@@ -203,10 +203,12 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
const genesisHash = GENESIS_BLOCK_HEADER_HASH.toString();
|
|
207
|
+
|
|
206
208
|
return {
|
|
207
|
-
latest: { hash: latestBlockHash
|
|
208
|
-
proven: { hash: provenBlockHash
|
|
209
|
-
finalized: { hash: finalizedBlockHash
|
|
209
|
+
latest: { hash: latestBlockHash ?? genesisHash, number: latestBlockNumber },
|
|
210
|
+
proven: { hash: provenBlockHash ?? genesisHash, number: provenBlockNumber },
|
|
211
|
+
finalized: { hash: finalizedBlockHash ?? genesisHash, number: finalizedBlockNumber },
|
|
210
212
|
};
|
|
211
213
|
}
|
|
212
214
|
|
|
@@ -214,15 +216,16 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
214
216
|
this.log.debug(`Handling block stream event ${event.type}`);
|
|
215
217
|
switch (event.type) {
|
|
216
218
|
case 'blocks-added':
|
|
217
|
-
await this.handleLatestL2Blocks(event.blocks);
|
|
219
|
+
await this.handleLatestL2Blocks(event.blocks.map(b => b.block.toL2Block()));
|
|
218
220
|
break;
|
|
219
221
|
case 'chain-finalized': {
|
|
220
222
|
// TODO (alexg): I think we can prune the block hashes map here
|
|
221
223
|
await this.setBlockHash(event.block);
|
|
222
|
-
const from = (await this.getSyncedFinalizedBlockNum()) + 1;
|
|
224
|
+
const from = BlockNumber((await this.getSyncedFinalizedBlockNum()) + 1);
|
|
223
225
|
const limit = event.block.number - from + 1;
|
|
224
226
|
if (limit > 0) {
|
|
225
|
-
|
|
227
|
+
const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
|
|
228
|
+
await this.handleFinalizedL2Blocks(oldBlocks.map(b => b.toL2Block()));
|
|
226
229
|
}
|
|
227
230
|
break;
|
|
228
231
|
}
|
|
@@ -284,7 +287,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
284
287
|
(this.attestationPool === undefined || (await this.attestationPool?.isEmpty()))
|
|
285
288
|
) {
|
|
286
289
|
// if mempools are empty, we don't care about syncing prior blocks
|
|
287
|
-
this.initBlockStream(this.latestBlockNumberAtStart);
|
|
290
|
+
this.initBlockStream(BlockNumber(this.latestBlockNumberAtStart));
|
|
288
291
|
this.setCurrentState(P2PClientState.RUNNING);
|
|
289
292
|
this.syncPromise = Promise.resolve();
|
|
290
293
|
await this.p2pService.start();
|
|
@@ -332,7 +335,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
332
335
|
return this.p2pService.addReqRespSubProtocol(subProtocol, handler, validator);
|
|
333
336
|
}
|
|
334
337
|
|
|
335
|
-
private initBlockStream(startingBlock?:
|
|
338
|
+
private initBlockStream(startingBlock?: BlockNumber) {
|
|
336
339
|
if (!this.blockStream) {
|
|
337
340
|
const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
|
|
338
341
|
this.blockStream = new TraceableL2BlockStream(
|
|
@@ -371,16 +374,21 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
371
374
|
}
|
|
372
375
|
|
|
373
376
|
@trackSpan('p2pClient.broadcastProposal', async proposal => ({
|
|
374
|
-
[Attributes.SLOT_NUMBER]: proposal.slotNumber
|
|
377
|
+
[Attributes.SLOT_NUMBER]: proposal.slotNumber,
|
|
375
378
|
[Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
|
|
376
|
-
[Attributes.P2P_ID]: (await proposal.
|
|
379
|
+
[Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
|
|
377
380
|
}))
|
|
378
381
|
public broadcastProposal(proposal: BlockProposal): Promise<void> {
|
|
379
|
-
this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber
|
|
382
|
+
this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber} to peers`);
|
|
380
383
|
return this.p2pService.propagate(proposal);
|
|
381
384
|
}
|
|
382
385
|
|
|
383
|
-
public async
|
|
386
|
+
public async broadcastAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
387
|
+
this.log.verbose(`Broadcasting ${attestations.length} attestations to peers`);
|
|
388
|
+
await Promise.all(attestations.map(att => this.p2pService.propagate(att)));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
public async getAttestationsForSlot(slot: SlotNumber, proposalId?: string): Promise<BlockAttestation[]> {
|
|
384
392
|
return (
|
|
385
393
|
(await (proposalId
|
|
386
394
|
? this.attestationPool?.getAttestationsForSlotAndProposal(slot, proposalId)
|
|
@@ -643,20 +651,20 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
643
651
|
* Public function to check the latest block number that the P2P client is synced to.
|
|
644
652
|
* @returns Block number of latest L2 Block we've synced with.
|
|
645
653
|
*/
|
|
646
|
-
public async getSyncedLatestBlockNum(): Promise<
|
|
647
|
-
return (await this.synchedLatestBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
|
|
654
|
+
public async getSyncedLatestBlockNum(): Promise<BlockNumber> {
|
|
655
|
+
return (await this.synchedLatestBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
648
656
|
}
|
|
649
657
|
|
|
650
658
|
/**
|
|
651
659
|
* Public function to check the latest proven block number that the P2P client is synced to.
|
|
652
660
|
* @returns Block number of latest proven L2 Block we've synced with.
|
|
653
661
|
*/
|
|
654
|
-
public async getSyncedProvenBlockNum(): Promise<
|
|
655
|
-
return (await this.synchedProvenBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
|
|
662
|
+
public async getSyncedProvenBlockNum(): Promise<BlockNumber> {
|
|
663
|
+
return (await this.synchedProvenBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
656
664
|
}
|
|
657
665
|
|
|
658
|
-
public async getSyncedFinalizedBlockNum(): Promise<
|
|
659
|
-
return (await this.synchedFinalizedBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
|
|
666
|
+
public async getSyncedFinalizedBlockNum(): Promise<BlockNumber> {
|
|
667
|
+
return (await this.synchedFinalizedBlockNumber.getAsync()) ?? BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
660
668
|
}
|
|
661
669
|
|
|
662
670
|
/** Returns latest L2 slot for which we have seen an L2 block. */
|
|
@@ -672,7 +680,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
672
680
|
const blockNumber = await this.getSyncedLatestBlockNum();
|
|
673
681
|
const blockHash =
|
|
674
682
|
blockNumber === 0
|
|
675
|
-
?
|
|
683
|
+
? GENESIS_BLOCK_HEADER_HASH.toString()
|
|
676
684
|
: await this.l2BlockSource
|
|
677
685
|
.getBlockHeader(blockNumber)
|
|
678
686
|
.then(header => header?.hash())
|
|
@@ -680,8 +688,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
680
688
|
|
|
681
689
|
return {
|
|
682
690
|
state: this.currentState,
|
|
683
|
-
syncedToL2Block: { number: blockNumber, hash: blockHash },
|
|
684
|
-
}
|
|
691
|
+
syncedToL2Block: { number: blockNumber, hash: blockHash! },
|
|
692
|
+
};
|
|
685
693
|
}
|
|
686
694
|
|
|
687
695
|
/**
|
|
@@ -689,10 +697,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
689
697
|
* @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
|
|
690
698
|
* @returns Empty promise.
|
|
691
699
|
*/
|
|
692
|
-
private async markTxsAsMinedFromBlocks(blocks:
|
|
700
|
+
private async markTxsAsMinedFromBlocks(blocks: L2BlockNew[]): Promise<void> {
|
|
693
701
|
for (const block of blocks) {
|
|
694
702
|
const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
|
|
695
|
-
await this.txPool.markAsMined(txHashes, block.
|
|
703
|
+
await this.txPool.markAsMined(txHashes, block.header);
|
|
696
704
|
}
|
|
697
705
|
}
|
|
698
706
|
|
|
@@ -701,33 +709,33 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
701
709
|
* @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
|
|
702
710
|
* @returns Empty promise.
|
|
703
711
|
*/
|
|
704
|
-
private async handleLatestL2Blocks(blocks:
|
|
712
|
+
private async handleLatestL2Blocks(blocks: L2BlockNew[]): Promise<void> {
|
|
705
713
|
if (!blocks.length) {
|
|
706
714
|
return Promise.resolve();
|
|
707
715
|
}
|
|
708
716
|
|
|
709
|
-
await this.markTxsAsMinedFromBlocks(blocks
|
|
710
|
-
await this.startCollectingMissingTxs(blocks
|
|
717
|
+
await this.markTxsAsMinedFromBlocks(blocks);
|
|
718
|
+
await this.startCollectingMissingTxs(blocks);
|
|
711
719
|
|
|
712
|
-
const lastBlock = blocks.at(-1)
|
|
720
|
+
const lastBlock = blocks.at(-1)!;
|
|
713
721
|
|
|
714
722
|
await Promise.all(
|
|
715
723
|
blocks.map(async block =>
|
|
716
724
|
this.setBlockHash({
|
|
717
|
-
number: block.
|
|
718
|
-
hash: await block.
|
|
725
|
+
number: block.number,
|
|
726
|
+
hash: await block.hash().then(h => h.toString()),
|
|
719
727
|
}),
|
|
720
728
|
),
|
|
721
729
|
);
|
|
722
730
|
|
|
723
731
|
await this.synchedLatestBlockNumber.set(lastBlock.number);
|
|
724
|
-
await this.synchedLatestSlot.set(lastBlock.header.getSlot());
|
|
732
|
+
await this.synchedLatestSlot.set(BigInt(lastBlock.header.getSlot()));
|
|
725
733
|
this.log.verbose(`Synched to latest block ${lastBlock.number}`);
|
|
726
734
|
await this.startServiceIfSynched();
|
|
727
735
|
}
|
|
728
736
|
|
|
729
737
|
/** Request txs for unproven blocks so the prover node has more chances to get them. */
|
|
730
|
-
private async startCollectingMissingTxs(blocks:
|
|
738
|
+
private async startCollectingMissingTxs(blocks: L2BlockNew[]): Promise<void> {
|
|
731
739
|
try {
|
|
732
740
|
// TODO(#15435): If the archiver has lagged behind L1, the reported proven block number may
|
|
733
741
|
// be much lower than the actual one, and it does not update until the pending chain is
|
|
@@ -760,7 +768,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
760
768
|
* @param blocks - A list of finalized L2 blocks.
|
|
761
769
|
* @returns Empty promise.
|
|
762
770
|
*/
|
|
763
|
-
private async handleFinalizedL2Blocks(blocks:
|
|
771
|
+
private async handleFinalizedL2Blocks(blocks: L2BlockNew[]): Promise<void> {
|
|
764
772
|
if (!blocks.length) {
|
|
765
773
|
return Promise.resolve();
|
|
766
774
|
}
|
|
@@ -786,7 +794,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
786
794
|
* Updates the tx pool after a chain prune.
|
|
787
795
|
* @param latestBlock - The block number the chain was pruned to.
|
|
788
796
|
*/
|
|
789
|
-
private async handlePruneL2Blocks(latestBlock:
|
|
797
|
+
private async handlePruneL2Blocks(latestBlock: BlockNumber): Promise<void> {
|
|
790
798
|
const txsToDelete = new Map<string, TxHash>();
|
|
791
799
|
const minedTxs = await this.txPool.getMinedTxHashes();
|
|
792
800
|
|
package/src/config.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
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
14
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
15
15
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -164,6 +164,12 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig, TxCollectionCo
|
|
|
164
164
|
|
|
165
165
|
/** Whether to delete transactions from the pool after a reorg instead of moving them back to pending. */
|
|
166
166
|
txPoolDeleteTxsAfterReorg: boolean;
|
|
167
|
+
|
|
168
|
+
/** Alters the format of p2p messages to include things like broadcast timestamp FOR TESTING ONLY */
|
|
169
|
+
debugP2PInstrumentMessages: boolean;
|
|
170
|
+
|
|
171
|
+
/** Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus */
|
|
172
|
+
fishermanMode: boolean;
|
|
167
173
|
}
|
|
168
174
|
|
|
169
175
|
export const DEFAULT_P2P_PORT = 40400;
|
|
@@ -406,7 +412,7 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
|
406
412
|
},
|
|
407
413
|
dropTransactionsProbability: {
|
|
408
414
|
env: 'P2P_DROP_TX_CHANCE',
|
|
409
|
-
description: 'The probability that a transaction is discarded. - For testing purposes only',
|
|
415
|
+
description: 'The probability that a transaction is discarded (0 - 1). - For testing purposes only',
|
|
410
416
|
...floatConfigHelper(0),
|
|
411
417
|
},
|
|
412
418
|
disableTransactions: {
|
|
@@ -420,6 +426,17 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
|
420
426
|
description: 'Whether to delete transactions from the pool after a reorg instead of moving them back to pending.',
|
|
421
427
|
...booleanConfigHelper(false),
|
|
422
428
|
},
|
|
429
|
+
debugP2PInstrumentMessages: {
|
|
430
|
+
env: 'DEBUG_P2P_INSTRUMENT_MESSAGES',
|
|
431
|
+
description: 'Alters the format of p2p messages to include things like broadcast timestamp FOR TESTING ONLY',
|
|
432
|
+
...booleanConfigHelper(false),
|
|
433
|
+
},
|
|
434
|
+
fishermanMode: {
|
|
435
|
+
env: 'FISHERMAN_MODE',
|
|
436
|
+
description:
|
|
437
|
+
'Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus.',
|
|
438
|
+
...booleanConfigHelper(false),
|
|
439
|
+
},
|
|
423
440
|
...p2pReqRespConfigMappings,
|
|
424
441
|
...chainConfigMappings,
|
|
425
442
|
...txCollectionConfigMappings,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class AttestationPoolError extends Error {
|
|
2
|
+
constructor(message?: string) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'AttestationPoolError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class ProposalSlotCapExceededError extends AttestationPoolError {
|
|
9
|
+
constructor(message?: string) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'ProposalSlotCapExceededError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -21,6 +22,15 @@ export interface AttestationPool {
|
|
|
21
22
|
*/
|
|
22
23
|
getBlockProposal(id: string): Promise<BlockProposal | undefined>;
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Check if a block proposal exists in the pool
|
|
27
|
+
*
|
|
28
|
+
* @param idOrProposal - The ID of the block proposal or the block proposal itself to check. The ID is proposal.payload.archive
|
|
29
|
+
*
|
|
30
|
+
* @return True if the block proposal exists, false otherwise.
|
|
31
|
+
*/
|
|
32
|
+
hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean>;
|
|
33
|
+
|
|
24
34
|
/**
|
|
25
35
|
* AddAttestations
|
|
26
36
|
*
|
|
@@ -42,7 +52,7 @@ export interface AttestationPool {
|
|
|
42
52
|
*
|
|
43
53
|
* @param slot - The oldest slot to keep.
|
|
44
54
|
*/
|
|
45
|
-
deleteAttestationsOlderThan(slot:
|
|
55
|
+
deleteAttestationsOlderThan(slot: SlotNumber): Promise<void>;
|
|
46
56
|
|
|
47
57
|
/**
|
|
48
58
|
* Delete Attestations for slot
|
|
@@ -51,7 +61,7 @@ export interface AttestationPool {
|
|
|
51
61
|
*
|
|
52
62
|
* @param slot - The slot to delete.
|
|
53
63
|
*/
|
|
54
|
-
deleteAttestationsForSlot(slot:
|
|
64
|
+
deleteAttestationsForSlot(slot: SlotNumber): Promise<void>;
|
|
55
65
|
|
|
56
66
|
/**
|
|
57
67
|
* Delete Attestations for slot and proposal
|
|
@@ -61,7 +71,7 @@ export interface AttestationPool {
|
|
|
61
71
|
* @param slot - The slot to delete.
|
|
62
72
|
* @param proposalId - The proposal to delete.
|
|
63
73
|
*/
|
|
64
|
-
deleteAttestationsForSlotAndProposal(slot:
|
|
74
|
+
deleteAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<void>;
|
|
65
75
|
|
|
66
76
|
/**
|
|
67
77
|
* Get all Attestations for all proposals for a given slot
|
|
@@ -71,7 +81,7 @@ export interface AttestationPool {
|
|
|
71
81
|
* @param slot - The slot to query
|
|
72
82
|
* @return BlockAttestations
|
|
73
83
|
*/
|
|
74
|
-
getAttestationsForSlot(slot:
|
|
84
|
+
getAttestationsForSlot(slot: SlotNumber): Promise<BlockAttestation[]>;
|
|
75
85
|
|
|
76
86
|
/**
|
|
77
87
|
* Get Attestations for slot and given proposal
|
|
@@ -82,7 +92,38 @@ export interface AttestationPool {
|
|
|
82
92
|
* @param proposalId - The proposal to query
|
|
83
93
|
* @return BlockAttestations
|
|
84
94
|
*/
|
|
85
|
-
getAttestationsForSlotAndProposal(slot:
|
|
95
|
+
getAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<BlockAttestation[]>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Check if a specific attestation exists in the pool
|
|
99
|
+
*
|
|
100
|
+
* @param attestation - The attestation to check
|
|
101
|
+
* @return True if the attestation exists, false otherwise
|
|
102
|
+
*/
|
|
103
|
+
hasAttestation(attestation: BlockAttestation): Promise<boolean>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Returns whether adding this proposal is permitted at current capacity:
|
|
107
|
+
* - True if the proposal already exists, allow overwrite to keep parity with tests.
|
|
108
|
+
* - True if the slot is below the proposal cap.
|
|
109
|
+
* - False if the slot is at/above cap and this would be a new unique proposal.
|
|
110
|
+
*
|
|
111
|
+
* @param block - The block proposal to check
|
|
112
|
+
* @returns True if the proposal can be added (or already exists), false otherwise.
|
|
113
|
+
*/
|
|
114
|
+
canAddProposal(block: BlockProposal): Promise<boolean>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Returns whether an attestation would be accepted for (slot, proposalId):
|
|
118
|
+
* - True if the attestation already exists for this sender.
|
|
119
|
+
* - True if the attestation cap for (slot, proposalId) has not been reached.
|
|
120
|
+
* - False if the cap is reached and this attestation would be a new unique entry.
|
|
121
|
+
*
|
|
122
|
+
* @param attestation - The attestation to check
|
|
123
|
+
* @param committeeSize - Committee size for the attestation's slot, implementation may add a small buffer
|
|
124
|
+
* @returns True if the attestation can be added, false otherwise.
|
|
125
|
+
*/
|
|
126
|
+
canAddAttestation(attestation: BlockAttestation, committeeSize: number): Promise<boolean>;
|
|
86
127
|
|
|
87
128
|
/** Returns whether the pool is empty. */
|
|
88
129
|
isEmpty(): Promise<boolean>;
|