From b9af16ad99824e7cedb99fb1268661b83d809cc8 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 19 Jan 2022 16:07:50 +0530 Subject: [PATCH] Support watched storage slots in the service to fill indexing gap --- cmd/serve.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index 5a7c3d20..90f45cd5 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -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 { - params.WatchedAddresses = append(params.WatchedAddresses, common.HexToAddress(fillWatchedAddress.Address)) + 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")) }