[WIP] Add a service to fill indexing gap for watched addresses #135

Closed
prathamesh0 wants to merge 16 commits from pm-watched-addresses into master
Showing only changes of commit b9af16ad99 - Show all commits

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 {
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"))
}