Skip to content

Commit

Permalink
fix(rln-relay): sync from deployed block number
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Aug 31, 2023
1 parent 654e0a2 commit 23f65b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
9 changes: 7 additions & 2 deletions waku/v2/protocol/rln/group_manager/dynamic/web3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
17 changes: 12 additions & 5 deletions waku/v2/protocol/rln/web3/web3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand Down

0 comments on commit 23f65b4

Please sign in to comment.