Skip to content

Commit 1d08f90

Browse files
committed
proper naming in BlockTxsRequest
1 parent 9e1d53c commit 1d08f90

File tree

10 files changed

+68
-68
lines changed

10 files changed

+68
-68
lines changed

yarn-project/p2p/src/client/test/p2p_client.integration_batch_txs.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ describe('p2p client integration batch txs', () => {
105105
await sleep(1000);
106106
};
107107

108-
const createBlockProposal = (blockNumber: number, blockHash: Fr, txHashes: TxHash[]) => {
108+
const createBlockProposal = (blockNumber: number, archiveRoot: Fr, txHashes: TxHash[]) => {
109109
return makeBlockProposal({
110110
signer: Secp256k1Signer.random(),
111111
blockHeader: makeBlockHeader(1, { blockNumber: BlockNumber(blockNumber) }),
112-
archiveRoot: blockHash,
112+
archiveRoot,
113113
txHashes,
114114
});
115115
};
@@ -173,8 +173,8 @@ describe('p2p client integration batch txs', () => {
173173
const txHashes = await Promise.all(txs.map(tx => tx.getTxHash()));
174174

175175
const blockNumber = 5;
176-
const blockHash = Fr.random();
177-
const blockProposal = await createBlockProposal(blockNumber, blockHash, txHashes);
176+
const archiveRoot = Fr.random();
177+
const blockProposal = await createBlockProposal(blockNumber, archiveRoot, txHashes);
178178

179179
// Distribute transactions across peers (simulating partial knowledge)
180180
// Peer 0 has no txs (client requesting)

yarn-project/p2p/src/client/test/p2p_client.integration_block_txs.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('p2p client integration block txs protocol ', () => {
4141
let clients: P2PClient[] = [];
4242

4343
const blockNumber = BlockNumber(5);
44-
const blockHash = Fr.random();
44+
const archiveRoot = Fr.random();
4545
let txs: Tx[];
4646
let txHashes: TxHash[];
4747
let blockProposal: BlockProposal;
@@ -100,7 +100,7 @@ describe('p2p client integration block txs protocol ', () => {
100100

101101
txs = await Promise.all(times(5, i => createMockTxWithMetadata(p2pBaseConfig, i)));
102102
txHashes = await Promise.all(txs.map(tx => tx.getTxHash()));
103-
blockProposal = await createBlockProposal(BlockNumber(blockNumber), blockHash, txHashes);
103+
blockProposal = await createBlockProposal(BlockNumber(blockNumber), archiveRoot, txHashes);
104104
attestationPool.getBlockProposal.mockResolvedValue(blockProposal);
105105
});
106106

@@ -122,11 +122,11 @@ describe('p2p client integration block txs protocol ', () => {
122122
await sleep(1000);
123123
};
124124

125-
const createBlockProposal = (blockNumber: BlockNumber, blockHash: Fr, txHashes: TxHash[]) => {
125+
const createBlockProposal = (blockNumber: BlockNumber, archiveRoot: Fr, txHashes: TxHash[]) => {
126126
return makeBlockProposal({
127127
signer: Secp256k1Signer.random(),
128128
blockHeader: makeBlockHeader(1, { blockNumber }),
129-
archiveRoot: blockHash,
129+
archiveRoot,
130130
txHashes,
131131
});
132132
};
@@ -171,11 +171,11 @@ describe('p2p client integration block txs protocol ', () => {
171171
blockProposal,
172172
txHashes.filter((_, i) => requestedIndices.includes(i)),
173173
);
174-
//const response = await sendBlockTxsRequest(blockHash, requestedIndices, txs.length);
174+
//const response = await sendBlockTxsRequest(archiveRoot, requestedIndices, txs.length);
175175

176176
expect(response.status).toBe(ReqRespStatus.SUCCESS);
177177
const blockTxsResponse = BlockTxsResponse.fromBuffer(response.data);
178-
expect(blockTxsResponse.blockHash.equals(blockHash)).toBe(true);
178+
expect(blockTxsResponse.archiveRoot.equals(archiveRoot)).toBe(true);
179179
expect(blockTxsResponse.txs.length).toBe(requestedIndices.length);
180180
expect(blockTxsResponse.txIndices.getTrueIndices()).toEqual([0, 1, 2, 3, 4]);
181181

@@ -211,7 +211,7 @@ describe('p2p client integration block txs protocol ', () => {
211211

212212
expect(response.status).toBe(ReqRespStatus.SUCCESS);
213213
const blockTxsResponse = BlockTxsResponse.fromBuffer(response.data);
214-
expect(blockTxsResponse.blockHash.equals(blockHash)).toBe(true);
214+
expect(blockTxsResponse.archiveRoot.equals(archiveRoot)).toBe(true);
215215
expect(blockTxsResponse.txs.length).toBe(2); // Only txs at indices 0 and 2 are returned
216216
expect(blockTxsResponse.txIndices.getTrueIndices()).toEqual([0, 2, 3]);
217217

@@ -235,7 +235,7 @@ describe('p2p client integration block txs protocol ', () => {
235235

236236
expect(response.status).toBe(ReqRespStatus.SUCCESS);
237237
const blockTxsResponse = BlockTxsResponse.fromBuffer(response.data);
238-
expect(blockTxsResponse.blockHash.equals(blockHash)).toBe(true);
238+
expect(blockTxsResponse.archiveRoot.equals(archiveRoot)).toBe(true);
239239
expect(blockTxsResponse.txs.length).toBe(0);
240240
expect(blockTxsResponse.txIndices.getTrueIndices()).toEqual([]);
241241
});
@@ -260,7 +260,7 @@ describe('p2p client integration block txs protocol ', () => {
260260

261261
expect(response.status).toBe(ReqRespStatus.SUCCESS);
262262
const blockTxsResponse = BlockTxsResponse.fromBuffer(response.data);
263-
expect(blockTxsResponse.blockHash.equals(blockHash)).toBe(true);
263+
expect(blockTxsResponse.archiveRoot.equals(archiveRoot)).toBe(true);
264264
expect(blockTxsResponse.txs.length).toBe(requestedIndices.length);
265265
expect(blockTxsResponse.txIndices.getTrueIndices()).toEqual([0, 1, 2, 3, 4]);
266266

@@ -297,7 +297,7 @@ describe('p2p client integration block txs protocol ', () => {
297297

298298
expect(response.status).toBe(ReqRespStatus.SUCCESS);
299299
const blockTxsResponse = BlockTxsResponse.fromBuffer(response.data);
300-
expect(blockTxsResponse.blockHash.equals(blockHash)).toBe(true);
300+
expect(blockTxsResponse.archiveRoot.equals(archiveRoot)).toBe(true);
301301
expect(blockTxsResponse.txs.length).toBe(2); // Only 2 txs returned
302302
expect(blockTxsResponse.txIndices.getTrueIndices()).toEqual([1, 3]); // Only indices 1 and 3 available
303303

@@ -337,8 +337,8 @@ describe('p2p client integration block txs protocol ', () => {
337337
expect(response.status).toBe(ReqRespStatus.SUCCESS);
338338
const blockTxsResponse = BlockTxsResponse.fromBuffer(response.data);
339339

340-
// When peer doesn't have proposal but has txs, it returns Fr.ZERO as blockHash
341-
expect(blockTxsResponse.blockHash.equals(Fr.ZERO)).toBe(true);
340+
// When peer doesn't have proposal but has txs, it returns Fr.ZERO as archive root
341+
expect(blockTxsResponse.archiveRoot.equals(Fr.ZERO)).toBe(true);
342342
expect(blockTxsResponse.txs.length).toBe(2); // Only 2 txs available
343343
expect(blockTxsResponse.txIndices.getLength()).toBe(0); // Empty BitVector when no proposal
344344

@@ -367,7 +367,7 @@ describe('p2p client integration block txs protocol ', () => {
367367
expect(response.status).toBe(ReqRespStatus.SUCCESS);
368368
const blockTxsResponse = BlockTxsResponse.fromBuffer(response.data);
369369

370-
expect(blockTxsResponse.blockHash.equals(Fr.ZERO)).toBe(true);
370+
expect(blockTxsResponse.archiveRoot.equals(Fr.ZERO)).toBe(true);
371371
expect(blockTxsResponse.txs.length).toBe(1); // Only 1 tx available
372372
expect(blockTxsResponse.txIndices.getLength()).toBe(0);
373373

@@ -389,7 +389,7 @@ describe('p2p client integration block txs protocol ', () => {
389389
expect(response.status).toBe(ReqRespStatus.SUCCESS);
390390
const blockTxsResponse = BlockTxsResponse.fromBuffer(response.data);
391391

392-
expect(blockTxsResponse.blockHash.equals(Fr.ZERO)).toBe(true);
392+
expect(blockTxsResponse.archiveRoot.equals(Fr.ZERO)).toBe(true);
393393
expect(blockTxsResponse.txs.length).toBe(0); // No txs available
394394
expect(blockTxsResponse.txIndices.getLength()).toBe(0);
395395
});

yarn-project/p2p/src/services/libp2p/libp2p_service.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,19 @@ describe('LibP2PService', () => {
210210
service.createRequestedTxValidator = () => stubValidator;
211211
});
212212

213-
function makeRequest(blockHash: Fr, length: number, indices: number[]): BlockTxsRequest {
213+
function makeRequest(archiveRoot: Fr, length: number, indices: number[]): BlockTxsRequest {
214214
return {
215-
blockHash,
215+
archiveRoot,
216216
txIndices: BitVector.init(length, indices),
217217
} as BlockTxsRequest;
218218
}
219219

220-
function makeResponse(blockHash: Fr, length: number, indices: number[], txHashes: string[]): BlockTxsResponse {
220+
function makeResponse(archiveRoot: Fr, length: number, indices: number[], txHashes: string[]): BlockTxsResponse {
221221
const txs = txHashes.map(h => ({
222222
getTxHash: () => ({ toString: () => h }),
223223
})) as any[];
224224
return {
225-
blockHash,
225+
archiveRoot,
226226
txs,
227227
txIndices: BitVector.init(length, indices),
228228
} as BlockTxsResponse;
@@ -248,7 +248,7 @@ describe('LibP2PService', () => {
248248
};
249249
}
250250

251-
it('should penalize and reject on block hash mismatch', async () => {
251+
it('should penalize and reject on archive root mismatch', async () => {
252252
const reqHash = Fr.random();
253253
const otherHash = Fr.random();
254254
const request = makeRequest(reqHash, 5, [0, 2]);

yarn-project/p2p/src/services/libp2p/libp2p_service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
12141214
* @returns True if the requested block transactions are valid, false otherwise.
12151215
*/
12161216
@trackSpan('Libp2pService.validateRequestedBlockTxs', request => ({
1217-
[Attributes.BLOCK_HASH]: request.blockHash.toString(),
1217+
[Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString(),
12181218
}))
12191219
private async validateRequestedBlockTxs(
12201220
request: BlockTxsRequest,
@@ -1224,10 +1224,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
12241224
const requestedTxValidator = this.createRequestedTxValidator();
12251225

12261226
try {
1227-
if (!response.blockHash.equals(request.blockHash)) {
1227+
if (!response.archiveRoot.equals(request.archiveRoot)) {
12281228
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
12291229
throw new ValidationError(
1230-
`Received block txs for unexpected block: expected ${request.blockHash.toString()}, got ${response.blockHash.toString()}`,
1230+
`Received block txs for unexpected archive root: expected ${request.archiveRoot.toString()}, got ${response.archiveRoot.toString()}`,
12311231
);
12321232
}
12331233

@@ -1257,7 +1257,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
12571257
}
12581258

12591259
// Given proposal (should have locally), ensure returned txs are valid subset and match request indices
1260-
const proposal = await this.mempools.attestationPool.getBlockProposal(request.blockHash.toString());
1260+
const proposal = await this.mempools.attestationPool.getBlockProposal(request.archiveRoot.toString());
12611261
if (proposal) {
12621262
// Build intersected indices
12631263
const intersectIdx = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
@@ -1277,7 +1277,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
12771277
} else {
12781278
// No local proposal, cannot check the membership/order of the returned txs
12791279
this.logger.warn(
1280-
`Block proposal not found for block hash ${request.blockHash.toString()}; cannot validate membership/order of returned txs`,
1280+
`Block proposal not found for archive root ${request.archiveRoot.toString()}; cannot validate membership/order of returned txs`,
12811281
);
12821282
return false;
12831283
}

yarn-project/p2p/src/services/reqresp/batch-tx-requester/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The requester classifies peers into three categories to optimize fetching:
7171
### Blind Phase → Smart Phase Transition
7272

7373
Peers transition from "dumb" to "smart" when they respond with a valid `BlockTxsResponse` containing:
74-
1. A matching `blockHash`
74+
1. A matching `archiveRoot`
7575
2. A non-empty `txIndices` BitVector indicating which transactions they have
7676
3. At least one transaction we're still missing
7777

@@ -81,10 +81,10 @@ Peers transition from "dumb" to "smart" when they respond with a valid `BlockTxs
8181
│ ┌────────────────────────────────────────────────────────────────────────┐ │
8282
│ │ Initial State: All peers are "dumb" (except pinned peer) │ │
8383
│ │ │ │
84-
│ │ Request: [blockHash, txHashes (full list), txIndices (BitVector)] │ │
84+
│ │ Request: [archiveRoot, txHashes (full list), txIndices (BitVector)] │ │
8585
│ │ └─ Include full hashes because peer may not have proposal │ │
8686
│ │ │ │
87-
│ │ Response: [blockHash, txs[], txIndices (what peer has)] │ │
87+
│ │ Response: [archiveRoot, txs[], txIndices (what peer has)] │ │
8888
│ │ └─ Tells us exactly which txs this peer can provide │ │
8989
│ └────────────────────────────────────────────────────────────────────────┘ │
9090
└──────────────────────────────────────────────────────────────────────────────┘
@@ -97,10 +97,10 @@ Peers transition from "dumb" to "smart" when they respond with a valid `BlockTxs
9797
│ ┌────────────────────────────────────────────────────────────────────────┐ │
9898
│ │ Peer promoted to "smart" - we know exactly what they have │ │
9999
│ │ │ │
100-
│ │ Request: [blockHash, txIndices (BitVector only)] │ │
100+
│ │ Request: [archiveRoot, txIndices (BitVector only)] │ │
101101
│ │ └─ No need for full hashes, peer has the proposal │ │
102102
│ │ │ │
103-
│ │ Response: [blockHash, txs[], txIndices (updated availability)] │ │
103+
│ │ Response: [archiveRoot, txs[], txIndices (updated availability)] │ │
104104
│ │ └─ May have received more txs since last response │ │
105105
│ └────────────────────────────────────────────────────────────────────────┘ │
106106
└──────────────────────────────────────────────────────────────────────────────┘
@@ -152,7 +152,7 @@ The `BatchTxRequester` runs three types of workers concurrently:
152152

153153
```typescript
154154
class BlockTxsRequest {
155-
blockHash: Fr; // 32-byte hash of the proposed block header
155+
archiveRoot: Fr; // Archive root after the proposed block is applied
156156
txHashes: TxHashArray; // Full tx hashes (for dumb peers without proposal)
157157
txIndices: BitVector; // Which txs from proposal we're requesting (1 = want)
158158
}
@@ -162,7 +162,7 @@ class BlockTxsRequest {
162162

163163
```typescript
164164
class BlockTxsResponse {
165-
blockHash: Fr; // Echo back the block hash
165+
archiveRoot: Fr; // Echo back the proposal archive root
166166
txs: TxArray; // Actual transaction data
167167
txIndices: BitVector; // Which txs the peer has available (1 = have)
168168
}

yarn-project/p2p/src/services/reqresp/batch-tx-requester/batch_tx_requester.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ describe('BatchTxRequester', () => {
6363
txValidator = new AlwaysValidTxValidator();
6464

6565
const signer = Secp256k1Signer.random();
66-
const blockHash = Fr.random();
66+
const archiveRoot = Fr.random();
6767
blockProposal = await makeBlockProposal({
6868
signer,
6969
blockHeader: makeBlockHeader(1, { blockNumber: BlockNumber(1) }),
70-
archiveRoot: blockHash,
70+
archiveRoot,
7171
txHashes: [],
7272
});
7373
});

yarn-project/p2p/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,9 @@ export class BatchTxRequester {
605605
}
606606

607607
private isBlockResponseValid(response: BlockTxsResponse): boolean {
608-
const blockIdsMatch = this.blockProposal.archive.toString() === response.blockHash.toString();
608+
const archiveRootsMatch = this.blockProposal.archive.toString() === response.archiveRoot.toString();
609609
const peerHasSomeTxsFromProposal = !response.txIndices.isEmpty();
610-
return blockIdsMatch && peerHasSomeTxsFromProposal;
610+
return archiveRootsMatch && peerHasSomeTxsFromProposal;
611611
}
612612

613613
private peerHasSomeTxsWeAreMissing(_peerId: PeerId, response: BlockTxsResponse): boolean {

0 commit comments

Comments
 (0)