Skip to content

Commit

Permalink
add socket, support deregister to avs
Browse files Browse the repository at this point in the history
  • Loading branch information
fyInALT committed Apr 1, 2024
1 parent e6848eb commit 71e723b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
40 changes: 40 additions & 0 deletions cli/actions/deregister_operator_with_avs.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 1 addition & 4 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions core/config/avs_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
5 changes: 5 additions & 0 deletions operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 31 additions & 1 deletion operator/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 71e723b

Please sign in to comment.