[WIP] Add a service to fill indexing gap for watched addresses #135
14
cmd/serve.go
14
cmd/serve.go
@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/ethereum/go-ethereum/statediff"
|
"github.com/ethereum/go-ethereum/statediff"
|
||||||
|
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||||
"github.com/mailgun/groupcache/v2"
|
"github.com/mailgun/groupcache/v2"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -304,6 +305,7 @@ func startStateTrieValidator(config *s.Config, server s.Server) {
|
|||||||
|
|
||||||
type WatchedAddress struct {
|
type WatchedAddress struct {
|
||||||
Address string `db:"address"`
|
Address string `db:"address"`
|
||||||
|
Kind int `db:"kind"`
|
||||||
CreatedAt uint64 `db:"created_at"`
|
CreatedAt uint64 `db:"created_at"`
|
||||||
WatchedAt uint64 `db:"watched_at"`
|
WatchedAt uint64 `db:"watched_at"`
|
||||||
LastFilledAt uint64 `db:"last_filled_at"`
|
LastFilledAt uint64 `db:"last_filled_at"`
|
||||||
@ -337,7 +339,15 @@ func startWatchedAddressGapFiller(config *s.Config) {
|
|||||||
fillAddresses := []interface{}{}
|
fillAddresses := []interface{}{}
|
||||||
for _, fillWatchedAddress := range fillWatchedAddresses {
|
for _, fillWatchedAddress := range fillWatchedAddresses {
|
||||||
if blockNumber >= fillWatchedAddress.startBlock && blockNumber <= fillWatchedAddress.endBlock {
|
if blockNumber >= fillWatchedAddress.startBlock && blockNumber <= fillWatchedAddress.endBlock {
|
||||||
|
switch fillWatchedAddress.Kind {
|
||||||
|
case sdtypes.WatchedAddress.Int():
|
||||||
params.WatchedAddresses = append(params.WatchedAddresses, common.HexToAddress(fillWatchedAddress.Address))
|
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)
|
fillAddresses = append(fillAddresses, fillWatchedAddress.Address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -541,6 +551,6 @@ func init() {
|
|||||||
viper.BindPFlag("validator.everyNthBlock", serveCmd.PersistentFlags().Lookup("validator-every-nth-block"))
|
viper.BindPFlag("validator.everyNthBlock", serveCmd.PersistentFlags().Lookup("validator-every-nth-block"))
|
||||||
|
|
||||||
// watched address gap filler flags
|
// watched address gap filler flags
|
||||||
viper.BindPFlag("watch.fill.enabled", serveCmd.PersistentFlags().Lookup("watch-fill-enabled"))
|
viper.BindPFlag("watch.fill.enabled", serveCmd.PersistentFlags().Lookup("watched-address-gap-filler-enabled"))
|
||||||
viper.BindPFlag("watch.fill.interval", serveCmd.PersistentFlags().Lookup("watch-fill-interval"))
|
viper.BindPFlag("watch.fill.interval", serveCmd.PersistentFlags().Lookup("watched-address-gap-filler-interval"))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user