Skip to content

Commit b8693c5

Browse files
authored
validateReceivedMessage: check duplicate message first (#223)
1 parent 9e93427 commit b8693c5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ts/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -932,13 +932,6 @@ export default class Gossipsub extends EventEmitter {
932932
async validateReceivedMessage(propagationSource: PeerId, rpcMsg: RPC.IMessage): Promise<ReceivedMessageResult> {
933933
this.metrics?.onMsgRecvPreValidation(rpcMsg.topic)
934934

935-
// Perform basic validation on message and convert to RawGossipsubMessage for fastMsgIdFn()
936-
const validationResult = await validateToRawMessage(this.globalSignaturePolicy, rpcMsg)
937-
938-
if (!validationResult.valid) {
939-
return { code: MessageStatus.invalid, reason: RejectReason.Error, error: validationResult.error }
940-
}
941-
942935
// Fast message ID stuff
943936
const fastMsgIdStr = this.fastMsgIdFn?.(rpcMsg)
944937
const msgIdCached = fastMsgIdStr && this.fastMsgIdCache?.get(fastMsgIdStr)
@@ -948,6 +941,13 @@ export default class Gossipsub extends EventEmitter {
948941
return { code: MessageStatus.duplicate, msgId: msgIdCached }
949942
}
950943

944+
// Perform basic validation on message and convert to RawGossipsubMessage for fastMsgIdFn()
945+
const validationResult = await validateToRawMessage(this.globalSignaturePolicy, rpcMsg)
946+
947+
if (!validationResult.valid) {
948+
return { code: MessageStatus.invalid, reason: RejectReason.Error, error: validationResult.error }
949+
}
950+
951951
// Try and perform the data transform to the message. If it fails, consider it invalid.
952952
let data: Uint8Array
953953
try {

0 commit comments

Comments
 (0)