Fix ResultDefect on success and stale test stubs in lightpush retry path

Two bugs left by a bad merge:

1. lightpush.nim: isRlnRelatedFailure was computed before firstResult.isOk()
   was checked, accessing firstResult.error unconditionally. When publish
   succeeds, this raises a ResultDefect. Reorder the guard so isOk()/isNone()
   short-circuits before the error fields are touched.

2. test_wakunode_lightpush.nim: the 420-retry stubs used descriptions
   ("simulated stale merkle path", "still stale") that don't contain
   RlnValidatorErrorMsg. The code gates 420 retries on that substring to
   distinguish RLN rejections from unrelated INVALID_MESSAGE responses
   (e.g. oversized messages). Update stubs to emit RlnValidatorErrorMsg so
   the retry path fires as the tests expect.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
stubbsta 2026-07-07 10:03:48 +02:00
parent 26b8d2fa6e
commit 43dff68f49
No known key found for this signature in database
2 changed files with 6 additions and 5 deletions

View File

@ -335,13 +335,14 @@ proc lightpushPublish*(
# also returned for non-RLN rejections (e.g. oversized messages), so require
# the error description to contain RlnValidatorErrorMsg — matching the legacy
# lightpush path — to avoid unbounded on-chain RPCs on non-RLN errors.
if firstResult.isOk() or rln.isNone():
return firstResult
let isRlnRelatedFailure =
firstResult.error.code == LightPushErrorCode.OUT_OF_RLN_PROOF or
(
firstResult.error.code == LightPushErrorCode.OUT_OF_RLN_PROOF or (
firstResult.error.code == LightPushErrorCode.INVALID_MESSAGE and
firstResult.error.desc.get("").contains(RlnValidatorErrorMsg)
)
if firstResult.isOk() or rln.isNone() or not isRlnRelatedFailure:
if not isRlnRelatedFailure:
return firstResult
info "lightpush send rejected; refreshing merkle proof and retrying once",

View File

@ -231,7 +231,7 @@ suite "RLN Proofs as a Lightpush Service":
inc callCount
if callCount == 1:
return lighpushErrorResult(
LightPushErrorCode.INVALID_MESSAGE, "simulated stale merkle path"
LightPushErrorCode.INVALID_MESSAGE, RlnValidatorErrorMsg
)
return lightpushSuccessResult(1)
server.wakuLightPush.pushHandler = stub
@ -287,7 +287,7 @@ suite "RLN Proofs as a Lightpush Service":
pubsubTopic: PubsubTopic, message: WakuMessage
): Future[WakuLightPushResult] {.async.} =
inc callCount
return lighpushErrorResult(LightPushErrorCode.INVALID_MESSAGE, "still stale")
return lighpushErrorResult(LightPushErrorCode.INVALID_MESSAGE, RlnValidatorErrorMsg)
server.wakuLightPush.pushHandler = stub
let response = await server.lightpushPublish(some(pubsubTopic), message)