@aztec/p2p 0.83.0 → 0.83.1-nightly.20250404
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/factory.d.ts +2 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +3 -3
- package/dest/client/p2p_client.d.ts +2 -1
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/config.d.ts +16 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +53 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +10 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/gas_validator.js +76 -0
- package/dest/msg_validators/tx_validator/index.d.ts +4 -0
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +4 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +13 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +83 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/test_utils.js +22 -0
- package/dest/services/libp2p/libp2p_service.d.ts +6 -3
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +36 -9
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -2
- package/package.json +12 -10
- package/src/client/factory.ts +4 -3
- package/src/client/p2p_client.ts +2 -1
- package/src/config.ts +64 -1
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +95 -0
- package/src/msg_validators/tx_validator/index.ts +4 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +104 -0
- package/src/msg_validators/tx_validator/test_utils.ts +43 -0
- package/src/services/libp2p/libp2p_service.ts +42 -7
- package/src/test-helpers/reqresp-nodes.ts +3 -2
|
@@ -4,7 +4,10 @@ import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log
|
|
|
4
4
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
5
5
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
6
6
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
7
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
7
8
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
9
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
10
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
8
11
|
import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
9
12
|
import {
|
|
10
13
|
BlockAttestation,
|
|
@@ -16,7 +19,7 @@ import {
|
|
|
16
19
|
getTopicTypeForClientType,
|
|
17
20
|
metricsTopicStrToLabels,
|
|
18
21
|
} from '@aztec/stdlib/p2p';
|
|
19
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
22
|
+
import { DatabasePublicStateSource, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
20
23
|
import { Tx, type TxHash, type TxValidationResult } from '@aztec/stdlib/tx';
|
|
21
24
|
import { Attributes, OtelMetricsAdapter, type TelemetryClient, WithTracer, trackSpan } from '@aztec/telemetry-client';
|
|
22
25
|
|
|
@@ -43,10 +46,13 @@ import { createLibp2p } from 'libp2p';
|
|
|
43
46
|
import type { P2PConfig } from '../../config.js';
|
|
44
47
|
import type { MemPools } from '../../mem_pools/interface.js';
|
|
45
48
|
import { AttestationValidator, BlockProposalValidator } from '../../msg_validators/index.js';
|
|
49
|
+
import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validator/allowed_public_setup.js';
|
|
46
50
|
import {
|
|
47
51
|
DataTxValidator,
|
|
48
52
|
DoubleSpendTxValidator,
|
|
53
|
+
GasTxValidator,
|
|
49
54
|
MetadataTxValidator,
|
|
55
|
+
PhasesTxValidator,
|
|
50
56
|
TxProofValidator,
|
|
51
57
|
} from '../../msg_validators/tx_validator/index.js';
|
|
52
58
|
import { GossipSubEvent } from '../../types/index.js';
|
|
@@ -95,6 +101,8 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
95
101
|
// Trusted peers ids
|
|
96
102
|
private trustedPeersIds: PeerId[] = [];
|
|
97
103
|
|
|
104
|
+
private feesCache: { blockNumber: number; gasFees: GasFees } | undefined;
|
|
105
|
+
|
|
98
106
|
/**
|
|
99
107
|
* Callback for when a block is received from a peer.
|
|
100
108
|
* @param block - The block received from the peer.
|
|
@@ -110,7 +118,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
110
118
|
private node: PubSubLibp2p,
|
|
111
119
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
112
120
|
private mempools: MemPools<T>,
|
|
113
|
-
private
|
|
121
|
+
private archiver: L2BlockSource & ContractDataSource,
|
|
114
122
|
epochCache: EpochCacheInterface,
|
|
115
123
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
116
124
|
private worldStateSynchronizer: WorldStateSynchronizer,
|
|
@@ -164,7 +172,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
164
172
|
peerDiscoveryService: PeerDiscoveryService,
|
|
165
173
|
peerId: PeerId,
|
|
166
174
|
mempools: MemPools<T>,
|
|
167
|
-
l2BlockSource: L2BlockSource,
|
|
175
|
+
l2BlockSource: L2BlockSource & ContractDataSource,
|
|
168
176
|
epochCache: EpochCacheInterface,
|
|
169
177
|
proofVerifier: ClientProtocolCircuitVerifier,
|
|
170
178
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
@@ -322,7 +330,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
322
330
|
// Create request response protocol handlers
|
|
323
331
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
324
332
|
const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
|
|
325
|
-
const blockHandler = reqRespBlockHandler(this.
|
|
333
|
+
const blockHandler = reqRespBlockHandler(this.archiver);
|
|
326
334
|
|
|
327
335
|
const requestResponseHandlers = {
|
|
328
336
|
[ReqRespSubProtocol.PING]: pingHandler,
|
|
@@ -686,8 +694,8 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
686
694
|
[Attributes.TX_HASH]: (await tx.getTxHash()).toString(),
|
|
687
695
|
}))
|
|
688
696
|
private async validatePropagatedTx(tx: Tx, peerId: PeerId): Promise<boolean> {
|
|
689
|
-
const blockNumber = (await this.
|
|
690
|
-
const messageValidators = this.createMessageValidators(blockNumber);
|
|
697
|
+
const blockNumber = (await this.archiver.getBlockNumber()) + 1;
|
|
698
|
+
const messageValidators = await this.createMessageValidators(blockNumber);
|
|
691
699
|
const outcome = await this.runValidations(tx, messageValidators);
|
|
692
700
|
|
|
693
701
|
if (outcome.allPassed) {
|
|
@@ -705,6 +713,17 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
705
713
|
return false;
|
|
706
714
|
}
|
|
707
715
|
|
|
716
|
+
private async getGasFees(blockNumber: number): Promise<GasFees> {
|
|
717
|
+
if (blockNumber === this.feesCache?.blockNumber) {
|
|
718
|
+
return this.feesCache.gasFees;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
const header = await this.archiver.getBlockHeader(blockNumber);
|
|
722
|
+
const gasFees = header?.globalVariables.gasFees ?? GasFees.empty();
|
|
723
|
+
this.feesCache = { blockNumber, gasFees };
|
|
724
|
+
return gasFees;
|
|
725
|
+
}
|
|
726
|
+
|
|
708
727
|
/**
|
|
709
728
|
* Create message validators for the given block number.
|
|
710
729
|
*
|
|
@@ -714,7 +733,11 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
714
733
|
* @param blockNumber - The block number to create validators for.
|
|
715
734
|
* @returns The message validators.
|
|
716
735
|
*/
|
|
717
|
-
private createMessageValidators(blockNumber: number): Record<string, MessageValidator
|
|
736
|
+
private async createMessageValidators(blockNumber: number): Promise<Record<string, MessageValidator>> {
|
|
737
|
+
const merkleTree = this.worldStateSynchronizer.getCommitted();
|
|
738
|
+
const gasFees = await this.getGasFees(blockNumber - 1);
|
|
739
|
+
const allowedInSetup = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
740
|
+
|
|
718
741
|
return {
|
|
719
742
|
dataValidator: {
|
|
720
743
|
validator: new DataTxValidator(),
|
|
@@ -742,6 +765,18 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
742
765
|
}),
|
|
743
766
|
severity: PeerErrorSeverity.HighToleranceError,
|
|
744
767
|
},
|
|
768
|
+
gasValidator: {
|
|
769
|
+
validator: new GasTxValidator(
|
|
770
|
+
new DatabasePublicStateSource(merkleTree),
|
|
771
|
+
ProtocolContractAddress.FeeJuice,
|
|
772
|
+
gasFees,
|
|
773
|
+
),
|
|
774
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
775
|
+
},
|
|
776
|
+
phasesValidator: {
|
|
777
|
+
validator: new PhasesTxValidator(this.archiver, allowedInSetup, blockNumber),
|
|
778
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
779
|
+
},
|
|
745
780
|
};
|
|
746
781
|
}
|
|
747
782
|
|
|
@@ -4,6 +4,7 @@ import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
|
4
4
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
5
5
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
6
6
|
import { type ChainConfig, emptyChainConfig } from '@aztec/stdlib/config';
|
|
7
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
7
8
|
import type { ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
8
9
|
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
9
10
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
@@ -98,7 +99,7 @@ export async function createLibp2pNode(
|
|
|
98
99
|
export async function createTestLibP2PService<T extends P2PClientType>(
|
|
99
100
|
clientType: T,
|
|
100
101
|
boostrapAddrs: string[] = [],
|
|
101
|
-
|
|
102
|
+
archiver: L2BlockSource & ContractDataSource,
|
|
102
103
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
103
104
|
epochCache: EpochCache,
|
|
104
105
|
mempools: MemPools<T>,
|
|
@@ -131,7 +132,7 @@ export async function createTestLibP2PService<T extends P2PClientType>(
|
|
|
131
132
|
p2pNode as PubSubLibp2p,
|
|
132
133
|
discoveryService,
|
|
133
134
|
mempools,
|
|
134
|
-
|
|
135
|
+
archiver,
|
|
135
136
|
epochCache,
|
|
136
137
|
proofVerifier,
|
|
137
138
|
worldStateSynchronizer,
|