@aztec/p2p 0.71.0 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts +2 -2
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +1 -1
- package/dest/client/factory.js +4 -4
- package/dest/client/p2p_client.d.ts +13 -16
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +55 -67
- 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 +11 -19
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +6 -13
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +74 -80
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +5 -5
- package/dest/mem_pools/attestation_pool/mocks.d.ts +3 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +3 -3
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +9 -9
- 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 +60 -54
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +7 -7
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +17 -18
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +7 -7
- 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.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +48 -47
- package/dest/mocks/index.d.ts +3 -3
- package/dest/mocks/index.d.ts.map +1 -1
- package/dest/mocks/index.js +19 -18
- package/dest/msg_validators/attestation_validator/attestation_validator.js +2 -2
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +2 -2
- package/dest/msg_validators/tx_validator/block_header_validator.js +3 -3
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +7 -7
- package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -3
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +9 -9
- package/dest/services/data_store.d.ts +4 -4
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +7 -7
- package/dest/services/dummy_service.d.ts +7 -0
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +10 -1
- package/dest/services/libp2p/libp2p_service.d.ts +19 -15
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +163 -134
- package/dest/services/peer-manager/metrics.d.ts +12 -0
- package/dest/services/peer-manager/metrics.d.ts.map +1 -0
- package/dest/services/peer-manager/metrics.js +26 -0
- package/dest/services/{peer_manager.d.ts → peer-manager/peer_manager.d.ts} +24 -8
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -0
- package/dest/services/peer-manager/peer_manager.js +395 -0
- package/dest/services/{peer-scoring → peer-manager}/peer_scoring.d.ts +3 -0
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -0
- package/dest/services/peer-manager/peer_scoring.js +84 -0
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +45 -0
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -0
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +81 -0
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +61 -0
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -0
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +175 -0
- package/dest/services/reqresp/interface.d.ts +17 -4
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +34 -11
- package/dest/services/reqresp/metrics.d.ts +15 -0
- package/dest/services/reqresp/metrics.d.ts.map +1 -0
- package/dest/services/reqresp/metrics.js +42 -0
- package/dest/services/reqresp/protocols/block.d.ts +4 -0
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block.js +9 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts +51 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/goodbye.js +92 -0
- package/dest/services/reqresp/protocols/index.d.ts +9 -0
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/index.js +9 -0
- package/dest/services/reqresp/protocols/ping.d.ts +9 -0
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/ping.js +9 -0
- package/dest/services/reqresp/{handlers.d.ts → protocols/status.d.ts} +1 -7
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/status.js +9 -0
- package/dest/services/reqresp/protocols/tx.d.ts +13 -0
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/tx.js +23 -0
- package/dest/services/reqresp/rate-limiter/index.d.ts.map +1 -0
- package/dest/services/reqresp/{rate_limiter → rate-limiter}/index.js +1 -1
- package/dest/services/reqresp/{rate_limiter → rate-limiter}/rate_limiter.d.ts +3 -3
- package/dest/services/reqresp/{rate_limiter → rate-limiter}/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/{rate_limiter → rate-limiter}/rate_limiter.js +4 -4
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -0
- package/dest/services/reqresp/rate-limiter/rate_limits.js +55 -0
- package/dest/services/reqresp/reqresp.d.ts +33 -6
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +414 -249
- package/dest/services/service.d.ts +8 -0
- package/dest/services/service.d.ts.map +1 -1
- package/dest/util.d.ts +6 -2
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +2 -2
- package/package.json +8 -8
- package/src/bootstrap/bootstrap.ts +2 -2
- package/src/client/factory.ts +3 -3
- package/src/client/p2p_client.ts +68 -80
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +14 -22
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +100 -94
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +4 -4
- package/src/mem_pools/attestation_pool/mocks.ts +5 -5
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +84 -73
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +26 -23
- package/src/mem_pools/tx_pool/tx_pool.ts +7 -7
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +50 -47
- package/src/mocks/index.ts +19 -20
- package/src/msg_validators/attestation_validator/attestation_validator.ts +1 -1
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
- package/src/msg_validators/tx_validator/data_validator.ts +12 -9
- package/src/msg_validators/tx_validator/double_spend_validator.ts +2 -2
- package/src/msg_validators/tx_validator/metadata_validator.ts +8 -8
- package/src/services/data_store.ts +9 -9
- package/src/services/dummy_service.ts +13 -0
- package/src/services/libp2p/libp2p_service.ts +212 -163
- package/src/services/peer-manager/metrics.ts +41 -0
- package/src/services/{peer_manager.ts → peer-manager/peer_manager.ts} +73 -23
- package/src/services/{peer-scoring → peer-manager}/peer_scoring.ts +16 -3
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +94 -0
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +211 -0
- package/src/services/reqresp/interface.ts +39 -16
- package/src/services/reqresp/metrics.ts +57 -0
- package/src/services/reqresp/protocols/block.ts +15 -0
- package/src/services/reqresp/protocols/goodbye.ts +101 -0
- package/src/services/reqresp/protocols/index.ts +8 -0
- package/src/services/reqresp/protocols/ping.ts +8 -0
- package/src/services/reqresp/{handlers.ts → protocols/status.ts} +0 -9
- package/src/services/reqresp/protocols/tx.ts +29 -0
- package/src/services/reqresp/{rate_limiter → rate-limiter}/rate_limiter.ts +3 -3
- package/src/services/reqresp/{rate_limiter → rate-limiter}/rate_limits.ts +24 -4
- package/src/services/reqresp/reqresp.ts +231 -26
- package/src/services/service.ts +12 -0
- package/src/util.ts +11 -4
- package/dest/services/peer-scoring/peer_scoring.d.ts.map +0 -1
- package/dest/services/peer-scoring/peer_scoring.js +0 -75
- package/dest/services/peer_manager.d.ts.map +0 -1
- package/dest/services/peer_manager.js +0 -358
- package/dest/services/reqresp/handlers.d.ts.map +0 -1
- package/dest/services/reqresp/handlers.js +0 -17
- package/dest/services/reqresp/rate_limiter/index.d.ts.map +0 -1
- package/dest/services/reqresp/rate_limiter/rate_limits.d.ts.map +0 -1
- package/dest/services/reqresp/rate_limiter/rate_limits.js +0 -35
- /package/dest/services/reqresp/{rate_limiter → rate-limiter}/index.d.ts +0 -0
- /package/dest/services/reqresp/{rate_limiter → rate-limiter}/rate_limits.d.ts +0 -0
- /package/src/services/reqresp/{rate_limiter → rate-limiter}/index.ts +0 -0
package/src/mocks/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
type WorldStateSynchronizer,
|
|
7
7
|
} from '@aztec/circuit-types';
|
|
8
8
|
import { type EpochCache } from '@aztec/epoch-cache';
|
|
9
|
+
import { timesParallel } from '@aztec/foundation/collection';
|
|
9
10
|
import { type DataStoreConfig } from '@aztec/kv-store/config';
|
|
10
11
|
import { openTmpStore } from '@aztec/kv-store/lmdb';
|
|
11
12
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -26,17 +27,15 @@ import { type BootnodeConfig, type P2PConfig } from '../config.js';
|
|
|
26
27
|
import { type MemPools } from '../mem_pools/interface.js';
|
|
27
28
|
import { DiscV5Service } from '../services/discv5/discV5_service.js';
|
|
28
29
|
import { LibP2PService } from '../services/libp2p/libp2p_service.js';
|
|
29
|
-
import { type
|
|
30
|
+
import { type PeerScoring } from '../services/peer-manager/peer_scoring.js';
|
|
30
31
|
import { type P2PReqRespConfig } from '../services/reqresp/config.js';
|
|
31
|
-
import { pingHandler, statusHandler } from '../services/reqresp/handlers.js';
|
|
32
32
|
import {
|
|
33
|
-
|
|
33
|
+
ReqRespSubProtocol,
|
|
34
34
|
type ReqRespSubProtocolHandlers,
|
|
35
35
|
type ReqRespSubProtocolValidators,
|
|
36
|
-
STATUS_PROTOCOL,
|
|
37
|
-
TX_REQ_PROTOCOL,
|
|
38
36
|
noopValidator,
|
|
39
37
|
} from '../services/reqresp/interface.js';
|
|
38
|
+
import { pingHandler, statusHandler } from '../services/reqresp/protocols/index.js';
|
|
40
39
|
import { ReqResp } from '../services/reqresp/reqresp.js';
|
|
41
40
|
import { type PubSubLibp2p } from '../util.js';
|
|
42
41
|
|
|
@@ -151,25 +150,29 @@ export type ReqRespNode = {
|
|
|
151
150
|
|
|
152
151
|
// Mock sub protocol handlers
|
|
153
152
|
export const MOCK_SUB_PROTOCOL_HANDLERS: ReqRespSubProtocolHandlers = {
|
|
154
|
-
[
|
|
155
|
-
[
|
|
156
|
-
[
|
|
153
|
+
[ReqRespSubProtocol.PING]: pingHandler,
|
|
154
|
+
[ReqRespSubProtocol.STATUS]: statusHandler,
|
|
155
|
+
[ReqRespSubProtocol.TX]: (_msg: any) => Promise.resolve(Buffer.from('tx')),
|
|
156
|
+
[ReqRespSubProtocol.GOODBYE]: (_msg: any) => Promise.resolve(Buffer.from('goodbye')),
|
|
157
|
+
[ReqRespSubProtocol.BLOCK]: (_msg: any) => Promise.resolve(Buffer.from('block')),
|
|
157
158
|
};
|
|
158
159
|
|
|
159
160
|
// By default, all requests are valid
|
|
160
161
|
// If you want to test an invalid response, you can override the validator
|
|
161
162
|
export const MOCK_SUB_PROTOCOL_VALIDATORS: ReqRespSubProtocolValidators = {
|
|
162
|
-
[
|
|
163
|
-
[
|
|
164
|
-
[
|
|
163
|
+
[ReqRespSubProtocol.PING]: noopValidator,
|
|
164
|
+
[ReqRespSubProtocol.STATUS]: noopValidator,
|
|
165
|
+
[ReqRespSubProtocol.TX]: noopValidator,
|
|
166
|
+
[ReqRespSubProtocol.GOODBYE]: noopValidator,
|
|
167
|
+
[ReqRespSubProtocol.BLOCK]: noopValidator,
|
|
165
168
|
};
|
|
166
169
|
|
|
167
170
|
/**
|
|
168
171
|
* @param numberOfNodes - the number of nodes to create
|
|
169
172
|
* @returns An array of the created nodes
|
|
170
173
|
*/
|
|
171
|
-
export const createNodes =
|
|
172
|
-
return
|
|
174
|
+
export const createNodes = (peerScoring: PeerScoring, numberOfNodes: number): Promise<ReqRespNode[]> => {
|
|
175
|
+
return timesParallel(numberOfNodes, () => createReqResp(peerScoring));
|
|
173
176
|
};
|
|
174
177
|
|
|
175
178
|
export const startNodes = async (
|
|
@@ -183,22 +186,18 @@ export const startNodes = async (
|
|
|
183
186
|
};
|
|
184
187
|
|
|
185
188
|
export const stopNodes = async (nodes: ReqRespNode[]): Promise<void> => {
|
|
186
|
-
const stopPromises = [];
|
|
187
|
-
for (const node of nodes) {
|
|
188
|
-
stopPromises.push(node.req.stop());
|
|
189
|
-
stopPromises.push(node.p2p.stop());
|
|
190
|
-
}
|
|
189
|
+
const stopPromises = nodes.flatMap(node => [node.req.stop(), node.p2p.stop()]);
|
|
191
190
|
await Promise.all(stopPromises);
|
|
192
191
|
};
|
|
193
192
|
|
|
194
193
|
// Create a req resp node, exposing the underlying p2p node
|
|
195
|
-
export const createReqResp = async (
|
|
194
|
+
export const createReqResp = async (peerScoring: PeerScoring): Promise<ReqRespNode> => {
|
|
196
195
|
const p2p = await createLibp2pNode();
|
|
197
196
|
const config: P2PReqRespConfig = {
|
|
198
197
|
overallRequestTimeoutMs: 4000,
|
|
199
198
|
individualRequestTimeoutMs: 2000,
|
|
200
199
|
};
|
|
201
|
-
const req = new ReqResp(config, p2p,
|
|
200
|
+
const req = new ReqResp(config, p2p, peerScoring);
|
|
202
201
|
return {
|
|
203
202
|
p2p,
|
|
204
203
|
req,
|
|
@@ -16,7 +16,7 @@ export class AttestationValidator implements P2PValidator<BlockAttestation> {
|
|
|
16
16
|
return PeerErrorSeverity.HighToleranceError;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const attester = message.getSender();
|
|
19
|
+
const attester = await message.getSender();
|
|
20
20
|
if (!(await this.epochCache.isInCommittee(attester))) {
|
|
21
21
|
return PeerErrorSeverity.HighToleranceError;
|
|
22
22
|
}
|
|
@@ -19,7 +19,7 @@ export class BlockProposalValidator implements P2PValidator<BlockProposal> {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
// Check that the block proposal is from the current or next proposer
|
|
22
|
-
const proposer = block.getSender();
|
|
22
|
+
const proposer = await block.getSender();
|
|
23
23
|
if (!proposer.equals(currentProposer) && !proposer.equals(nextProposer)) {
|
|
24
24
|
return PeerErrorSeverity.HighToleranceError;
|
|
25
25
|
}
|
|
@@ -15,9 +15,9 @@ export class BlockHeaderTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
async validateTx(tx: T): Promise<TxValidationResult> {
|
|
18
|
-
const [index] = await this.#archiveSource.getArchiveIndices([tx.data.constants.historicalHeader.hash()]);
|
|
18
|
+
const [index] = await this.#archiveSource.getArchiveIndices([await tx.data.constants.historicalHeader.hash()]);
|
|
19
19
|
if (index === undefined) {
|
|
20
|
-
this.#log.warn(`Rejecting tx ${Tx.getHash(tx)} for referencing an unknown block header`);
|
|
20
|
+
this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for referencing an unknown block header`);
|
|
21
21
|
return { result: 'invalid', reason: ['Block header not found'] };
|
|
22
22
|
}
|
|
23
23
|
return { result: 'valid' };
|
|
@@ -5,10 +5,10 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
5
5
|
#log = createLogger('p2p:tx_validator:tx_data');
|
|
6
6
|
|
|
7
7
|
validateTx(tx: Tx): Promise<TxValidationResult> {
|
|
8
|
-
return
|
|
8
|
+
return this.#hasCorrectExecutionRequests(tx);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
#hasCorrectExecutionRequests(tx: Tx): TxValidationResult {
|
|
11
|
+
async #hasCorrectExecutionRequests(tx: Tx): Promise<TxValidationResult> {
|
|
12
12
|
const callRequests = [
|
|
13
13
|
...tx.data.getRevertiblePublicCallRequests(),
|
|
14
14
|
...tx.data.getNonRevertiblePublicCallRequests(),
|
|
@@ -21,13 +21,16 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
21
21
|
);
|
|
22
22
|
return { result: 'invalid', reason: ['Wrong number of execution requests for public calls'] };
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const invalidExecutionRequestIndex = (
|
|
25
|
+
await Promise.all(
|
|
26
|
+
tx.enqueuedPublicFunctionCalls.map(
|
|
27
|
+
async (execRequest, i) => !(await execRequest.isForCallRequest(callRequests[i])),
|
|
28
|
+
),
|
|
29
|
+
)
|
|
30
|
+
).findIndex(Boolean);
|
|
28
31
|
if (invalidExecutionRequestIndex !== -1) {
|
|
29
32
|
this.#log.warn(
|
|
30
|
-
`Rejecting tx ${Tx.getHash(
|
|
33
|
+
`Rejecting tx ${await Tx.getHash(
|
|
31
34
|
tx,
|
|
32
35
|
)} because of incorrect execution requests for public call at index ${invalidExecutionRequestIndex}.`,
|
|
33
36
|
);
|
|
@@ -37,9 +40,9 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
37
40
|
const teardownCallRequest = tx.data.getTeardownPublicCallRequest();
|
|
38
41
|
const isInvalidTeardownExecutionRequest =
|
|
39
42
|
(!teardownCallRequest && !tx.publicTeardownFunctionCall.isEmpty()) ||
|
|
40
|
-
(teardownCallRequest && !tx.publicTeardownFunctionCall.isForCallRequest(teardownCallRequest));
|
|
43
|
+
(teardownCallRequest && !(await tx.publicTeardownFunctionCall.isForCallRequest(teardownCallRequest)));
|
|
41
44
|
if (isInvalidTeardownExecutionRequest) {
|
|
42
|
-
this.#log.warn(`Rejecting tx ${Tx.getHash(tx)} because of incorrect teardown execution requests.`);
|
|
45
|
+
this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} because of incorrect teardown execution requests.`);
|
|
43
46
|
return { result: 'invalid', reason: ['Incorrect teardown execution request'] };
|
|
44
47
|
}
|
|
45
48
|
|
|
@@ -19,12 +19,12 @@ export class DoubleSpendTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
19
19
|
// Ditch this tx if it has repeated nullifiers
|
|
20
20
|
const uniqueNullifiers = new Set(nullifiers);
|
|
21
21
|
if (uniqueNullifiers.size !== nullifiers.length) {
|
|
22
|
-
this.#log.warn(`Rejecting tx ${Tx.getHash(tx)} for emitting duplicate nullifiers`);
|
|
22
|
+
this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for emitting duplicate nullifiers`);
|
|
23
23
|
return { result: 'invalid', reason: ['Duplicate nullifier in tx'] };
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
if ((await this.#nullifierSource.nullifiersExist(nullifiers.map(n => n.toBuffer()))).some(Boolean)) {
|
|
27
|
-
this.#log.warn(`Rejecting tx ${Tx.getHash(tx)} for repeating a nullifier`);
|
|
27
|
+
this.#log.warn(`Rejecting tx ${await Tx.getHash(tx)} for repeating a nullifier`);
|
|
28
28
|
return { result: 'invalid', reason: ['Existing nullifier'] };
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -7,21 +7,21 @@ export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
7
7
|
|
|
8
8
|
constructor(private chainId: Fr, private blockNumber: Fr) {}
|
|
9
9
|
|
|
10
|
-
validateTx(tx: T): Promise<TxValidationResult> {
|
|
10
|
+
async validateTx(tx: T): Promise<TxValidationResult> {
|
|
11
11
|
const errors = [];
|
|
12
|
-
if (!this.#hasCorrectChainId(tx)) {
|
|
12
|
+
if (!(await this.#hasCorrectChainId(tx))) {
|
|
13
13
|
errors.push('Incorrect chain id');
|
|
14
14
|
}
|
|
15
|
-
if (!this.#isValidForBlockNumber(tx)) {
|
|
15
|
+
if (!(await this.#isValidForBlockNumber(tx))) {
|
|
16
16
|
errors.push('Invalid block number');
|
|
17
17
|
}
|
|
18
|
-
return
|
|
18
|
+
return errors.length > 0 ? { result: 'invalid', reason: errors } : { result: 'valid' };
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
#hasCorrectChainId(tx: T): boolean {
|
|
21
|
+
async #hasCorrectChainId(tx: T): Promise<boolean> {
|
|
22
22
|
if (!tx.data.constants.txContext.chainId.equals(this.chainId)) {
|
|
23
23
|
this.#log.warn(
|
|
24
|
-
`Rejecting tx ${Tx.getHash(
|
|
24
|
+
`Rejecting tx ${await Tx.getHash(
|
|
25
25
|
tx,
|
|
26
26
|
)} because of incorrect chain ${tx.data.constants.txContext.chainId.toNumber()} != ${this.chainId.toNumber()}`,
|
|
27
27
|
);
|
|
@@ -31,12 +31,12 @@ export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
#isValidForBlockNumber(tx: T): boolean {
|
|
34
|
+
async #isValidForBlockNumber(tx: T): Promise<boolean> {
|
|
35
35
|
const maxBlockNumber = tx.data.rollupValidationRequests.maxBlockNumber;
|
|
36
36
|
|
|
37
37
|
if (maxBlockNumber.isSome && maxBlockNumber.value < this.blockNumber) {
|
|
38
38
|
this.#log.warn(
|
|
39
|
-
`Rejecting tx ${Tx.getHash(tx)} for low max block number. Tx max block number: ${
|
|
39
|
+
`Rejecting tx ${await Tx.getHash(tx)} for low max block number. Tx max block number: ${
|
|
40
40
|
maxBlockNumber.value
|
|
41
41
|
}, current block number: ${this.blockNumber}.`,
|
|
42
42
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { filter, map, sort, take } from '@aztec/foundation/iterable';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
3
3
|
|
|
4
4
|
import { type Batch, type Datastore, Key, type KeyQuery, type Pair, type Query } from 'interface-datastore';
|
|
5
5
|
import type { AwaitIterable } from 'interface-store';
|
|
@@ -25,31 +25,31 @@ class KeyNotFoundError extends Error {
|
|
|
25
25
|
|
|
26
26
|
export class AztecDatastore implements Datastore {
|
|
27
27
|
#memoryDatastore: Map<string, MemoryItem>;
|
|
28
|
-
#dbDatastore:
|
|
28
|
+
#dbDatastore: AztecAsyncMap<string, Uint8Array>;
|
|
29
29
|
|
|
30
30
|
#batchOps: BatchOp[] = [];
|
|
31
31
|
|
|
32
32
|
private maxMemoryItems: number;
|
|
33
33
|
|
|
34
|
-
constructor(db:
|
|
34
|
+
constructor(db: AztecAsyncKVStore, { maxMemoryItems } = { maxMemoryItems: 50 }) {
|
|
35
35
|
this.#memoryDatastore = new Map();
|
|
36
36
|
this.#dbDatastore = db.openMap('p2p_datastore');
|
|
37
37
|
|
|
38
38
|
this.maxMemoryItems = maxMemoryItems;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
has(key: Key): boolean {
|
|
42
|
-
return this.#memoryDatastore.has(key.toString()) || this.#dbDatastore.
|
|
41
|
+
async has(key: Key): Promise<boolean> {
|
|
42
|
+
return this.#memoryDatastore.has(key.toString()) || (await this.#dbDatastore.hasAsync(key.toString()));
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
get(key: Key): Uint8Array {
|
|
45
|
+
async get(key: Key): Promise<Uint8Array> {
|
|
46
46
|
const keyStr = key.toString();
|
|
47
47
|
const memoryItem = this.#memoryDatastore.get(keyStr);
|
|
48
48
|
if (memoryItem) {
|
|
49
49
|
memoryItem.lastAccessedMs = Date.now();
|
|
50
50
|
return memoryItem.data;
|
|
51
51
|
}
|
|
52
|
-
const dbItem = this.#dbDatastore.
|
|
52
|
+
const dbItem = await this.#dbDatastore.getAsync(keyStr);
|
|
53
53
|
|
|
54
54
|
if (!dbItem) {
|
|
55
55
|
throw new KeyNotFoundError(`Key not found`);
|
|
@@ -73,7 +73,7 @@ export class AztecDatastore implements Datastore {
|
|
|
73
73
|
for await (const key of source) {
|
|
74
74
|
yield {
|
|
75
75
|
key,
|
|
76
|
-
value: this.get(key),
|
|
76
|
+
value: await this.get(key),
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -202,7 +202,7 @@ export class AztecDatastore implements Datastore {
|
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
for (const [key, value] of this.#dbDatastore.
|
|
205
|
+
for await (const [key, value] of this.#dbDatastore.entriesAsync()) {
|
|
206
206
|
if (!this.#memoryDatastore.has(key)) {
|
|
207
207
|
yield {
|
|
208
208
|
key: new Key(key),
|
|
@@ -61,6 +61,19 @@ export class DummyP2PService implements P2PService {
|
|
|
61
61
|
return Promise.resolve(undefined);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Sends a batch request to a peer.
|
|
66
|
+
* @param _protocol - The protocol to send the request on.
|
|
67
|
+
* @param _requests - The requests to send.
|
|
68
|
+
* @returns The responses from the peer, otherwise undefined.
|
|
69
|
+
*/
|
|
70
|
+
public sendBatchRequest<Protocol extends ReqRespSubProtocol>(
|
|
71
|
+
_protocol: Protocol,
|
|
72
|
+
_requests: InstanceType<SubProtocolMap[Protocol]['request']>[],
|
|
73
|
+
): Promise<InstanceType<SubProtocolMap[Protocol]['response']>[]> {
|
|
74
|
+
return Promise.resolve([]);
|
|
75
|
+
}
|
|
76
|
+
|
|
64
77
|
/**
|
|
65
78
|
* Returns the ENR of the peer.
|
|
66
79
|
* @returns The ENR of the peer, otherwise undefined.
|