diff --git a/src/index.ts b/src/index.ts index 5e539b3b..63d8f76b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -85,6 +85,10 @@ type ReceivedMessageResult = | ({ code: MessageStatus.invalid; msgIdStr?: MsgIdStr } & RejectReasonObj) | { code: MessageStatus.valid; messageId: MessageId; msg: Message } +export type PublishOpts = { + skipDuplicateCheck: boolean +} + export const multicodec: string = constants.GossipsubIDv11 export interface GossipsubOpts extends GossipsubOptsSpec, PubSubInit { @@ -1922,7 +1926,7 @@ export class GossipSub extends EventEmitter implements Initiali * * For messages not from us, this class uses `forwardMessage`. */ - async publish(topic: TopicStr, data: Uint8Array): Promise { + async publish(topic: TopicStr, data: Uint8Array, opts?: PublishOpts): Promise { const transformedData = this.dataTransform ? this.dataTransform.outboundTransform(topic, data) : data if (this.publishConfig == null) { @@ -1936,7 +1940,7 @@ export class GossipSub extends EventEmitter implements Initiali const msgId = await this.msgIdFn(msg) const msgIdStr = this.msgIdToStrFn(msgId) - if (this.seenCache.has(msgIdStr)) { + if (!opts?.skipDuplicateCheck && this.seenCache.has(msgIdStr)) { // This message has already been seen. We don't re-publish messages that have already // been published on the network. throw Error('PublishError.Duplicate')