Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rln-relay): sync from deployed block number #701

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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