-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: use MUID for gossipsub message id
- Loading branch information
1 parent
23540ca
commit 5f61914
Showing
5 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Message } from "@libp2p/interface-pubsub"; | ||
import { sha256 } from "@noble/hashes/sha256"; | ||
import { messageHash } from "@waku/message-hash"; | ||
import { proto_message } from "@waku/proto"; | ||
import { concat } from "@waku/utils"; | ||
import debug from "debug"; | ||
|
||
import { toProtoMessage } from "../to_proto_message.js"; | ||
|
||
const log = debug("waku:relay:message-id"); | ||
export function gossipsubMessageId( | ||
message: Message | ||
): Promise<Uint8Array> | Uint8Array { | ||
const startTime = performance.now(); | ||
|
||
let result; | ||
try { | ||
const protoMessage = toProtoMessage( | ||
proto_message.WakuMessage.decode(message.data) | ||
); | ||
|
||
result = messageHash(message.topic, protoMessage); | ||
|
||
if (protoMessage.meta) { | ||
result = concat([result, protoMessage.meta]); | ||
} | ||
} catch (e) { | ||
log("Failed to deserialize message, falling back to standard message id"); | ||
result = sha256(message.data); | ||
} | ||
const endTime = performance.now(); | ||
log(`Gossipsub message id generation: ${endTime - startTime}ms`); | ||
return result; | ||
} |