From b205f31605fa4fe6082de8b79d8c859367d8ccd8 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Thu, 12 Oct 2023 13:20:43 +0530 Subject: [PATCH] Setup essential Nitro config --- cmd/common.go | 18 ++++++++++++++++++ cmd/serve.go | 18 ++++++++++-------- go.mod | 4 ++-- go.sum | 4 ++-- pkg/serve/config.go | 24 ++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/cmd/common.go b/cmd/common.go index 3e575621..3268d0e3 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -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")) +} diff --git a/cmd/serve.go b/cmd/serve.go index a5ccea1b..15ac0325 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -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" diff --git a/go.mod b/go.mod index dcc1f3f9..ab79ea18 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/ethereum/go-ethereum v1.12.0 // TODO: Investigate github.com/google/uuid v1.3.0 github.com/graph-gophers/graphql-go v1.3.0 - github.com/hashicorp/golang-lru/v2 v2.0.5 github.com/ipfs/go-cid v0.4.1 github.com/jmoiron/sqlx v1.3.5 github.com/joho/godotenv v1.4.0 @@ -92,6 +91,7 @@ require ( github.com/hashicorp/go-bexpr v0.1.12 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect + github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/holiman/bloomfilter/v2 v2.0.3 // indirect github.com/holiman/uint256 v1.2.3 // indirect @@ -300,4 +300,4 @@ replace ( github.com/cerc-io/ipfs-ethdb/v5 => git.vdb.to/deep-stack/ipfs-ethdb/v5 v5.0.1-alpha.0.20231003124335-b6cf70668a07 ) -replace github.com/statechannels/go-nitro v0.1.1 => github.com/cerc-io/go-nitro v0.1.2-0.20231012043644-1b31b5133214 +replace github.com/statechannels/go-nitro v0.1.1 => github.com/cerc-io/go-nitro v0.1.2-0.20231012062355-dc2cb28411a5 diff --git a/go.sum b/go.sum index cc9c89ae..0576ff8c 100644 --- a/go.sum +++ b/go.sum @@ -116,8 +116,8 @@ github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/ceramicnetwork/go-dag-jose v0.1.0 h1:yJ/HVlfKpnD3LdYP03AHyTvbm3BpPiz2oZiOeReJRdU= github.com/ceramicnetwork/go-dag-jose v0.1.0/go.mod h1:qYA1nYt0X8u4XoMAVoOV3upUVKtrxy/I670Dg5F0wjI= -github.com/cerc-io/go-nitro v0.1.2-0.20231012043644-1b31b5133214 h1:nrkG2Rym9jOpIFD9MyVLTkfrxyG3Uf0ibusIHeQDKQk= -github.com/cerc-io/go-nitro v0.1.2-0.20231012043644-1b31b5133214/go.mod h1:gkKL37JcSo54ybLTI6VJRmP75bWEu9i1kc9RYmQLp+I= +github.com/cerc-io/go-nitro v0.1.2-0.20231012062355-dc2cb28411a5 h1:wMrhik+HPv/cdhyWL0nUImZ0XGFZ0el4eSY7QjwH0aA= +github.com/cerc-io/go-nitro v0.1.2-0.20231012062355-dc2cb28411a5/go.mod h1:gkKL37JcSo54ybLTI6VJRmP75bWEu9i1kc9RYmQLp+I= github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= diff --git a/pkg/serve/config.go b/pkg/serve/config.go index 7c12b3bb..08bc06ec 100644 --- a/pkg/serve/config.go +++ b/pkg/serve/config.go @@ -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)