From 50c9dee79e4dbecc308f27a7db45b5b5bff28e41 Mon Sep 17 00:00:00 2001 From: Wellington Barbosa Date: Mon, 18 Dec 2023 16:01:22 -0700 Subject: [PATCH 1/7] Auto correct the IP if the operator set their IP to localhost when opt-in --- node/node.go | 11 +---------- node/plugin/cmd/main.go | 19 ++++++++++++++++++- node/plugin/config.go | 33 +++++++++++++++++++++++++++++++++ node/utils.go | 12 ++++++++++++ 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/node/node.go b/node/node.go index 290fb232a..93a8e110e 100644 --- a/node/node.go +++ b/node/node.go @@ -375,7 +375,7 @@ func (n *Node) checkCurrentNodeIp(ctx context.Context) { case <-ctx.Done(): return case <-t.C: - newSocketAddr, err := n.socketAddress(ctx) + newSocketAddr, err := SocketAddress(ctx, n.PubIPProvider, n.Config.DispersalPort, n.Config.RetrievalPort) if err != nil { n.Logger.Error("failed to get socket address", "err", err) continue @@ -385,15 +385,6 @@ func (n *Node) checkCurrentNodeIp(ctx context.Context) { } } -func (n *Node) socketAddress(ctx context.Context) (string, error) { - ip, err := n.PubIPProvider.PublicIPAddress(ctx) - if err != nil { - return "", fmt.Errorf("failed to get public ip address from IP provider: %w", err) - } - socket := core.MakeOperatorSocket(ip, n.Config.DispersalPort, n.Config.RetrievalPort) - return socket.String(), nil -} - // we only need to build the sdk clients for eigenmetrics right now, // but we might eventually want to move as much as possible to the sdk func buildSdkClients(config *Config, logger common.Logger) (*constructor.Clients, error) { diff --git a/node/plugin/cmd/main.go b/node/plugin/cmd/main.go index 70ab230fd..51687a82f 100644 --- a/node/plugin/cmd/main.go +++ b/node/plugin/cmd/main.go @@ -5,10 +5,12 @@ import ( "fmt" "log" "os" + "strings" "time" "github.com/Layr-Labs/eigenda/common/geth" "github.com/Layr-Labs/eigenda/common/logging" + "github.com/Layr-Labs/eigenda/common/pubip" "github.com/Layr-Labs/eigenda/core" "github.com/Layr-Labs/eigenda/core/eth" "github.com/Layr-Labs/eigenda/node" @@ -114,8 +116,19 @@ func pluginOps(ctx *cli.Context) { return } + pubIPProvider := pubip.ProviderOrDefault(config.PubIPProvider) + + socket := string(core.MakeOperatorSocket(config.Hostname, config.DispersalPort, config.RetrievalPort)) + if isLocalhost(socket) { + socket, err = node.SocketAddress(context.Background(), pubIPProvider, config.DispersalPort, config.RetrievalPort) + if err != nil { + log.Printf("Error: failed to create EigenDA transactor: %v", err) + return + } + } + operator := &node.Operator{ - Socket: config.Socket, + Socket: socket, Timeout: 10 * time.Second, KeyPair: keyPair, OperatorId: keyPair.GetPubKeyG1().GetOperatorID(), @@ -141,3 +154,7 @@ func pluginOps(ctx *cli.Context) { log.Fatalf("Fatal: unsupported operation: %s", config.Operation) } } + +func isLocalhost(socket string) bool { + return strings.Contains(socket, "localhost") || strings.Contains(socket, "127.0.0.1") || strings.Contains(socket, "0.0.0.0") +} diff --git a/node/plugin/config.go b/node/plugin/config.go index a4d41af7f..3f9721c8b 100644 --- a/node/plugin/config.go +++ b/node/plugin/config.go @@ -14,6 +14,31 @@ import ( var ( /* Required Flags */ + HostnameFlag = cli.StringFlag{ + Name: "hostname", + Usage: "Hostname at which node is available", + Required: true, + EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "HOSTNAME"), + } + DispersalPortFlag = cli.StringFlag{ + Name: "dispersal-port", + Usage: "Port at which node registers to listen for dispersal calls", + Required: true, + EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "DISPERSAL_PORT"), + } + RetrievalPortFlag = cli.StringFlag{ + Name: "retrieval-port", + Usage: "Port at which node registers to listen for retrieval calls", + Required: true, + EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "RETRIEVAL_PORT"), + } + PubIPProviderFlag = cli.StringFlag{ + Name: "public-ip-provider", + Usage: "The ip provider service used to obtain a operator's public IP [seeip (default), ipify)", + Required: true, + EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "PUBLIC_IP_PROVIDER"), + } + // The operation to run. OperationFlag = cli.StringFlag{ Name: "operation", @@ -99,6 +124,10 @@ var ( ) type Config struct { + Hostname string + RetrievalPort string + DispersalPort string + PubIPProvider string Operation string EcdsaKeyFile string BlsKeyFile string @@ -130,6 +159,10 @@ func NewConfig(ctx *cli.Context) (*Config, error) { } return &Config{ + Hostname: ctx.GlobalString(HostnameFlag.Name), + DispersalPort: ctx.GlobalString(DispersalPortFlag.Name), + RetrievalPort: ctx.GlobalString(RetrievalPortFlag.Name), + PubIPProvider: ctx.GlobalString(PubIPProviderFlag.Name), Operation: op, EcdsaKeyPassword: ctx.GlobalString(EcdsaKeyPasswordFlag.Name), BlsKeyPassword: ctx.GlobalString(BlsKeyPasswordFlag.Name), diff --git a/node/utils.go b/node/utils.go index 1166136b4..e493887d6 100644 --- a/node/utils.go +++ b/node/utils.go @@ -2,9 +2,12 @@ package node import ( "bytes" + "context" "encoding/binary" "errors" + "fmt" + "github.com/Layr-Labs/eigenda/common/pubip" "github.com/Layr-Labs/eigenda/core" ) @@ -80,3 +83,12 @@ func DecodeBatchExpirationKey(key []byte) (int64, error) { ts := int64(binary.BigEndian.Uint64(key[len(key)-8:])) return ts, nil } + +func SocketAddress(ctx context.Context, provider pubip.Provider, dispersalPort string, retrievalPort string) (string, error) { + ip, err := provider.PublicIPAddress(ctx) + if err != nil { + return "", fmt.Errorf("failed to get public ip address from IP provider: %w", err) + } + socket := core.MakeOperatorSocket(ip, dispersalPort, retrievalPort) + return socket.String(), nil +} From ae29f52443e16102f82e9256799df64a25a22f4c Mon Sep 17 00:00:00 2001 From: Wellington Barbosa Date: Tue, 19 Dec 2023 12:10:54 -0700 Subject: [PATCH 2/7] Parse socket config --- node/plugin/cmd/main.go | 20 +++++++++++++++++--- node/plugin/config.go | 24 ------------------------ 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/node/plugin/cmd/main.go b/node/plugin/cmd/main.go index 51687a82f..aeeb2a46b 100644 --- a/node/plugin/cmd/main.go +++ b/node/plugin/cmd/main.go @@ -116,11 +116,25 @@ func pluginOps(ctx *cli.Context) { return } - pubIPProvider := pubip.ProviderOrDefault(config.PubIPProvider) + s := strings.Split(config.Socket, ":") + if len(s) != 2 { + log.Printf("Error: invalid socket address format: %s", config.Socket) + return + } + hostname := s[0] + dispersalPort := s[1] + + s = strings.Split(config.Socket, ";") + if len(s) != 2 { + log.Printf("Error: invalid socket address format, missing retrieval port: %s", config.Socket) + return + } + retrievalPort := s[1] - socket := string(core.MakeOperatorSocket(config.Hostname, config.DispersalPort, config.RetrievalPort)) + socket := string(core.MakeOperatorSocket(hostname, dispersalPort, retrievalPort)) if isLocalhost(socket) { - socket, err = node.SocketAddress(context.Background(), pubIPProvider, config.DispersalPort, config.RetrievalPort) + pubIPProvider := pubip.ProviderOrDefault(config.PubIPProvider) + socket, err = node.SocketAddress(context.Background(), pubIPProvider, dispersalPort, retrievalPort) if err != nil { log.Printf("Error: failed to create EigenDA transactor: %v", err) return diff --git a/node/plugin/config.go b/node/plugin/config.go index 3f9721c8b..1800ff4e6 100644 --- a/node/plugin/config.go +++ b/node/plugin/config.go @@ -14,24 +14,6 @@ import ( var ( /* Required Flags */ - HostnameFlag = cli.StringFlag{ - Name: "hostname", - Usage: "Hostname at which node is available", - Required: true, - EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "HOSTNAME"), - } - DispersalPortFlag = cli.StringFlag{ - Name: "dispersal-port", - Usage: "Port at which node registers to listen for dispersal calls", - Required: true, - EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "DISPERSAL_PORT"), - } - RetrievalPortFlag = cli.StringFlag{ - Name: "retrieval-port", - Usage: "Port at which node registers to listen for retrieval calls", - Required: true, - EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "RETRIEVAL_PORT"), - } PubIPProviderFlag = cli.StringFlag{ Name: "public-ip-provider", Usage: "The ip provider service used to obtain a operator's public IP [seeip (default), ipify)", @@ -124,9 +106,6 @@ var ( ) type Config struct { - Hostname string - RetrievalPort string - DispersalPort string PubIPProvider string Operation string EcdsaKeyFile string @@ -159,9 +138,6 @@ func NewConfig(ctx *cli.Context) (*Config, error) { } return &Config{ - Hostname: ctx.GlobalString(HostnameFlag.Name), - DispersalPort: ctx.GlobalString(DispersalPortFlag.Name), - RetrievalPort: ctx.GlobalString(RetrievalPortFlag.Name), PubIPProvider: ctx.GlobalString(PubIPProviderFlag.Name), Operation: op, EcdsaKeyPassword: ctx.GlobalString(EcdsaKeyPasswordFlag.Name), From c5e18229c53216a0aa6f34807233dcc2fa2e4d14 Mon Sep 17 00:00:00 2001 From: Wellington Barbosa Date: Tue, 19 Dec 2023 12:13:26 -0700 Subject: [PATCH 3/7] fix error message --- node/plugin/cmd/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/plugin/cmd/main.go b/node/plugin/cmd/main.go index aeeb2a46b..db648c406 100644 --- a/node/plugin/cmd/main.go +++ b/node/plugin/cmd/main.go @@ -136,7 +136,7 @@ func pluginOps(ctx *cli.Context) { pubIPProvider := pubip.ProviderOrDefault(config.PubIPProvider) socket, err = node.SocketAddress(context.Background(), pubIPProvider, dispersalPort, retrievalPort) if err != nil { - log.Printf("Error: failed to create EigenDA transactor: %v", err) + log.Printf("Error: failed to get socket address from ip provider: %v", err) return } } From 29ecdb80de2b8ee63ad0cccf532b442103862883 Mon Sep 17 00:00:00 2001 From: Wellington Barbosa Date: Wed, 20 Dec 2023 09:53:51 -0700 Subject: [PATCH 4/7] Add improvements from code review --- core/state.go | 21 +++++++++++++++++++++ node/plugin/cmd/main.go | 16 +++------------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/core/state.go b/core/state.go index de57f0a1c..1bc536a4f 100644 --- a/core/state.go +++ b/core/state.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math/big" + "strings" ) // Operators @@ -18,6 +19,26 @@ func MakeOperatorSocket(nodeIP, dispersalPort, retrievalPort string) OperatorSoc return OperatorSocket(fmt.Sprintf("%s:%s;%s", nodeIP, dispersalPort, retrievalPort)) } +func ParseOperatorSocket(operatorSocket string) (socket string, dispersalPort string, retrievalPort string, err error) { + s := strings.Split(operatorSocket, ":") + if len(s) != 2 { + err = fmt.Errorf("invalid socket address format: %s", operatorSocket) + return + } + hostname := s[0] + dispersalPort = s[1] + + s = strings.Split(operatorSocket, ";") + if len(s) != 2 { + err = fmt.Errorf("invalid socket address format, missing retrieval port: %s", operatorSocket) + return + } + retrievalPort = s[1] + + socket = string(MakeOperatorSocket(hostname, dispersalPort, retrievalPort)) + return +} + type StakeAmount *big.Int // OperatorInfo contains information about an operator which is stored on the blockchain state, diff --git a/node/plugin/cmd/main.go b/node/plugin/cmd/main.go index db648c406..f912e7a31 100644 --- a/node/plugin/cmd/main.go +++ b/node/plugin/cmd/main.go @@ -116,22 +116,12 @@ func pluginOps(ctx *cli.Context) { return } - s := strings.Split(config.Socket, ":") - if len(s) != 2 { - log.Printf("Error: invalid socket address format: %s", config.Socket) - return - } - hostname := s[0] - dispersalPort := s[1] - - s = strings.Split(config.Socket, ";") - if len(s) != 2 { - log.Printf("Error: invalid socket address format, missing retrieval port: %s", config.Socket) + socket, dispersalPort, retrievalPort, err := core.ParseOperatorSocket(config.Socket) + if err != nil { + log.Printf("Error: failed to parse operator socket: %v", err) return } - retrievalPort := s[1] - socket := string(core.MakeOperatorSocket(hostname, dispersalPort, retrievalPort)) if isLocalhost(socket) { pubIPProvider := pubip.ProviderOrDefault(config.PubIPProvider) socket, err = node.SocketAddress(context.Background(), pubIPProvider, dispersalPort, retrievalPort) From b6da79832dc9cc66aed37f234beb681d295f2ec6 Mon Sep 17 00:00:00 2001 From: Wellington Barbosa Date: Wed, 20 Dec 2023 14:43:10 -0700 Subject: [PATCH 5/7] Add improvements from code review --- core/state.go | 5 ++--- node/plugin/cmd/main.go | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/state.go b/core/state.go index 1bc536a4f..3f19893b5 100644 --- a/core/state.go +++ b/core/state.go @@ -19,13 +19,13 @@ func MakeOperatorSocket(nodeIP, dispersalPort, retrievalPort string) OperatorSoc return OperatorSocket(fmt.Sprintf("%s:%s;%s", nodeIP, dispersalPort, retrievalPort)) } -func ParseOperatorSocket(operatorSocket string) (socket string, dispersalPort string, retrievalPort string, err error) { +func ParseOperatorSocket(operatorSocket string) (host string, dispersalPort string, retrievalPort string, err error) { s := strings.Split(operatorSocket, ":") if len(s) != 2 { err = fmt.Errorf("invalid socket address format: %s", operatorSocket) return } - hostname := s[0] + host = s[0] dispersalPort = s[1] s = strings.Split(operatorSocket, ";") @@ -35,7 +35,6 @@ func ParseOperatorSocket(operatorSocket string) (socket string, dispersalPort st } retrievalPort = s[1] - socket = string(MakeOperatorSocket(hostname, dispersalPort, retrievalPort)) return } diff --git a/node/plugin/cmd/main.go b/node/plugin/cmd/main.go index f912e7a31..35cb5f276 100644 --- a/node/plugin/cmd/main.go +++ b/node/plugin/cmd/main.go @@ -116,12 +116,13 @@ func pluginOps(ctx *cli.Context) { return } - socket, dispersalPort, retrievalPort, err := core.ParseOperatorSocket(config.Socket) + host, dispersalPort, retrievalPort, err := core.ParseOperatorSocket(config.Socket) if err != nil { log.Printf("Error: failed to parse operator socket: %v", err) return } + socket := string(core.MakeOperatorSocket(host, dispersalPort, retrievalPort)) if isLocalhost(socket) { pubIPProvider := pubip.ProviderOrDefault(config.PubIPProvider) socket, err = node.SocketAddress(context.Background(), pubIPProvider, dispersalPort, retrievalPort) From 6dcb4d53ef80c69a67620a05dd22aa6b004475fc Mon Sep 17 00:00:00 2001 From: Wellington Barbosa Date: Wed, 20 Dec 2023 15:16:46 -0700 Subject: [PATCH 6/7] Fix issue parsing operator socket --- core/state.go | 14 +++++++------- core/test/core_test.go | 9 +++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/core/state.go b/core/state.go index 3f19893b5..521153dae 100644 --- a/core/state.go +++ b/core/state.go @@ -20,20 +20,20 @@ func MakeOperatorSocket(nodeIP, dispersalPort, retrievalPort string) OperatorSoc } func ParseOperatorSocket(operatorSocket string) (host string, dispersalPort string, retrievalPort string, err error) { - s := strings.Split(operatorSocket, ":") + s := strings.Split(operatorSocket, ";") if len(s) != 2 { - err = fmt.Errorf("invalid socket address format: %s", operatorSocket) + err = fmt.Errorf("invalid socket address format, missing retrieval port: %s", operatorSocket) return } - host = s[0] - dispersalPort = s[1] + retrievalPort = s[1] - s = strings.Split(operatorSocket, ";") + s = strings.Split(s[0], ":") if len(s) != 2 { - err = fmt.Errorf("invalid socket address format, missing retrieval port: %s", operatorSocket) + err = fmt.Errorf("invalid socket address format: %s", operatorSocket) return } - retrievalPort = s[1] + host = s[0] + dispersalPort = s[1] return } diff --git a/core/test/core_test.go b/core/test/core_test.go index be741470e..49f13197f 100644 --- a/core/test/core_test.go +++ b/core/test/core_test.go @@ -256,3 +256,12 @@ func TestCoreLibrary(t *testing.T) { } } + +func TestParseOperatorSocket(t *testing.T) { + operatorSocket := "localhost:1234;5678" + host, dispersalPort, retrievalPort, err := core.ParseOperatorSocket(operatorSocket) + assert.NoError(t, err) + assert.Equal(t, "localhost", host) + assert.Equal(t, "1234", dispersalPort) + assert.Equal(t, "5678", retrievalPort) +} From dfade7f41a95ba2cf237a08259745aa5ab8ef085 Mon Sep 17 00:00:00 2001 From: Wellington Barbosa Date: Wed, 20 Dec 2023 16:48:51 -0700 Subject: [PATCH 7/7] Add couple improvments --- core/state.go | 8 ++++---- core/test/core_test.go | 8 ++++++++ node/plugin/cmd/main.go | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/state.go b/core/state.go index 521153dae..6df4e0c6f 100644 --- a/core/state.go +++ b/core/state.go @@ -19,17 +19,17 @@ func MakeOperatorSocket(nodeIP, dispersalPort, retrievalPort string) OperatorSoc return OperatorSocket(fmt.Sprintf("%s:%s;%s", nodeIP, dispersalPort, retrievalPort)) } -func ParseOperatorSocket(operatorSocket string) (host string, dispersalPort string, retrievalPort string, err error) { - s := strings.Split(operatorSocket, ";") +func ParseOperatorSocket(socket string) (host string, dispersalPort string, retrievalPort string, err error) { + s := strings.Split(socket, ";") if len(s) != 2 { - err = fmt.Errorf("invalid socket address format, missing retrieval port: %s", operatorSocket) + err = fmt.Errorf("invalid socket address format, missing retrieval port: %s", socket) return } retrievalPort = s[1] s = strings.Split(s[0], ":") if len(s) != 2 { - err = fmt.Errorf("invalid socket address format: %s", operatorSocket) + err = fmt.Errorf("invalid socket address format: %s", socket) return } host = s[0] diff --git a/core/test/core_test.go b/core/test/core_test.go index 49f13197f..89214c239 100644 --- a/core/test/core_test.go +++ b/core/test/core_test.go @@ -264,4 +264,12 @@ func TestParseOperatorSocket(t *testing.T) { assert.Equal(t, "localhost", host) assert.Equal(t, "1234", dispersalPort) assert.Equal(t, "5678", retrievalPort) + + _, _, _, err = core.ParseOperatorSocket("localhost:12345678") + assert.NotNil(t, err) + assert.Equal(t, "invalid socket address format, missing retrieval port: localhost:12345678", err.Error()) + + _, _, _, err = core.ParseOperatorSocket("localhost1234;5678") + assert.NotNil(t, err) + assert.Equal(t, "invalid socket address format: localhost1234;5678", err.Error()) } diff --git a/node/plugin/cmd/main.go b/node/plugin/cmd/main.go index 03d04daa6..387522d5b 100644 --- a/node/plugin/cmd/main.go +++ b/node/plugin/cmd/main.go @@ -99,13 +99,13 @@ func pluginOps(ctx *cli.Context) { return } - host, dispersalPort, retrievalPort, err := core.ParseOperatorSocket(config.Socket) + _, dispersalPort, retrievalPort, err := core.ParseOperatorSocket(config.Socket) if err != nil { log.Printf("Error: failed to parse operator socket: %v", err) return } - socket := string(core.MakeOperatorSocket(host, dispersalPort, retrievalPort)) + socket := config.Socket if isLocalhost(socket) { pubIPProvider := pubip.ProviderOrDefault(config.PubIPProvider) socket, err = node.SocketAddress(context.Background(), pubIPProvider, dispersalPort, retrievalPort)