From 8ddd0aab55ce33a6effa602fba712e925aefd00c Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 7 Oct 2021 15:25:34 +0300 Subject: [PATCH] [#888] neofs-adm: set contract hashes on read Non-alphabet contract are always deployed from committee so it makes sense to calculate hashes in one place. Signed-off-by: Evgenii Stratonikov --- .../internal/modules/morph/initialize_deploy.go | 16 +++++++++------- .../internal/modules/morph/initialize_nns.go | 12 +++++------- .../modules/morph/initialize_transfer.go | 8 +++----- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go index 45e74a9c..9a7080c3 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go @@ -74,8 +74,7 @@ func (c *initializeContext) deployNNS(method string) error { return err } - h := state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name) - if _, err := c.Client.GetContractStateByHash(h); err == nil && method != "update" { + if _, err := c.Client.GetContractStateByHash(cs.Hash); err == nil && method != "update" { return nil } @@ -123,13 +122,11 @@ func (c *initializeContext) deployNNS(method string) error { func (c *initializeContext) deployContracts(method string) error { mgmtHash := c.nativeHash(nativenames.Management) - sender := c.CommitteeAcc.Contract.ScriptHash() for _, ctrName := range contractList { - cs, err := c.readContract(ctrName) + _, err := c.readContract(ctrName) if err != nil { return err } - cs.Hash = state.CreateContractHash(sender, cs.NEF.Checksum, cs.Manifest.Name) } alphaCs, err := c.readContract(alphabetContract) @@ -264,13 +261,18 @@ func (c *initializeContext) readContract(ctrName string) (*contractState, error) return nil, fmt.Errorf("can't parse manifest file: %w", err) } - c.Contracts[ctrName] = &contractState{ + cs := &contractState{ NEF: &nf, RawNEF: rawNef, Manifest: m, RawManifest: rawManif, } - return c.Contracts[ctrName], nil + if ctrName != alphabetContract { + cs.Hash = state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), + cs.NEF.Checksum, cs.Manifest.Name) + } + c.Contracts[ctrName] = cs + return cs, nil } func getContractDeployParameters(rawNef, rawManif []byte, deployData []smartcontract.Parameter) []smartcontract.Parameter { diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go index 920e1a9d..e1de223e 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go @@ -24,18 +24,17 @@ const defaultNameServiceSysfee = 4000_0000 const defaultRegisterSysfee = 10_0000_0000 + defaultNameServiceDomainPrice func (c *initializeContext) setNNS() error { - cs, err := c.readContract(nnsContract) + nnsCs, err := c.readContract(nnsContract) if err != nil { return err } - h := state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name) - ok, err := c.nnsRootRegistered(h) + ok, err := c.nnsRootRegistered(nnsCs.Hash) if err != nil { return err } else if !ok { bw := io.NewBufBinWriter() - emit.AppCall(bw.BinWriter, h, "addRoot", callflag.All, "neofs") + emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRoot", callflag.All, "neofs") if err := c.sendCommitteeTx(bw.Bytes(), -1); err != nil { return fmt.Errorf("can't add domain root to NNS: %w", err) } @@ -52,7 +51,7 @@ func (c *initializeContext) setNNS() error { alphaCs.Hash = state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name) domain := getAlphabetNNSDomain(i) - if err := c.nnsRegisterDomain(h, alphaCs.Hash, domain); err != nil { + if err := c.nnsRegisterDomain(nnsCs.Hash, alphaCs.Hash, domain); err != nil { return err } c.Command.Printf("NNS: Set %s -> %s\n", domain, alphaCs.Hash.StringLE()) @@ -63,10 +62,9 @@ func (c *initializeContext) setNNS() error { if err != nil { return err } - cs.Hash = state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name) domain := ctrName + ".neofs" - if err := c.nnsRegisterDomain(h, cs.Hash, domain); err != nil { + if err := c.nnsRegisterDomain(nnsCs.Hash, cs.Hash, domain); err != nil { return err } c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE()) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go b/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go index b7ef6fc9..27e07d5c 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go @@ -5,7 +5,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" - "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/rpc/client" scContext "github.com/nspcc-dev/neo-go/pkg/smartcontract/context" @@ -133,18 +132,17 @@ func (c *initializeContext) multiSign(tx *transaction.Transaction, accType strin func (c *initializeContext) transferGASToProxy() error { gasHash := c.nativeHash(nativenames.Gas) - cs, err := c.readContract(proxyContract) + proxyCs, err := c.readContract(proxyContract) if err != nil { return err } - h := state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name) - bal, err := c.Client.NEP17BalanceOf(gasHash, h) + bal, err := c.Client.NEP17BalanceOf(gasHash, proxyCs.Hash) if err != nil || bal > 0 { return err } - tx, err := c.Client.CreateNEP17TransferTx(c.CommitteeAcc, h, gasHash, initialProxyGASAmount, 0, nil, nil) + tx, err := c.Client.CreateNEP17TransferTx(c.CommitteeAcc, proxyCs.Hash, gasHash, initialProxyGASAmount, 0, nil, nil) if err != nil { return err }