diff --git a/packages/gossipsub/.aegir.js b/packages/gossipsub/.aegir.js index b3d7d69e84..45c4d2a7f8 100644 --- a/packages/gossipsub/.aegir.js +++ b/packages/gossipsub/.aegir.js @@ -1,6 +1,6 @@ /** @type {import('aegir').PartialOptions} */ export default { build: { - bundlesizeMax: '85KB' + bundlesizeMax: '62KB' } } diff --git a/packages/gossipsub/package.json b/packages/gossipsub/package.json index 40aa7f8b8a..dc8a2e4569 100644 --- a/packages/gossipsub/package.json +++ b/packages/gossipsub/package.json @@ -43,6 +43,7 @@ }, "scripts": { "lint": "aegir lint", + "dep-check": "aegir dep-check", "release": "aegir release --no-types", "build": "aegir build", "generate": "protons ./src/message/rpc.proto", @@ -75,7 +76,7 @@ "@libp2p/interface": "^3.1.0", "@libp2p/interface-internal": "^3.0.9", "@libp2p/peer-id": "^6.0.4", - "@libp2p/pubsub": "^10.0.0", + "@libp2p/utils": "^7.0.9", "@multiformats/multiaddr": "^13.0.1", "denque": "^2.1.0", "it-length-prefixed": "^10.0.1", @@ -90,7 +91,6 @@ "@chainsafe/as-sha256": "^1.2.0", "@dapplion/benchmark": "^1.0.0", "@libp2p/floodsub": "^11.0.10", - "@libp2p/interface-compliance-tests": "^7.0.10", "@libp2p/logger": "^6.2.2", "@libp2p/peer-store": "^12.0.9", "@types/node": "^22.18.1", diff --git a/packages/gossipsub/src/utils/msgIdFn.ts b/packages/gossipsub/src/utils/msgIdFn.ts index 59b00e749a..7dc4b2da5f 100644 --- a/packages/gossipsub/src/utils/msgIdFn.ts +++ b/packages/gossipsub/src/utils/msgIdFn.ts @@ -1,6 +1,22 @@ -import { msgId } from '@libp2p/pubsub/utils' +import { publicKeyToProtobuf } from '@libp2p/crypto/keys' import { sha256 } from 'multiformats/hashes/sha2' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import type { Message } from '../index.js' +import type { PublicKey } from '@libp2p/interface' + +/** + * Generate a message id, based on the `key` and `seqno` + */ +export const msgId = (key: PublicKey, seqno: bigint): Uint8Array => { + const seqnoBytes = uint8ArrayFromString(seqno.toString(16).padStart(16, '0'), 'base16') + const keyBytes = publicKeyToProtobuf(key) + + const msgId = new Uint8Array(keyBytes.byteLength + seqnoBytes.length) + msgId.set(keyBytes, 0) + msgId.set(seqnoBytes, keyBytes.byteLength) + + return msgId +} /** * Generate a message id, based on the `key` and `seqno` diff --git a/packages/gossipsub/test/message-cache.spec.ts b/packages/gossipsub/test/message-cache.spec.ts index e3f76d1538..3ad8f8a23c 100644 --- a/packages/gossipsub/test/message-cache.spec.ts +++ b/packages/gossipsub/test/message-cache.spec.ts @@ -1,12 +1,17 @@ -import * as utils from '@libp2p/pubsub/utils' +import { randomBytes } from '@libp2p/crypto' import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { MessageCache } from '../src/message-cache.js' import { messageIdToString } from '../src/utils/messageIdToString.js' import { getMsgId } from './utils/index.js' import type { RPC } from '../src/message/rpc.js' import type { MessageId } from '../src/types.js' +function randomSeqno (): bigint { + return BigInt(`0x${uint8ArrayToString(randomBytes(8), 'base16')}`) +} + const toMessageId = (msgId: Uint8Array): MessageId => { return { msgId, @@ -28,7 +33,7 @@ describe('Testing Message Cache Operations', () => { return { from: new Uint8Array(0), data: uint8ArrayFromString(n.toString()), - seqno: uint8ArrayFromString(utils.randomSeqno().toString(16).padStart(16, '0'), 'base16'), + seqno: uint8ArrayFromString(randomSeqno().toString(16).padStart(16, '0'), 'base16'), topic } }