Support watched storage slots in the service to fill indexing gap

This commit is contained in:
Prathamesh Musale 2022-01-19 16:07:50 +05:30
parent 6c90c366bd
commit b9af16ad99

View File

@ -30,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/statediff"
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
"github.com/mailgun/groupcache/v2"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -304,6 +305,7 @@ func startStateTrieValidator(config *s.Config, server s.Server) {
type WatchedAddress struct {
Address string `db:"address"`
Kind int `db:"kind"`
CreatedAt uint64 `db:"created_at"`
WatchedAt uint64 `db:"watched_at"`
LastFilledAt uint64 `db:"last_filled_at"`
@ -337,7 +339,15 @@ func startWatchedAddressGapFiller(config *s.Config) {
fillAddresses := []interface{}{}
for _, fillWatchedAddress := range fillWatchedAddresses {
if blockNumber >= fillWatchedAddress.startBlock && blockNumber <= fillWatchedAddress.endBlock {
switch fillWatchedAddress.Kind {
case sdtypes.WatchedAddress.Int():
params.WatchedAddresses = append(params.WatchedAddresses, common.HexToAddress(fillWatchedAddress.Address))
case sdtypes.WatchedStorageSlot.Int():
params.WatchedStorageSlots = append(params.WatchedStorageSlots, common.HexToHash(fillWatchedAddress.Address))
default:
log.Fatalf("Unexpected kind %d:", fillWatchedAddress.Kind)
}
fillAddresses = append(fillAddresses, fillWatchedAddress.Address)
}
}
@ -541,6 +551,6 @@ func init() {
viper.BindPFlag("validator.everyNthBlock", serveCmd.PersistentFlags().Lookup("validator-every-nth-block"))
// watched address gap filler flags
viper.BindPFlag("watch.fill.enabled", serveCmd.PersistentFlags().Lookup("watch-fill-enabled"))
viper.BindPFlag("watch.fill.interval", serveCmd.PersistentFlags().Lookup("watch-fill-interval"))
viper.BindPFlag("watch.fill.enabled", serveCmd.PersistentFlags().Lookup("watched-address-gap-filler-enabled"))
viper.BindPFlag("watch.fill.interval", serveCmd.PersistentFlags().Lookup("watched-address-gap-filler-interval"))
}