@aztec/p2p 2.1.2 → 2.1.3

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.
@@ -691,6 +691,6 @@ _ts_decorate([
691
691
  trackSpan('p2pClient.broadcastProposal', async (proposal)=>({
692
692
  [Attributes.SLOT_NUMBER]: proposal.slotNumber.toNumber(),
693
693
  [Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
694
- [Attributes.P2P_ID]: (await proposal.p2pMessageIdentifier()).toString()
694
+ [Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString()
695
695
  }))
696
696
  ], P2PClient.prototype, "broadcastProposal", null);
@@ -123,6 +123,14 @@ export declare class LibP2PService<T extends P2PClientType = P2PClientType.Full>
123
123
  result: boolean;
124
124
  topicType?: TopicType;
125
125
  };
126
+ /**
127
+ * Safely deserializes a P2PMessage from raw message data.
128
+ * @param msgId - The message ID.
129
+ * @param source - The peer ID of the message source.
130
+ * @param data - The raw message data.
131
+ * @returns The deserialized P2PMessage or undefined if deserialization fails.
132
+ */
133
+ private safelyDeserializeP2PMessage;
126
134
  /**
127
135
  * Handles a new gossip message that was received by the client.
128
136
  * @param topic - The message's topic.
@@ -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;AAE9D,OAAO,EAAE,KAAK,MAAM,EAA6C,MAAM,uBAAuB,CAAC;AAI/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,QAAQ,EAAE,sBAAsB,EAAE,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,CAAC,EACjE,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,+BAA+B,CAAC,CAAC,CAAC,CAAC;cAsB9B,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAyCnF;;;;;OAKG;YACW,0BAA0B;YA8C1B,oBAAoB;YA6CpB,yBAAyB;IAiCvC;;;OAGG;YAMW,oBAAoB;IAIlC;;;OAGG;IACU,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,OAAO,EAAE,CAAC;IAYvD;;;;;;;;;;;;;OAaG;YAMW,mBAAmB;YAmCnB,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"}
@@ -98,7 +98,7 @@ import { P2PInstrumentation } from './instrumentation.js';
98
98
  this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
99
99
  this.blockReceivedCallback = async (block)=>{
100
100
  this.logger.debug(`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber.toNumber()} from peer.`, {
101
- p2pMessageIdentifier: await block.p2pMessageIdentifier()
101
+ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier()
102
102
  });
103
103
  return undefined;
104
104
  };
@@ -463,11 +463,33 @@ import { P2PInstrumentation } from './instrumentation.js';
463
463
  };
464
464
  }
465
465
  /**
466
+ * Safely deserializes a P2PMessage from raw message data.
467
+ * @param msgId - The message ID.
468
+ * @param source - The peer ID of the message source.
469
+ * @param data - The raw message data.
470
+ * @returns The deserialized P2PMessage or undefined if deserialization fails.
471
+ */ safelyDeserializeP2PMessage(msgId, source, data) {
472
+ try {
473
+ return P2PMessage.fromMessageData(Buffer.from(data));
474
+ } catch (err) {
475
+ this.logger.error(`Error deserializing P2PMessage`, err, {
476
+ msgId,
477
+ source: source.toString()
478
+ });
479
+ this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Reject);
480
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
481
+ return undefined;
482
+ }
483
+ }
484
+ /**
466
485
  * Handles a new gossip message that was received by the client.
467
486
  * @param topic - The message's topic.
468
487
  * @param data - The message data
469
488
  */ async handleNewGossipMessage(msg, msgId, source) {
470
- const p2pMessage = P2PMessage.fromMessageData(Buffer.from(msg.data));
489
+ const p2pMessage = this.safelyDeserializeP2PMessage(msgId, source, msg.data);
490
+ if (!p2pMessage) {
491
+ return;
492
+ }
471
493
  const preValidationResult = this.preValidateReceivedMessage(msg, msgId, source);
472
494
  if (!preValidationResult.result) {
473
495
  return;
@@ -491,6 +513,7 @@ import { P2PInstrumentation } from './instrumentation.js';
491
513
  try {
492
514
  resultAndObj = await validationFunc();
493
515
  } catch (err) {
516
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
494
517
  this.logger.error(`Error deserializing and validating gossipsub message`, err, {
495
518
  msgId,
496
519
  source: source.toString(),
@@ -584,7 +607,7 @@ import { P2PInstrumentation } from './instrumentation.js';
584
607
  return;
585
608
  }
586
609
  this.logger.debug(`Received attestation for slot ${attestation.slotNumber.toNumber()} from external peer ${source.toString()}`, {
587
- p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
610
+ p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
588
611
  slot: attestation.slotNumber.toNumber(),
589
612
  archive: attestation.archive.toString(),
590
613
  source: source.toString()
@@ -633,7 +656,7 @@ import { P2PInstrumentation } from './instrumentation.js';
633
656
  const slot = block.slotNumber.toBigInt();
634
657
  const previousSlot = slot - 1n;
635
658
  this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
636
- p2pMessageIdentifier: await block.p2pMessageIdentifier(),
659
+ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
637
660
  slot: block.slotNumber.toNumber(),
638
661
  archive: block.archive.toString(),
639
662
  source: sender.toString()
@@ -651,7 +674,7 @@ import { P2PInstrumentation } from './instrumentation.js';
651
674
  if (attestations?.length) {
652
675
  for (const attestation of attestations){
653
676
  this.logger.verbose(`Broadcasting attestation for slot ${attestation.slotNumber.toNumber()}`, {
654
- p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
677
+ p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
655
678
  slot: attestation.slotNumber.toNumber(),
656
679
  archive: attestation.archive.toString()
657
680
  });
@@ -669,7 +692,7 @@ import { P2PInstrumentation } from './instrumentation.js';
669
692
  * Propagates provided message to peers.
670
693
  * @param message - The message to propagate.
671
694
  */ async propagate(message) {
672
- const p2pMessageIdentifier = await message.p2pMessageIdentifier();
695
+ const p2pMessageIdentifier = await message.p2pMessageLoggingIdentifier();
673
696
  this.logger.trace(`Message ${p2pMessageIdentifier} queued`, {
674
697
  p2pMessageIdentifier
675
698
  });
@@ -887,7 +910,7 @@ import { P2PInstrumentation } from './instrumentation.js';
887
910
  }
888
911
  async sendToPeers(message) {
889
912
  const parent = message.constructor;
890
- const identifier = await message.p2pMessageIdentifier().then((i)=>i.toString());
913
+ const identifier = await message.p2pMessageLoggingIdentifier().then((i)=>i.toString());
891
914
  this.logger.trace(`Sending message ${identifier}`, {
892
915
  p2pMessageIdentifier: identifier
893
916
  });
@@ -918,14 +941,14 @@ _ts_decorate([
918
941
  trackSpan('Libp2pService.processValidBlockProposal', async (block)=>({
919
942
  [Attributes.SLOT_NUMBER]: block.slotNumber.toNumber(),
920
943
  [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
921
- [Attributes.P2P_ID]: await block.p2pMessageIdentifier().then((i)=>i.toString())
944
+ [Attributes.P2P_ID]: await block.p2pMessageLoggingIdentifier().then((i)=>i.toString())
922
945
  }))
923
946
  ], LibP2PService.prototype, "processValidBlockProposal", null);
924
947
  _ts_decorate([
925
948
  trackSpan('Libp2pService.broadcastAttestation', async (attestation)=>({
926
949
  [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toNumber(),
927
950
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
928
- [Attributes.P2P_ID]: await attestation.p2pMessageIdentifier().then((i)=>i.toString())
951
+ [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
929
952
  }))
930
953
  ], LibP2PService.prototype, "broadcastAttestation", null);
931
954
  _ts_decorate([
@@ -942,7 +965,7 @@ _ts_decorate([
942
965
  trackSpan('Libp2pService.validateAttestation', async (_, attestation)=>({
943
966
  [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toNumber(),
944
967
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
945
- [Attributes.P2P_ID]: await attestation.p2pMessageIdentifier().then((i)=>i.toString())
968
+ [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
946
969
  }))
947
970
  ], LibP2PService.prototype, "validateAttestation", null);
948
971
  _ts_decorate([
package/dest/util.d.ts CHANGED
@@ -35,6 +35,7 @@ export declare function convertToMultiaddr(address: string, port: number, protoc
35
35
  * Queries the public IP address of the machine.
36
36
  */
37
37
  export declare function getPublicIp(): Promise<string>;
38
+ export declare function isValidIpAddress(address: string): boolean;
38
39
  export declare function resolveAddressIfNecessary(address: string, port: string): Promise<string>;
39
40
  export declare function configureP2PClientAddresses(_config: P2PConfig & DataStoreConfig): Promise<P2PConfig & DataStoreConfig>;
40
41
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAuB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAE7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAIpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAI7C,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IACxF,QAAQ,EAAE;QACR,MAAM,EAAE,IAAI,CACV,SAAS,EACT,kBAAkB,GAAG,qBAAqB,GAAG,SAAS,GAAG,WAAW,GAAG,+BAA+B,GAAG,QAAQ,CAClH,GAAG;YAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAA;SAAE,CAAC;KAClD,CAAC;CACH;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;IAC9B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C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAW9F;AAcD,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,SAAS,GAAG,eAAe,GACnC,OAAO,CAAC,SAAS,GAAG,eAAe,CAAC,CAmBtC;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE;IAAE,gBAAgB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,EACzG,KAAK,EAAE,iBAAiB,EACxB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CA2D9B;AAED;;;;GAIG;AACH,wBAAsB,gCAAgC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAS1F"}
package/dest/util.js CHANGED
@@ -3,6 +3,7 @@ import { generateKeyPair, marshalPrivateKey, unmarshalPrivateKey } from '@libp2p
3
3
  import { createFromPrivKey } from '@libp2p/peer-id-factory';
4
4
  import { resolve } from 'dns/promises';
5
5
  import { promises as fs } from 'fs';
6
+ import net from 'net';
6
7
  import path from 'path';
7
8
  const PEER_ID_DATA_DIR_FILE = 'p2p-private-key';
8
9
  /**
@@ -22,9 +23,17 @@ const PEER_ID_DATA_DIR_FILE = 'p2p-private-key';
22
23
  /**
23
24
  * Queries the public IP address of the machine.
24
25
  */ export async function getPublicIp() {
25
- const resp = await fetch('http://checkip.amazonaws.com/');
26
+ const resp = await fetch('https://checkip.amazonaws.com/');
26
27
  const text = await resp.text();
27
- return text.trim();
28
+ const address = text.trim();
29
+ if (!isValidIpAddress(address)) {
30
+ throw new Error(`Received invalid IP address from checkip service: ${address}`);
31
+ }
32
+ return address;
33
+ }
34
+ export function isValidIpAddress(address) {
35
+ const netType = net.isIP(address);
36
+ return netType === 4;
28
37
  }
29
38
  export async function resolveAddressIfNecessary(address, port) {
30
39
  const multiaddrPrefix = addressToMultiAddressType(address);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/p2p",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
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": "2.1.2",
71
- "@aztec/epoch-cache": "2.1.2",
72
- "@aztec/ethereum": "2.1.2",
73
- "@aztec/foundation": "2.1.2",
74
- "@aztec/kv-store": "2.1.2",
75
- "@aztec/noir-contracts.js": "2.1.2",
76
- "@aztec/noir-protocol-circuits-types": "2.1.2",
77
- "@aztec/protocol-contracts": "2.1.2",
78
- "@aztec/simulator": "2.1.2",
79
- "@aztec/stdlib": "2.1.2",
80
- "@aztec/telemetry-client": "2.1.2",
70
+ "@aztec/constants": "2.1.3",
71
+ "@aztec/epoch-cache": "2.1.3",
72
+ "@aztec/ethereum": "2.1.3",
73
+ "@aztec/foundation": "2.1.3",
74
+ "@aztec/kv-store": "2.1.3",
75
+ "@aztec/noir-contracts.js": "2.1.3",
76
+ "@aztec/noir-protocol-circuits-types": "2.1.3",
77
+ "@aztec/protocol-contracts": "2.1.3",
78
+ "@aztec/simulator": "2.1.3",
79
+ "@aztec/stdlib": "2.1.3",
80
+ "@aztec/telemetry-client": "2.1.3",
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": "2.1.2",
108
- "@aztec/world-state": "2.1.2",
107
+ "@aztec/archiver": "2.1.3",
108
+ "@aztec/world-state": "2.1.3",
109
109
  "@jest/globals": "^30.0.0",
110
110
  "@types/jest": "^30.0.0",
111
111
  "@types/node": "^22.15.17",
@@ -373,7 +373,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
373
373
  @trackSpan('p2pClient.broadcastProposal', async proposal => ({
374
374
  [Attributes.SLOT_NUMBER]: proposal.slotNumber.toNumber(),
375
375
  [Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
376
- [Attributes.P2P_ID]: (await proposal.p2pMessageIdentifier()).toString(),
376
+ [Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
377
377
  }))
378
378
  public broadcastProposal(proposal: BlockProposal): Promise<void> {
379
379
  this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber.toNumber()} to peers`);
@@ -172,7 +172,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
172
172
  this.blockReceivedCallback = async (block: BlockProposal): Promise<BlockAttestation[] | undefined> => {
173
173
  this.logger.debug(
174
174
  `Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber.toNumber()} from peer.`,
175
- { p2pMessageIdentifier: await block.p2pMessageIdentifier() },
175
+ { p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
176
176
  );
177
177
  return undefined;
178
178
  };
@@ -649,13 +649,37 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
649
649
  return { result: true, topicType };
650
650
  }
651
651
 
652
+ /**
653
+ * Safely deserializes a P2PMessage from raw message data.
654
+ * @param msgId - The message ID.
655
+ * @param source - The peer ID of the message source.
656
+ * @param data - The raw message data.
657
+ * @returns The deserialized P2PMessage or undefined if deserialization fails.
658
+ */
659
+ private safelyDeserializeP2PMessage(msgId: string, source: PeerId, data: Uint8Array): P2PMessage | undefined {
660
+ try {
661
+ return P2PMessage.fromMessageData(Buffer.from(data));
662
+ } catch (err) {
663
+ this.logger.error(`Error deserializing P2PMessage`, err, {
664
+ msgId,
665
+ source: source.toString(),
666
+ });
667
+ this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Reject);
668
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
669
+ return undefined;
670
+ }
671
+ }
672
+
652
673
  /**
653
674
  * Handles a new gossip message that was received by the client.
654
675
  * @param topic - The message's topic.
655
676
  * @param data - The message data
656
677
  */
657
678
  protected async handleNewGossipMessage(msg: Message, msgId: string, source: PeerId) {
658
- const p2pMessage = P2PMessage.fromMessageData(Buffer.from(msg.data));
679
+ const p2pMessage = this.safelyDeserializeP2PMessage(msgId, source, msg.data);
680
+ if (!p2pMessage) {
681
+ return;
682
+ }
659
683
 
660
684
  const preValidationResult = this.preValidateReceivedMessage(msg, msgId, source);
661
685
 
@@ -687,6 +711,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
687
711
  try {
688
712
  resultAndObj = await validationFunc();
689
713
  } catch (err) {
714
+ this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
690
715
  this.logger.error(`Error deserializing and validating gossipsub message`, err, {
691
716
  msgId,
692
717
  source: source.toString(),
@@ -785,7 +810,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
785
810
  this.logger.debug(
786
811
  `Received attestation for slot ${attestation.slotNumber.toNumber()} from external peer ${source.toString()}`,
787
812
  {
788
- p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
813
+ p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
789
814
  slot: attestation.slotNumber.toNumber(),
790
815
  archive: attestation.archive.toString(),
791
816
  source: source.toString(),
@@ -838,13 +863,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
838
863
  @trackSpan('Libp2pService.processValidBlockProposal', async block => ({
839
864
  [Attributes.SLOT_NUMBER]: block.slotNumber.toNumber(),
840
865
  [Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
841
- [Attributes.P2P_ID]: await block.p2pMessageIdentifier().then(i => i.toString()),
866
+ [Attributes.P2P_ID]: await block.p2pMessageLoggingIdentifier().then(i => i.toString()),
842
867
  }))
843
868
  private async processValidBlockProposal(block: BlockProposal, sender: PeerId) {
844
869
  const slot = block.slotNumber.toBigInt();
845
870
  const previousSlot = slot - 1n;
846
871
  this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
847
- p2pMessageIdentifier: await block.p2pMessageIdentifier(),
872
+ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
848
873
  slot: block.slotNumber.toNumber(),
849
874
  archive: block.archive.toString(),
850
875
  source: sender.toString(),
@@ -864,7 +889,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
864
889
  if (attestations?.length) {
865
890
  for (const attestation of attestations) {
866
891
  this.logger.verbose(`Broadcasting attestation for slot ${attestation.slotNumber.toNumber()}`, {
867
- p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
892
+ p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
868
893
  slot: attestation.slotNumber.toNumber(),
869
894
  archive: attestation.archive.toString(),
870
895
  });
@@ -880,7 +905,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
880
905
  @trackSpan('Libp2pService.broadcastAttestation', async attestation => ({
881
906
  [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toNumber(),
882
907
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
883
- [Attributes.P2P_ID]: await attestation.p2pMessageIdentifier().then(i => i.toString()),
908
+ [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
884
909
  }))
885
910
  private async broadcastAttestation(attestation: BlockAttestation) {
886
911
  await this.propagate(attestation);
@@ -891,7 +916,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
891
916
  * @param message - The message to propagate.
892
917
  */
893
918
  public async propagate<T extends Gossipable>(message: T) {
894
- const p2pMessageIdentifier = await message.p2pMessageIdentifier();
919
+ const p2pMessageIdentifier = await message.p2pMessageLoggingIdentifier();
895
920
  this.logger.trace(`Message ${p2pMessageIdentifier} queued`, { p2pMessageIdentifier });
896
921
  void this.jobQueue
897
922
  .put(async () => {
@@ -1125,7 +1150,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1125
1150
  @trackSpan('Libp2pService.validateAttestation', async (_, attestation) => ({
1126
1151
  [Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toNumber(),
1127
1152
  [Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
1128
- [Attributes.P2P_ID]: await attestation.p2pMessageIdentifier().then(i => i.toString()),
1153
+ [Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
1129
1154
  }))
1130
1155
  public async validateAttestation(peerId: PeerId, attestation: BlockAttestation): Promise<boolean> {
1131
1156
  const severity = await this.attestationValidator.validate(attestation);
@@ -1168,7 +1193,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
1168
1193
  private async sendToPeers<T extends Gossipable>(message: T) {
1169
1194
  const parent = message.constructor as typeof Gossipable;
1170
1195
 
1171
- const identifier = await message.p2pMessageIdentifier().then(i => i.toString());
1196
+ const identifier = await message.p2pMessageLoggingIdentifier().then(i => i.toString());
1172
1197
  this.logger.trace(`Sending message ${identifier}`, { p2pMessageIdentifier: identifier });
1173
1198
 
1174
1199
  const recipientsNum = await this.publishToTopic(this.topicStrings[parent.p2pTopic], message);
package/src/util.ts CHANGED
@@ -12,6 +12,7 @@ import { createFromPrivKey } from '@libp2p/peer-id-factory';
12
12
  import { resolve } from 'dns/promises';
13
13
  import { promises as fs } from 'fs';
14
14
  import type { Libp2p } from 'libp2p';
15
+ import net from 'net';
15
16
  import path from 'path';
16
17
 
17
18
  import type { P2PConfig } from './config.js';
@@ -56,9 +57,18 @@ export function convertToMultiaddr(address: string, port: number, protocol: 'tcp
56
57
  * Queries the public IP address of the machine.
57
58
  */
58
59
  export async function getPublicIp(): Promise<string> {
59
- const resp = await fetch('http://checkip.amazonaws.com/');
60
+ const resp = await fetch('https://checkip.amazonaws.com/');
60
61
  const text = await resp.text();
61
- return text.trim();
62
+ const address = text.trim();
63
+ if (!isValidIpAddress(address)) {
64
+ throw new Error(`Received invalid IP address from checkip service: ${address}`);
65
+ }
66
+ return address;
67
+ }
68
+
69
+ export function isValidIpAddress(address: string): boolean {
70
+ const netType = net.isIP(address);
71
+ return netType === 4;
62
72
  }
63
73
 
64
74
  export async function resolveAddressIfNecessary(address: string, port: string): Promise<string> {