Skip to content

Commit

Permalink
Support update-socket operation from node plugin (Layr-Labs#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim authored Apr 10, 2024
1 parent b52bdcb commit cd0155f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 4 additions & 4 deletions node/plugin/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,31 @@ func pluginOps(ctx *cli.Context) {
RegisterNodeAtStart: false,
}
churnerClient := node.NewChurnerClient(config.ChurnerUrl, true, operator.Timeout, logger)
if config.Operation == "opt-in" {
if config.Operation == plugin.OperationOptIn {
log.Printf("Info: Operator with Operator Address: %x is opting in to EigenDA", sk.Address)
err = node.RegisterOperator(context.Background(), operator, tx, churnerClient, logger.With("component", "NodeOperator"))
if err != nil {
log.Printf("Error: failed to opt-in EigenDA Node Network for operator ID: %x, operator address: %x, error: %v", operatorID, sk.Address, err)
return
}
log.Printf("Info: successfully opt-in the EigenDA, for operator ID: %x, operator address: %x, socket: %s, and quorums: %v", operatorID, sk.Address, config.Socket, config.QuorumIDList)
} else if config.Operation == "opt-out" {
} else if config.Operation == plugin.OperationOptOut {
log.Printf("Info: Operator with Operator Address: %x and OperatorID: %x is opting out of EigenDA", sk.Address, operatorID)
err = node.DeregisterOperator(context.Background(), operator, keyPair, tx)
if err != nil {
log.Printf("Error: failed to opt-out EigenDA Node Network for operator ID: %x, operator address: %x, quorums: %v, error: %v", operatorID, sk.Address, config.QuorumIDList, err)
return
}
log.Printf("Info: successfully opt-out the EigenDA, for operator ID: %x, operator address: %x", operatorID, sk.Address)
} else if config.Operation == "update-socket" {
} else if config.Operation == plugin.OperationUpdateSocket {
log.Printf("Info: Operator with Operator Address: %x is updating its socket: %s", sk.Address, config.Socket)
err = node.UpdateOperatorSocket(context.Background(), tx, config.Socket)
if err != nil {
log.Printf("Error: failed to update socket for operator ID: %x, operator address: %x, socket: %s, error: %v", operatorID, sk.Address, config.Socket, err)
return
}
log.Printf("Info: successfully updated socket, for operator ID: %x, operator address: %x, socket: %s", operatorID, sk.Address, config.Socket)
} else if config.Operation == "list-quorums" {
} else if config.Operation == plugin.OperationListQuorums {
quorumIds, err := tx.GetRegisteredQuorumIdsForOperator(context.Background(), operatorID)
if err != nil {
log.Printf("Error: failed to get quorum(s) for operatorID: %x, operator address: %x, error: %v", operatorID, sk.Address, err)
Expand Down
14 changes: 12 additions & 2 deletions node/plugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import (
"github.com/urfave/cli"
)

const (
OperationOptIn = "opt-in"
OperationOptOut = "opt-out"
OperationUpdateSocket = "update-socket"
OperationListQuorums = "list-quorums"
)

var (
/* Required Flags */

Expand All @@ -25,7 +32,7 @@ var (
OperationFlag = cli.StringFlag{
Name: "operation",
Required: true,
Usage: "Supported operations: opt-in, opt-out, list-quorums",
Usage: "Supported operations: opt-in, opt-out, update-socket, list-quorums",
EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "OPERATION"),
}

Expand Down Expand Up @@ -136,7 +143,10 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
}

op := ctx.GlobalString(OperationFlag.Name)
if op != "opt-in" && op != "opt-out" && op != "list-quorums" {
if len(op) == 0 {
return nil, errors.New("operation type not provided")
}
if op != OperationOptIn && op != OperationOptOut && op != OperationUpdateSocket && op != OperationListQuorums {
return nil, errors.New("unsupported operation type")
}

Expand Down

0 comments on commit cd0155f

Please sign in to comment.