mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 14:03:06 +00:00
chore: rln_relay simplify code a little (#3392)
This commit is contained in:
parent
fc4ca7798c
commit
2d6e5ef9ad
@ -722,13 +722,13 @@ suite "Waku rln relay":
|
||||
# validate messages
|
||||
# validateMessage proc checks the validity of the message fields and adds it to the log (if valid)
|
||||
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
|
||||
msgValidate2 = wakuRlnRelay.validateMessageAndUpdateLog(wm2, some(time))
|
||||
msgValidate2 = wakuRlnRelay.validateMessageAndUpdateLog(wm2)
|
||||
# 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
|
||||
msgValidate4 = wakuRlnRelay.validateMessageAndUpdateLog(wm4, some(time))
|
||||
msgValidate4 = wakuRlnRelay.validateMessageAndUpdateLog(wm4)
|
||||
|
||||
check:
|
||||
msgValidate1 == MessageValidationResult.Valid
|
||||
@ -778,9 +778,9 @@ suite "Waku rln relay":
|
||||
# validate messages
|
||||
# validateMessage proc checks the validity of the message fields and adds it to the log (if valid)
|
||||
let
|
||||
msgValidate1 = wakuRlnRelay1.validateMessageAndUpdateLog(wm1, some(time))
|
||||
msgValidate1 = wakuRlnRelay1.validateMessageAndUpdateLog(wm1)
|
||||
# since this message is from a different sender, it should be validated successfully
|
||||
msgValidate2 = wakuRlnRelay1.validateMessageAndUpdateLog(wm2, some(time))
|
||||
msgValidate2 = wakuRlnRelay1.validateMessageAndUpdateLog(wm2)
|
||||
|
||||
check:
|
||||
msgValidate1 == MessageValidationResult.Valid
|
||||
|
||||
@ -184,7 +184,7 @@ proc absDiff*(e1, e2: Epoch): uint64 =
|
||||
return epoch2 - epoch1
|
||||
|
||||
proc validateMessage*(
|
||||
rlnPeer: WakuRLNRelay, msg: WakuMessage, timeOption = none(float64)
|
||||
rlnPeer: WakuRLNRelay, msg: WakuMessage
|
||||
): MessageValidationResult =
|
||||
## 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
|
||||
@ -204,12 +204,8 @@ proc validateMessage*(
|
||||
|
||||
# checks if the `msg`'s epoch is far from the current epoch
|
||||
# it corresponds to the validation of rln external nullifier
|
||||
var epoch: Epoch
|
||||
if timeOption.isSome():
|
||||
epoch = rlnPeer.calcEpoch(timeOption.get())
|
||||
else:
|
||||
# get current rln epoch
|
||||
epoch = rlnPeer.getCurrentEpoch()
|
||||
# get current rln epoch
|
||||
let epoch: Epoch = rlnPeer.getCurrentEpoch()
|
||||
|
||||
let
|
||||
msgEpoch = proof.epoch
|
||||
@ -273,12 +269,12 @@ proc validateMessage*(
|
||||
return MessageValidationResult.Valid
|
||||
|
||||
proc validateMessageAndUpdateLog*(
|
||||
rlnPeer: WakuRLNRelay, msg: WakuMessage, timeOption = none(float64)
|
||||
rlnPeer: WakuRLNRelay, msg: WakuMessage
|
||||
): MessageValidationResult =
|
||||
## validates the message and updates the log to prevent double messaging
|
||||
## in future messages
|
||||
|
||||
let isValidMessage = rlnPeer.validateMessage(msg, timeOption)
|
||||
let isValidMessage = rlnPeer.validateMessage(msg)
|
||||
|
||||
let decodeRes = RateLimitProof.init(msg.proof)
|
||||
if decodeRes.isErr():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user