Skip to content

Commit

Permalink
validateReceivedMessage: check duplicate message first (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths authored Apr 4, 2022
1 parent 9e93427 commit b8693c5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,13 +932,6 @@ export default class Gossipsub extends EventEmitter {
async validateReceivedMessage(propagationSource: PeerId, rpcMsg: RPC.IMessage): Promise<ReceivedMessageResult> {
this.metrics?.onMsgRecvPreValidation(rpcMsg.topic)

// Perform basic validation on message and convert to RawGossipsubMessage for fastMsgIdFn()
const validationResult = await validateToRawMessage(this.globalSignaturePolicy, rpcMsg)

if (!validationResult.valid) {
return { code: MessageStatus.invalid, reason: RejectReason.Error, error: validationResult.error }
}

// Fast message ID stuff
const fastMsgIdStr = this.fastMsgIdFn?.(rpcMsg)
const msgIdCached = fastMsgIdStr && this.fastMsgIdCache?.get(fastMsgIdStr)
Expand All @@ -948,6 +941,13 @@ export default class Gossipsub extends EventEmitter {
return { code: MessageStatus.duplicate, msgId: msgIdCached }
}

// Perform basic validation on message and convert to RawGossipsubMessage for fastMsgIdFn()
const validationResult = await validateToRawMessage(this.globalSignaturePolicy, rpcMsg)

if (!validationResult.valid) {
return { code: MessageStatus.invalid, reason: RejectReason.Error, error: validationResult.error }
}

// Try and perform the data transform to the message. If it fails, consider it invalid.
let data: Uint8Array
try {
Expand Down

0 comments on commit b8693c5

Please sign in to comment.