From 9d4be867793f658948b0c559610f044b3469f957 Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Thu, 18 Jan 2024 13:38:23 -0800 Subject: [PATCH] add utility to update socket (#188) --- core/tx.go | 2 +- node/operator.go | 7 ++++++- node/plugin/cmd/main.go | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/tx.go b/core/tx.go index dfd494bee..0c6861b19 100644 --- a/core/tx.go +++ b/core/tx.go @@ -58,7 +58,7 @@ type Transactor interface { // are also returned. GetOperatorStakes(ctx context.Context, operatorID OperatorID, blockNumber uint32) (OperatorStakes, []QuorumID, error) - // GetOperatorStakes returns the stakes of all operators within the supplied quorums. The returned stakes are for the block number supplied. + // GetOperatorStakesForQuorums returns the stakes of all operators within the supplied quorums. The returned stakes are for the block number supplied. // The indices of the operators within each quorum are also returned. GetOperatorStakesForQuorums(ctx context.Context, quorums []QuorumID, blockNumber uint32) (OperatorStakes, error) diff --git a/node/operator.go b/node/operator.go index 456dabdbe..8566cd8b8 100644 --- a/node/operator.go +++ b/node/operator.go @@ -25,7 +25,7 @@ type Operator struct { QuorumIDs []core.QuorumID } -// Register operator registers the operator with the given public key for the given quorum IDs. +// RegisterOperator operator registers the operator with the given public key for the given quorum IDs. func RegisterOperator(ctx context.Context, operator *Operator, transactor core.Transactor, churnerUrl string, useSecureGrpc bool, logger common.Logger) error { registeredQuorumIds, err := transactor.GetRegisteredQuorumIdsForOperator(ctx, operator.OperatorId) if err != nil { @@ -111,6 +111,11 @@ func UpdateOperatorQuorums( return RegisterOperator(ctx, operator, transactor, churnerUrl, useSecureGrpc, logger) } +// UpdateOperatorSocket updates the socket for the given operator +func UpdateOperatorSocket(ctx context.Context, transactor core.Transactor, socket string) error { + return transactor.UpdateOperatorSocket(ctx, socket) +} + func requestChurnApproval(ctx context.Context, operator *Operator, churnerUrl string, useSecureGrpc bool, logger common.Logger) (*grpcchurner.ChurnReply, error) { logger.Info("churner url", "url", churnerUrl) diff --git a/node/plugin/cmd/main.go b/node/plugin/cmd/main.go index e3fbe59ed..504beacb9 100644 --- a/node/plugin/cmd/main.go +++ b/node/plugin/cmd/main.go @@ -146,6 +146,14 @@ func pluginOps(ctx *cli.Context) { return } log.Printf("Info: successfully updated quorums, for operator ID: %x, operator address: %x, socket: %s, and quorums: %v", operatorID, sk.Address, config.Socket, config.QuorumIDList) + } else if config.Operation == "update-socket" { + 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 { log.Fatalf("Fatal: unsupported operation: %s", config.Operation) }