fix(core): clone messages at mutation sites now aliasing under ref

Under ref semantics `var m = someMessage; m.field = ...` mutates the
shared instance the caller still holds. Fix the outbound mutation sites:

- waku_relay/protocol.nim publish: replace the local `var message` +
  timestamp patch with `wakuMessage.ensureTimestampSet()`
- rln/proof.nim attachRLNProof: clone before writing `.proof`
- rest_api relay attachRlnProofAndValidate: clone before writing `.proof`

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
NagyZoltanPeter 2026-07-15 04:47:21 +02:00
parent 1339be1f5e
commit 5d3fb0cff0
No known key found for this signature in database
GPG Key ID: 3E1F97CF4A7B6F42
3 changed files with 3 additions and 5 deletions

View File

@ -69,7 +69,7 @@ proc attachRlnProofAndValidate(
## RlnValidatorErrorMsg), schedules a background merkle proof refresh and
## fails early with StaleProofSuspected — the caller decides whether to
## retry. Callers invoke only when RLN is mounted.
var msg = message
let msg = message.clone()
msg.proof = (
await rln.generateRLNProof(msg.toRLNSignal(), float64(getTime().toUnix()))
).valueOr:

View File

@ -89,7 +89,7 @@ proc attachRLNProof*(
## Returns the message with a freshly generated RLN proof, replacing any
## existing one and drawing a new message id. Retry paths suspecting a stale
## path should call `invalidateMerkleProofCache` first.
var msgWithProof = message
let msgWithProof = message.clone()
msgWithProof.proof = (
await r.generateRLNProof(message.toRLNSignal(), float64(getTime().toUnix()))
).valueOr:

View File

@ -689,9 +689,7 @@ proc publish*(
if pubsubTopic.isEmptyOrWhitespace():
return err(NoTopicSpecified)
var message = wakuMessage
if message.timestamp == 0:
message.timestamp = getNowInNanosecondTime()
let message = wakuMessage.ensureTimestampSet()
let data = message.encode().buffer