@aztec/p2p 0.86.0 → 0.87.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.map +1 -1
- package/dest/client/factory.d.ts +4 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +16 -14
- package/dest/client/index.d.ts +1 -0
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +155 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +26 -164
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +185 -114
- package/dest/config.d.ts +5 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +6 -11
- package/dest/enr/generate-enr.d.ts +9 -1
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +24 -2
- package/dest/index.d.ts +1 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +2 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +4 -4
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +1 -0
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +8 -2
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +1 -0
- 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 -2
- 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/tx_pool/aztec_kv_tx_pool.d.ts +4 -0
- 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 +50 -14
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +3 -0
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +9 -0
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +9 -0
- 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 +13 -5
- package/dest/msg_validators/attestation_validator/attestation_validator.js +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +15 -14
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +0 -2
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +2 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +14 -0
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/factory.js +62 -0
- package/dest/msg_validators/tx_validator/gas_validator.js +3 -3
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +8 -4
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +35 -17
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +1 -1
- package/dest/services/discv5/discV5_service.d.ts +2 -2
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +9 -13
- package/dest/services/dummy_service.d.ts +3 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +6 -1
- package/dest/services/encoding.d.ts +1 -3
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.d.ts +4 -2
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +94 -88
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +11 -2
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -2
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +41 -21
- package/dest/services/reqresp/interface.d.ts +1 -3
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.d.ts +0 -2
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.js +1 -1
- package/dest/services/reqresp/protocols/ping.d.ts +0 -2
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +0 -2
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.d.ts +1 -3
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +13 -10
- package/dest/services/service.d.ts +4 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +2 -2
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +11 -6
- package/dest/testbench/testbench.js +1 -1
- package/dest/testbench/worker_client_manager.d.ts +0 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +2 -2
- package/dest/types/index.d.ts +1 -0
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +1 -0
- package/dest/versioning.d.ts +2 -2
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +6 -1
- package/package.json +15 -15
- package/src/bootstrap/bootstrap.ts +1 -1
- package/src/client/factory.ts +38 -33
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +186 -0
- package/src/client/p2p_client.ts +226 -287
- package/src/config.ts +11 -18
- package/src/enr/generate-enr.ts +35 -3
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +3 -0
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +4 -4
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +11 -4
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +10 -3
- package/src/mem_pools/attestation_pool/mocks.ts +2 -2
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +79 -34
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +16 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +12 -0
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +9 -3
- 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 +1 -1
- package/src/msg_validators/tx_validator/data_validator.ts +24 -18
- package/src/msg_validators/tx_validator/double_spend_validator.ts +2 -2
- package/src/msg_validators/tx_validator/factory.ts +94 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +3 -3
- package/src/msg_validators/tx_validator/metadata_validator.ts +50 -14
- package/src/msg_validators/tx_validator/phases_validator.ts +6 -2
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +1 -1
- package/src/services/discv5/discV5_service.ts +14 -12
- package/src/services/dummy_service.ts +8 -2
- package/src/services/libp2p/libp2p_service.ts +102 -111
- package/src/services/peer-manager/metrics.ts +4 -1
- package/src/services/peer-manager/peer_manager.ts +18 -1
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +5 -1
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +42 -19
- package/src/services/reqresp/metrics.ts +4 -1
- package/src/services/reqresp/protocols/goodbye.ts +1 -1
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +4 -1
- package/src/services/reqresp/reqresp.ts +12 -12
- package/src/services/service.ts +7 -1
- package/src/test-helpers/make-test-p2p-clients.ts +2 -1
- package/src/test-helpers/reqresp-nodes.ts +1 -1
- package/src/testbench/p2p_client_testbench_worker.ts +10 -4
- package/src/testbench/testbench.ts +1 -1
- package/src/testbench/worker_client_manager.ts +2 -2
- package/src/types/index.ts +1 -0
- package/src/versioning.ts +8 -1
|
@@ -26,7 +26,7 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
26
26
|
async #hasCorrectCalldata(tx: Tx): Promise<TxValidationResult> {
|
|
27
27
|
if (tx.publicFunctionCalldata.length !== tx.numberOfPublicCalls()) {
|
|
28
28
|
const reason = TX_ERROR_CALLDATA_COUNT_MISMATCH;
|
|
29
|
-
this.#log.
|
|
29
|
+
this.#log.verbose(
|
|
30
30
|
`Rejecting tx ${await Tx.getHash(tx)}. Reason: ${reason}. Expected ${tx.numberOfPublicCalls()}. Got ${
|
|
31
31
|
tx.publicFunctionCalldata.length
|
|
32
32
|
}.`,
|
|
@@ -36,7 +36,7 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
36
36
|
|
|
37
37
|
if (tx.getTotalPublicCalldataCount() > MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS) {
|
|
38
38
|
const reason = TX_ERROR_CALLDATA_COUNT_TOO_LARGE;
|
|
39
|
-
this.#log.
|
|
39
|
+
this.#log.verbose(
|
|
40
40
|
`Rejecting tx ${await Tx.getHash(
|
|
41
41
|
tx,
|
|
42
42
|
)}. Reason: ${reason}. Expected no greater than ${MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS} fields. Got ${tx.getTotalPublicCalldataCount()}.`,
|
|
@@ -50,7 +50,7 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
50
50
|
const hash = await computeCalldataHash(calldata);
|
|
51
51
|
if (!hash.equals(request.calldataHash)) {
|
|
52
52
|
const reason = TX_ERROR_INCORRECT_CALLDATA;
|
|
53
|
-
this.#log.
|
|
53
|
+
this.#log.verbose(`Rejecting tx ${await Tx.getHash(tx)}. Reason: ${reason}. Call request index: ${i}.`);
|
|
54
54
|
return { result: 'invalid', reason: [reason] };
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -60,44 +60,50 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
60
60
|
|
|
61
61
|
async #hasCorrectContractClassLogs(tx: Tx): Promise<TxValidationResult> {
|
|
62
62
|
const contractClassLogsHashes = tx.data.getNonEmptyContractClassLogsHashes();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.#log.warn(
|
|
63
|
+
if (contractClassLogsHashes.length !== tx.contractClassLogs.length) {
|
|
64
|
+
this.#log.verbose(
|
|
66
65
|
`Rejecting tx ${await Tx.getHash(tx)} because of mismatched number of contract class logs. Expected ${
|
|
67
66
|
contractClassLogsHashes.length
|
|
68
|
-
}. Got ${
|
|
67
|
+
}. Got ${tx.contractClassLogs.length}.`,
|
|
69
68
|
);
|
|
70
69
|
return { result: 'invalid', reason: [TX_ERROR_CONTRACT_CLASS_LOG_COUNT] };
|
|
71
70
|
}
|
|
71
|
+
|
|
72
|
+
const expectedHashes = await Promise.all(tx.contractClassLogs.map(l => l.hash()));
|
|
72
73
|
for (const [i, logHash] of contractClassLogsHashes.entries()) {
|
|
73
|
-
const
|
|
74
|
-
if (!logHash.value.equals(
|
|
75
|
-
if (
|
|
76
|
-
const matchingLogIndex =
|
|
77
|
-
this.#log.
|
|
74
|
+
const hash = expectedHashes[i];
|
|
75
|
+
if (!logHash.value.equals(hash)) {
|
|
76
|
+
if (expectedHashes.some(h => logHash.value.equals(h))) {
|
|
77
|
+
const matchingLogIndex = expectedHashes.findIndex(l => logHash.value.equals(l));
|
|
78
|
+
this.#log.verbose(
|
|
78
79
|
`Rejecting tx ${await Tx.getHash(
|
|
79
80
|
tx,
|
|
80
81
|
)} because of mismatched contract class logs indices. Expected ${i} from the kernel's log hashes. Got ${matchingLogIndex} in the tx.`,
|
|
81
82
|
);
|
|
82
83
|
return { result: 'invalid', reason: [TX_ERROR_CONTRACT_CLASS_LOG_SORTING] };
|
|
83
84
|
} else {
|
|
84
|
-
this.#log.
|
|
85
|
+
this.#log.verbose(
|
|
85
86
|
`Rejecting tx ${await Tx.getHash(tx)} because of mismatched contract class logs. Expected hash ${
|
|
86
87
|
logHash.value
|
|
87
|
-
} from the kernels. Got ${
|
|
88
|
+
} from the kernels. Got ${hash} in the tx.`,
|
|
88
89
|
);
|
|
89
90
|
return { result: 'invalid', reason: [TX_ERROR_CONTRACT_CLASS_LOGS] };
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
|
|
94
|
+
const expectedMinLength = 1 + tx.contractClassLogs[i].fields.findLastIndex(f => !f.isZero());
|
|
95
|
+
if (logHash.logHash.length < expectedMinLength) {
|
|
96
|
+
this.#log.verbose(
|
|
97
|
+
`Rejecting tx ${await Tx.getHash(
|
|
98
|
+
tx,
|
|
99
|
+
)} because of incorrect contract class log length. Expected the length to be at least ${expectedMinLength}. Got ${
|
|
95
100
|
logHash.logHash.length
|
|
96
|
-
}
|
|
101
|
+
}.`,
|
|
97
102
|
);
|
|
98
103
|
return { result: 'invalid', reason: [TX_ERROR_CONTRACT_CLASS_LOG_LENGTH] };
|
|
99
104
|
}
|
|
100
105
|
}
|
|
106
|
+
|
|
101
107
|
return { result: 'valid' };
|
|
102
108
|
}
|
|
103
109
|
}
|
|
@@ -26,12 +26,12 @@ export class DoubleSpendTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
26
26
|
// Ditch this tx if it has repeated nullifiers
|
|
27
27
|
const uniqueNullifiers = new Set(nullifiers);
|
|
28
28
|
if (uniqueNullifiers.size !== nullifiers.length) {
|
|
29
|
-
this.#log.
|
|
29
|
+
this.#log.verbose(`Rejecting tx ${await Tx.getHash(tx)} for emitting duplicate nullifiers`);
|
|
30
30
|
return { result: 'invalid', reason: [TX_ERROR_DUPLICATE_NULLIFIER_IN_TX] };
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
if ((await this.#nullifierSource.nullifiersExist(nullifiers.map(n => n.toBuffer()))).some(Boolean)) {
|
|
34
|
-
this.#log.
|
|
34
|
+
this.#log.verbose(`Rejecting tx ${await Tx.getHash(tx)} for repeating a nullifier`);
|
|
35
35
|
return { result: 'invalid', reason: [TX_ERROR_EXISTING_NULLIFIER] };
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
3
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
4
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
5
|
+
import type { GasFees } from '@aztec/stdlib/gas';
|
|
6
|
+
import type {
|
|
7
|
+
AllowedElement,
|
|
8
|
+
ClientProtocolCircuitVerifier,
|
|
9
|
+
WorldStateSynchronizer,
|
|
10
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
11
|
+
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
12
|
+
import { DatabasePublicStateSource, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
13
|
+
import type { Tx, TxValidationResult } from '@aztec/stdlib/tx';
|
|
14
|
+
|
|
15
|
+
import { ArchiveCache } from './archive_cache.js';
|
|
16
|
+
import { BlockHeaderTxValidator } from './block_header_validator.js';
|
|
17
|
+
import { DataTxValidator } from './data_validator.js';
|
|
18
|
+
import { DoubleSpendTxValidator } from './double_spend_validator.js';
|
|
19
|
+
import { GasTxValidator } from './gas_validator.js';
|
|
20
|
+
import { MetadataTxValidator } from './metadata_validator.js';
|
|
21
|
+
import { PhasesTxValidator } from './phases_validator.js';
|
|
22
|
+
import { TxProofValidator } from './tx_proof_validator.js';
|
|
23
|
+
|
|
24
|
+
export interface MessageValidator {
|
|
25
|
+
validator: {
|
|
26
|
+
validateTx(tx: Tx): Promise<TxValidationResult>;
|
|
27
|
+
};
|
|
28
|
+
severity: PeerErrorSeverity;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function createTxMessageValidators(
|
|
32
|
+
blockNumber: number,
|
|
33
|
+
worldStateSynchronizer: WorldStateSynchronizer,
|
|
34
|
+
gasFees: GasFees,
|
|
35
|
+
l1ChainId: number,
|
|
36
|
+
rollupVersion: number,
|
|
37
|
+
protocolContractTreeRoot: Fr,
|
|
38
|
+
contractDataSource: ContractDataSource,
|
|
39
|
+
proofVerifier: ClientProtocolCircuitVerifier,
|
|
40
|
+
allowedInSetup: AllowedElement[] = [],
|
|
41
|
+
): Record<string, MessageValidator>[] {
|
|
42
|
+
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
43
|
+
|
|
44
|
+
return [
|
|
45
|
+
{
|
|
46
|
+
dataValidator: {
|
|
47
|
+
validator: new DataTxValidator(),
|
|
48
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
49
|
+
},
|
|
50
|
+
metadataValidator: {
|
|
51
|
+
validator: new MetadataTxValidator({
|
|
52
|
+
l1ChainId: new Fr(l1ChainId),
|
|
53
|
+
rollupVersion: new Fr(rollupVersion),
|
|
54
|
+
blockNumber: new Fr(blockNumber),
|
|
55
|
+
protocolContractTreeRoot,
|
|
56
|
+
vkTreeRoot: getVKTreeRoot(),
|
|
57
|
+
}),
|
|
58
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
59
|
+
},
|
|
60
|
+
doubleSpendValidator: {
|
|
61
|
+
validator: new DoubleSpendTxValidator({
|
|
62
|
+
nullifiersExist: async (nullifiers: Buffer[]) => {
|
|
63
|
+
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
64
|
+
const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
65
|
+
return indices.map(index => index !== undefined);
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
69
|
+
},
|
|
70
|
+
gasValidator: {
|
|
71
|
+
validator: new GasTxValidator(
|
|
72
|
+
new DatabasePublicStateSource(merkleTree),
|
|
73
|
+
ProtocolContractAddress.FeeJuice,
|
|
74
|
+
gasFees,
|
|
75
|
+
),
|
|
76
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
77
|
+
},
|
|
78
|
+
phasesValidator: {
|
|
79
|
+
validator: new PhasesTxValidator(contractDataSource, allowedInSetup, blockNumber),
|
|
80
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
81
|
+
},
|
|
82
|
+
blockHeaderValidator: {
|
|
83
|
+
validator: new BlockHeaderTxValidator(new ArchiveCache(merkleTree)),
|
|
84
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
proofValidator: {
|
|
89
|
+
validator: new TxProofValidator(proofVerifier),
|
|
90
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
}
|
|
@@ -55,7 +55,7 @@ export class GasTxValidator implements TxValidator<Tx> {
|
|
|
55
55
|
maxFeesPerGas.feePerL2Gas.lt(this.#gasFees.feePerL2Gas);
|
|
56
56
|
|
|
57
57
|
if (notEnoughMaxFees) {
|
|
58
|
-
this.#log.
|
|
58
|
+
this.#log.verbose(`Skipping transaction ${await tx.getTxHash()} due to insufficient fee per gas`, {
|
|
59
59
|
txMaxFeesPerGas: maxFeesPerGas.toInspect(),
|
|
60
60
|
currentGasFees: this.#gasFees.toInspect(),
|
|
61
61
|
});
|
|
@@ -71,7 +71,7 @@ export class GasTxValidator implements TxValidator<Tx> {
|
|
|
71
71
|
const minGasLimits = new Gas(FIXED_DA_GAS, FIXED_L2_GAS);
|
|
72
72
|
|
|
73
73
|
if (minGasLimits.gtAny(gasLimits)) {
|
|
74
|
-
this.#log.
|
|
74
|
+
this.#log.verbose(`Rejecting transaction due to the gas limit(s) not being above the minimum gas limit`, {
|
|
75
75
|
gasLimits,
|
|
76
76
|
minGasLimits,
|
|
77
77
|
});
|
|
@@ -113,7 +113,7 @@ export class GasTxValidator implements TxValidator<Tx> {
|
|
|
113
113
|
|
|
114
114
|
const balance = claimFunctionCall ? initialBalance.add(claimFunctionCall.args[1]) : initialBalance;
|
|
115
115
|
if (balance.lt(feeLimit)) {
|
|
116
|
-
this.#log.
|
|
116
|
+
this.#log.verbose(`Rejecting transaction due to not enough fee payer balance`, {
|
|
117
117
|
feePayer,
|
|
118
118
|
balance: balance.toBigInt(),
|
|
119
119
|
feeLimit: feeLimit.toBigInt(),
|
|
@@ -2,8 +2,10 @@ import type { Fr } from '@aztec/foundation/fields';
|
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import {
|
|
4
4
|
type AnyTx,
|
|
5
|
-
|
|
5
|
+
TX_ERROR_INCORRECT_L1_CHAIN_ID,
|
|
6
|
+
TX_ERROR_INCORRECT_PROTOCOL_CONTRACT_TREE_ROOT,
|
|
6
7
|
TX_ERROR_INCORRECT_ROLLUP_VERSION,
|
|
8
|
+
TX_ERROR_INCORRECT_VK_TREE_ROOT,
|
|
7
9
|
TX_ERROR_INVALID_BLOCK_NUMBER,
|
|
8
10
|
Tx,
|
|
9
11
|
type TxValidationResult,
|
|
@@ -13,12 +15,14 @@ import {
|
|
|
13
15
|
export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
14
16
|
#log = createLogger('p2p:tx_validator:tx_metadata');
|
|
15
17
|
|
|
16
|
-
constructor(
|
|
18
|
+
constructor(
|
|
19
|
+
private values: { l1ChainId: Fr; rollupVersion: Fr; blockNumber: Fr; vkTreeRoot: Fr; protocolContractTreeRoot: Fr },
|
|
20
|
+
) {}
|
|
17
21
|
|
|
18
22
|
async validateTx(tx: T): Promise<TxValidationResult> {
|
|
19
23
|
const errors = [];
|
|
20
|
-
if (!(await this.#
|
|
21
|
-
errors.push(
|
|
24
|
+
if (!(await this.#hasCorrectL1ChainId(tx))) {
|
|
25
|
+
errors.push(TX_ERROR_INCORRECT_L1_CHAIN_ID);
|
|
22
26
|
}
|
|
23
27
|
if (!(await this.#hasCorrectRollupVersion(tx))) {
|
|
24
28
|
errors.push(TX_ERROR_INCORRECT_ROLLUP_VERSION);
|
|
@@ -26,15 +30,47 @@ export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
26
30
|
if (!(await this.#isValidForBlockNumber(tx))) {
|
|
27
31
|
errors.push(TX_ERROR_INVALID_BLOCK_NUMBER);
|
|
28
32
|
}
|
|
33
|
+
if (!(await this.#hasCorrectVkTreeRoot(tx))) {
|
|
34
|
+
errors.push(TX_ERROR_INCORRECT_VK_TREE_ROOT);
|
|
35
|
+
}
|
|
36
|
+
if (!(await this.#hasCorrectProtocolContractTreeRoot(tx))) {
|
|
37
|
+
errors.push(TX_ERROR_INCORRECT_PROTOCOL_CONTRACT_TREE_ROOT);
|
|
38
|
+
}
|
|
29
39
|
return errors.length > 0 ? { result: 'invalid', reason: errors } : { result: 'valid' };
|
|
30
40
|
}
|
|
31
41
|
|
|
32
|
-
async #
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
async #hasCorrectVkTreeRoot(tx: T): Promise<boolean> {
|
|
43
|
+
// This gets implicitly tested in the proof validator, but we can get a much cheaper check here by looking early at the vk.
|
|
44
|
+
if (!tx.data.constants.vkTreeRoot.equals(this.values.vkTreeRoot)) {
|
|
45
|
+
this.#log.verbose(
|
|
46
|
+
`Rejecting tx ${await Tx.getHash(
|
|
47
|
+
tx,
|
|
48
|
+
)} because of incorrect vk tree root ${tx.data.constants.vkTreeRoot.toString()} != ${this.values.vkTreeRoot.toString()}`,
|
|
49
|
+
);
|
|
50
|
+
return false;
|
|
51
|
+
} else {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async #hasCorrectProtocolContractTreeRoot(tx: T): Promise<boolean> {
|
|
57
|
+
if (!tx.data.constants.protocolContractTreeRoot.equals(this.values.protocolContractTreeRoot)) {
|
|
58
|
+
this.#log.verbose(
|
|
59
|
+
`Rejecting tx ${await Tx.getHash(
|
|
60
|
+
tx,
|
|
61
|
+
)} because of incorrect protocol contract tree root ${tx.data.constants.protocolContractTreeRoot.toString()} != ${this.values.protocolContractTreeRoot.toString()}`,
|
|
62
|
+
);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async #hasCorrectL1ChainId(tx: T): Promise<boolean> {
|
|
69
|
+
if (!tx.data.constants.txContext.chainId.equals(this.values.l1ChainId)) {
|
|
70
|
+
this.#log.verbose(
|
|
35
71
|
`Rejecting tx ${await Tx.getHash(
|
|
36
72
|
tx,
|
|
37
|
-
)} because of incorrect chain ${tx.data.constants.txContext.chainId.toNumber()} != ${this.
|
|
73
|
+
)} because of incorrect L1 chain ${tx.data.constants.txContext.chainId.toNumber()} != ${this.values.l1ChainId.toNumber()}`,
|
|
38
74
|
);
|
|
39
75
|
return false;
|
|
40
76
|
} else {
|
|
@@ -45,11 +81,11 @@ export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
45
81
|
async #isValidForBlockNumber(tx: T): Promise<boolean> {
|
|
46
82
|
const maxBlockNumber = tx.data.rollupValidationRequests.maxBlockNumber;
|
|
47
83
|
|
|
48
|
-
if (maxBlockNumber.isSome && maxBlockNumber.value < this.blockNumber) {
|
|
49
|
-
this.#log.
|
|
84
|
+
if (maxBlockNumber.isSome && maxBlockNumber.value < this.values.blockNumber) {
|
|
85
|
+
this.#log.verbose(
|
|
50
86
|
`Rejecting tx ${await Tx.getHash(tx)} for low max block number. Tx max block number: ${
|
|
51
87
|
maxBlockNumber.value
|
|
52
|
-
}, current block number: ${this.blockNumber}.`,
|
|
88
|
+
}, current block number: ${this.values.blockNumber}.`,
|
|
53
89
|
);
|
|
54
90
|
return false;
|
|
55
91
|
} else {
|
|
@@ -58,11 +94,11 @@ export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
58
94
|
}
|
|
59
95
|
|
|
60
96
|
async #hasCorrectRollupVersion(tx: T): Promise<boolean> {
|
|
61
|
-
if (!tx.data.constants.txContext.version.equals(this.rollupVersion)) {
|
|
62
|
-
this.#log.
|
|
97
|
+
if (!tx.data.constants.txContext.version.equals(this.values.rollupVersion)) {
|
|
98
|
+
this.#log.verbose(
|
|
63
99
|
`Rejecting tx ${await Tx.getHash(
|
|
64
100
|
tx,
|
|
65
|
-
)} because of incorrect rollup version ${tx.data.constants.txContext.version.toNumber()} != ${this.rollupVersion.toNumber()}`,
|
|
101
|
+
)} because of incorrect rollup version ${tx.data.constants.txContext.version.toNumber()} != ${this.values.rollupVersion.toNumber()}`,
|
|
66
102
|
);
|
|
67
103
|
return false;
|
|
68
104
|
} else {
|
|
@@ -16,7 +16,11 @@ export class PhasesTxValidator implements TxValidator<Tx> {
|
|
|
16
16
|
#log = createLogger('sequencer:tx_validator:tx_phases');
|
|
17
17
|
private contractsDB: PublicContractsDB;
|
|
18
18
|
|
|
19
|
-
constructor(
|
|
19
|
+
constructor(
|
|
20
|
+
contracts: ContractDataSource,
|
|
21
|
+
private setupAllowList: AllowedElement[],
|
|
22
|
+
private blockNumber: number,
|
|
23
|
+
) {
|
|
20
24
|
this.contractsDB = new PublicContractsDB(contracts);
|
|
21
25
|
}
|
|
22
26
|
|
|
@@ -37,7 +41,7 @@ export class PhasesTxValidator implements TxValidator<Tx> {
|
|
|
37
41
|
const setupFns = getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP);
|
|
38
42
|
for (const setupFn of setupFns) {
|
|
39
43
|
if (!(await this.isOnAllowList(setupFn, this.setupAllowList))) {
|
|
40
|
-
this.#log.
|
|
44
|
+
this.#log.verbose(
|
|
41
45
|
`Rejecting tx ${await Tx.getHash(tx)} because it calls setup function not on allow list: ${
|
|
42
46
|
setupFn.request.contractAddress
|
|
43
47
|
}:${setupFn.functionSelector}`,
|
|
@@ -9,7 +9,7 @@ export class TxProofValidator implements TxValidator<Tx> {
|
|
|
9
9
|
|
|
10
10
|
async validateTx(tx: Tx): Promise<TxValidationResult> {
|
|
11
11
|
if (!(await this.verifier.verifyProof(tx))) {
|
|
12
|
-
this.#log.
|
|
12
|
+
this.#log.verbose(`Rejecting tx ${await Tx.getHash(tx)} for invalid proof`);
|
|
13
13
|
return { result: 'invalid', reason: [TX_ERROR_INVALID_PROOF] };
|
|
14
14
|
}
|
|
15
15
|
this.#log.trace(`Accepted ${await Tx.getHash(tx)} with valid proof`);
|
|
@@ -10,9 +10,9 @@ import { type Multiaddr, multiaddr } from '@multiformats/multiaddr';
|
|
|
10
10
|
import EventEmitter from 'events';
|
|
11
11
|
|
|
12
12
|
import type { P2PConfig } from '../../config.js';
|
|
13
|
+
import { createNodeENR } from '../../enr/generate-enr.js';
|
|
13
14
|
import { AZTEC_ENR_KEY, Discv5Event, PeerEvent } from '../../types/index.js';
|
|
14
15
|
import { convertToMultiaddr } from '../../util.js';
|
|
15
|
-
import { setAztecEnrKey } from '../../versioning.js';
|
|
16
16
|
import { type PeerDiscoveryService, PeerDiscoveryState } from '../service.js';
|
|
17
17
|
|
|
18
18
|
const delayBeforeStart = 2000; // 2sec
|
|
@@ -22,7 +22,7 @@ const delayBeforeStart = 2000; // 2sec
|
|
|
22
22
|
*/
|
|
23
23
|
export class DiscV5Service extends EventEmitter implements PeerDiscoveryService {
|
|
24
24
|
/** The Discv5 instance */
|
|
25
|
-
private discv5:
|
|
25
|
+
private discv5: Discv5EventEmitter;
|
|
26
26
|
|
|
27
27
|
/** This instance's ENR */
|
|
28
28
|
private enr: SignableENR;
|
|
@@ -47,6 +47,7 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
47
47
|
constructor(
|
|
48
48
|
private peerId: PeerId,
|
|
49
49
|
private config: P2PConfig,
|
|
50
|
+
private readonly packageVersion: string,
|
|
50
51
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
51
52
|
private logger = createLogger('p2p:discv5_service'),
|
|
52
53
|
configOverrides: Partial<IDiscv5CreateOptions> = {},
|
|
@@ -57,10 +58,6 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
57
58
|
this.bootstrapNodeEnrs = bootstrapNodes.map(x => ENR.decodeTxt(x));
|
|
58
59
|
const privatePeerEnrs = new Set(privatePeers);
|
|
59
60
|
this.trustedPeerEnrs = trustedPeers.filter(x => !privatePeerEnrs.has(x)).map(x => ENR.decodeTxt(x));
|
|
60
|
-
// create ENR from PeerId
|
|
61
|
-
this.enr = SignableENR.createFromPeerId(peerId);
|
|
62
|
-
// Add aztec identification to ENR
|
|
63
|
-
this.versions = setAztecEnrKey(this.enr, config);
|
|
64
61
|
|
|
65
62
|
// If no overridden broadcast port is provided, use the p2p port as the broadcast port
|
|
66
63
|
if (!p2pBroadcastPort) {
|
|
@@ -72,19 +69,24 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
72
69
|
ip4: multiaddr(convertToMultiaddr(config.listenAddress, p2pPort, 'udp')),
|
|
73
70
|
};
|
|
74
71
|
|
|
72
|
+
let multiAddrUdp, multiAddrTcp;
|
|
75
73
|
if (p2pIp) {
|
|
76
|
-
|
|
74
|
+
multiAddrTcp = multiaddr(
|
|
77
75
|
`${convertToMultiaddr(p2pIp!, config.p2pBroadcastPort!, 'tcp')}/p2p/${peerId.toString()}`,
|
|
78
76
|
);
|
|
79
|
-
|
|
77
|
+
multiAddrUdp = multiaddr(
|
|
80
78
|
`${convertToMultiaddr(p2pIp!, config.p2pBroadcastPort!, 'udp')}/p2p/${peerId.toString()}`,
|
|
81
79
|
);
|
|
82
|
-
|
|
83
|
-
// set location multiaddr in ENR record
|
|
84
|
-
this.enr.setLocationMultiaddr(multiAddrUdp);
|
|
85
|
-
this.enr.setLocationMultiaddr(multiAddrTcp);
|
|
86
80
|
}
|
|
87
81
|
|
|
82
|
+
({ enr: this.enr, versions: this.versions } = createNodeENR(
|
|
83
|
+
peerId,
|
|
84
|
+
multiAddrUdp,
|
|
85
|
+
multiAddrTcp,
|
|
86
|
+
config,
|
|
87
|
+
this.packageVersion,
|
|
88
|
+
));
|
|
89
|
+
|
|
88
90
|
const metricsRegistry = new OtelMetricsAdapter(telemetry);
|
|
89
91
|
this.discv5 = Discv5.create({
|
|
90
92
|
enr: this.enr,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
2
2
|
import type { BlockAttestation, BlockProposal, Gossipable } from '@aztec/stdlib/p2p';
|
|
3
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
3
|
+
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
import type { ENR } from '@chainsafe/enr';
|
|
6
6
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -38,7 +38,9 @@ export class DummyP2PService implements P2PService {
|
|
|
38
38
|
* Called to have the given message propagated through the P2P network.
|
|
39
39
|
* @param _ - The message to be propagated.
|
|
40
40
|
*/
|
|
41
|
-
public propagate<T extends Gossipable>(_: T) {
|
|
41
|
+
public propagate<T extends Gossipable>(_: T) {
|
|
42
|
+
return Promise.resolve();
|
|
43
|
+
}
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
46
|
* Called upon receipt of settled transactions.
|
|
@@ -84,6 +86,10 @@ export class DummyP2PService implements P2PService {
|
|
|
84
86
|
public getEnr(): undefined {
|
|
85
87
|
return undefined;
|
|
86
88
|
}
|
|
89
|
+
|
|
90
|
+
validate(_txs: Tx[]): Promise<void> {
|
|
91
|
+
return Promise.resolve();
|
|
92
|
+
}
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
/**
|