@aztec/p2p 0.87.6 → 1.0.0-nightly.20250604
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/interface.d.ts +2 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +3 -3
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +2 -4
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +1 -1
- 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 +1 -1
- 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/data_validator.js +4 -4
- package/dest/services/dummy_service.d.ts +3 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.d.ts +11 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +29 -0
- package/dest/services/libp2p/libp2p_service.d.ts +3 -2
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +41 -26
- package/dest/services/service.d.ts +1 -1
- package/dest/services/service.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +1 -1
- package/package.json +12 -12
- package/src/client/interface.ts +2 -2
- package/src/client/p2p_client.ts +4 -6
- package/src/mem_pools/attestation_pool/attestation_pool.ts +1 -1
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +6 -1
- 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/data_validator.ts +4 -4
- package/src/services/dummy_service.ts +8 -5
- package/src/services/libp2p/instrumentation.ts +39 -0
- package/src/services/libp2p/libp2p_service.ts +56 -28
- package/src/services/service.ts +4 -1
- package/src/testbench/p2p_client_testbench_worker.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { L2BlockId } from '@aztec/stdlib/block';
|
|
2
|
-
import type {
|
|
2
|
+
import type { P2PApiFull } from '@aztec/stdlib/interfaces/server';
|
|
3
3
|
import type { BlockProposal, P2PClientType } from '@aztec/stdlib/p2p';
|
|
4
4
|
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
5
|
import type { ENR } from '@chainsafe/enr';
|
|
@@ -31,7 +31,7 @@ export interface P2PSyncState {
|
|
|
31
31
|
/**
|
|
32
32
|
* Interface of a P2P client.
|
|
33
33
|
**/
|
|
34
|
-
export type P2P<T extends P2PClientType = P2PClientType.Full> =
|
|
34
|
+
export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> & {
|
|
35
35
|
/**
|
|
36
36
|
* Broadcasts a block proposal to other peers.
|
|
37
37
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/client/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/client/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,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,SAAS,CAAC;IAE1B,+BAA+B;IAC/B,WAAW,IAAI,IAAI,CAAC;IAEpB,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3D,8BAA8B;IAC9B,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC,qBAAqB;IACrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,CAAC"}
|
|
@@ -9,7 +9,7 @@ import type { ENR } from '@chainsafe/enr';
|
|
|
9
9
|
import type { PeerId } from '@libp2p/interface';
|
|
10
10
|
import { type P2PConfig } from '../config.js';
|
|
11
11
|
import type { MemPools } from '../mem_pools/interface.js';
|
|
12
|
-
import type { P2PService } from '../services/service.js';
|
|
12
|
+
import type { P2PBlockReceivedCallback, P2PService } from '../services/service.js';
|
|
13
13
|
import { type P2P, type P2PSyncState } from './interface.js';
|
|
14
14
|
/**
|
|
15
15
|
* The P2P client implementation.
|
|
@@ -70,8 +70,8 @@ export declare class P2PClient<T extends P2PClientType = P2PClientType.Full> ext
|
|
|
70
70
|
sync(): Promise<void>;
|
|
71
71
|
broadcastProposal(proposal: BlockProposal): Promise<void>;
|
|
72
72
|
getAttestationsForSlot(slot: bigint, proposalId?: string): Promise<BlockAttestation[]>;
|
|
73
|
-
|
|
74
|
-
registerBlockProposalHandler(handler:
|
|
73
|
+
addAttestations(attestations: BlockAttestation[]): Promise<void>;
|
|
74
|
+
registerBlockProposalHandler(handler: P2PBlockReceivedCallback): void;
|
|
75
75
|
/**
|
|
76
76
|
* Uses the Request Response protocol to request a transaction from the network.
|
|
77
77
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p2p_client.d.ts","sourceRoot":"","sources":["../../src/client/p2p_client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAsC,MAAM,iBAAiB,CAAC;AAC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O,CAAC,IAAI,CAAC;IAK7C;;;;OAIG;IACI,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAIrE,MAAM,IAAI,GAAG,GAAG,SAAS;IAIzB,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAInD;;;;;QAKI;IACS,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzD;;;OAGG;IACI,OAAO;IAId;;;OAGG;IACU,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvD;;;OAGG;IACU,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1C,0BAA0B,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1D,iEAAiE;IACpD,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAInD;;;OAGG;IACU,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC;IAgB/C;;;;OAIG;YACW,wBAAwB;IAOtC;;;;OAIG;YACW,mBAAmB;IAQjC;;;;OAIG;YACW,oBAAoB;IAyBlC,uFAAuF;YACzE,mCAAmC;IAsBjD;;;;OAIG;YACW,uBAAuB;IAkBrC;;;OAGG;YACW,mBAAmB;YAkDnB,qBAAqB;IA0BnC;;;OAGG;IACH,OAAO,CAAC,eAAe;IAMhB,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC;;;OAGG;IACI,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAGhE"}
|
|
@@ -253,10 +253,8 @@ import { P2PClientState } from './interface.js';
|
|
|
253
253
|
async getAttestationsForSlot(slot, proposalId) {
|
|
254
254
|
return await (proposalId ? this.attestationPool?.getAttestationsForSlotAndProposal(slot, proposalId) : this.attestationPool?.getAttestationsForSlot(slot)) ?? [];
|
|
255
255
|
}
|
|
256
|
-
|
|
257
|
-
return this.attestationPool?.addAttestations(
|
|
258
|
-
attestation
|
|
259
|
-
]) ?? Promise.resolve();
|
|
256
|
+
addAttestations(attestations) {
|
|
257
|
+
return this.attestationPool?.addAttestations(attestations) ?? Promise.resolve();
|
|
260
258
|
}
|
|
261
259
|
// REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
262
260
|
// ^ This pattern is not my favorite (md)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aztec_kv_tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/aztec_kv_tx_pool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAA0D,MAAM,iBAAiB,CAAC;AAGjH,OAAO,KAAK,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAIxG,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAInF,OAAO,EAAE,YAAY,EAAE,MAAM,oDAAoD,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AAGpF,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE1D;;GAEG;AACH,qBAAa,aAAc,YAAW,MAAM;;IAS1C,0GAA0G;IAC1G,oBAAoB,EAAE,MAAM,CAAK;IA6CjC;;;;;;;OAOG;gBAED,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,iBAAiB,EAC1B,sBAAsB,EAAE,sBAAsB,EAC9C,SAAS,GAAE,eAAsC,EACjD,MAAM,GAAE,aAAkB,EAC1B,GAAG,SAA8B;IAyBtB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAO3B,WAAW,CAAC,QAAQ,EAAE,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AAO,CAAC,IAAI,CAAC;IAK/D;;;;OAIG;IACH,SAAS,CAAC,oBAAoB,CAAC,EAAE,EAAE,wBAAwB,GAAG,cAAc;IAI5E;;;;OAIG;IACH,SAAS,CAAC,kBAAkB,CAAC,EAAE,EAAE,wBAAwB,GAAG,YAAY;IAIxE;;;;;OAKG;YACW,kBAAkB;IAoBhC;;;;OAIG;YACW,UAAU;IAiCxB;;;;;;OAMG;YACW,mBAAmB;IA8CjC;;;;;;;;;;OAUG;YACW,0BAA0B;IAwDxC;;;;;OAKG;YACW,yBAAyB;YAqCzB,mBAAmB;YAMnB,sBAAsB;YAOtB,sBAAsB;CAOrC"}
|
|
@@ -379,7 +379,7 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
379
379
|
}
|
|
380
380
|
tailIdx++;
|
|
381
381
|
}
|
|
382
|
-
const archivedTx = new Tx(tx.data, ClientIvcProof.empty(), tx.
|
|
382
|
+
const archivedTx = new Tx(tx.data, ClientIvcProof.empty(), tx.contractClassLogFields, tx.publicFunctionCalldata);
|
|
383
383
|
const txHash = txHashes[i].toString();
|
|
384
384
|
await this.#archivedTxs.set(txHash, archivedTx.toBuffer());
|
|
385
385
|
await this.#archivedTxIndices.set(headIdx, txHash);
|
|
@@ -5,7 +5,7 @@ export class AttestationValidator {
|
|
|
5
5
|
this.epochCache = epochCache;
|
|
6
6
|
}
|
|
7
7
|
async validate(message) {
|
|
8
|
-
const { currentSlot, nextSlot } = await this.epochCache.
|
|
8
|
+
const { currentSlot, nextSlot } = await this.epochCache.getProposerAttesterAddressInCurrentOrNextSlot();
|
|
9
9
|
const slotNumberBigInt = message.payload.header.slotNumber.toBigInt();
|
|
10
10
|
if (slotNumberBigInt !== currentSlot && slotNumberBigInt !== nextSlot) {
|
|
11
11
|
return PeerErrorSeverity.HighToleranceError;
|
|
@@ -8,7 +8,7 @@ export class BlockProposalValidator {
|
|
|
8
8
|
this.logger = createLogger('p2p:block_proposal_validator');
|
|
9
9
|
}
|
|
10
10
|
async validate(block) {
|
|
11
|
-
const { currentProposer, nextProposer, currentSlot, nextSlot } = await this.epochCache.
|
|
11
|
+
const { currentProposer, nextProposer, currentSlot, nextSlot } = await this.epochCache.getProposerAttesterAddressInCurrentOrNextSlot();
|
|
12
12
|
// Check that the attestation is for the current or next slot
|
|
13
13
|
const slotNumberBigInt = block.payload.header.slotNumber.toBigInt();
|
|
14
14
|
if (slotNumberBigInt !== currentSlot && slotNumberBigInt !== nextSlot) {
|
|
@@ -51,8 +51,8 @@ export class DataTxValidator {
|
|
|
51
51
|
}
|
|
52
52
|
async #hasCorrectContractClassLogs(tx) {
|
|
53
53
|
const contractClassLogsHashes = tx.data.getNonEmptyContractClassLogsHashes();
|
|
54
|
-
if (contractClassLogsHashes.length !== tx.
|
|
55
|
-
this.#log.verbose(`Rejecting tx ${await Tx.getHash(tx)} because of mismatched number of contract class logs. Expected ${contractClassLogsHashes.length}. Got ${tx.
|
|
54
|
+
if (contractClassLogsHashes.length !== tx.contractClassLogFields.length) {
|
|
55
|
+
this.#log.verbose(`Rejecting tx ${await Tx.getHash(tx)} because of mismatched number of contract class logs. Expected ${contractClassLogsHashes.length}. Got ${tx.contractClassLogFields.length}.`);
|
|
56
56
|
return {
|
|
57
57
|
result: 'invalid',
|
|
58
58
|
reason: [
|
|
@@ -60,7 +60,7 @@ export class DataTxValidator {
|
|
|
60
60
|
]
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
const expectedHashes = await Promise.all(tx.
|
|
63
|
+
const expectedHashes = await Promise.all(tx.contractClassLogFields.map((l)=>l.hash()));
|
|
64
64
|
for (const [i, logHash] of contractClassLogsHashes.entries()){
|
|
65
65
|
const hash = expectedHashes[i];
|
|
66
66
|
if (!logHash.value.equals(hash)) {
|
|
@@ -83,7 +83,7 @@ export class DataTxValidator {
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
const expectedMinLength = 1 + tx.
|
|
86
|
+
const expectedMinLength = 1 + tx.contractClassLogFields[i].fields.findLastIndex((f)=>!f.isZero());
|
|
87
87
|
if (logHash.logHash.length < expectedMinLength) {
|
|
88
88
|
this.#log.verbose(`Rejecting tx ${await Tx.getHash(tx)} because of incorrect contract class log length. Expected the length to be at least ${expectedMinLength}. Got ${logHash.logHash.length}.`);
|
|
89
89
|
return {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Gossipable } from '@aztec/stdlib/p2p';
|
|
3
3
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
4
4
|
import type { ENR } from '@chainsafe/enr';
|
|
5
5
|
import type { PeerId } from '@libp2p/interface';
|
|
6
6
|
import EventEmitter from 'events';
|
|
7
7
|
import type { ReqRespSubProtocol, SubProtocolMap } from './reqresp/interface.js';
|
|
8
|
-
import { type P2PService, type PeerDiscoveryService, PeerDiscoveryState } from './service.js';
|
|
8
|
+
import { type P2PBlockReceivedCallback, type P2PService, type PeerDiscoveryService, PeerDiscoveryState } from './service.js';
|
|
9
9
|
/**
|
|
10
10
|
* A dummy implementation of the P2P Service.
|
|
11
11
|
*/
|
|
@@ -35,7 +35,7 @@ export declare class DummyP2PService implements P2PService {
|
|
|
35
35
|
/**
|
|
36
36
|
* Register a callback into the validator client for when a block proposal is received
|
|
37
37
|
*/
|
|
38
|
-
registerBlockReceivedCallback(_callback:
|
|
38
|
+
registerBlockReceivedCallback(_callback: P2PBlockReceivedCallback): void;
|
|
39
39
|
/**
|
|
40
40
|
* Sends a request to a peer.
|
|
41
41
|
* @param _protocol - The protocol to send the request on.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dummy_service.d.ts","sourceRoot":"","sources":["../../src/services/dummy_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"dummy_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AAQ,EACnB,SAAS,EAAE,YAAY,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,GAC7D,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;IAIhE;;;OAGG;IACI,MAAM,IAAI,SAAS;IAI1B,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAGpC;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,YAAa,YAAW,oBAAoB;IACzF,OAAO,CAAC,YAAY,CAA8B;IAC3C,iBAAiB,EAAE,GAAG,EAAE,CAAM;IAErC;;;OAGG;IACI,KAAK;IAIZ;;;OAGG;IACI,IAAI;IAIX;;;OAGG;IACI,YAAY;IAIZ,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;IAInC,SAAS,IAAI,kBAAkB;IAI/B,MAAM,IAAI,SAAS;CAG3B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Timer } from '@aztec/foundation/timer';
|
|
2
|
+
import type { TopicType } from '@aztec/stdlib/p2p';
|
|
3
|
+
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
4
|
+
export declare class P2PInstrumentation {
|
|
5
|
+
private messageValidationDuration;
|
|
6
|
+
private messagePrevalidationCount;
|
|
7
|
+
constructor(client: TelemetryClient, name: string);
|
|
8
|
+
recordMessageValidation(topicName: TopicType, timerOrMs: Timer | number): void;
|
|
9
|
+
incMessagePrevalidationStatus(passed: boolean, topicName: TopicType | undefined): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../../src/services/libp2p/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAIL,KAAK,eAAe,EAGrB,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,yBAAyB,CAAY;IAC7C,OAAO,CAAC,yBAAyB,CAAgB;gBAErC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM;IAe1C,uBAAuB,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,GAAG,MAAM;IAKvE,6BAA6B,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS;CAGvF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Attributes, Metrics, ValueType } from '@aztec/telemetry-client';
|
|
2
|
+
export class P2PInstrumentation {
|
|
3
|
+
messageValidationDuration;
|
|
4
|
+
messagePrevalidationCount;
|
|
5
|
+
constructor(client, name){
|
|
6
|
+
const meter = client.getMeter(name);
|
|
7
|
+
this.messageValidationDuration = meter.createHistogram(Metrics.P2P_GOSSIP_MESSAGE_VALIDATION_DURATION, {
|
|
8
|
+
unit: 'ms',
|
|
9
|
+
description: 'How long validating a gossiped message takes',
|
|
10
|
+
valueType: ValueType.INT
|
|
11
|
+
});
|
|
12
|
+
this.messagePrevalidationCount = meter.createUpDownCounter(Metrics.P2P_GOSSIP_MESSAGE_PREVALIDATION_COUNT, {
|
|
13
|
+
description: 'How many message pass/fail prevalidation',
|
|
14
|
+
valueType: ValueType.INT
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
recordMessageValidation(topicName, timerOrMs) {
|
|
18
|
+
const ms = typeof timerOrMs === 'number' ? timerOrMs : timerOrMs.ms();
|
|
19
|
+
this.messageValidationDuration.record(Math.ceil(ms), {
|
|
20
|
+
[Attributes.TOPIC_NAME]: topicName
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
incMessagePrevalidationStatus(passed, topicName) {
|
|
24
|
+
this.messagePrevalidationCount.add(1, {
|
|
25
|
+
[Attributes.TOPIC_NAME]: topicName,
|
|
26
|
+
[Attributes.OK]: passed
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -3,7 +3,7 @@ import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
|
3
3
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
4
4
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
5
5
|
import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
6
|
-
import { BlockAttestation, BlockProposal, type Gossipable, P2PClientType } from '@aztec/stdlib/p2p';
|
|
6
|
+
import { BlockAttestation, BlockProposal, type Gossipable, P2PClientType, TopicType } from '@aztec/stdlib/p2p';
|
|
7
7
|
import { Tx } from '@aztec/stdlib/tx';
|
|
8
8
|
import { type TelemetryClient, WithTracer } from '@aztec/telemetry-client';
|
|
9
9
|
import type { ENR } from '@chainsafe/enr';
|
|
@@ -46,6 +46,7 @@ export declare class LibP2PService<T extends P2PClientType = P2PClientType.Full>
|
|
|
46
46
|
*/
|
|
47
47
|
private blockReceivedCallback;
|
|
48
48
|
private gossipSubEventHandler;
|
|
49
|
+
private instrumentation;
|
|
49
50
|
constructor(clientType: T, config: P2PConfig, node: PubSubLibp2p, peerDiscoveryService: PeerDiscoveryService, mempools: MemPools<T>, archiver: L2BlockSource & ContractDataSource, epochCache: EpochCacheInterface, proofVerifier: ClientProtocolCircuitVerifier, worldStateSynchronizer: WorldStateSynchronizer, telemetry: TelemetryClient, logger?: import("@aztec/foundation/log").Logger);
|
|
50
51
|
/**
|
|
51
52
|
* Creates an instance of the LibP2P service.
|
|
@@ -112,7 +113,7 @@ export declare class LibP2PService<T extends P2PClientType = P2PClientType.Full>
|
|
|
112
113
|
protected validateReceivedMessage<T>(validationFunc: () => Promise<{
|
|
113
114
|
result: boolean;
|
|
114
115
|
obj: T;
|
|
115
|
-
}>, msgId: string, source: PeerId): Promise<{
|
|
116
|
+
}>, msgId: string, source: PeerId, topicType: TopicType): Promise<{
|
|
116
117
|
result: boolean;
|
|
117
118
|
obj: T | undefined;
|
|
118
119
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p_service.d.ts","sourceRoot":"","sources":["../../../src/services/libp2p/libp2p_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"libp2p_service.d.ts","sourceRoot":"","sources":["../../../src/services/libp2p/libp2p_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAK9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACvH,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,KAAK,UAAU,EACf,aAAa,EAGb,SAAS,EAIV,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,EAAE,EAAwC,MAAM,kBAAkB,CAAC;AAE5E,OAAO,EAAkC,KAAK,eAAe,EAAE,UAAU,EAAa,MAAM,yBAAyB,CAAC;AAEtH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAa1C,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,MAAM,EAAwB,MAAM,mBAAmB,CAAC;AAEpF,OAAO,iBAAiB,CAAC;AAKzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,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AI,CAAC;IAgB/C;;;;;;;;OAQG;YACW,uBAAuB;IAiBrC;;;;;OAKG;YACW,cAAc;IA4B5B;;;;;;;;;;OAUG;YACW,wBAAwB;IAuBtC;;;;;OAKG;IAOU,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAUjG;;;;;OAKG;IAIU,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAWnF,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;YAI7B,WAAW;YAcX,UAAU;CAYzB"}
|
|
@@ -7,6 +7,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
7
7
|
import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
8
8
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
9
9
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
10
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
10
11
|
import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
|
|
11
12
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
12
13
|
import { BlockAttestation, BlockProposal, P2PClientType, P2PMessage, PeerErrorSeverity, TopicType, createTopicString, getTopicTypeForClientType, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
|
|
@@ -43,6 +44,7 @@ import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol } from '../reqresp/
|
|
|
43
44
|
import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js';
|
|
44
45
|
import { pingHandler, reqRespBlockHandler, reqRespTxHandler, statusHandler } from '../reqresp/protocols/index.js';
|
|
45
46
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
47
|
+
import { P2PInstrumentation } from './instrumentation.js';
|
|
46
48
|
/**
|
|
47
49
|
* Lib P2P implementation of the P2PService interface.
|
|
48
50
|
*/ export class LibP2PService extends WithTracer {
|
|
@@ -75,8 +77,10 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
75
77
|
* @returns The attestation for the block, if any.
|
|
76
78
|
*/ blockReceivedCallback;
|
|
77
79
|
gossipSubEventHandler;
|
|
80
|
+
instrumentation;
|
|
78
81
|
constructor(clientType, config, node, peerDiscoveryService, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger = createLogger('p2p:libp2p_service')){
|
|
79
82
|
super(telemetry, 'LibP2PService'), this.clientType = clientType, this.config = config, this.node = node, this.peerDiscoveryService = peerDiscoveryService, this.mempools = mempools, this.archiver = archiver, this.proofVerifier = proofVerifier, this.worldStateSynchronizer = worldStateSynchronizer, this.logger = logger, this.jobQueue = new SerialQueue(), this.msgIdSeenValidators = {}, this.protocolVersion = '', this.topicStrings = {}, this.trustedPeersIds = [];
|
|
83
|
+
this.instrumentation = new P2PInstrumentation(telemetry, 'LibP2PService');
|
|
80
84
|
this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
81
85
|
this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
82
86
|
this.msgIdSeenValidators[TopicType.block_attestation] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
@@ -366,23 +370,28 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
366
370
|
return result.recipients.length;
|
|
367
371
|
}
|
|
368
372
|
preValidateReceivedMessage(msg, msgId, source) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
373
|
+
let topicType;
|
|
374
|
+
switch(msg.topic){
|
|
375
|
+
case this.topicStrings[TopicType.tx]:
|
|
376
|
+
topicType = TopicType.tx;
|
|
377
|
+
break;
|
|
378
|
+
case this.topicStrings[TopicType.block_attestation]:
|
|
379
|
+
topicType = TopicType.block_attestation;
|
|
380
|
+
break;
|
|
381
|
+
case this.topicStrings[TopicType.block_proposal]:
|
|
382
|
+
topicType = TopicType.block_proposal;
|
|
383
|
+
break;
|
|
384
|
+
default:
|
|
385
|
+
this.logger.error(`Received message on unknown topic: ${msg.topic}`);
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
const validator = topicType ? this.msgIdSeenValidators[topicType] : undefined;
|
|
382
389
|
if (!validator || !validator.addMessage(msgId)) {
|
|
390
|
+
this.instrumentation.incMessagePrevalidationStatus(false, topicType);
|
|
383
391
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
384
392
|
return false;
|
|
385
393
|
}
|
|
394
|
+
this.instrumentation.incMessagePrevalidationStatus(true, topicType);
|
|
386
395
|
return true;
|
|
387
396
|
}
|
|
388
397
|
/**
|
|
@@ -412,16 +421,20 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
412
421
|
}
|
|
413
422
|
return;
|
|
414
423
|
}
|
|
415
|
-
async validateReceivedMessage(validationFunc, msgId, source) {
|
|
424
|
+
async validateReceivedMessage(validationFunc, msgId, source, topicType) {
|
|
416
425
|
let resultAndObj = {
|
|
417
426
|
result: false,
|
|
418
427
|
obj: undefined
|
|
419
428
|
};
|
|
429
|
+
const timer = new Timer();
|
|
420
430
|
try {
|
|
421
431
|
resultAndObj = await validationFunc();
|
|
422
432
|
} catch (err) {
|
|
423
433
|
this.logger.error(`Error deserialising and validating message `, err);
|
|
424
434
|
}
|
|
435
|
+
if (resultAndObj.result) {
|
|
436
|
+
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
437
|
+
}
|
|
425
438
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result && resultAndObj.obj ? TopicValidatorResult.Accept : TopicValidatorResult.Reject);
|
|
426
439
|
return resultAndObj;
|
|
427
440
|
}
|
|
@@ -434,7 +447,7 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
434
447
|
obj: tx
|
|
435
448
|
};
|
|
436
449
|
};
|
|
437
|
-
const { result, obj: tx } = await this.validateReceivedMessage(validationFunc, msgId, source);
|
|
450
|
+
const { result, obj: tx } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.tx);
|
|
438
451
|
if (!result || !tx) {
|
|
439
452
|
return;
|
|
440
453
|
}
|
|
@@ -463,7 +476,7 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
463
476
|
obj: attestation
|
|
464
477
|
};
|
|
465
478
|
};
|
|
466
|
-
const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source);
|
|
479
|
+
const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_attestation);
|
|
467
480
|
if (!result || !attestation) {
|
|
468
481
|
return;
|
|
469
482
|
}
|
|
@@ -490,7 +503,7 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
490
503
|
obj: block
|
|
491
504
|
};
|
|
492
505
|
};
|
|
493
|
-
const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source);
|
|
506
|
+
const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_proposal);
|
|
494
507
|
if (!result || !block) {
|
|
495
508
|
return;
|
|
496
509
|
}
|
|
@@ -513,17 +526,19 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
513
526
|
}
|
|
514
527
|
// Mark the txs in this proposal as non-evictable
|
|
515
528
|
await this.mempools.txPool.markTxsAsNonEvictable(block.payload.txHashes);
|
|
516
|
-
const
|
|
529
|
+
const attestations = await this.blockReceivedCallback(block, sender);
|
|
517
530
|
// TODO: fix up this pattern - the abstraction is not nice
|
|
518
531
|
// The attestation can be undefined if no handler is registered / the validator deems the block invalid
|
|
519
|
-
if (
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
532
|
+
if (attestations?.length) {
|
|
533
|
+
for (const attestation of attestations){
|
|
534
|
+
this.logger.verbose(`Broadcasting attestation for block ${attestation.blockNumber.toNumber()} slot ${attestation.slotNumber.toNumber()}`, {
|
|
535
|
+
p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
|
|
536
|
+
slot: attestation.slotNumber.toNumber(),
|
|
537
|
+
archive: attestation.archive.toString(),
|
|
538
|
+
block: attestation.blockNumber.toNumber()
|
|
539
|
+
});
|
|
540
|
+
await this.broadcastAttestation(attestation);
|
|
541
|
+
}
|
|
527
542
|
}
|
|
528
543
|
}
|
|
529
544
|
/**
|
|
@@ -9,7 +9,7 @@ export declare enum PeerDiscoveryState {
|
|
|
9
9
|
RUNNING = "running",
|
|
10
10
|
STOPPED = "stopped"
|
|
11
11
|
}
|
|
12
|
-
export type P2PBlockReceivedCallback = (block: BlockProposal, sender: PeerId) => Promise<BlockAttestation | undefined>;
|
|
12
|
+
export type P2PBlockReceivedCallback = (block: BlockProposal, sender: PeerId) => Promise<BlockAttestation[] | undefined>;
|
|
13
13
|
/**
|
|
14
14
|
* The interface for a P2P service implementation.
|
|
15
15
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/services/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACrF,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE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,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAAC;IACjE,IAAI,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC;IAElD,SAAS,IAAI,kBAAkB,CAAC;IAEhC,MAAM,IAAI,GAAG,GAAG,SAAS,CAAC;IAE1B,iBAAiB,EAAE,GAAG,EAAE,CAAC;CAC1B"}
|
|
@@ -63,7 +63,7 @@ function mockEpochCache() {
|
|
|
63
63
|
ts: 0n
|
|
64
64
|
}),
|
|
65
65
|
computeProposerIndex: ()=>0n,
|
|
66
|
-
|
|
66
|
+
getProposerAttesterAddressInCurrentOrNextSlot: ()=>Promise.resolve({
|
|
67
67
|
currentProposer: EthAddress.ZERO,
|
|
68
68
|
nextProposer: EthAddress.ZERO,
|
|
69
69
|
currentSlot: 0n,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/p2p",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-nightly.20250604",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -63,16 +63,16 @@
|
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@aztec/constants": "0.
|
|
67
|
-
"@aztec/epoch-cache": "0.
|
|
68
|
-
"@aztec/foundation": "0.
|
|
69
|
-
"@aztec/kv-store": "0.
|
|
70
|
-
"@aztec/noir-contracts.js": "0.
|
|
71
|
-
"@aztec/noir-protocol-circuits-types": "0.
|
|
72
|
-
"@aztec/protocol-contracts": "0.
|
|
73
|
-
"@aztec/simulator": "0.
|
|
74
|
-
"@aztec/stdlib": "0.
|
|
75
|
-
"@aztec/telemetry-client": "0.
|
|
66
|
+
"@aztec/constants": "1.0.0-nightly.20250604",
|
|
67
|
+
"@aztec/epoch-cache": "1.0.0-nightly.20250604",
|
|
68
|
+
"@aztec/foundation": "1.0.0-nightly.20250604",
|
|
69
|
+
"@aztec/kv-store": "1.0.0-nightly.20250604",
|
|
70
|
+
"@aztec/noir-contracts.js": "1.0.0-nightly.20250604",
|
|
71
|
+
"@aztec/noir-protocol-circuits-types": "1.0.0-nightly.20250604",
|
|
72
|
+
"@aztec/protocol-contracts": "1.0.0-nightly.20250604",
|
|
73
|
+
"@aztec/simulator": "1.0.0-nightly.20250604",
|
|
74
|
+
"@aztec/stdlib": "1.0.0-nightly.20250604",
|
|
75
|
+
"@aztec/telemetry-client": "1.0.0-nightly.20250604",
|
|
76
76
|
"@chainsafe/discv5": "9.0.0",
|
|
77
77
|
"@chainsafe/enr": "3.0.0",
|
|
78
78
|
"@chainsafe/libp2p-gossipsub": "13.0.0",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"xxhash-wasm": "^1.1.0"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
|
-
"@aztec/archiver": "0.
|
|
104
|
+
"@aztec/archiver": "1.0.0-nightly.20250604",
|
|
105
105
|
"@jest/globals": "^29.5.0",
|
|
106
106
|
"@types/jest": "^29.5.0",
|
|
107
107
|
"@types/node": "^22.15.17",
|
package/src/client/interface.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { L2BlockId } from '@aztec/stdlib/block';
|
|
2
|
-
import type {
|
|
2
|
+
import type { P2PApiFull } from '@aztec/stdlib/interfaces/server';
|
|
3
3
|
import type { BlockProposal, P2PClientType } from '@aztec/stdlib/p2p';
|
|
4
4
|
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
@@ -36,7 +36,7 @@ export interface P2PSyncState {
|
|
|
36
36
|
/**
|
|
37
37
|
* Interface of a P2P client.
|
|
38
38
|
**/
|
|
39
|
-
export type P2P<T extends P2PClientType = P2PClientType.Full> =
|
|
39
|
+
export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> & {
|
|
40
40
|
/**
|
|
41
41
|
* Broadcasts a block proposal to other peers.
|
|
42
42
|
*
|
package/src/client/p2p_client.ts
CHANGED
|
@@ -31,7 +31,7 @@ import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_
|
|
|
31
31
|
import type { MemPools } from '../mem_pools/interface.js';
|
|
32
32
|
import type { TxPool } from '../mem_pools/tx_pool/index.js';
|
|
33
33
|
import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
|
|
34
|
-
import type { P2PService } from '../services/service.js';
|
|
34
|
+
import type { P2PBlockReceivedCallback, P2PService } from '../services/service.js';
|
|
35
35
|
import { TxCollector } from '../services/tx_collector.js';
|
|
36
36
|
import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
|
|
37
37
|
|
|
@@ -331,15 +331,13 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
331
331
|
);
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
public
|
|
335
|
-
return this.attestationPool?.addAttestations(
|
|
334
|
+
public addAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
335
|
+
return this.attestationPool?.addAttestations(attestations) ?? Promise.resolve();
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
// REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
339
339
|
// ^ This pattern is not my favorite (md)
|
|
340
|
-
public registerBlockProposalHandler(
|
|
341
|
-
handler: (block: BlockProposal, sender: any) => Promise<BlockAttestation | undefined>,
|
|
342
|
-
): void {
|
|
340
|
+
public registerBlockProposalHandler(handler: P2PBlockReceivedCallback): void {
|
|
343
341
|
this.p2pService.registerBlockReceivedCallback(handler);
|
|
344
342
|
}
|
|
345
343
|
|
|
@@ -486,7 +486,12 @@ export class AztecKVTxPool implements TxPool {
|
|
|
486
486
|
tailIdx++;
|
|
487
487
|
}
|
|
488
488
|
|
|
489
|
-
const archivedTx: Tx = new Tx(
|
|
489
|
+
const archivedTx: Tx = new Tx(
|
|
490
|
+
tx.data,
|
|
491
|
+
ClientIvcProof.empty(),
|
|
492
|
+
tx.contractClassLogFields,
|
|
493
|
+
tx.publicFunctionCalldata,
|
|
494
|
+
);
|
|
490
495
|
const txHash = txHashes[i].toString();
|
|
491
496
|
await this.#archivedTxs.set(txHash, archivedTx.toBuffer());
|
|
492
497
|
await this.#archivedTxIndices.set(headIdx, txHash);
|
|
@@ -9,7 +9,7 @@ export class AttestationValidator implements P2PValidator<BlockAttestation> {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
async validate(message: BlockAttestation): Promise<PeerErrorSeverity | undefined> {
|
|
12
|
-
const { currentSlot, nextSlot } = await this.epochCache.
|
|
12
|
+
const { currentSlot, nextSlot } = await this.epochCache.getProposerAttesterAddressInCurrentOrNextSlot();
|
|
13
13
|
|
|
14
14
|
const slotNumberBigInt = message.payload.header.slotNumber.toBigInt();
|
|
15
15
|
if (slotNumberBigInt !== currentSlot && slotNumberBigInt !== nextSlot) {
|
|
@@ -13,7 +13,7 @@ export class BlockProposalValidator implements P2PValidator<BlockProposal> {
|
|
|
13
13
|
|
|
14
14
|
async validate(block: BlockProposal): Promise<PeerErrorSeverity | undefined> {
|
|
15
15
|
const { currentProposer, nextProposer, currentSlot, nextSlot } =
|
|
16
|
-
await this.epochCache.
|
|
16
|
+
await this.epochCache.getProposerAttesterAddressInCurrentOrNextSlot();
|
|
17
17
|
|
|
18
18
|
// Check that the attestation is for the current or next slot
|
|
19
19
|
const slotNumberBigInt = block.payload.header.slotNumber.toBigInt();
|
|
@@ -60,16 +60,16 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
60
60
|
|
|
61
61
|
async #hasCorrectContractClassLogs(tx: Tx): Promise<TxValidationResult> {
|
|
62
62
|
const contractClassLogsHashes = tx.data.getNonEmptyContractClassLogsHashes();
|
|
63
|
-
if (contractClassLogsHashes.length !== tx.
|
|
63
|
+
if (contractClassLogsHashes.length !== tx.contractClassLogFields.length) {
|
|
64
64
|
this.#log.verbose(
|
|
65
65
|
`Rejecting tx ${await Tx.getHash(tx)} because of mismatched number of contract class logs. Expected ${
|
|
66
66
|
contractClassLogsHashes.length
|
|
67
|
-
}. Got ${tx.
|
|
67
|
+
}. Got ${tx.contractClassLogFields.length}.`,
|
|
68
68
|
);
|
|
69
69
|
return { result: 'invalid', reason: [TX_ERROR_CONTRACT_CLASS_LOG_COUNT] };
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
const expectedHashes = await Promise.all(tx.
|
|
72
|
+
const expectedHashes = await Promise.all(tx.contractClassLogFields.map(l => l.hash()));
|
|
73
73
|
for (const [i, logHash] of contractClassLogsHashes.entries()) {
|
|
74
74
|
const hash = expectedHashes[i];
|
|
75
75
|
if (!logHash.value.equals(hash)) {
|
|
@@ -91,7 +91,7 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
const expectedMinLength = 1 + tx.
|
|
94
|
+
const expectedMinLength = 1 + tx.contractClassLogFields[i].fields.findLastIndex(f => !f.isZero());
|
|
95
95
|
if (logHash.logHash.length < expectedMinLength) {
|
|
96
96
|
this.#log.verbose(
|
|
97
97
|
`Rejecting tx ${await Tx.getHash(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Gossipable } from '@aztec/stdlib/p2p';
|
|
3
3
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
import type { ENR } from '@chainsafe/enr';
|
|
@@ -7,7 +7,12 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
7
7
|
import EventEmitter from 'events';
|
|
8
8
|
|
|
9
9
|
import type { ReqRespSubProtocol, SubProtocolMap } from './reqresp/interface.js';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
type P2PBlockReceivedCallback,
|
|
12
|
+
type P2PService,
|
|
13
|
+
type PeerDiscoveryService,
|
|
14
|
+
PeerDiscoveryState,
|
|
15
|
+
} from './service.js';
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
18
|
* A dummy implementation of the P2P Service.
|
|
@@ -51,9 +56,7 @@ export class DummyP2PService implements P2PService {
|
|
|
51
56
|
/**
|
|
52
57
|
* Register a callback into the validator client for when a block proposal is received
|
|
53
58
|
*/
|
|
54
|
-
public registerBlockReceivedCallback(
|
|
55
|
-
_callback: (block: BlockProposal, sender: PeerId) => Promise<BlockAttestation>,
|
|
56
|
-
) {}
|
|
59
|
+
public registerBlockReceivedCallback(_callback: P2PBlockReceivedCallback) {}
|
|
57
60
|
|
|
58
61
|
/**
|
|
59
62
|
* Sends a request to a peer.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Timer } from '@aztec/foundation/timer';
|
|
2
|
+
import type { TopicType } from '@aztec/stdlib/p2p';
|
|
3
|
+
import {
|
|
4
|
+
Attributes,
|
|
5
|
+
type Histogram,
|
|
6
|
+
Metrics,
|
|
7
|
+
type TelemetryClient,
|
|
8
|
+
type UpDownCounter,
|
|
9
|
+
ValueType,
|
|
10
|
+
} from '@aztec/telemetry-client';
|
|
11
|
+
|
|
12
|
+
export class P2PInstrumentation {
|
|
13
|
+
private messageValidationDuration: Histogram;
|
|
14
|
+
private messagePrevalidationCount: UpDownCounter;
|
|
15
|
+
|
|
16
|
+
constructor(client: TelemetryClient, name: string) {
|
|
17
|
+
const meter = client.getMeter(name);
|
|
18
|
+
|
|
19
|
+
this.messageValidationDuration = meter.createHistogram(Metrics.P2P_GOSSIP_MESSAGE_VALIDATION_DURATION, {
|
|
20
|
+
unit: 'ms',
|
|
21
|
+
description: 'How long validating a gossiped message takes',
|
|
22
|
+
valueType: ValueType.INT,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
this.messagePrevalidationCount = meter.createUpDownCounter(Metrics.P2P_GOSSIP_MESSAGE_PREVALIDATION_COUNT, {
|
|
26
|
+
description: 'How many message pass/fail prevalidation',
|
|
27
|
+
valueType: ValueType.INT,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public recordMessageValidation(topicName: TopicType, timerOrMs: Timer | number) {
|
|
32
|
+
const ms = typeof timerOrMs === 'number' ? timerOrMs : timerOrMs.ms();
|
|
33
|
+
this.messageValidationDuration.record(Math.ceil(ms), { [Attributes.TOPIC_NAME]: topicName });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public incMessagePrevalidationStatus(passed: boolean, topicName: TopicType | undefined) {
|
|
37
|
+
this.messagePrevalidationCount.add(1, { [Attributes.TOPIC_NAME]: topicName, [Attributes.OK]: passed });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
|
2
2
|
import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
4
4
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
5
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
5
6
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
6
7
|
import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
|
|
7
8
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
@@ -65,6 +66,7 @@ import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js';
|
|
|
65
66
|
import { pingHandler, reqRespBlockHandler, reqRespTxHandler, statusHandler } from '../reqresp/protocols/index.js';
|
|
66
67
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
67
68
|
import type { P2PBlockReceivedCallback, P2PService, PeerDiscoveryService } from '../service.js';
|
|
69
|
+
import { P2PInstrumentation } from './instrumentation.js';
|
|
68
70
|
|
|
69
71
|
interface ValidationResult {
|
|
70
72
|
name: string;
|
|
@@ -107,6 +109,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
107
109
|
|
|
108
110
|
private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
|
|
109
111
|
|
|
112
|
+
private instrumentation: P2PInstrumentation;
|
|
113
|
+
|
|
110
114
|
constructor(
|
|
111
115
|
private clientType: T,
|
|
112
116
|
private config: P2PConfig,
|
|
@@ -122,6 +126,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
122
126
|
) {
|
|
123
127
|
super(telemetry, 'LibP2PService');
|
|
124
128
|
|
|
129
|
+
this.instrumentation = new P2PInstrumentation(telemetry, 'LibP2PService');
|
|
130
|
+
|
|
125
131
|
this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
126
132
|
this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
127
133
|
this.msgIdSeenValidators[TopicType.block_attestation] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
@@ -161,7 +167,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
161
167
|
|
|
162
168
|
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
163
169
|
|
|
164
|
-
this.blockReceivedCallback = async (block: BlockProposal): Promise<BlockAttestation | undefined> => {
|
|
170
|
+
this.blockReceivedCallback = async (block: BlockProposal): Promise<BlockAttestation[] | undefined> => {
|
|
165
171
|
this.logger.debug(
|
|
166
172
|
`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber.toNumber()} from peer.`,
|
|
167
173
|
{ p2pMessageIdentifier: await block.p2pMessageIdentifier() },
|
|
@@ -501,25 +507,33 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
501
507
|
}
|
|
502
508
|
|
|
503
509
|
protected preValidateReceivedMessage(msg: Message, msgId: string, source: PeerId) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
510
|
+
let topicType: TopicType | undefined;
|
|
511
|
+
|
|
512
|
+
switch (msg.topic) {
|
|
513
|
+
case this.topicStrings[TopicType.tx]:
|
|
514
|
+
topicType = TopicType.tx;
|
|
515
|
+
break;
|
|
516
|
+
case this.topicStrings[TopicType.block_attestation]:
|
|
517
|
+
topicType = TopicType.block_attestation;
|
|
518
|
+
break;
|
|
519
|
+
case this.topicStrings[TopicType.block_proposal]:
|
|
520
|
+
topicType = TopicType.block_proposal;
|
|
521
|
+
break;
|
|
522
|
+
default:
|
|
523
|
+
this.logger.error(`Received message on unknown topic: ${msg.topic}`);
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
516
526
|
|
|
517
|
-
const validator =
|
|
527
|
+
const validator = topicType ? this.msgIdSeenValidators[topicType] : undefined;
|
|
518
528
|
|
|
519
529
|
if (!validator || !validator.addMessage(msgId)) {
|
|
530
|
+
this.instrumentation.incMessagePrevalidationStatus(false, topicType);
|
|
520
531
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
521
532
|
return false;
|
|
522
533
|
}
|
|
534
|
+
|
|
535
|
+
this.instrumentation.incMessagePrevalidationStatus(true, topicType);
|
|
536
|
+
|
|
523
537
|
return true;
|
|
524
538
|
}
|
|
525
539
|
|
|
@@ -559,14 +573,20 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
559
573
|
validationFunc: () => Promise<{ result: boolean; obj: T }>,
|
|
560
574
|
msgId: string,
|
|
561
575
|
source: PeerId,
|
|
576
|
+
topicType: TopicType,
|
|
562
577
|
): Promise<{ result: boolean; obj: T | undefined }> {
|
|
563
578
|
let resultAndObj: { result: boolean; obj: T | undefined } = { result: false, obj: undefined };
|
|
579
|
+
const timer = new Timer();
|
|
564
580
|
try {
|
|
565
581
|
resultAndObj = await validationFunc();
|
|
566
582
|
} catch (err) {
|
|
567
583
|
this.logger.error(`Error deserialising and validating message `, err);
|
|
568
584
|
}
|
|
569
585
|
|
|
586
|
+
if (resultAndObj.result) {
|
|
587
|
+
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
588
|
+
}
|
|
589
|
+
|
|
570
590
|
this.node.services.pubsub.reportMessageValidationResult(
|
|
571
591
|
msgId,
|
|
572
592
|
source.toString(),
|
|
@@ -582,7 +602,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
582
602
|
return { result, obj: tx };
|
|
583
603
|
};
|
|
584
604
|
|
|
585
|
-
const { result, obj: tx } = await this.validateReceivedMessage<Tx>(validationFunc, msgId, source);
|
|
605
|
+
const { result, obj: tx } = await this.validateReceivedMessage<Tx>(validationFunc, msgId, source, TopicType.tx);
|
|
586
606
|
if (!result || !tx) {
|
|
587
607
|
return;
|
|
588
608
|
}
|
|
@@ -613,6 +633,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
613
633
|
validationFunc,
|
|
614
634
|
msgId,
|
|
615
635
|
source,
|
|
636
|
+
TopicType.block_attestation,
|
|
616
637
|
);
|
|
617
638
|
if (!result || !attestation) {
|
|
618
639
|
return;
|
|
@@ -640,7 +661,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
640
661
|
return { result, obj: block };
|
|
641
662
|
};
|
|
642
663
|
|
|
643
|
-
const { result, obj: block } = await this.validateReceivedMessage<BlockProposal>(
|
|
664
|
+
const { result, obj: block } = await this.validateReceivedMessage<BlockProposal>(
|
|
665
|
+
validationFunc,
|
|
666
|
+
msgId,
|
|
667
|
+
source,
|
|
668
|
+
TopicType.block_proposal,
|
|
669
|
+
);
|
|
644
670
|
if (!result || !block) {
|
|
645
671
|
return;
|
|
646
672
|
}
|
|
@@ -674,21 +700,23 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
674
700
|
|
|
675
701
|
// Mark the txs in this proposal as non-evictable
|
|
676
702
|
await this.mempools.txPool.markTxsAsNonEvictable(block.payload.txHashes);
|
|
677
|
-
const
|
|
703
|
+
const attestations = await this.blockReceivedCallback(block, sender);
|
|
678
704
|
|
|
679
705
|
// TODO: fix up this pattern - the abstraction is not nice
|
|
680
706
|
// The attestation can be undefined if no handler is registered / the validator deems the block invalid
|
|
681
|
-
if (
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
707
|
+
if (attestations?.length) {
|
|
708
|
+
for (const attestation of attestations) {
|
|
709
|
+
this.logger.verbose(
|
|
710
|
+
`Broadcasting attestation for block ${attestation.blockNumber.toNumber()} slot ${attestation.slotNumber.toNumber()}`,
|
|
711
|
+
{
|
|
712
|
+
p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
|
|
713
|
+
slot: attestation.slotNumber.toNumber(),
|
|
714
|
+
archive: attestation.archive.toString(),
|
|
715
|
+
block: attestation.blockNumber.toNumber(),
|
|
716
|
+
},
|
|
717
|
+
);
|
|
718
|
+
await this.broadcastAttestation(attestation);
|
|
719
|
+
}
|
|
692
720
|
}
|
|
693
721
|
}
|
|
694
722
|
|
package/src/services/service.ts
CHANGED
|
@@ -13,7 +13,10 @@ export enum PeerDiscoveryState {
|
|
|
13
13
|
STOPPED = 'stopped',
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export type P2PBlockReceivedCallback = (
|
|
16
|
+
export type P2PBlockReceivedCallback = (
|
|
17
|
+
block: BlockProposal,
|
|
18
|
+
sender: PeerId,
|
|
19
|
+
) => Promise<BlockAttestation[] | undefined>;
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* The interface for a P2P service implementation.
|
|
@@ -73,7 +73,7 @@ function mockEpochCache(): EpochCacheInterface {
|
|
|
73
73
|
getProposerIndexEncoding: () => '0x' as `0x${string}`,
|
|
74
74
|
getEpochAndSlotNow: () => ({ epoch: 0n, slot: 0n, ts: 0n }),
|
|
75
75
|
computeProposerIndex: () => 0n,
|
|
76
|
-
|
|
76
|
+
getProposerAttesterAddressInCurrentOrNextSlot: () =>
|
|
77
77
|
Promise.resolve({
|
|
78
78
|
currentProposer: EthAddress.ZERO,
|
|
79
79
|
nextProposer: EthAddress.ZERO,
|