forked from cerc-io/ipld-eth-server
Fix getLogs query (avoid repeated execution, separate tx, and improve performance) (#250)
* Avoid repeated queries in getLogs. * Rewrite query for speed and simplicity. * Make default limit 500
This commit is contained in:
@@ -56,6 +56,7 @@ const (
|
||||
ETH_FORWARD_ETH_CALLS = "ETH_FORWARD_ETH_CALLS"
|
||||
ETH_FORWARD_GET_STORAGE_AT = "ETH_FORWARD_GET_STORAGE_AT"
|
||||
ETH_PROXY_ON_ERROR = "ETH_PROXY_ON_ERROR"
|
||||
ETH_GETLOGS_BLOCK_LIMIT = "ETH_GETLOGS_BLOCK_LIMIT"
|
||||
|
||||
VALIDATOR_ENABLED = "VALIDATOR_ENABLED"
|
||||
VALIDATOR_EVERY_NTH_BLOCK = "VALIDATOR_EVERY_NTH_BLOCK"
|
||||
@@ -107,6 +108,7 @@ type Config struct {
|
||||
ForwardEthCalls bool
|
||||
ForwardGetStorageAt bool
|
||||
ProxyOnError bool
|
||||
GetLogsBlockLimit int64
|
||||
NodeNetworkID string
|
||||
|
||||
// Cache configuration.
|
||||
@@ -134,6 +136,7 @@ func NewConfig() (*Config, error) {
|
||||
viper.BindEnv("ethereum.forwardEthCalls", ETH_FORWARD_ETH_CALLS)
|
||||
viper.BindEnv("ethereum.forwardGetStorageAt", ETH_FORWARD_GET_STORAGE_AT)
|
||||
viper.BindEnv("ethereum.proxyOnError", ETH_PROXY_ON_ERROR)
|
||||
viper.BindEnv("ethereum.getLogsBlockLimit", ETH_GETLOGS_BLOCK_LIMIT)
|
||||
viper.BindEnv("log.file", "LOG_FILE")
|
||||
viper.BindEnv("log.level", "LOG_LEVEL")
|
||||
|
||||
@@ -152,6 +155,12 @@ func NewConfig() (*Config, error) {
|
||||
c.ProxyOnError = viper.GetBool("ethereum.proxyOnError")
|
||||
c.EthHttpEndpoint = ethHTTPEndpoint
|
||||
|
||||
if viper.IsSet("ethereum.getLogsBlockLimit") {
|
||||
c.GetLogsBlockLimit = viper.GetInt64("ethereum.getLogsBlockLimit")
|
||||
} else {
|
||||
c.GetLogsBlockLimit = 500
|
||||
}
|
||||
|
||||
// websocket server
|
||||
wsEnabled := viper.GetBool("server.ws")
|
||||
if wsEnabled {
|
||||
|
||||
@@ -72,6 +72,8 @@ type Service struct {
|
||||
forwardEthCalls bool
|
||||
// whether to forward eth_getStorageAt directly to proxy node
|
||||
forwardGetStorageAt bool
|
||||
// the maximum size of the block range to use in GetLogs
|
||||
getLogsBlockLimit int64
|
||||
// whether to forward all calls to proxy node if they throw an error locally
|
||||
proxyOnError bool
|
||||
// eth node network id
|
||||
@@ -88,6 +90,7 @@ func NewServer(settings *Config) (Server, error) {
|
||||
sap.stateDiffTimeout = settings.StateDiffTimeout
|
||||
sap.forwardEthCalls = settings.ForwardEthCalls
|
||||
sap.forwardGetStorageAt = settings.ForwardGetStorageAt
|
||||
sap.getLogsBlockLimit = settings.GetLogsBlockLimit
|
||||
sap.proxyOnError = settings.ProxyOnError
|
||||
sap.nodeNetworkId = settings.NodeNetworkID
|
||||
var err error
|
||||
@@ -128,6 +131,7 @@ func (sap *Service) APIs() []rpc.API {
|
||||
ForwardGetStorageAt: sap.forwardGetStorageAt,
|
||||
ProxyOnError: sap.proxyOnError,
|
||||
StateDiffTimeout: sap.stateDiffTimeout,
|
||||
GetLogsBlockLimit: sap.getLogsBlockLimit,
|
||||
}
|
||||
ethAPI, err := eth.NewPublicEthAPI(sap.backend, sap.client, conf)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user