From 419e15972cb27d923f41d7ddc6b929cd8013b889 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 3 Jun 2025 13:00:43 +0000 Subject: [PATCH 1/3] chore: merge conflicts --- .../p2p/src/services/libp2p/libp2p_service.ts | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/yarn-project/p2p/src/services/libp2p/libp2p_service.ts b/yarn-project/p2p/src/services/libp2p/libp2p_service.ts index f302e31ca229..7e48ef509ec5 100644 --- a/yarn-project/p2p/src/services/libp2p/libp2p_service.ts +++ b/yarn-project/p2p/src/services/libp2p/libp2p_service.ts @@ -66,6 +66,7 @@ import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js'; import { pingHandler, reqRespBlockHandler, reqRespTxHandler, statusHandler } from '../reqresp/protocols/index.js'; import { ReqResp } from '../reqresp/reqresp.js'; import type { P2PBlockReceivedCallback, P2PService, PeerDiscoveryService } from '../service.js'; +import { P2PInstrumentation } from './instrumentation.js'; interface ValidationResult { name: string; @@ -125,6 +126,8 @@ export class LibP2PService extends ) { super(telemetry, 'LibP2PService'); + this.instrumentation = new P2PInstrumentation(telemetry, 'LibP2PService'); + this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize); this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize); this.msgIdSeenValidators[TopicType.block_attestation] = new MessageSeenValidator(config.seenMessageCacheSize); @@ -504,25 +507,33 @@ export class LibP2PService extends } protected preValidateReceivedMessage(msg: Message, msgId: string, source: PeerId) { - const getValidator = () => { - if (msg.topic === this.topicStrings[TopicType.tx]) { - return this.msgIdSeenValidators[TopicType.tx]; - } - if (msg.topic === this.topicStrings[TopicType.block_attestation]) { - return this.msgIdSeenValidators[TopicType.block_attestation]; - } - if (msg.topic === this.topicStrings[TopicType.block_proposal]) { - return this.msgIdSeenValidators[TopicType.block_proposal]; - } - this.logger.error(`Received message on unknown topic: ${msg.topic}`); - }; + let topicType: TopicType | undefined; + + switch (msg.topic) { + case this.topicStrings[TopicType.tx]: + topicType = TopicType.tx; + break; + case this.topicStrings[TopicType.block_attestation]: + topicType = TopicType.block_attestation; + break; + case this.topicStrings[TopicType.block_proposal]: + topicType = TopicType.block_proposal; + break; + default: + this.logger.error(`Received message on unknown topic: ${msg.topic}`); + break; + } - const validator = getValidator(); + const validator = topicType ? this.msgIdSeenValidators[topicType] : undefined; if (!validator || !validator.addMessage(msgId)) { + this.instrumentation.incMessagePrevalidationStatus(false, topicType); this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore); return false; } + + this.instrumentation.incMessagePrevalidationStatus(true, topicType); + return true; } From d057c22cb3da13f65316a2b83ee0b61a33ea9162 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 3 Jun 2025 15:05:27 +0000 Subject: [PATCH 2/3] chore: remove duplicate test --- yarn-project/validator-client/src/validator.test.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/yarn-project/validator-client/src/validator.test.ts b/yarn-project/validator-client/src/validator.test.ts index dfec457d277e..afa236bf316f 100644 --- a/yarn-project/validator-client/src/validator.test.ts +++ b/yarn-project/validator-client/src/validator.test.ts @@ -261,15 +261,6 @@ describe('ValidatorClient', () => { expect(p2pClient.getTxsByHash).toHaveBeenCalledWith(proposal.payload.txHashes, sender); }); - it('should request txs even if not attestor in this slot', async () => { - p2pClient.hasTxsInPool.mockImplementation(txHashes => Promise.resolve(times(txHashes.length, () => false))); - epochCache.isInCommittee.mockResolvedValue(false); - - const attestation = await validatorClient.attestToProposal(proposal, sender); - expect(attestation).toBeUndefined(); - expect(p2pClient.getTxsByHash).toHaveBeenCalledWith(proposal.payload.txHashes, sender); - }); - it('should throw an error if the transactions are not available', async () => { // Mock the p2pClient.getTxStatus to return undefined for all transactions p2pClient.getTxStatus.mockResolvedValue(undefined); From 1d5a2c178a40d082286298226050e841101f3985 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 3 Jun 2025 15:08:36 +0000 Subject: [PATCH 3/3] chore: remove duplicate test --- yarn-project/validator-client/src/validator.test.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/yarn-project/validator-client/src/validator.test.ts b/yarn-project/validator-client/src/validator.test.ts index afa236bf316f..335121b56c3f 100644 --- a/yarn-project/validator-client/src/validator.test.ts +++ b/yarn-project/validator-client/src/validator.test.ts @@ -253,14 +253,6 @@ describe('ValidatorClient', () => { expect(p2pClient.getTxsByHash).toHaveBeenCalledWith(proposal.payload.txHashes, sender); }); - it('should request txs if missing for attesting', async () => { - p2pClient.hasTxsInPool.mockImplementation(txHashes => Promise.resolve(times(txHashes.length, i => i === 0))); - - const attestation = await validatorClient.attestToProposal(proposal, sender); - expect(attestation).toBeDefined(); - expect(p2pClient.getTxsByHash).toHaveBeenCalledWith(proposal.payload.txHashes, sender); - }); - it('should throw an error if the transactions are not available', async () => { // Mock the p2pClient.getTxStatus to return undefined for all transactions p2pClient.getTxStatus.mockResolvedValue(undefined);