-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use messageHash as msgIdFn #1361
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { SignaturePolicy } from "@chainsafe/libp2p-gossipsub/types"; | |
import type { Libp2p } from "@libp2p/interface-libp2p"; | ||
import type { PubSub } from "@libp2p/interface-pubsub"; | ||
import { sha256 } from "@noble/hashes/sha256"; | ||
import { DefaultPubSubTopic } from "@waku/core"; | ||
import { DefaultPubSubTopic, message } from "@waku/core"; | ||
import { | ||
ActiveSubscriptions, | ||
Callback, | ||
|
@@ -24,6 +24,7 @@ import { | |
SendError, | ||
SendResult, | ||
} from "@waku/interfaces"; | ||
import { messageHash } from "@waku/message-hash"; | ||
import { groupByContentTopic, isSizeValid, toAsyncIterator } from "@waku/utils"; | ||
import debug from "debug"; | ||
|
||
|
@@ -249,7 +250,17 @@ export function wakuGossipSub( | |
return (components: GossipSubComponents) => { | ||
init = { | ||
...init, | ||
msgIdFn: ({ data }) => sha256(data), | ||
msgIdFn: ({ topic, data }) => { | ||
try { | ||
const protoMessage = message.fromBytesToProtoMessage(data); | ||
return messageHash(topic, protoMessage); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem with this implementation is that in case It leads to inability of a user to send a message to the a pubSub/contentTopic in case someone already published a message with the same text. Second problem of using |
||
} catch (e) { | ||
log( | ||
"Failed to hash as ProtoMessage, falling back to sha256 from data." | ||
); | ||
return sha256(data); | ||
} | ||
}, | ||
// Ensure that no signature is included nor expected in the messages. | ||
globalSignaturePolicy: SignaturePolicy.StrictNoSign, | ||
fallbackToFloodsub: false, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe should move it to
@waku/utils/message
🤔