mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-13 07:14:10 +00:00
fix(rln-relay): sync from deployed block number
This commit is contained in:
parent
84fa332e1c
commit
f9ed8d973c
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user