Setup essential Nitro config

This commit is contained in:
Prathamesh Musale 2023-10-12 13:20:43 +05:30
parent e9e17c2be1
commit cb2c23da8a
3 changed files with 52 additions and 8 deletions

View File

@ -35,3 +35,21 @@ func addDatabaseFlags(command *cobra.Command) {
viper.BindPFlag("database.user", command.PersistentFlags().Lookup("database-user"))
viper.BindPFlag("database.password", command.PersistentFlags().Lookup("database-password"))
}
func addNitroFlags(command *cobra.Command) {
// nitro flags
command.PersistentFlags().String("nitro-pk", "", "nitro pk")
command.PersistentFlags().String("nitro-chainPk", "", "nitro chainPk")
command.PersistentFlags().String("nitro-chainUrl", "", "nitro chainUrl")
command.PersistentFlags().String("nitro-naAddress", "", "nitro naAddress")
command.PersistentFlags().String("nitro-vpaAddress", "", "nitro vpaAddress")
command.PersistentFlags().String("nitro-caAddress", "", "nitro caAddress")
// nitro flag bindings
viper.BindPFlag("nitro.pk", command.PersistentFlags().Lookup("nitro-pk"))
viper.BindPFlag("nitro.chainPk", command.PersistentFlags().Lookup("nitro-chainPk"))
viper.BindPFlag("nitro.chainUrl", command.PersistentFlags().Lookup("nitro-chainUrl"))
viper.BindPFlag("nitro.naAddress", command.PersistentFlags().Lookup("nitro-naAddress"))
viper.BindPFlag("nitro.vpaAddress", command.PersistentFlags().Lookup("nitro-vpaAddress"))
viper.BindPFlag("nitro.caAddress", command.PersistentFlags().Lookup("nitro-caAddress"))
}

View File

@ -85,7 +85,7 @@ func serve() {
server.Serve(wg)
// TODO: Create required config for Nitro node
nitroNode, err := initializeNitroNode()
nitroNode, err := initializeNitroNode(serverConfig.Nitro)
if err != nil {
panic(err)
}
@ -290,6 +290,8 @@ func init() {
addDatabaseFlags(serveCmd)
addNitroFlags(serveCmd)
// flags for all config variables
// eth graphql and json-rpc parameters
serveCmd.PersistentFlags().Bool("server-graphql", false, "turn on the eth graphql server")
@ -370,19 +372,19 @@ func init() {
viper.BindPFlag("validator.everyNthBlock", serveCmd.PersistentFlags().Lookup("validator-every-nth-block"))
}
func initializeNitroNode() (*nitroNode.Node, error) {
func initializeNitroNode(nitroConfig *s.NitroConfig) (*nitroNode.Node, error) {
// TODO: Configure
pkString := ""
pkString := nitroConfig.Pk
useDurableStore := true
durableStoreFolder := "./data/nitro-store"
msgPort := 3005
wsMsgPort := 5005
chainUrl := "ws://127.0.0.1:8545"
chainUrl := nitroConfig.ChainUrl
chainStartBlock := uint64(0)
chainPk := ""
naAddress := ""
vpaAddress := ""
caAddress := ""
chainPk := nitroConfig.ChainPk
naAddress := nitroConfig.NaAddress
vpaAddress := nitroConfig.VpaAddress
caAddress := nitroConfig.CaAddress
chainAuthToken := ""
publicIp := "0.0.0.0"

View File

@ -81,6 +81,15 @@ const (
DATABASE_MAX_CONN_LIFETIME = "DATABASE_MAX_CONN_LIFETIME"
)
type NitroConfig struct {
Pk string
ChainPk string
ChainUrl string
NaAddress string
VpaAddress string
CaAddress string
}
// Config struct
type Config struct {
DB *sqlx.DB
@ -116,6 +125,8 @@ type Config struct {
StateValidationEnabled bool
StateValidationEveryNthBlock uint64
Nitro *NitroConfig
}
// NewConfig is used to initialize a watcher config from a .toml file
@ -248,6 +259,8 @@ func NewConfig() (*Config, error) {
c.loadValidatorConfig()
c.loadNitroConfig()
return c, err
}
@ -280,6 +293,17 @@ func (c *Config) dbInit() {
c.DBConfig.MaxConnLifetime = time.Duration(viper.GetInt("database.maxLifetime"))
}
func (c *Config) loadNitroConfig() {
c.Nitro = &NitroConfig{}
c.Nitro.Pk = viper.GetString("nitro.pk")
c.Nitro.ChainPk = viper.GetString("nitro.chainPk")
c.Nitro.ChainUrl = viper.GetString("nitro.chainUrl")
c.Nitro.NaAddress = viper.GetString("nitro.naAddress")
c.Nitro.VpaAddress = viper.GetString("nitro.vpaAddress")
c.Nitro.CaAddress = viper.GetString("nitro.caAddress")
}
func (c *Config) loadGroupCacheConfig() {
viper.BindEnv("groupcache.pool.enabled", ethServerShared.GcachePoolEnabled)
viper.BindEnv("groupcache.pool.httpEndpoint", ethServerShared.GcachePoolHttpPath)