From 71e723b9cbd0bcf80faa869f090a5a9aba17dc7b Mon Sep 17 00:00:00 2001 From: fyInALT Date: Mon, 1 Apr 2024 21:16:35 +0800 Subject: [PATCH] add socket, support deregister to avs --- cli/actions/deregister_operator_with_avs.go | 40 +++++++++++++++++++++ cli/main.go | 5 +-- core/config/avs_config.go | 1 + operator/operator.go | 5 +++ operator/registration.go | 32 ++++++++++++++++- 5 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 cli/actions/deregister_operator_with_avs.go diff --git a/cli/actions/deregister_operator_with_avs.go b/cli/actions/deregister_operator_with_avs.go new file mode 100644 index 0000000..36e7e40 --- /dev/null +++ b/cli/actions/deregister_operator_with_avs.go @@ -0,0 +1,40 @@ +package actions + +import ( + "encoding/json" + "log" + + sdkutils "github.com/Layr-Labs/eigensdk-go/utils" + "github.com/alt-research/avs/core/config" + "github.com/alt-research/avs/operator" + "github.com/urfave/cli" +) + +func DeregisterOperatorWithAvs(ctx *cli.Context) error { + configPath := ctx.GlobalString(config.ConfigFileFlag.Name) + nodeConfig := config.NodeConfig{} + + if configPath != "" { + err := sdkutils.ReadYamlConfig(configPath, &nodeConfig) + if err != nil { + return err + } + configJson, err := json.MarshalIndent(nodeConfig, "", " ") + if err != nil { + log.Fatalf(err.Error()) + } + log.Println("Config:", string(configJson)) + } + + operator, err := operator.NewOperatorFromConfig(nodeConfig) + if err != nil { + return err + } + + err = operator.DeregisterOperatorWithAvs() + if err != nil { + return err + } + + return nil +} diff --git a/cli/main.go b/cli/main.go index f09ab78..684603e 100644 --- a/cli/main.go +++ b/cli/main.go @@ -47,10 +47,7 @@ func main() { { Name: "deregister-operator-with-avs", Aliases: []string{"d"}, - Action: func(ctx *cli.Context) error { - log.Fatal("Command not implemented.") - return nil - }, + Action: actions.DeregisterOperatorWithAvs, }, { Name: "print-operator-status", diff --git a/core/config/avs_config.go b/core/config/avs_config.go index 4b60b75..13ba692 100644 --- a/core/config/avs_config.go +++ b/core/config/avs_config.go @@ -16,4 +16,5 @@ type NodeConfig struct { EnableNodeApi bool `yaml:"enable_node_api"` OperatorServerIpPortAddr string `yaml:"operator_server_ip_port_addr"` MetadataURI string `yaml:"metadata_uri"` + OperatorSocket string `yaml:"operator_socket"` } diff --git a/operator/operator.go b/operator/operator.go index 8ac9366..a766080 100644 --- a/operator/operator.go +++ b/operator/operator.go @@ -152,6 +152,11 @@ func withEnvConfig(c config.NodeConfig) config.NodeConfig { c.MetadataURI = metadataURI } + operatorSocket, ok := os.LookupEnv("OPERATOR_SOCKET") + if ok && operatorSocket != "" { + c.OperatorSocket = operatorSocket + } + configJson, err := json.MarshalIndent(c, "", " ") if err != nil { panic(err) diff --git a/operator/registration.go b/operator/registration.go index 59d8c35..81e736c 100644 --- a/operator/registration.go +++ b/operator/registration.go @@ -52,7 +52,7 @@ func (o *Operator) RegisterOperatorWithAvs( ) error { // hardcode these things for now quorumNumbers := []byte{0} - socket := "Not Needed" + socket := o.config.OperatorSocket operatorToAvsRegistrationSigSalt := [32]byte{123} curBlockNum, err := o.ethClient.BlockNumber(context.Background()) if err != nil { @@ -93,6 +93,36 @@ func (o *Operator) RegisterOperatorWithAvs( return nil } +// Deregistration specific functions +func (o *Operator) DeregisterOperatorWithAvs() error { + // hardcode these things for now + quorumNumbers := []byte{0} + operatorAddr := o.operatorAddr + o.logger.Info( + "DeregisterOperatorFromAvs", + "quorumNumbers", quorumNumbers[0], + "operatorAddr", operatorAddr, + ) + + quorumNumbersToSDK := make([]sdktypes.QuorumNum, len(quorumNumbers)) + for i, _ := range quorumNumbers { + quorumNumbersToSDK[i] = sdktypes.QuorumNum(uint8(quorumNumbers[i])) + } + + _, err := o.avsWriter.DeregisterOperator( + context.Background(), + quorumNumbersToSDK, + regcoord.BN254G1Point{}, + ) + if err != nil { + o.logger.Error("Unable to deregister operator with avs registry coordinator", err) + return err + } + o.logger.Infof("Deregister operator with avs registry coordinator.") + + return nil +} + // PRINTING STATUS OF OPERATOR: 1 // operator address: 0xa0ee7a142d267c1f36714e4a8f75612f20a79720 // dummy token balance: 0