Update config for in process Nitro node

This commit is contained in:
neeraj 2023-10-17 15:44:14 +05:30 committed by Prathamesh Musale
parent 551efea107
commit cb3558d24f
4 changed files with 49 additions and 9 deletions

View File

@ -42,12 +42,18 @@ func addNitroFlags(command *cobra.Command) {
command.PersistentFlags().String("nitro-pk", "", "nitro pk")
command.PersistentFlags().String("nitro-chain-pk", "", "nitro chainPk")
command.PersistentFlags().String("nitro-chain-url", "", "nitro chainUrl")
command.PersistentFlags().String("nitro-chain-url", "ws://127.0.0.1:8545", "nitro chainUrl")
command.PersistentFlags().String("nitro-na-address", "", "nitro naAddress")
command.PersistentFlags().String("nitro-vpa-address", "", "nitro vpaAddress")
command.PersistentFlags().String("nitro-ca-address", "", "nitro caAddress")
command.PersistentFlags().Bool("nitro-use-durable-store", false, "nitro useDurableStore")
command.PersistentFlags().String("nitro-durable-store-folder", "", "nitro durableStoreFolder")
command.PersistentFlags().Int("nitro-msg-port", 3005, "nitro msgPort")
command.PersistentFlags().Int("nitro-rpc-port", 4005, "nitro rpcPort")
command.PersistentFlags().Int("nitro-ws-msg-port", 5005, "nitro wsMsgPort")
command.PersistentFlags().Uint("nitro-chain-start-block", 0, "nitro chainStartBlock")
command.PersistentFlags().String("nitro-tls-cert-filepath", "./nitroTLS/statechannels.org.pem", "nitro tlsCertFilepath")
command.PersistentFlags().String("nitro-tls-key-filepath", "./nitroTLS/statechannels.org_key.pem", "nitro tlsKeyFilepath")
command.PersistentFlags().String("nitro-endpoint", "", "nitro endpoint")
@ -62,6 +68,12 @@ func addNitroFlags(command *cobra.Command) {
viper.BindPFlag("nitro.inProcesssNode.caAddress", command.PersistentFlags().Lookup("nitro-ca-address"))
viper.BindPFlag("nitro.inProcesssNode.useDurableStore", command.PersistentFlags().Lookup("nitro-use-durable-store"))
viper.BindPFlag("nitro.inProcesssNode.durableStoreFolder", command.PersistentFlags().Lookup("nitro-durable-store"))
viper.BindPFlag("nitro.inProcesssNode.msgPort", command.PersistentFlags().Lookup("nitro-msg-port"))
viper.BindPFlag("nitro.inProcesssNode.rpcPort", command.PersistentFlags().Lookup("nitro-rpc-port"))
viper.BindPFlag("nitro.inProcesssNode.wsMsgPort", command.PersistentFlags().Lookup("nitro-ws-msg-port"))
viper.BindPFlag("nitro.inProcesssNode.chainStartBlock", command.PersistentFlags().Lookup("nitro-chain-start-block"))
viper.BindPFlag("nitro.inProcesssNode.tlsCertFilepath", command.PersistentFlags().Lookup("nitro-tls-cert-filepath"))
viper.BindPFlag("nitro.inProcesssNode.tlsKeyFilepath", command.PersistentFlags().Lookup("nitro-tls-key-filepath"))
viper.BindPFlag("nitro.remoteNode.nitroEndpoint", command.PersistentFlags().Lookup("nitro-endpoint"))
}

View File

@ -111,10 +111,9 @@ func serve() {
pm.Start(wg)
defer pm.Stop()
// TODO: Read from config file
rpcPort := 4005
tlsCertFilepath := ""
tlsKeyFilepath := ""
rpcPort := nitroConfig.InProcessNode.RpcPort
tlsCertFilepath := nitroConfig.InProcessNode.TlsCertFilepath
tlsKeyFilepath := nitroConfig.InProcessNode.TlsKeyFilepath
var cert *tls.Certificate
if tlsCertFilepath != "" && tlsKeyFilepath != "" {
@ -422,14 +421,13 @@ func init() {
// https://github.com/cerc-io/go-nitro/blob/release-v0.1.1-ts-port-0.1.7/internal/node/node.go#L17
func initNitroNode(config *s.InProcessNitroNodeConfig) (*nitroNode.Node, error) {
// TODO: Read from config file
pkString := config.Pk
useDurableStore := config.UseDurableStore
durableStoreFolder := config.DurableStoreFolder
msgPort := 3005
wsMsgPort := 5005
msgPort := config.MsgPort
wsMsgPort := config.WsMsgPort
chainUrl := config.ChainUrl
chainStartBlock := uint64(0)
chainStartBlock := config.ChainStartBlock
chainPk := config.ChainPk
naAddress := config.NaAddress
vpaAddress := config.VpaAddress

View File

@ -44,6 +44,12 @@
caAddress = "" # NITRO_CA_ADDRESS
useDurableStore = true # NITRO_USE_DURABLE_STORE
durableStoreFolder = "./data/nitronode" # NITRO_DURABLE_STORE_FOLDER
msgPort = 3005
rpcPort = 4005
wsMsgPort = 5005
chainStartBlock = 0
tlsCertFilepath = "./nitroTLS/statechannels.org.pem"
tlsKeyFilepath = "./nitroTLS/statechannels.org_key.pem"
[nitro.remoteNode]
nitroEndpoint = "127.0.0.1:4005/api/v1" # NITRO_ENDPOINT

View File

@ -90,6 +90,12 @@ const (
NITRO_USE_DURABLE_STORE = "NITRO_USE_DURABLE_STORE"
NITRO_DURABLE_STORE_FOLDER = "NITRO_DURABLE_STORE_FOLDER"
NITRO_ENDPOINT = "NITRO_ENDPOINT"
NITRO_MSG_PORT = "NITRO_MSG_PORT"
NITRO_WS_MSG_PORT = "NITRO_WS_MSG_PORT"
NITRO_RPC_PORT = "NITRO_RPC_PORT"
NITRO_CHAIN_START_BLOCK = "NITRO_CHAIN_START_BLOCK"
NITRO_TLS_CERT_FILEPATH = "NITRO_TLS_CERT_FILEPATH"
NITRO_TLS_KEY_FILEPATH = "NITRO_TLS_KEY_FILEPATH"
)
type InProcessNitroNodeConfig struct {
@ -101,6 +107,12 @@ type InProcessNitroNodeConfig struct {
CaAddress string
UseDurableStore bool
DurableStoreFolder string
RpcPort int
MsgPort int
WsMsgPort int
ChainStartBlock uint64
TlsCertFilepath string
TlsKeyFilepath string
}
type RemoteNitroNodeConfig struct {
@ -329,6 +341,12 @@ func (c *Config) loadNitroConfig() {
viper.BindEnv("nitro.inProcesssNode.caAddress", NITRO_CA_ADDRESS)
viper.BindEnv("nitro.inProcesssNode.useDurableStore", NITRO_USE_DURABLE_STORE)
viper.BindEnv("nitro.inProcesssNode.durableStoreFolder", NITRO_DURABLE_STORE_FOLDER)
viper.BindEnv("nitro.inProcesssNode.msgPort", NITRO_MSG_PORT)
viper.BindEnv("nitro.inProcesssNode.rpcPort", NITRO_RPC_PORT)
viper.BindEnv("nitro.inProcesssNode.wsMsgPort", NITRO_WS_MSG_PORT)
viper.BindEnv("nitro.inProcesssNode.chainStartBlock", NITRO_CHAIN_START_BLOCK)
viper.BindEnv("nitro.inProcesssNode.tlsCertFilepath", NITRO_TLS_CERT_FILEPATH)
viper.BindEnv("nitro.inProcesssNode.tlsKeyFilepath", NITRO_TLS_KEY_FILEPATH)
viper.BindEnv("nitro.remoteNode.nitroEndpoint", NITRO_ENDPOINT)
@ -342,6 +360,12 @@ func (c *Config) loadNitroConfig() {
c.Nitro.InProcessNode.CaAddress = viper.GetString("nitro.inProcesssNode.caAddress")
c.Nitro.InProcessNode.UseDurableStore = viper.GetBool("nitro.inProcesssNode.useDurableStore")
c.Nitro.InProcessNode.DurableStoreFolder = viper.GetString("nitro.inProcesssNode.durableStoreFolder")
c.Nitro.InProcessNode.MsgPort = viper.GetInt("nitro.inProcesssNode.msgPort")
c.Nitro.InProcessNode.RpcPort = viper.GetInt("nitro.inProcesssNode.rpcPort")
c.Nitro.InProcessNode.WsMsgPort = viper.GetInt("nitro.inProcesssNode.wsMsgPort")
c.Nitro.InProcessNode.ChainStartBlock = viper.GetUint64("nitro.inProcesssNode.chainStartBlock")
c.Nitro.InProcessNode.TlsCertFilepath = viper.GetString("nitro.inProcesssNode.tlsCertFilepath")
c.Nitro.InProcessNode.TlsKeyFilepath = viper.GetString("nitro.inProcesssNode.tlsKeyFilepath")
c.Nitro.RemoteNode.NitroEndpoint = viper.GetString("nitro.remoteNode.nitroEndpoint")
}