mirror of https://github.com/status-im/go-waku.git
fix: add lock to nullifier log
This commit is contained in:
parent
e91fd0e649
commit
1a8543f98f
|
@ -6,6 +6,7 @@ import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"errors"
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
@ -50,8 +51,10 @@ type WakuRLNRelay struct {
|
||||||
// pubsubTopic is the topic for which rln relay is mounted
|
// pubsubTopic is the topic for which rln relay is mounted
|
||||||
pubsubTopic string
|
pubsubTopic string
|
||||||
contentTopic string
|
contentTopic string
|
||||||
|
|
||||||
// the log of nullifiers and Shamir shares of the past messages grouped per epoch
|
// the log of nullifiers and Shamir shares of the past messages grouped per epoch
|
||||||
nullifierLog map[r.Epoch][]r.ProofMetadata
|
nullifierLogLock sync.RWMutex
|
||||||
|
nullifierLog map[r.Epoch][]r.ProofMetadata
|
||||||
|
|
||||||
registrationHandler RegistrationHandler
|
registrationHandler RegistrationHandler
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
|
@ -112,7 +115,9 @@ func (rln *WakuRLNRelay) HasDuplicate(msg *pb.WakuMessage) (bool, error) {
|
||||||
ShareY: msgProof.ShareY,
|
ShareY: msgProof.ShareY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rln.nullifierLogLock.RLock()
|
||||||
proofs, ok := rln.nullifierLog[msgProof.Epoch]
|
proofs, ok := rln.nullifierLog[msgProof.Epoch]
|
||||||
|
rln.nullifierLogLock.RUnlock()
|
||||||
|
|
||||||
// check if the epoch exists
|
// check if the epoch exists
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -154,6 +159,8 @@ func (rln *WakuRLNRelay) updateLog(msg *pb.WakuMessage) (bool, error) {
|
||||||
ShareY: msgProof.ShareY,
|
ShareY: msgProof.ShareY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rln.nullifierLogLock.Lock()
|
||||||
|
defer rln.nullifierLogLock.Unlock()
|
||||||
proofs, ok := rln.nullifierLog[msgProof.Epoch]
|
proofs, ok := rln.nullifierLog[msgProof.Epoch]
|
||||||
|
|
||||||
// check if the epoch exists
|
// check if the epoch exists
|
||||||
|
@ -183,7 +190,6 @@ func (rln *WakuRLNRelay) ValidateMessage(msg *pb.WakuMessage, optionalTime *time
|
||||||
// the `msg` does not violate the rate limit
|
// the `msg` does not violate the rate limit
|
||||||
// `timeOption` indicates Unix epoch time (fractional part holds sub-seconds)
|
// `timeOption` indicates Unix epoch time (fractional part holds sub-seconds)
|
||||||
// if `timeOption` is supplied, then the current epoch is calculated based on that
|
// if `timeOption` is supplied, then the current epoch is calculated based on that
|
||||||
|
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return MessageValidationResult_Unknown, errors.New("nil message")
|
return MessageValidationResult_Unknown, errors.New("nil message")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue