Skip to content

Commit

Permalink
feat: return empty array if ignoreDuplicateMessages is enabled (Chain…
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Feb 15, 2023
1 parent f7f59cd commit 64780ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export interface GossipsubOpts extends GossipsubOptsSpec, PubSubInit {
/** Do not throw `InsufficientPeers` error if publishing to zero peers */
allowPublishToZeroPeers: boolean
/** Do not throw `PublishError.Duplicate` if publishing duplicate messages */
allowPublishDuplicates: boolean
ignoreDuplicateMessages: boolean
/** For a single stream, await processing each RPC before processing the next */
awaitRpcHandler: boolean
/** For a single RPC, await processing each message before processing the next */
Expand Down Expand Up @@ -2016,11 +2016,14 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements PubSub<G
const msgIdStr = this.msgIdToStrFn(msgId)

// Current publish opt takes precedence global opts, while preserving false value
const allowPublishDuplicates = opts?.allowPublishDuplicates ?? this.opts.allowPublishDuplicates
const ignoreDuplicateMessages = opts?.ignoreDuplicateMessages ?? this.opts.ignoreDuplicateMessages

if (this.seenCache.has(msgIdStr) && !allowPublishDuplicates) {
if (this.seenCache.has(msgIdStr)) {
// This message has already been seen. We don't re-publish messages that have already
// been published on the network.
if (ignoreDuplicateMessages) {
return { recipients: [] }
}
throw Error('PublishError.Duplicate')
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export enum SignaturePolicy {

export type PublishOpts = {
allowPublishToZeroPeers?: boolean
allowPublishDuplicates?: boolean
ignoreDuplicateMessages?: boolean
}

export enum PublishConfigType {
Expand Down

0 comments on commit 64780ed

Please sign in to comment.