@aztec/p2p 3.0.0-nightly.20251119 → 3.0.0-nightly.20251120
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 +3 -1
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +1 -0
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +4 -0
- package/dest/services/libp2p/libp2p_service.d.ts +14 -2
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +96 -6
- package/package.json +14 -14
- package/src/client/interface.ts +4 -1
- package/src/client/p2p_client.ts +5 -0
- package/src/services/libp2p/libp2p_service.ts +110 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EthAddress, L2BlockId } from '@aztec/stdlib/block';
|
|
2
2
|
import type { P2PApiFull } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type { BlockProposal, P2PClientType } from '@aztec/stdlib/p2p';
|
|
3
|
+
import type { BlockAttestation, BlockProposal, P2PClientType } from '@aztec/stdlib/p2p';
|
|
4
4
|
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
5
|
import type { PeerId } from '@libp2p/interface';
|
|
6
6
|
import type { ENR } from '@nethermindeth/enr';
|
|
@@ -40,6 +40,8 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
40
40
|
* @param proposal - the block proposal
|
|
41
41
|
*/
|
|
42
42
|
broadcastProposal(proposal: BlockProposal): Promise<void>;
|
|
43
|
+
/** Broadcasts block attestations to other peers. */
|
|
44
|
+
broadcastAttestations(attestations: BlockAttestation[]): Promise<void>;
|
|
43
45
|
/**
|
|
44
46
|
* Registers a callback from the validator client that determines how to behave when
|
|
45
47
|
* foreign block proposals are received
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/client/interface.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AC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAE5F,4FAA4F;IAC5F,8BAA8B,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;CAC7D,CAAC"}
|
|
@@ -81,6 +81,7 @@ export declare class P2PClient<T extends P2PClientType = P2PClientType.Full> ext
|
|
|
81
81
|
/** Triggers a sync to the archiver. Used for testing. */
|
|
82
82
|
sync(): Promise<void>;
|
|
83
83
|
broadcastProposal(proposal: BlockProposal): Promise<void>;
|
|
84
|
+
broadcastAttestations(attestations: BlockAttestation[]): Promise<void>;
|
|
84
85
|
getAttestationsForSlot(slot: bigint, proposalId?: string): Promise<BlockAttestation[]>;
|
|
85
86
|
addAttestations(attestations: BlockAttestation[]): Promise<void>;
|
|
86
87
|
deleteAttestation(attestation: BlockAttestation): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p2p_client.d.ts","sourceRoot":"","sources":["../../src/client/p2p_client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAsC,MAAM,iBAAiB,CAAC;AAC7F,OAAO,KAAK,EACV,UAAU,EAGV,aAAa,EAEb,kBAAkB,EAClB,MAAM,EAEP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,KAAK,QAAQ,EAAW,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAEL,KAAK,eAAe,EAEpB,UAAU,EAGX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,K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uBAAuB;IAsBrC;;;OAGG;YACW,mBAAmB;YA+CnB,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;IAIxD,yBAAyB,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;CAGnG"}
|
|
@@ -291,6 +291,10 @@ import { P2PClientState } from './interface.js';
|
|
|
291
291
|
this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber.toNumber()} to peers`);
|
|
292
292
|
return this.p2pService.propagate(proposal);
|
|
293
293
|
}
|
|
294
|
+
async broadcastAttestations(attestations) {
|
|
295
|
+
this.log.verbose(`Broadcasting ${attestations.length} attestations to peers`);
|
|
296
|
+
await Promise.all(attestations.map((att)=>this.p2pService.propagate(att)));
|
|
297
|
+
}
|
|
294
298
|
async getAttestationsForSlot(slot, proposalId) {
|
|
295
299
|
return await (proposalId ? this.attestationPool?.getAttestationsForSlotAndProposal(slot, proposalId) : this.attestationPool?.getAttestationsForSlot(slot)) ?? [];
|
|
296
300
|
}
|
|
@@ -159,7 +159,7 @@ export declare class LibP2PService<T extends P2PClientType = P2PClientType.Full>
|
|
|
159
159
|
*/
|
|
160
160
|
propagate<T extends Gossipable>(message: T): Promise<void>;
|
|
161
161
|
/**
|
|
162
|
-
* Validate the requested block transactions.
|
|
162
|
+
* Validate the requested block transactions. Allow partial returns.
|
|
163
163
|
* @param request - The block transactions request.
|
|
164
164
|
* @param response - The block transactions response.
|
|
165
165
|
* @param peerId - The ID of the peer that made the request.
|
|
@@ -176,11 +176,23 @@ export declare class LibP2PService<T extends P2PClientType = P2PClientType.Full>
|
|
|
176
176
|
* ReqRespSubProtocol.TX subprotocol validation.
|
|
177
177
|
*
|
|
178
178
|
* @param requestedTxHash - The collection of the txs that was requested.
|
|
179
|
-
* @param responseTx - The
|
|
179
|
+
* @param responseTx - The collection of txs that was received as a response to the request.
|
|
180
180
|
* @param peerId - The peer ID of the peer that sent the tx.
|
|
181
181
|
* @returns True if the whole collection of txs is valid, false otherwise.
|
|
182
182
|
*/
|
|
183
183
|
private validateRequestedTxs;
|
|
184
|
+
/**
|
|
185
|
+
* Validates a BLOCK response.
|
|
186
|
+
*
|
|
187
|
+
* If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
|
|
188
|
+
* Penalizes on block number mismatch or hash mismatch.
|
|
189
|
+
*
|
|
190
|
+
* @param requestedBlockNumber - The requested block number.
|
|
191
|
+
* @param responseBlock - The block returned by the peer.
|
|
192
|
+
* @param peerId - The peer that returned the block.
|
|
193
|
+
* @returns True if the response is valid, false otherwise.
|
|
194
|
+
*/
|
|
195
|
+
private validateRequestedBlock;
|
|
184
196
|
private createRequestedTxValidator;
|
|
185
197
|
private validateRequestedTx;
|
|
186
198
|
private validatePropagatedTx;
|
|
@@ -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;AAG9D,OAAO,EAAE,KAAK,MAAM,EAA6C,MAAM,uBAAuB,CAAC;AAI/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,OAAO,KAAK,EAAE,UAAU,
|
|
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;AAG9D,OAAO,EAAE,KAAK,MAAM,EAA6C,MAAM,uBAAuB,CAAC;AAI/F,OAAO,KAAK,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B;IAoBlC;;;;;;;;;;OAUG;YAIW,sBAAsB;IAiCpC,OAAO,CAAC,0BAA0B;YAapB,mBAAmB;YAuBnB,oBAAoB;YA4BpB,UAAU;IAWX,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB/C;;;;;;;;;OASG;YACW,uBAAuB;IAwBrC;;;;;OAKG;YACW,cAAc;IA4B5B;;;;;;;;;;OAUG;YACW,wBAAwB;IAuBtC;;;;;OAKG;IAMU,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;IAIpC,yBAAyB,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;YAIpF,WAAW;YAcX,UAAU;CAYzB"}
|
|
@@ -342,9 +342,9 @@ import { P2PInstrumentation } from './instrumentation.js';
|
|
|
342
342
|
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
343
343
|
const reqrespSubProtocolValidators = {
|
|
344
344
|
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
345
|
-
// TODO(#11336): A request validator for blocks
|
|
346
345
|
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
347
|
-
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this)
|
|
346
|
+
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
347
|
+
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this)
|
|
348
348
|
};
|
|
349
349
|
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
|
|
350
350
|
this.logger.info(`Started P2P service`, {
|
|
@@ -757,15 +757,61 @@ import { P2PInstrumentation } from './instrumentation.js';
|
|
|
757
757
|
});
|
|
758
758
|
}
|
|
759
759
|
/**
|
|
760
|
-
* Validate the requested block transactions.
|
|
760
|
+
* Validate the requested block transactions. Allow partial returns.
|
|
761
761
|
* @param request - The block transactions request.
|
|
762
762
|
* @param response - The block transactions response.
|
|
763
763
|
* @param peerId - The ID of the peer that made the request.
|
|
764
764
|
* @returns True if the requested block transactions are valid, false otherwise.
|
|
765
|
-
*/ async validateRequestedBlockTxs(
|
|
765
|
+
*/ async validateRequestedBlockTxs(request, response, peerId) {
|
|
766
766
|
const requestedTxValidator = this.createRequestedTxValidator();
|
|
767
767
|
try {
|
|
768
|
-
|
|
768
|
+
if (!response.blockHash.equals(request.blockHash)) {
|
|
769
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
770
|
+
throw new ValidationError(`Received block txs for unexpected block: expected ${request.blockHash.toString()}, got ${response.blockHash.toString()}`);
|
|
771
|
+
}
|
|
772
|
+
if (response.txIndices.getLength() !== request.txIndices.getLength()) {
|
|
773
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
774
|
+
throw new ValidationError(`Received block txs with mismatched bitvector length: expected ${request.txIndices.getLength()}, got ${response.txIndices.getLength()}`);
|
|
775
|
+
}
|
|
776
|
+
// Check no duplicates and not exceeding returnable count
|
|
777
|
+
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
778
|
+
const availableIndices = new Set(response.txIndices.getTrueIndices());
|
|
779
|
+
const maxReturnable = [
|
|
780
|
+
...requestedIndices
|
|
781
|
+
].filter((i)=>availableIndices.has(i)).length;
|
|
782
|
+
const returnedHashes = await Promise.all(response.txs.map((tx)=>tx.getTxHash().toString()));
|
|
783
|
+
const uniqueReturned = new Set(returnedHashes.map((h)=>h.toString()));
|
|
784
|
+
if (uniqueReturned.size !== returnedHashes.length) {
|
|
785
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
786
|
+
throw new ValidationError(`Received duplicate txs in block txs response`);
|
|
787
|
+
}
|
|
788
|
+
if (response.txs.length > maxReturnable) {
|
|
789
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
790
|
+
throw new ValidationError(`Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`);
|
|
791
|
+
}
|
|
792
|
+
// Given proposal (should have locally), ensure returned txs are valid subset and match request indices
|
|
793
|
+
const proposal = await this.mempools.attestationPool?.getBlockProposal(request.blockHash.toString());
|
|
794
|
+
if (proposal) {
|
|
795
|
+
// Build intersected indices
|
|
796
|
+
const intersectIdx = request.txIndices.getTrueIndices().filter((i)=>response.txIndices.isSet(i));
|
|
797
|
+
// Enforce subset membership and preserve increasing order by index.
|
|
798
|
+
const hashToIndexInProposal = new Map(proposal.txHashes.map((h, i)=>[
|
|
799
|
+
h.toString(),
|
|
800
|
+
i
|
|
801
|
+
]));
|
|
802
|
+
const allowedIndexSet = new Set(intersectIdx);
|
|
803
|
+
const indices = returnedHashes.map((h)=>hashToIndexInProposal.get(h));
|
|
804
|
+
const allAllowed = indices.every((idx)=>idx !== undefined && allowedIndexSet.has(idx));
|
|
805
|
+
const strictlyIncreasing = indices.every((idx, i)=>i === 0 ? idx !== undefined : idx > indices[i - 1]);
|
|
806
|
+
if (!allAllowed || !strictlyIncreasing) {
|
|
807
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
808
|
+
throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
|
|
809
|
+
}
|
|
810
|
+
} else {
|
|
811
|
+
// No local proposal, cannot check the membership/order of the returned txs
|
|
812
|
+
this.logger.warn(`Block proposal not found for block hash ${request.blockHash.toString()}; cannot validate membership/order of returned txs`);
|
|
813
|
+
return false;
|
|
814
|
+
}
|
|
769
815
|
await Promise.all(response.txs.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator)));
|
|
770
816
|
return true;
|
|
771
817
|
} catch (e) {
|
|
@@ -787,7 +833,7 @@ import { P2PInstrumentation } from './instrumentation.js';
|
|
|
787
833
|
* ReqRespSubProtocol.TX subprotocol validation.
|
|
788
834
|
*
|
|
789
835
|
* @param requestedTxHash - The collection of the txs that was requested.
|
|
790
|
-
* @param responseTx - The
|
|
836
|
+
* @param responseTx - The collection of txs that was received as a response to the request.
|
|
791
837
|
* @param peerId - The peer ID of the peer that sent the tx.
|
|
792
838
|
* @returns True if the whole collection of txs is valid, false otherwise.
|
|
793
839
|
*/ async validateRequestedTxs(requestedTxHash, responseTx, peerId) {
|
|
@@ -807,6 +853,45 @@ import { P2PInstrumentation } from './instrumentation.js';
|
|
|
807
853
|
return false;
|
|
808
854
|
}
|
|
809
855
|
}
|
|
856
|
+
/**
|
|
857
|
+
* Validates a BLOCK response.
|
|
858
|
+
*
|
|
859
|
+
* If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
|
|
860
|
+
* Penalizes on block number mismatch or hash mismatch.
|
|
861
|
+
*
|
|
862
|
+
* @param requestedBlockNumber - The requested block number.
|
|
863
|
+
* @param responseBlock - The block returned by the peer.
|
|
864
|
+
* @param peerId - The peer that returned the block.
|
|
865
|
+
* @returns True if the response is valid, false otherwise.
|
|
866
|
+
*/ async validateRequestedBlock(requestedBlockNumber, responseBlock, peerId) {
|
|
867
|
+
try {
|
|
868
|
+
const reqNum = Number(requestedBlockNumber.toString());
|
|
869
|
+
if (responseBlock.number !== reqNum) {
|
|
870
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
871
|
+
return false;
|
|
872
|
+
}
|
|
873
|
+
const local = await this.archiver.getBlock(reqNum);
|
|
874
|
+
if (!local) {
|
|
875
|
+
// We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
|
|
876
|
+
// TODO: Consider extending this validator to accept an expected hash or
|
|
877
|
+
// performing quorum-based checks when using P2P syncing prior to L1 sync.
|
|
878
|
+
this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
|
|
879
|
+
return false;
|
|
880
|
+
}
|
|
881
|
+
const [localHash, respHash] = await Promise.all([
|
|
882
|
+
local.hash(),
|
|
883
|
+
responseBlock.hash()
|
|
884
|
+
]);
|
|
885
|
+
if (!localHash.equals(respHash)) {
|
|
886
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
887
|
+
return false;
|
|
888
|
+
}
|
|
889
|
+
return true;
|
|
890
|
+
} catch (e) {
|
|
891
|
+
this.logger.warn(`Error validating requested block`, e);
|
|
892
|
+
return false;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
810
895
|
createRequestedTxValidator() {
|
|
811
896
|
return new AggregateTxValidator(new DataTxValidator(), new MetadataTxValidator({
|
|
812
897
|
l1ChainId: new Fr(this.config.l1ChainId),
|
|
@@ -1048,6 +1133,11 @@ _ts_decorate([
|
|
|
1048
1133
|
[Attributes.TX_HASH]: requestedTxHash.toString()
|
|
1049
1134
|
}))
|
|
1050
1135
|
], LibP2PService.prototype, "validateRequestedTxs", null);
|
|
1136
|
+
_ts_decorate([
|
|
1137
|
+
trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock)=>({
|
|
1138
|
+
[Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString()
|
|
1139
|
+
}))
|
|
1140
|
+
], LibP2PService.prototype, "validateRequestedBlock", null);
|
|
1051
1141
|
_ts_decorate([
|
|
1052
1142
|
trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
|
|
1053
1143
|
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/p2p",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.20251120",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -67,17 +67,17 @@
|
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@aztec/constants": "3.0.0-nightly.
|
|
71
|
-
"@aztec/epoch-cache": "3.0.0-nightly.
|
|
72
|
-
"@aztec/ethereum": "3.0.0-nightly.
|
|
73
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
74
|
-
"@aztec/kv-store": "3.0.0-nightly.
|
|
75
|
-
"@aztec/noir-contracts.js": "3.0.0-nightly.
|
|
76
|
-
"@aztec/noir-protocol-circuits-types": "3.0.0-nightly.
|
|
77
|
-
"@aztec/protocol-contracts": "3.0.0-nightly.
|
|
78
|
-
"@aztec/simulator": "3.0.0-nightly.
|
|
79
|
-
"@aztec/stdlib": "3.0.0-nightly.
|
|
80
|
-
"@aztec/telemetry-client": "3.0.0-nightly.
|
|
70
|
+
"@aztec/constants": "3.0.0-nightly.20251120",
|
|
71
|
+
"@aztec/epoch-cache": "3.0.0-nightly.20251120",
|
|
72
|
+
"@aztec/ethereum": "3.0.0-nightly.20251120",
|
|
73
|
+
"@aztec/foundation": "3.0.0-nightly.20251120",
|
|
74
|
+
"@aztec/kv-store": "3.0.0-nightly.20251120",
|
|
75
|
+
"@aztec/noir-contracts.js": "3.0.0-nightly.20251120",
|
|
76
|
+
"@aztec/noir-protocol-circuits-types": "3.0.0-nightly.20251120",
|
|
77
|
+
"@aztec/protocol-contracts": "3.0.0-nightly.20251120",
|
|
78
|
+
"@aztec/simulator": "3.0.0-nightly.20251120",
|
|
79
|
+
"@aztec/stdlib": "3.0.0-nightly.20251120",
|
|
80
|
+
"@aztec/telemetry-client": "3.0.0-nightly.20251120",
|
|
81
81
|
"@chainsafe/libp2p-gossipsub": "13.0.0",
|
|
82
82
|
"@chainsafe/libp2p-noise": "^15.0.0",
|
|
83
83
|
"@chainsafe/libp2p-yamux": "^6.0.2",
|
|
@@ -104,8 +104,8 @@
|
|
|
104
104
|
"xxhash-wasm": "^1.1.0"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
|
-
"@aztec/archiver": "3.0.0-nightly.
|
|
108
|
-
"@aztec/world-state": "3.0.0-nightly.
|
|
107
|
+
"@aztec/archiver": "3.0.0-nightly.20251120",
|
|
108
|
+
"@aztec/world-state": "3.0.0-nightly.20251120",
|
|
109
109
|
"@jest/globals": "^30.0.0",
|
|
110
110
|
"@types/jest": "^30.0.0",
|
|
111
111
|
"@types/node": "^22.15.17",
|
package/src/client/interface.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EthAddress, L2BlockId } from '@aztec/stdlib/block';
|
|
2
2
|
import type { P2PApiFull } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type { BlockProposal, P2PClientType } from '@aztec/stdlib/p2p';
|
|
3
|
+
import type { BlockAttestation, BlockProposal, P2PClientType } from '@aztec/stdlib/p2p';
|
|
4
4
|
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
6
6
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -50,6 +50,9 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
50
50
|
*/
|
|
51
51
|
broadcastProposal(proposal: BlockProposal): Promise<void>;
|
|
52
52
|
|
|
53
|
+
/** Broadcasts block attestations to other peers. */
|
|
54
|
+
broadcastAttestations(attestations: BlockAttestation[]): Promise<void>;
|
|
55
|
+
|
|
53
56
|
/**
|
|
54
57
|
* Registers a callback from the validator client that determines how to behave when
|
|
55
58
|
* foreign block proposals are received
|
package/src/client/p2p_client.ts
CHANGED
|
@@ -380,6 +380,11 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
380
380
|
return this.p2pService.propagate(proposal);
|
|
381
381
|
}
|
|
382
382
|
|
|
383
|
+
public async broadcastAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
384
|
+
this.log.verbose(`Broadcasting ${attestations.length} attestations to peers`);
|
|
385
|
+
await Promise.all(attestations.map(att => this.p2pService.propagate(att)));
|
|
386
|
+
}
|
|
387
|
+
|
|
383
388
|
public async getAttestationsForSlot(slot: bigint, proposalId?: string): Promise<BlockAttestation[]> {
|
|
384
389
|
return (
|
|
385
390
|
(await (proposalId
|
|
@@ -8,7 +8,7 @@ import { Timer } from '@aztec/foundation/timer';
|
|
|
8
8
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
9
9
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
10
10
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
11
|
-
import type { EthAddress, L2BlockSource } from '@aztec/stdlib/block';
|
|
11
|
+
import type { EthAddress, L2Block, L2BlockSource } from '@aztec/stdlib/block';
|
|
12
12
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
13
13
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
14
14
|
import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
@@ -514,9 +514,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
514
514
|
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
515
515
|
const reqrespSubProtocolValidators = {
|
|
516
516
|
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
517
|
-
// TODO(#11336): A request validator for blocks
|
|
518
517
|
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
519
518
|
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
519
|
+
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
|
|
520
520
|
};
|
|
521
521
|
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
|
|
522
522
|
this.logger.info(`Started P2P service`, {
|
|
@@ -993,7 +993,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
993
993
|
}
|
|
994
994
|
|
|
995
995
|
/**
|
|
996
|
-
* Validate the requested block transactions.
|
|
996
|
+
* Validate the requested block transactions. Allow partial returns.
|
|
997
997
|
* @param request - The block transactions request.
|
|
998
998
|
* @param response - The block transactions response.
|
|
999
999
|
* @param peerId - The ID of the peer that made the request.
|
|
@@ -1003,14 +1003,71 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1003
1003
|
[Attributes.BLOCK_HASH]: request.blockHash.toString(),
|
|
1004
1004
|
}))
|
|
1005
1005
|
private async validateRequestedBlockTxs(
|
|
1006
|
-
|
|
1006
|
+
request: BlockTxsRequest,
|
|
1007
1007
|
response: BlockTxsResponse,
|
|
1008
1008
|
peerId: PeerId,
|
|
1009
1009
|
): Promise<boolean> {
|
|
1010
1010
|
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1011
1011
|
|
|
1012
1012
|
try {
|
|
1013
|
-
|
|
1013
|
+
if (!response.blockHash.equals(request.blockHash)) {
|
|
1014
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1015
|
+
throw new ValidationError(
|
|
1016
|
+
`Received block txs for unexpected block: expected ${request.blockHash.toString()}, got ${response.blockHash.toString()}`,
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
if (response.txIndices.getLength() !== request.txIndices.getLength()) {
|
|
1021
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1022
|
+
throw new ValidationError(
|
|
1023
|
+
`Received block txs with mismatched bitvector length: expected ${request.txIndices.getLength()}, got ${response.txIndices.getLength()}`,
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
// Check no duplicates and not exceeding returnable count
|
|
1028
|
+
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
1029
|
+
const availableIndices = new Set(response.txIndices.getTrueIndices());
|
|
1030
|
+
const maxReturnable = [...requestedIndices].filter(i => availableIndices.has(i)).length;
|
|
1031
|
+
|
|
1032
|
+
const returnedHashes = await Promise.all(response.txs.map(tx => tx.getTxHash().toString()));
|
|
1033
|
+
const uniqueReturned = new Set(returnedHashes.map(h => h.toString()));
|
|
1034
|
+
if (uniqueReturned.size !== returnedHashes.length) {
|
|
1035
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1036
|
+
throw new ValidationError(`Received duplicate txs in block txs response`);
|
|
1037
|
+
}
|
|
1038
|
+
if (response.txs.length > maxReturnable) {
|
|
1039
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1040
|
+
throw new ValidationError(
|
|
1041
|
+
`Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`,
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
// Given proposal (should have locally), ensure returned txs are valid subset and match request indices
|
|
1046
|
+
const proposal = await this.mempools.attestationPool?.getBlockProposal(request.blockHash.toString());
|
|
1047
|
+
if (proposal) {
|
|
1048
|
+
// Build intersected indices
|
|
1049
|
+
const intersectIdx = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
|
|
1050
|
+
|
|
1051
|
+
// Enforce subset membership and preserve increasing order by index.
|
|
1052
|
+
const hashToIndexInProposal = new Map<string, number>(
|
|
1053
|
+
proposal.txHashes.map((h, i) => [h.toString(), i] as [string, number]),
|
|
1054
|
+
);
|
|
1055
|
+
const allowedIndexSet = new Set(intersectIdx);
|
|
1056
|
+
const indices = returnedHashes.map(h => hashToIndexInProposal.get(h));
|
|
1057
|
+
const allAllowed = indices.every(idx => idx !== undefined && allowedIndexSet.has(idx));
|
|
1058
|
+
const strictlyIncreasing = indices.every((idx, i) => (i === 0 ? idx !== undefined : idx! > indices[i - 1]!));
|
|
1059
|
+
if (!allAllowed || !strictlyIncreasing) {
|
|
1060
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1061
|
+
throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
|
|
1062
|
+
}
|
|
1063
|
+
} else {
|
|
1064
|
+
// No local proposal, cannot check the membership/order of the returned txs
|
|
1065
|
+
this.logger.warn(
|
|
1066
|
+
`Block proposal not found for block hash ${request.blockHash.toString()}; cannot validate membership/order of returned txs`,
|
|
1067
|
+
);
|
|
1068
|
+
return false;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1014
1071
|
await Promise.all(response.txs.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator)));
|
|
1015
1072
|
return true;
|
|
1016
1073
|
} catch (e: any) {
|
|
@@ -1034,7 +1091,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1034
1091
|
* ReqRespSubProtocol.TX subprotocol validation.
|
|
1035
1092
|
*
|
|
1036
1093
|
* @param requestedTxHash - The collection of the txs that was requested.
|
|
1037
|
-
* @param responseTx - The
|
|
1094
|
+
* @param responseTx - The collection of txs that was received as a response to the request.
|
|
1038
1095
|
* @param peerId - The peer ID of the peer that sent the tx.
|
|
1039
1096
|
* @returns True if the whole collection of txs is valid, false otherwise.
|
|
1040
1097
|
*/
|
|
@@ -1061,6 +1118,53 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1061
1118
|
}
|
|
1062
1119
|
}
|
|
1063
1120
|
|
|
1121
|
+
/**
|
|
1122
|
+
* Validates a BLOCK response.
|
|
1123
|
+
*
|
|
1124
|
+
* If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
|
|
1125
|
+
* Penalizes on block number mismatch or hash mismatch.
|
|
1126
|
+
*
|
|
1127
|
+
* @param requestedBlockNumber - The requested block number.
|
|
1128
|
+
* @param responseBlock - The block returned by the peer.
|
|
1129
|
+
* @param peerId - The peer that returned the block.
|
|
1130
|
+
* @returns True if the response is valid, false otherwise.
|
|
1131
|
+
*/
|
|
1132
|
+
@trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock) => ({
|
|
1133
|
+
[Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString(),
|
|
1134
|
+
}))
|
|
1135
|
+
private async validateRequestedBlock(
|
|
1136
|
+
requestedBlockNumber: Fr,
|
|
1137
|
+
responseBlock: L2Block,
|
|
1138
|
+
peerId: PeerId,
|
|
1139
|
+
): Promise<boolean> {
|
|
1140
|
+
try {
|
|
1141
|
+
const reqNum = Number(requestedBlockNumber.toString());
|
|
1142
|
+
if (responseBlock.number !== reqNum) {
|
|
1143
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1144
|
+
return false;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
const local = await this.archiver.getBlock(reqNum);
|
|
1148
|
+
if (!local) {
|
|
1149
|
+
// We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
|
|
1150
|
+
// TODO: Consider extending this validator to accept an expected hash or
|
|
1151
|
+
// performing quorum-based checks when using P2P syncing prior to L1 sync.
|
|
1152
|
+
this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
|
|
1153
|
+
return false;
|
|
1154
|
+
}
|
|
1155
|
+
const [localHash, respHash] = await Promise.all([local.hash(), responseBlock.hash()]);
|
|
1156
|
+
if (!localHash.equals(respHash)) {
|
|
1157
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1158
|
+
return false;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
return true;
|
|
1162
|
+
} catch (e) {
|
|
1163
|
+
this.logger.warn(`Error validating requested block`, e);
|
|
1164
|
+
return false;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1064
1168
|
private createRequestedTxValidator(): TxValidator {
|
|
1065
1169
|
return new AggregateTxValidator(
|
|
1066
1170
|
new DataTxValidator(),
|