From 426fe979904ad4f7f9671c177788f2bd0b75c42e Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 8 Nov 2022 15:34:02 +0300 Subject: [PATCH] [#2026] neofs-adm: Make contract update idempotent Signed-off-by: Evgenii Stratonikov --- .../modules/morph/initialize_deploy.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go index be5c83d0c..605d92deb 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go @@ -27,6 +27,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/vmstate" + "github.com/nspcc-dev/neofs-contract/common" "github.com/nspcc-dev/neofs-contract/nns" "github.com/nspcc-dev/neofs-node/pkg/innerring" morphClient "github.com/nspcc-dev/neofs-node/pkg/morph/client" @@ -106,7 +107,11 @@ func (c *initializeContext) deployNNS(method string) error { nnsCs, err := c.nnsContractState() if err == nil { if nnsCs.NEF.Checksum == cs.NEF.Checksum { - c.Command.Println("NNS contract is already deployed.") + if method == deployMethodName { + c.Command.Println("NNS contract is already deployed.") + } else { + c.Command.Println("NNS contract is already updated.") + } return nil } h = nnsCs.Hash @@ -206,7 +211,10 @@ func (c *initializeContext) updateContracts() error { } if err := c.sendCommitteeTx(w.Bytes(), false); err != nil { - return err + if !strings.Contains(err.Error(), common.ErrAlreadyUpdated) { + return err + } + c.Command.Println("Alphabet contracts are already updated.") } w.Reset() @@ -243,7 +251,11 @@ func (c *initializeContext) updateContracts() error { params := getContractDeployParameters(cs, c.getContractDeployData(ctrName, keysParam)) res, err := c.CommitteeAct.MakeCall(invokeHash, method, params...) if err != nil { - return fmt.Errorf("deploy contract: %w", err) + if method != updateMethodName || !strings.Contains(err.Error(), common.ErrAlreadyUpdated) { + return fmt.Errorf("deploy contract: %w", err) + } + c.Command.Printf("%s contract is already updated.\n", ctrName) + continue } w.WriteBytes(res.Script)