Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto correct the IP if the operator set their IP to localhost when opt-in #136

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions core/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"strings"
)

// Operators
Expand All @@ -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) {
wmb-software-consulting marked this conversation as resolved.
Show resolved Hide resolved
s := strings.Split(operatorSocket, ":")
if len(s) != 2 {
err = fmt.Errorf("invalid socket address format: %s", operatorSocket)
return
}
hostname := s[0]
dispersalPort = s[1]
wmb-software-consulting marked this conversation as resolved.
Show resolved Hide resolved

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
wmb-software-consulting marked this conversation as resolved.
Show resolved Hide resolved
}

type StakeAmount *big.Int

// OperatorInfo contains information about an operator which is stored on the blockchain state,
Expand Down
11 changes: 1 addition & 10 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
23 changes: 22 additions & 1 deletion node/plugin/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -114,8 +116,23 @@ func pluginOps(ctx *cli.Context) {
return
}

socket, dispersalPort, retrievalPort, err := core.ParseOperatorSocket(config.Socket)
if err != nil {
log.Printf("Error: failed to parse operator socket: %v", err)
return
}

if isLocalhost(socket) {
pubIPProvider := pubip.ProviderOrDefault(config.PubIPProvider)
socket, err = node.SocketAddress(context.Background(), pubIPProvider, dispersalPort, retrievalPort)
if err != nil {
log.Printf("Error: failed to get socket address from ip provider: %v", err)
return
}
}

operator := &node.Operator{
Socket: config.Socket,
Socket: socket,
Timeout: 10 * time.Second,
KeyPair: keyPair,
OperatorId: keyPair.GetPubKeyG1().GetOperatorID(),
Expand All @@ -141,3 +158,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")
}
9 changes: 9 additions & 0 deletions node/plugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import (
var (
/* Required Flags */

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be required? @shrimalmadhur

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh umm - I don't think we should put it as required - can we make this as optional and by default point to seeip?

We can re-use the .env one in the setup

EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "PUBLIC_IP_PROVIDER"),
}

// The operation to run.
OperationFlag = cli.StringFlag{
Name: "operation",
Expand Down Expand Up @@ -99,6 +106,7 @@ var (
)

type Config struct {
PubIPProvider string
Operation string
EcdsaKeyFile string
BlsKeyFile string
Expand Down Expand Up @@ -130,6 +138,7 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
}

return &Config{
PubIPProvider: ctx.GlobalString(PubIPProviderFlag.Name),
Operation: op,
EcdsaKeyPassword: ctx.GlobalString(EcdsaKeyPasswordFlag.Name),
BlsKeyPassword: ctx.GlobalString(BlsKeyPasswordFlag.Name),
Expand Down
12 changes: 12 additions & 0 deletions node/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Loading