mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-27 14:05:18 +00:00
fix: panic if it is not possible to obtain the merkle root (#873)
This commit is contained in:
parent
ff94b1faf0
commit
5aa4d578aa
@ -244,10 +244,7 @@ func (gm *DynamicGroupManager) InsertMembers(toInsert *om.OrderedMap) error {
|
||||
|
||||
gm.metrics.RecordRegisteredMembership(gm.rln.LeavesSet())
|
||||
|
||||
_, err = gm.rootTracker.UpdateLatestRoot(pair.Key.(uint64))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gm.rootTracker.UpdateLatestRoot(pair.Key.(uint64))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -31,8 +31,7 @@ func TestHandler(t *testing.T) {
|
||||
rlnInstance, err := rln.NewRLN()
|
||||
require.NoError(t, err)
|
||||
|
||||
rootTracker, err := group_manager.NewMerkleRootTracker(5, rlnInstance)
|
||||
require.NoError(t, err)
|
||||
rootTracker := group_manager.NewMerkleRootTracker(5, rlnInstance)
|
||||
|
||||
_, cancel := context.WithCancel(context.TODO())
|
||||
defer cancel()
|
||||
|
@ -22,9 +22,9 @@ func TestFetchingLogic(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
rlnInstance, err := rln.NewRLN()
|
||||
require.NoError(t, err)
|
||||
rootTracker, err := group_manager.NewMerkleRootTracker(1, rlnInstance)
|
||||
require.NoError(t, err)
|
||||
//
|
||||
|
||||
rootTracker := group_manager.NewMerkleRootTracker(1, rlnInstance)
|
||||
|
||||
mf := MembershipFetcher{
|
||||
web3Config: &web3.Config{
|
||||
RLNContract: web3.RLNContract{
|
||||
|
@ -4,7 +4,9 @@ import (
|
||||
"bytes"
|
||||
"sync"
|
||||
|
||||
"github.com/waku-org/go-waku/waku/v2/utils"
|
||||
"github.com/waku-org/go-zerokit-rln/rln"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// RootsPerBlock stores the merkle root generated at N block number
|
||||
@ -27,18 +29,15 @@ type MerkleRootTracker struct {
|
||||
const maxBufferSize = 20
|
||||
|
||||
// NewMerkleRootTracker creates an instance of MerkleRootTracker
|
||||
func NewMerkleRootTracker(acceptableRootWindowSize int, rlnInstance *rln.RLN) (*MerkleRootTracker, error) {
|
||||
func NewMerkleRootTracker(acceptableRootWindowSize int, rlnInstance *rln.RLN) *MerkleRootTracker {
|
||||
result := &MerkleRootTracker{
|
||||
acceptableRootWindowSize: acceptableRootWindowSize,
|
||||
rln: rlnInstance,
|
||||
}
|
||||
|
||||
_, err := result.UpdateLatestRoot(0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.UpdateLatestRoot(0)
|
||||
|
||||
return result, nil
|
||||
return result
|
||||
}
|
||||
|
||||
// Backfill is used to pop merkle roots when there is a chain fork
|
||||
@ -102,18 +101,18 @@ func (m *MerkleRootTracker) IndexOf(root [32]byte) int {
|
||||
|
||||
// UpdateLatestRoot should be called when a block containing a new
|
||||
// IDCommitment is received so we can keep track of the merkle root change
|
||||
func (m *MerkleRootTracker) UpdateLatestRoot(blockNumber uint64) (rln.MerkleNode, error) {
|
||||
func (m *MerkleRootTracker) UpdateLatestRoot(blockNumber uint64) rln.MerkleNode {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
root, err := m.rln.GetMerkleRoot()
|
||||
if err != nil {
|
||||
return [32]byte{}, err
|
||||
utils.Logger().Named("root-tracker").Panic("could not retrieve merkle root", zap.Error(err))
|
||||
}
|
||||
|
||||
m.pushRoot(blockNumber, root)
|
||||
|
||||
return root, nil
|
||||
return root
|
||||
}
|
||||
|
||||
func (m *MerkleRootTracker) pushRoot(blockNumber uint64, root [32]byte) {
|
||||
|
@ -68,10 +68,7 @@ func (gm *StaticGroupManager) insertMembers(idCommitments []rln.IDCommitment) er
|
||||
|
||||
latestIndex := gm.nextIndex + uint64(len(idCommitments))
|
||||
|
||||
_, err = gm.rootTracker.UpdateLatestRoot(latestIndex)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gm.rootTracker.UpdateLatestRoot(latestIndex)
|
||||
|
||||
gm.nextIndex = latestIndex + 1
|
||||
|
||||
|
@ -140,8 +140,7 @@ func (s *WakuRLNRelayDynamicSuite) TestDynamicGroupManagement() {
|
||||
rlnInstance, err := rln.NewRLN()
|
||||
s.Require().NoError(err)
|
||||
|
||||
rt, err := group_manager.NewMerkleRootTracker(5, rlnInstance)
|
||||
s.Require().NoError(err)
|
||||
rt := group_manager.NewMerkleRootTracker(5, rlnInstance)
|
||||
|
||||
u1Credentials := s.generateCredentials(rlnInstance)
|
||||
appKeystore, err := keystore.New(s.tmpKeystorePath(), dynamic.RLNAppInfo, utils.Logger())
|
||||
|
@ -88,8 +88,7 @@ func (s *WakuRLNRelaySuite) TestUpdateLogAndHasDuplicate() {
|
||||
rlnInstance, err := r.NewRLN()
|
||||
s.Require().NoError(err)
|
||||
|
||||
rootTracker, err := group_manager.NewMerkleRootTracker(acceptableRootWindowSize, rlnInstance)
|
||||
s.Require().NoError(err)
|
||||
rootTracker := group_manager.NewMerkleRootTracker(acceptableRootWindowSize, rlnInstance)
|
||||
|
||||
rlnRelay := &WakuRLNRelay{
|
||||
nullifierLog: NewNullifierLog(context.TODO(), utils.Logger()),
|
||||
@ -184,10 +183,9 @@ func (s *WakuRLNRelaySuite) TestValidateMessage() {
|
||||
// Create a RLN instance
|
||||
rlnInstance, err := r.NewRLN()
|
||||
s.Require().NoError(err)
|
||||
//
|
||||
rootTracker, err := group_manager.NewMerkleRootTracker(acceptableRootWindowSize, rlnInstance)
|
||||
s.Require().NoError(err)
|
||||
//
|
||||
|
||||
rootTracker := group_manager.NewMerkleRootTracker(acceptableRootWindowSize, rlnInstance)
|
||||
|
||||
idCredential := groupKeyPairs[index]
|
||||
groupManager, err := static.NewStaticGroupManager(groupIDCommitments, idCredential, index, rlnInstance, rootTracker, utils.Logger())
|
||||
s.Require().NoError(err)
|
||||
|
@ -47,10 +47,8 @@ func GetRLNInstanceAndRootTracker(treePath string) (*rln.RLN, *group_manager.Mer
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
rootTracker, err := group_manager.NewMerkleRootTracker(acceptableRootWindowSize, rlnInstance)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
rootTracker := group_manager.NewMerkleRootTracker(acceptableRootWindowSize, rlnInstance)
|
||||
|
||||
return rlnInstance, rootTracker, nil
|
||||
}
|
||||
func New(
|
||||
|
Loading…
x
Reference in New Issue
Block a user