diff --git a/waku/v2/protocol/rln/group_manager/dynamic/web3.go b/waku/v2/protocol/rln/group_manager/dynamic/web3.go index d994c010d..7fa02d931 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/web3.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/web3.go @@ -21,10 +21,10 @@ type RegistrationEventHandler = func(*DynamicGroupManager, []*contracts.RLNMembe // It connects to the eth client, subscribes to the `MemberRegistered` event emitted from the `MembershipContract` // and collects all the events, for every received event, it calls the `handler` func (gm *DynamicGroupManager) HandleGroupUpdates(ctx context.Context, handler RegistrationEventHandler) error { - fromBlock := uint64(0) + fromBlock := gm.web3Config.RLNContract.DeployedBlockNumber metadata, err := gm.GetMetadata() if err != nil { - gm.log.Warn("could not load last processed block from metadata. Starting onchain sync from scratch", zap.Error(err)) + gm.log.Warn("could not load last processed block from metadata. Starting onchain sync from deployment block", zap.Error(err), zap.Uint64("deploymentBlock", gm.web3Config.RLNContract.DeployedBlockNumber)) } else { if gm.web3Config.ChainID.Cmp(metadata.ChainID) != 0 { return errors.New("persisted data: chain id mismatch") @@ -148,6 +148,8 @@ func (gm *DynamicGroupManager) getEvents(ctx context.Context, from uint64, to *u end = *toBlock } + gm.log.Info("loading events...", zap.Uint64("fromBlock", start), zap.Uint64("toBlock", end)) + evts, err := gm.fetchEvents(ctx, start, &end) if err != nil { if tooMuchDataRequestedError(err) { @@ -157,6 +159,9 @@ func (gm *DynamicGroupManager) getEvents(ctx context.Context, from uint64, to *u // multiplicative decrease batchSize = batchSize / multiplicativeDecreaseDivisor + + gm.log.Warn("too many logs requested!, retrying with a smaller chunk size", zap.Uint64("batchSize", batchSize)) + continue } return nil, err diff --git a/waku/v2/protocol/rln/web3/web3.go b/waku/v2/protocol/rln/web3/web3.go index 7a473c2e2..48f61ef5f 100644 --- a/waku/v2/protocol/rln/web3/web3.go +++ b/waku/v2/protocol/rln/web3/web3.go @@ -21,8 +21,9 @@ type RegistryContract struct { // that represents this contract type RLNContract struct { *contracts.RLN - Address common.Address - StorageIndex uint16 + Address common.Address + StorageIndex uint16 + DeployedBlockNumber uint64 } // Config is a helper struct that contains attributes for interaction with RLN smart contracts @@ -78,6 +79,11 @@ func BuildConfig(ctx context.Context, ethClientAddress string, registryAddress c return nil, err } + deploymentBlockNumber, err := rlnContract.DeployedBlockNumber(&bind.CallOpts{Context: ctx}) + if err != nil { + return nil, err + } + return &Config{ configured: true, ETHClientAddress: ethClientAddress, @@ -88,9 +94,10 @@ func BuildConfig(ctx context.Context, ethClientAddress string, registryAddress c Address: registryAddress, }, RLNContract: RLNContract{ - RLN: rlnContract, - Address: rlnContractAddress, - StorageIndex: storageIndex, + RLN: rlnContract, + Address: rlnContractAddress, + StorageIndex: storageIndex, + DeployedBlockNumber: uint64(deploymentBlockNumber), }, }, nil }