2020-02-19 22:32:59 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2019 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-08-31 15:58:16 +00:00
|
|
|
package serve
|
2020-02-19 22:32:59 +00:00
|
|
|
|
|
|
|
import (
|
2021-04-14 15:53:44 +00:00
|
|
|
"errors"
|
2020-10-26 13:58:37 +00:00
|
|
|
"fmt"
|
2020-10-20 20:33:18 +00:00
|
|
|
"math/big"
|
2020-05-30 03:02:47 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2022-03-10 09:53:03 +00:00
|
|
|
"time"
|
2020-02-25 22:38:27 +00:00
|
|
|
|
2023-09-21 06:55:26 +00:00
|
|
|
"github.com/cerc-io/plugeth-statediff/indexer/database/sql/postgres"
|
|
|
|
"github.com/cerc-io/plugeth-statediff/indexer/node"
|
|
|
|
"github.com/cerc-io/plugeth-statediff/utils"
|
2020-10-20 20:33:18 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2021-08-12 06:23:41 +00:00
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2022-03-10 09:53:03 +00:00
|
|
|
"github.com/jmoiron/sqlx"
|
2020-02-25 22:38:27 +00:00
|
|
|
"github.com/spf13/viper"
|
2020-10-20 20:33:18 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
"github.com/cerc-io/ipld-eth-server/v5/pkg/prom"
|
|
|
|
ethServerShared "github.com/cerc-io/ipld-eth-server/v5/pkg/shared"
|
2020-02-19 22:32:59 +00:00
|
|
|
)
|
|
|
|
|
2020-05-30 03:02:47 +00:00
|
|
|
// Env variables
|
|
|
|
const (
|
2023-04-14 06:26:46 +00:00
|
|
|
SERVER_WS_PATH = "SERVER_WS_PATH"
|
|
|
|
SERVER_IPC_PATH = "SERVER_IPC_PATH"
|
|
|
|
SERVER_HTTP_PATH = "SERVER_HTTP_PATH"
|
|
|
|
SERVER_GRAPHQL_PATH = "SERVER_GRAPHQL_PATH"
|
2021-12-27 18:25:54 +00:00
|
|
|
|
|
|
|
SERVER_MAX_IDLE_CONNECTIONS = "SERVER_MAX_IDLE_CONNECTIONS"
|
|
|
|
SERVER_MAX_OPEN_CONNECTIONS = "SERVER_MAX_OPEN_CONNECTIONS"
|
|
|
|
SERVER_MAX_CONN_LIFETIME = "SERVER_MAX_CONN_LIFETIME"
|
|
|
|
|
2023-01-10 23:39:21 +00:00
|
|
|
ETH_DEFAULT_SENDER_ADDR = "ETH_DEFAULT_SENDER_ADDR"
|
|
|
|
ETH_RPC_GAS_CAP = "ETH_RPC_GAS_CAP"
|
|
|
|
ETH_CHAIN_CONFIG = "ETH_CHAIN_CONFIG"
|
|
|
|
ETH_SUPPORTS_STATEDIFF = "ETH_SUPPORTS_STATEDIFF"
|
2023-01-13 01:18:12 +00:00
|
|
|
ETH_STATEDIFF_TIMEOUT = "ETH_STATEDIFF_TIMEOUT"
|
2023-01-10 23:39:21 +00:00
|
|
|
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"
|
2023-06-16 16:49:56 +00:00
|
|
|
ETH_GETLOGS_BLOCK_LIMIT = "ETH_GETLOGS_BLOCK_LIMIT"
|
2021-12-27 18:25:54 +00:00
|
|
|
|
|
|
|
VALIDATOR_ENABLED = "VALIDATOR_ENABLED"
|
|
|
|
VALIDATOR_EVERY_NTH_BLOCK = "VALIDATOR_EVERY_NTH_BLOCK"
|
2023-04-14 06:26:46 +00:00
|
|
|
|
|
|
|
HTTP_TIMEOUT = "HTTP_TIMEOUT"
|
|
|
|
|
|
|
|
ETH_WS_PATH = "ETH_WS_PATH"
|
|
|
|
ETH_HTTP_PATH = "ETH_HTTP_PATH"
|
|
|
|
ETH_NODE_ID = "ETH_NODE_ID"
|
|
|
|
ETH_CLIENT_NAME = "ETH_CLIENT_NAME"
|
|
|
|
ETH_GENESIS_BLOCK = "ETH_GENESIS_BLOCK"
|
|
|
|
ETH_NETWORK_ID = "ETH_NETWORK_ID"
|
|
|
|
ETH_CHAIN_ID = "ETH_CHAIN_ID"
|
|
|
|
|
|
|
|
DATABASE_NAME = "DATABASE_NAME"
|
|
|
|
DATABASE_HOSTNAME = "DATABASE_HOSTNAME"
|
|
|
|
DATABASE_PORT = "DATABASE_PORT"
|
|
|
|
DATABASE_USER = "DATABASE_USER"
|
|
|
|
DATABASE_PASSWORD = "DATABASE_PASSWORD"
|
|
|
|
DATABASE_MAX_IDLE_CONNECTIONS = "DATABASE_MAX_IDLE_CONNECTIONS"
|
|
|
|
DATABASE_MAX_OPEN_CONNECTIONS = "DATABASE_MAX_OPEN_CONNECTIONS"
|
|
|
|
DATABASE_MAX_CONN_LIFETIME = "DATABASE_MAX_CONN_LIFETIME"
|
2020-05-30 03:02:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config struct
|
2020-02-19 22:32:59 +00:00
|
|
|
type Config struct {
|
2022-03-10 09:53:03 +00:00
|
|
|
DB *sqlx.DB
|
|
|
|
DBConfig postgres.Config
|
2021-04-14 15:53:44 +00:00
|
|
|
|
|
|
|
WSEnabled bool
|
|
|
|
WSEndpoint string
|
|
|
|
|
|
|
|
HTTPEnabled bool
|
|
|
|
HTTPEndpoint string
|
|
|
|
|
|
|
|
IPCEnabled bool
|
|
|
|
IPCEndpoint string
|
|
|
|
|
|
|
|
EthGraphqlEnabled bool
|
|
|
|
EthGraphqlEndpoint string
|
|
|
|
|
2023-01-10 23:39:21 +00:00
|
|
|
ChainConfig *params.ChainConfig
|
|
|
|
DefaultSender *common.Address
|
|
|
|
RPCGasCap *big.Int
|
|
|
|
EthHttpEndpoint string
|
|
|
|
Client *rpc.Client
|
|
|
|
SupportStateDiff bool
|
2023-01-13 01:18:12 +00:00
|
|
|
StateDiffTimeout time.Duration
|
2023-01-10 23:39:21 +00:00
|
|
|
ForwardEthCalls bool
|
|
|
|
ForwardGetStorageAt bool
|
|
|
|
ProxyOnError bool
|
2023-06-16 16:49:56 +00:00
|
|
|
GetLogsBlockLimit int64
|
2023-01-10 23:39:21 +00:00
|
|
|
NodeNetworkID string
|
2021-09-21 12:10:55 +00:00
|
|
|
|
|
|
|
// Cache configuration.
|
|
|
|
GroupCache *ethServerShared.GroupCacheConfig
|
|
|
|
|
|
|
|
StateValidationEnabled bool
|
|
|
|
StateValidationEveryNthBlock uint64
|
2020-02-25 22:38:27 +00:00
|
|
|
}
|
|
|
|
|
2020-06-30 00:16:52 +00:00
|
|
|
// NewConfig is used to initialize a watcher config from a .toml file
|
|
|
|
// Separate chain watcher instances need to be ran with separate ipfs path in order to avoid lock contention on the ipfs repository lockfile
|
|
|
|
func NewConfig() (*Config, error) {
|
2020-02-25 22:38:27 +00:00
|
|
|
c := new(Config)
|
2020-08-31 15:47:06 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
viper.BindEnv("server.httpPath", SERVER_HTTP_PATH)
|
|
|
|
viper.BindEnv("server.wsPath", SERVER_WS_PATH)
|
|
|
|
viper.BindEnv("server.ipcPath", SERVER_IPC_PATH)
|
|
|
|
viper.BindEnv("server.graphqlPath", SERVER_GRAPHQL_PATH)
|
|
|
|
|
2021-12-27 18:25:54 +00:00
|
|
|
viper.BindEnv("ethereum.httpPath", ETH_HTTP_PATH)
|
|
|
|
viper.BindEnv("ethereum.rpcGasCap", ETH_RPC_GAS_CAP)
|
|
|
|
viper.BindEnv("ethereum.chainConfig", ETH_CHAIN_CONFIG)
|
|
|
|
viper.BindEnv("ethereum.supportsStateDiff", ETH_SUPPORTS_STATEDIFF)
|
2023-01-13 01:18:12 +00:00
|
|
|
viper.BindEnv("ethereum.stateDiffTimeout", ETH_STATEDIFF_TIMEOUT)
|
2021-12-27 18:25:54 +00:00
|
|
|
viper.BindEnv("ethereum.forwardEthCalls", ETH_FORWARD_ETH_CALLS)
|
2023-01-10 23:39:21 +00:00
|
|
|
viper.BindEnv("ethereum.forwardGetStorageAt", ETH_FORWARD_GET_STORAGE_AT)
|
2021-12-30 02:29:59 +00:00
|
|
|
viper.BindEnv("ethereum.proxyOnError", ETH_PROXY_ON_ERROR)
|
2023-06-16 16:49:56 +00:00
|
|
|
viper.BindEnv("ethereum.getLogsBlockLimit", ETH_GETLOGS_BLOCK_LIMIT)
|
2023-04-14 06:26:46 +00:00
|
|
|
viper.BindEnv("log.file", "LOG_FILE")
|
|
|
|
viper.BindEnv("log.level", "LOG_LEVEL")
|
2020-05-30 03:02:47 +00:00
|
|
|
|
2021-08-20 07:37:11 +00:00
|
|
|
c.dbInit()
|
2020-10-26 13:58:37 +00:00
|
|
|
ethHTTP := viper.GetString("ethereum.httpPath")
|
2021-04-16 13:56:02 +00:00
|
|
|
ethHTTPEndpoint := fmt.Sprintf("http://%s", ethHTTP)
|
2021-08-12 06:23:41 +00:00
|
|
|
nodeInfo, cli, err := getEthNodeAndClient(ethHTTPEndpoint)
|
2022-03-10 09:53:03 +00:00
|
|
|
c.NodeNetworkID = nodeInfo.NetworkID
|
2020-10-26 13:58:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
c.Client = cli
|
2021-02-24 16:50:26 +00:00
|
|
|
c.SupportStateDiff = viper.GetBool("ethereum.supportsStateDiff")
|
2021-12-27 18:25:54 +00:00
|
|
|
c.ForwardEthCalls = viper.GetBool("ethereum.forwardEthCalls")
|
2023-01-10 23:39:21 +00:00
|
|
|
c.ForwardGetStorageAt = viper.GetBool("ethereum.forwardGetStorageAt")
|
2021-12-30 02:29:59 +00:00
|
|
|
c.ProxyOnError = viper.GetBool("ethereum.proxyOnError")
|
2021-04-16 13:56:02 +00:00
|
|
|
c.EthHttpEndpoint = ethHTTPEndpoint
|
2020-10-26 13:58:37 +00:00
|
|
|
|
2023-06-16 16:49:56 +00:00
|
|
|
if viper.IsSet("ethereum.getLogsBlockLimit") {
|
|
|
|
c.GetLogsBlockLimit = viper.GetInt64("ethereum.getLogsBlockLimit")
|
|
|
|
} else {
|
|
|
|
c.GetLogsBlockLimit = 500
|
|
|
|
}
|
|
|
|
|
2021-04-14 15:53:44 +00:00
|
|
|
// websocket server
|
2023-04-14 06:26:46 +00:00
|
|
|
wsEnabled := viper.GetBool("server.ws")
|
2021-04-14 15:53:44 +00:00
|
|
|
if wsEnabled {
|
2023-04-14 06:26:46 +00:00
|
|
|
wsPath := viper.GetString("server.wsPath")
|
2021-04-14 15:53:44 +00:00
|
|
|
if wsPath == "" {
|
|
|
|
wsPath = "127.0.0.1:8080"
|
|
|
|
}
|
|
|
|
c.WSEndpoint = wsPath
|
2020-08-31 15:47:06 +00:00
|
|
|
}
|
2021-04-14 15:53:44 +00:00
|
|
|
c.WSEnabled = wsEnabled
|
|
|
|
|
|
|
|
// ipc server
|
2023-04-14 06:26:46 +00:00
|
|
|
ipcEnabled := viper.GetBool("server.ipc")
|
2021-04-14 15:53:44 +00:00
|
|
|
if ipcEnabled {
|
2023-04-14 06:26:46 +00:00
|
|
|
ipcPath := viper.GetString("server.ipcPath")
|
2021-04-14 15:53:44 +00:00
|
|
|
if ipcPath == "" {
|
|
|
|
home, err := os.UserHomeDir()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ipcPath = filepath.Join(home, ".vulcanize/vulcanize.ipc")
|
2020-05-30 03:02:47 +00:00
|
|
|
}
|
2021-04-14 15:53:44 +00:00
|
|
|
c.IPCEndpoint = ipcPath
|
2020-05-30 03:02:47 +00:00
|
|
|
}
|
2021-04-14 15:53:44 +00:00
|
|
|
c.IPCEnabled = ipcEnabled
|
|
|
|
|
|
|
|
// http server
|
2023-04-14 06:26:46 +00:00
|
|
|
httpEnabled := viper.GetBool("server.http")
|
2021-04-14 15:53:44 +00:00
|
|
|
if httpEnabled {
|
2023-04-14 06:26:46 +00:00
|
|
|
httpPath := viper.GetString("server.httpPath")
|
2021-04-14 15:53:44 +00:00
|
|
|
if httpPath == "" {
|
|
|
|
httpPath = "127.0.0.1:8081"
|
|
|
|
}
|
|
|
|
c.HTTPEndpoint = httpPath
|
|
|
|
}
|
|
|
|
c.HTTPEnabled = httpEnabled
|
|
|
|
|
|
|
|
// eth graphql endpoint
|
2023-04-14 06:26:46 +00:00
|
|
|
ethGraphqlEnabled := viper.GetBool("server.graphql")
|
2021-04-14 15:53:44 +00:00
|
|
|
if ethGraphqlEnabled {
|
2023-04-14 06:26:46 +00:00
|
|
|
ethGraphqlPath := viper.GetString("server.graphqlPath")
|
2021-04-14 15:53:44 +00:00
|
|
|
if ethGraphqlPath == "" {
|
|
|
|
ethGraphqlPath = "127.0.0.1:8082"
|
|
|
|
}
|
|
|
|
c.EthGraphqlEndpoint = ethGraphqlPath
|
2020-08-31 15:47:06 +00:00
|
|
|
}
|
2021-04-14 15:53:44 +00:00
|
|
|
c.EthGraphqlEnabled = ethGraphqlEnabled
|
|
|
|
|
2020-08-31 15:47:06 +00:00
|
|
|
overrideDBConnConfig(&c.DBConfig)
|
2022-05-18 05:52:18 +00:00
|
|
|
serveDB, err := ethServerShared.NewDB(c.DBConfig.DbConnectionString(), c.DBConfig)
|
2021-08-31 11:32:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-10 09:53:03 +00:00
|
|
|
prom.RegisterDBCollector(c.DBConfig.DatabaseName, serveDB)
|
2021-08-12 06:23:41 +00:00
|
|
|
c.DB = serveDB
|
2020-05-30 03:02:47 +00:00
|
|
|
|
2020-10-20 20:33:18 +00:00
|
|
|
rpcGasCapStr := viper.GetString("ethereum.rpcGasCap")
|
|
|
|
if rpcGasCapStr != "" {
|
|
|
|
if rpcGasCap, ok := new(big.Int).SetString(rpcGasCapStr, 10); ok {
|
|
|
|
c.RPCGasCap = rpcGasCap
|
|
|
|
}
|
2022-09-21 11:45:03 +00:00
|
|
|
} else {
|
|
|
|
c.RPCGasCap = big.NewInt(0)
|
2020-10-20 20:33:18 +00:00
|
|
|
}
|
2023-01-13 01:18:12 +00:00
|
|
|
if sdTimeout := viper.GetString("ethereum.stateDiffTimeout"); sdTimeout != "" {
|
|
|
|
var err error
|
|
|
|
if c.StateDiffTimeout, err = time.ParseDuration(sdTimeout); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c.StateDiffTimeout = ethServerShared.DefaultStateDiffTimeout
|
|
|
|
}
|
|
|
|
if c.StateDiffTimeout < 0 {
|
|
|
|
return nil, errors.New("ethereum.stateDiffTimeout < 0")
|
|
|
|
}
|
2021-03-10 16:18:32 +00:00
|
|
|
chainConfigPath := viper.GetString("ethereum.chainConfig")
|
|
|
|
if chainConfigPath != "" {
|
2023-09-21 06:55:26 +00:00
|
|
|
c.ChainConfig, err = utils.LoadConfig(chainConfigPath)
|
2021-03-10 16:18:32 +00:00
|
|
|
} else {
|
2023-09-21 06:55:26 +00:00
|
|
|
c.ChainConfig, err = utils.ChainConfig(nodeInfo.ChainID)
|
2021-03-10 16:18:32 +00:00
|
|
|
}
|
2021-09-21 12:10:55 +00:00
|
|
|
|
|
|
|
c.loadGroupCacheConfig()
|
|
|
|
|
|
|
|
c.loadValidatorConfig()
|
|
|
|
|
2020-10-20 20:33:18 +00:00
|
|
|
return c, err
|
2020-05-30 03:02:47 +00:00
|
|
|
}
|
|
|
|
|
2022-03-10 09:53:03 +00:00
|
|
|
func overrideDBConnConfig(con *postgres.Config) {
|
2021-12-27 18:25:54 +00:00
|
|
|
viper.BindEnv("database.server.maxIdle", SERVER_MAX_IDLE_CONNECTIONS)
|
|
|
|
viper.BindEnv("database.server.maxOpen", SERVER_MAX_OPEN_CONNECTIONS)
|
|
|
|
viper.BindEnv("database.server.maxLifetime", SERVER_MAX_CONN_LIFETIME)
|
2020-08-31 15:47:06 +00:00
|
|
|
con.MaxIdle = viper.GetInt("database.server.maxIdle")
|
2022-03-10 09:53:03 +00:00
|
|
|
con.MaxConns = viper.GetInt("database.server.maxOpen")
|
|
|
|
con.MaxConnLifetime = time.Duration(viper.GetInt("database.server.maxLifetime"))
|
2020-02-19 22:32:59 +00:00
|
|
|
}
|
2021-08-20 07:37:11 +00:00
|
|
|
|
2021-09-21 12:10:55 +00:00
|
|
|
func (c *Config) dbInit() {
|
2021-12-27 18:25:54 +00:00
|
|
|
viper.BindEnv("database.name", DATABASE_NAME)
|
|
|
|
viper.BindEnv("database.hostname", DATABASE_HOSTNAME)
|
|
|
|
viper.BindEnv("database.port", DATABASE_PORT)
|
|
|
|
viper.BindEnv("database.user", DATABASE_USER)
|
|
|
|
viper.BindEnv("database.password", DATABASE_PASSWORD)
|
|
|
|
viper.BindEnv("database.maxIdle", DATABASE_MAX_IDLE_CONNECTIONS)
|
|
|
|
viper.BindEnv("database.maxOpen", DATABASE_MAX_OPEN_CONNECTIONS)
|
|
|
|
viper.BindEnv("database.maxLifetime", DATABASE_MAX_CONN_LIFETIME)
|
2021-08-20 07:37:11 +00:00
|
|
|
|
2022-03-10 09:53:03 +00:00
|
|
|
c.DBConfig.DatabaseName = viper.GetString("database.name")
|
|
|
|
c.DBConfig.Hostname = viper.GetString("database.hostname")
|
|
|
|
c.DBConfig.Port = viper.GetInt("database.port")
|
|
|
|
c.DBConfig.Username = viper.GetString("database.user")
|
|
|
|
c.DBConfig.Password = viper.GetString("database.password")
|
2021-09-21 12:10:55 +00:00
|
|
|
c.DBConfig.MaxIdle = viper.GetInt("database.maxIdle")
|
2022-03-10 09:53:03 +00:00
|
|
|
c.DBConfig.MaxConns = viper.GetInt("database.maxOpen")
|
|
|
|
c.DBConfig.MaxConnLifetime = time.Duration(viper.GetInt("database.maxLifetime"))
|
2021-09-21 12:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) loadGroupCacheConfig() {
|
|
|
|
viper.BindEnv("groupcache.pool.enabled", ethServerShared.GcachePoolEnabled)
|
|
|
|
viper.BindEnv("groupcache.pool.httpEndpoint", ethServerShared.GcachePoolHttpPath)
|
|
|
|
viper.BindEnv("groupcache.pool.peerHttpEndpoints", ethServerShared.GcachePoolHttpPeers)
|
|
|
|
viper.BindEnv("groupcache.statedb.cacheSizeInMB", ethServerShared.GcacheStatedbCacheSize)
|
|
|
|
viper.BindEnv("groupcache.statedb.cacheExpiryInMins", ethServerShared.GcacheStatedbCacheExpiry)
|
|
|
|
viper.BindEnv("groupcache.statedb.logStatsIntervalInSecs", ethServerShared.GcacheStatedbLogStatsInterval)
|
|
|
|
|
|
|
|
gcc := ethServerShared.GroupCacheConfig{}
|
|
|
|
gcc.Pool.Enabled = viper.GetBool("groupcache.pool.enabled")
|
|
|
|
if gcc.Pool.Enabled {
|
|
|
|
gcc.Pool.HttpEndpoint = viper.GetString("groupcache.pool.httpEndpoint")
|
|
|
|
gcc.Pool.PeerHttpEndpoints = viper.GetStringSlice("groupcache.pool.peerHttpEndpoints")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Irrespective of whether the pool is enabled, we always use the hot/local cache.
|
|
|
|
gcc.StateDB.CacheSizeInMB = viper.GetInt("groupcache.statedb.cacheSizeInMB")
|
|
|
|
gcc.StateDB.CacheExpiryInMins = viper.GetInt("groupcache.statedb.cacheExpiryInMins")
|
|
|
|
gcc.StateDB.LogStatsIntervalInSecs = viper.GetInt("groupcache.statedb.logStatsIntervalInSecs")
|
|
|
|
|
|
|
|
c.GroupCache = &gcc
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) loadValidatorConfig() {
|
2021-12-27 18:25:54 +00:00
|
|
|
viper.BindEnv("validator.enabled", VALIDATOR_ENABLED)
|
|
|
|
viper.BindEnv("validator.everyNthBlock", VALIDATOR_EVERY_NTH_BLOCK)
|
2021-09-21 12:10:55 +00:00
|
|
|
|
|
|
|
c.StateValidationEnabled = viper.GetBool("validator.enabled")
|
|
|
|
c.StateValidationEveryNthBlock = viper.GetUint64("validator.everyNthBlock")
|
2021-08-20 07:37:11 +00:00
|
|
|
}
|
2023-04-14 06:26:46 +00:00
|
|
|
|
|
|
|
// GetEthNodeAndClient returns eth node info and client from path url
|
|
|
|
func getEthNodeAndClient(path string) (node.Info, *rpc.Client, error) {
|
|
|
|
viper.BindEnv("ethereum.nodeID", ETH_NODE_ID)
|
|
|
|
viper.BindEnv("ethereum.clientName", ETH_CLIENT_NAME)
|
|
|
|
viper.BindEnv("ethereum.genesisBlock", ETH_GENESIS_BLOCK)
|
|
|
|
viper.BindEnv("ethereum.networkID", ETH_NETWORK_ID)
|
|
|
|
viper.BindEnv("ethereum.chainID", ETH_CHAIN_ID)
|
|
|
|
|
|
|
|
rpcClient, err := rpc.Dial(path)
|
|
|
|
if err != nil {
|
|
|
|
return node.Info{}, nil, err
|
|
|
|
}
|
|
|
|
return node.Info{
|
|
|
|
ID: viper.GetString("ethereum.nodeID"),
|
|
|
|
ClientName: viper.GetString("ethereum.clientName"),
|
|
|
|
GenesisBlock: viper.GetString("ethereum.genesisBlock"),
|
|
|
|
NetworkID: viper.GetString("ethereum.networkID"),
|
|
|
|
ChainID: viper.GetUint64("ethereum.chainID"),
|
|
|
|
}, rpcClient, nil
|
|
|
|
}
|