cache misses trigger call out to statediffing geth to fill in the gap in Postgres

This commit is contained in:
Ian Norden
2021-02-24 10:50:26 -06:00
parent 7df5bbc99a
commit 211ec12009
16 changed files with 151 additions and 27 deletions
+13 -9
View File
@@ -48,19 +48,21 @@ const (
ETH_DEFAULT_SENDER_ADDR = "ETH_DEFAULT_SENDER_ADDR"
ETH_RPC_GAS_CAP = "ETH_RPC_GAS_CAP"
ETH_SUPPORTS_STATEDIFF = "ETH_SUPPORTS_STATEDIFF"
)
// Config struct
type Config struct {
DB *postgres.DB
DBConfig postgres.Config
WSEndpoint string
HTTPEndpoint string
IPCEndpoint string
ChainConfig *params.ChainConfig
DefaultSender *common.Address
RPCGasCap *big.Int
Client *rpc.Client
DB *postgres.DB
DBConfig postgres.Config
WSEndpoint string
HTTPEndpoint string
IPCEndpoint string
ChainConfig *params.ChainConfig
DefaultSender *common.Address
RPCGasCap *big.Int
Client *rpc.Client
SupportStateDiff bool
}
// NewConfig is used to initialize a watcher config from a .toml file
@@ -74,6 +76,7 @@ func NewConfig() (*Config, error) {
viper.BindEnv("ethereum.httpPath", shared.ETH_HTTP_PATH)
viper.BindEnv("ethereum.defaultSender", ETH_DEFAULT_SENDER_ADDR)
viper.BindEnv("ethereum.rpcGasCap", ETH_RPC_GAS_CAP)
viper.BindEnv("ethereum.supportsStateDiff", ETH_SUPPORTS_STATEDIFF)
c.DBConfig.Init()
@@ -83,6 +86,7 @@ func NewConfig() (*Config, error) {
return nil, err
}
c.Client = cli
c.SupportStateDiff = viper.GetBool("ethereum.supportsStateDiff")
wsPath := viper.GetString("server.wsPath")
if wsPath == "" {
+5 -1
View File
@@ -80,6 +80,8 @@ type Service struct {
serveWg *sync.WaitGroup
// rpc client for forwarding cache misses
client *rpc.Client
// whether the proxied client supports state diffing
supportsStateDiffing bool
// backend for the server
backend *eth.Backend
}
@@ -94,6 +96,8 @@ func NewServer(settings *Config) (Server, error) {
sap.QuitChan = make(chan bool)
sap.Subscriptions = make(map[common.Hash]map[rpc.ID]Subscription)
sap.SubscriptionTypes = make(map[common.Hash]eth.SubscriptionSettings)
sap.client = settings.Client
sap.supportsStateDiffing = settings.SupportStateDiff
var err error
sap.backend, err = eth.NewEthBackend(sap.db, &eth.Config{
ChainConfig: settings.ChainConfig,
@@ -141,7 +145,7 @@ func (sap *Service) APIs() []rpc.API {
return append(apis, rpc.API{
Namespace: eth.APIName,
Version: eth.APIVersion,
Service: eth.NewPublicEthAPI(sap.backend, sap.client),
Service: eth.NewPublicEthAPI(sap.backend, sap.client, sap.supportsStateDiffing),
Public: true,
})
}