mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-05 23:43:07 +00:00
chore: rln_relay simplify code a little (#3392)
This commit is contained in:
parent
df5dba7bc9
commit
7a6c00bd03
@ -722,13 +722,13 @@ suite "Waku rln relay":
|
|||||||
# validate messages
|
# validate messages
|
||||||
# validateMessage proc checks the validity of the message fields and adds it to the log (if valid)
|
# validateMessage proc checks the validity of the message fields and adds it to the log (if valid)
|
||||||
let
|
let
|
||||||
msgValidate1 = wakuRlnRelay.validateMessageAndUpdateLog(wm1, some(time))
|
msgValidate1 = wakuRlnRelay.validateMessageAndUpdateLog(wm1)
|
||||||
# wm2 is published within the same Epoch as wm1 and should be found as spam
|
# wm2 is published within the same Epoch as wm1 and should be found as spam
|
||||||
msgValidate2 = wakuRlnRelay.validateMessageAndUpdateLog(wm2, some(time))
|
msgValidate2 = wakuRlnRelay.validateMessageAndUpdateLog(wm2)
|
||||||
# a valid message should be validated successfully
|
# a valid message should be validated successfully
|
||||||
msgValidate3 = wakuRlnRelay.validateMessageAndUpdateLog(wm3, some(time))
|
msgValidate3 = wakuRlnRelay.validateMessageAndUpdateLog(wm3)
|
||||||
# wm4 has no rln proof and should not be validated
|
# wm4 has no rln proof and should not be validated
|
||||||
msgValidate4 = wakuRlnRelay.validateMessageAndUpdateLog(wm4, some(time))
|
msgValidate4 = wakuRlnRelay.validateMessageAndUpdateLog(wm4)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
msgValidate1 == MessageValidationResult.Valid
|
msgValidate1 == MessageValidationResult.Valid
|
||||||
@ -778,9 +778,9 @@ suite "Waku rln relay":
|
|||||||
# validate messages
|
# validate messages
|
||||||
# validateMessage proc checks the validity of the message fields and adds it to the log (if valid)
|
# validateMessage proc checks the validity of the message fields and adds it to the log (if valid)
|
||||||
let
|
let
|
||||||
msgValidate1 = wakuRlnRelay1.validateMessageAndUpdateLog(wm1, some(time))
|
msgValidate1 = wakuRlnRelay1.validateMessageAndUpdateLog(wm1)
|
||||||
# since this message is from a different sender, it should be validated successfully
|
# since this message is from a different sender, it should be validated successfully
|
||||||
msgValidate2 = wakuRlnRelay1.validateMessageAndUpdateLog(wm2, some(time))
|
msgValidate2 = wakuRlnRelay1.validateMessageAndUpdateLog(wm2)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
msgValidate1 == MessageValidationResult.Valid
|
msgValidate1 == MessageValidationResult.Valid
|
||||||
|
|||||||
@ -184,7 +184,7 @@ proc absDiff*(e1, e2: Epoch): uint64 =
|
|||||||
return epoch2 - epoch1
|
return epoch2 - epoch1
|
||||||
|
|
||||||
proc validateMessage*(
|
proc validateMessage*(
|
||||||
rlnPeer: WakuRLNRelay, msg: WakuMessage, timeOption = none(float64)
|
rlnPeer: WakuRLNRelay, msg: WakuMessage
|
||||||
): MessageValidationResult =
|
): MessageValidationResult =
|
||||||
## validate the supplied `msg` based on the waku-rln-relay routing protocol i.e.,
|
## validate the supplied `msg` based on the waku-rln-relay routing protocol i.e.,
|
||||||
## the `msg`'s epoch is within MaxEpochGap of the current epoch
|
## the `msg`'s epoch is within MaxEpochGap of the current epoch
|
||||||
@ -204,12 +204,8 @@ proc validateMessage*(
|
|||||||
|
|
||||||
# checks if the `msg`'s epoch is far from the current epoch
|
# checks if the `msg`'s epoch is far from the current epoch
|
||||||
# it corresponds to the validation of rln external nullifier
|
# it corresponds to the validation of rln external nullifier
|
||||||
var epoch: Epoch
|
# get current rln epoch
|
||||||
if timeOption.isSome():
|
let epoch: Epoch = rlnPeer.getCurrentEpoch()
|
||||||
epoch = rlnPeer.calcEpoch(timeOption.get())
|
|
||||||
else:
|
|
||||||
# get current rln epoch
|
|
||||||
epoch = rlnPeer.getCurrentEpoch()
|
|
||||||
|
|
||||||
let
|
let
|
||||||
msgEpoch = proof.epoch
|
msgEpoch = proof.epoch
|
||||||
@ -273,12 +269,12 @@ proc validateMessage*(
|
|||||||
return MessageValidationResult.Valid
|
return MessageValidationResult.Valid
|
||||||
|
|
||||||
proc validateMessageAndUpdateLog*(
|
proc validateMessageAndUpdateLog*(
|
||||||
rlnPeer: WakuRLNRelay, msg: WakuMessage, timeOption = none(float64)
|
rlnPeer: WakuRLNRelay, msg: WakuMessage
|
||||||
): MessageValidationResult =
|
): MessageValidationResult =
|
||||||
## validates the message and updates the log to prevent double messaging
|
## validates the message and updates the log to prevent double messaging
|
||||||
## in future messages
|
## in future messages
|
||||||
|
|
||||||
let isValidMessage = rlnPeer.validateMessage(msg, timeOption)
|
let isValidMessage = rlnPeer.validateMessage(msg)
|
||||||
|
|
||||||
let decodeRes = RateLimitProof.init(msg.proof)
|
let decodeRes = RateLimitProof.init(msg.proof)
|
||||||
if decodeRes.isErr():
|
if decodeRes.isErr():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user