From ba00fc4971170b9d610674a3bb100a688e13e0a5 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 1 Feb 2024 10:06:05 +0300 Subject: [PATCH] [#932] adm: Move contract name constants to `util` package Signed-off-by: Anton Nikiforov --- .../internal/modules/morph/ape_util.go | 2 +- .../internal/modules/morph/balance.go | 4 +- .../internal/modules/morph/config.go | 4 +- .../internal/modules/morph/container.go | 4 +- .../internal/modules/morph/dump_hashes.go | 2 +- .../internal/modules/morph/epoch.go | 2 +- .../internal/modules/morph/frostfsid.go | 2 +- .../modules/morph/initialize_deploy.go | 89 ++++++++----------- .../internal/modules/morph/initialize_nns.go | 4 +- .../modules/morph/initialize_register.go | 2 +- .../modules/morph/initialize_transfer.go | 2 +- .../modules/morph/netmap_candidates.go | 2 +- .../internal/modules/morph/proxy.go | 2 +- .../internal/modules/morph/remove_node.go | 2 +- .../internal/modules/morph/util/const.go | 11 +++ 15 files changed, 66 insertions(+), 68 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/morph/ape_util.go b/cmd/frostfs-adm/internal/modules/morph/ape_util.go index 59e85dda1..f9dcdffe8 100644 --- a/cmd/frostfs-adm/internal/modules/morph/ape_util.go +++ b/cmd/frostfs-adm/internal/modules/morph/ape_util.go @@ -97,7 +97,7 @@ func newPolicyContractInterface(cmd *cobra.Command) (*morph.ContractStorage, *ac nnsCs, err := r.GetContractByID(1) commonCmd.ExitOnErr(cmd, "can't get NNS contract state: %w", err) - ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(policyContract)) + ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(morphUtil.PolicyContract)) commonCmd.ExitOnErr(cmd, "unable to resolve policy contract hash: %w", err) return morph.NewContractStorage(ac, ch), ac diff --git a/cmd/frostfs-adm/internal/modules/morph/balance.go b/cmd/frostfs-adm/internal/modules/morph/balance.go index 8ee7aeeed..451d57954 100644 --- a/cmd/frostfs-adm/internal/modules/morph/balance.go +++ b/cmd/frostfs-adm/internal/modules/morph/balance.go @@ -64,7 +64,7 @@ func dumpBalances(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - nmHash, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(netmapContract)) + nmHash, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(morphUtil.NetmapContract)) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } @@ -137,7 +137,7 @@ func printStorageNodeBalances(cmd *cobra.Command, inv *invoker.Invoker, nmHash u } func printProxyContractBalance(cmd *cobra.Command, inv *invoker.Invoker, nnsHash util.Uint160) error { - h, err := morphUtil.NNSResolveHash(inv, nnsHash, morphUtil.DomainOf(proxyContract)) + h, err := morphUtil.NNSResolveHash(inv, nnsHash, morphUtil.DomainOf(morphUtil.ProxyContract)) if err != nil { return fmt.Errorf("can't get hash of the proxy contract: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/config.go b/cmd/frostfs-adm/internal/modules/morph/config.go index 3892d31b1..0d042d94a 100644 --- a/cmd/frostfs-adm/internal/modules/morph/config.go +++ b/cmd/frostfs-adm/internal/modules/morph/config.go @@ -38,7 +38,7 @@ func dumpNetworkConfig(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - nmHash, err := util.NNSResolveHash(inv, cs.Hash, util.DomainOf(netmapContract)) + nmHash, err := util.NNSResolveHash(inv, cs.Hash, util.DomainOf(util.NetmapContract)) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } @@ -96,7 +96,7 @@ func setConfigCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(netmapContract)) + nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(util.NetmapContract)) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/container.go b/cmd/frostfs-adm/internal/modules/morph/container.go index 5f59f7db5..5400a51c9 100644 --- a/cmd/frostfs-adm/internal/modules/morph/container.go +++ b/cmd/frostfs-adm/internal/modules/morph/container.go @@ -36,7 +36,7 @@ func getContainerContractHash(cmd *cobra.Command, inv *invoker.Invoker) (util.Ui if err != nil { return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err) } - ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(containerContract)) + ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(morphUtil.ContainerContract)) if err != nil { return util.Uint160{}, err } @@ -307,7 +307,7 @@ func fetchContainerContractHash(wCtx *initializeContext) (util.Uint160, error) { return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err) } - ch, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, morphUtil.DomainOf(containerContract)) + ch, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, morphUtil.DomainOf(morphUtil.ContainerContract)) if err != nil { return util.Uint160{}, fmt.Errorf("can't fetch container contract hash: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go b/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go index 05ef72843..ce3585c67 100644 --- a/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go +++ b/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go @@ -50,7 +50,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { return dumpCustomZoneHashes(cmd, cs.Hash, zone, c) } - infos := []contractDumpInfo{{name: nnsContract, hash: cs.Hash}} + infos := []contractDumpInfo{{name: morphUtil.NNSContract, hash: cs.Hash}} irSize := 0 for ; irSize < lastGlagoliticLetter; irSize++ { diff --git a/cmd/frostfs-adm/internal/modules/morph/epoch.go b/cmd/frostfs-adm/internal/modules/morph/epoch.go index 274568afc..7cb73e264 100644 --- a/cmd/frostfs-adm/internal/modules/morph/epoch.go +++ b/cmd/frostfs-adm/internal/modules/morph/epoch.go @@ -28,7 +28,7 @@ func forceNewEpochCmd(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - nmHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(netmapContract)) + nmHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(util2.NetmapContract)) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/frostfsid.go b/cmd/frostfs-adm/internal/modules/morph/frostfsid.go index 083fc9ed9..0ad8fe763 100644 --- a/cmd/frostfs-adm/internal/modules/morph/frostfsid.go +++ b/cmd/frostfs-adm/internal/modules/morph/frostfsid.go @@ -431,7 +431,7 @@ func newFrostfsIDClient(cmd *cobra.Command) (*frostfsidClient, error) { return nil, fmt.Errorf("can't get NNS contract info: %w", err) } - ffsidHash, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(frostfsIDContract)) + ffsidHash, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(morphUtil.FrostfsIDContract)) if err != nil { return nil, fmt.Errorf("can't get proxy contract hash: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go b/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go index 66caf8c19..e76a9f0d3 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go @@ -35,36 +35,23 @@ import ( "github.com/spf13/viper" ) -const ( - nnsContract = "nns" - frostfsContract = "frostfs" // not deployed in side-chain. - processingContract = "processing" // not deployed in side-chain. - alphabetContract = "alphabet" - balanceContract = "balance" - containerContract = "container" - frostfsIDContract = "frostfsid" - netmapContract = "netmap" - policyContract = "policy" - proxyContract = "proxy" -) - const frostfsIDAdminConfigKey = "frostfsid.admin" var ( contractList = []string{ - balanceContract, - containerContract, - frostfsIDContract, - netmapContract, - policyContract, - proxyContract, + morphUtil.BalanceContract, + morphUtil.ContainerContract, + morphUtil.FrostfsIDContract, + morphUtil.NetmapContract, + morphUtil.PolicyContract, + morphUtil.ProxyContract, } fullContractList = append([]string{ - frostfsContract, - processingContract, - nnsContract, - alphabetContract, + morphUtil.FrostfsContract, + morphUtil.ProcessingContract, + morphUtil.NNSContract, + morphUtil.AlphabetContract, }, contractList...) netmapConfigKeys = []string{ @@ -93,7 +80,7 @@ const ( ) func (c *initializeContext) deployNNS(method string) error { - cs := c.getContract(nnsContract) + cs := c.getContract(morphUtil.NNSContract) h := cs.Hash nnsCs, err := c.nnsContractState() @@ -126,7 +113,7 @@ func (c *initializeContext) deployNNS(method string) error { tx, err := c.CommitteeAct.MakeCall(invokeHash, method, params...) if err != nil { - return fmt.Errorf("failed to create deploy tx for %s: %w", nnsContract, err) + return fmt.Errorf("failed to create deploy tx for %s: %w", morphUtil.NNSContract, err) } if err := c.multiSignAndSend(tx, morphUtil.CommitteeAccountName); err != nil { @@ -137,7 +124,7 @@ func (c *initializeContext) deployNNS(method string) error { } func (c *initializeContext) updateContracts() error { - alphaCs := c.getContract(alphabetContract) + alphaCs := c.getContract(morphUtil.AlphabetContract) nnsCs, err := c.nnsContractState() if err != nil { @@ -296,7 +283,7 @@ func (c *initializeContext) deployAlphabetAccounts(nnsHash util.Uint160, w *io2. } func (c *initializeContext) deployContracts() error { - alphaCs := c.getContract(alphabetContract) + alphaCs := c.getContract(morphUtil.AlphabetContract) var keysParam []any @@ -422,7 +409,7 @@ func (c *initializeContext) readContracts(names []string) error { } for _, ctrName := range names { - if ctrName != alphabetContract { + if ctrName != morphUtil.AlphabetContract { cs := c.Contracts[ctrName] cs.Hash = state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name) @@ -524,19 +511,19 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an items := make([]any, 0, 6) switch ctrName { - case frostfsContract: + case morphUtil.FrostfsContract: items = append(items, - c.Contracts[processingContract].Hash, + c.Contracts[morphUtil.ProcessingContract].Hash, keysParam, smartcontract.Parameter{}) - case processingContract: - items = append(items, c.Contracts[frostfsContract].Hash) + case morphUtil.ProcessingContract: + items = append(items, c.Contracts[morphUtil.FrostfsContract].Hash) return items[1:], nil // no notary info - case balanceContract: + case morphUtil.BalanceContract: items = append(items, - c.Contracts[netmapContract].Hash, - c.Contracts[containerContract].Hash) - case containerContract: + c.Contracts[morphUtil.NetmapContract].Hash, + c.Contracts[morphUtil.ContainerContract].Hash) + case morphUtil.ContainerContract: // In case if NNS is updated multiple times, we can't calculate // it's actual hash based on local data, thus query chain. r := management.NewReader(c.ReadOnlyInvoker) @@ -545,12 +532,12 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an return nil, fmt.Errorf("get nns contract: %w", err) } items = append(items, - c.Contracts[netmapContract].Hash, - c.Contracts[balanceContract].Hash, - c.Contracts[frostfsIDContract].Hash, + c.Contracts[morphUtil.NetmapContract].Hash, + c.Contracts[morphUtil.BalanceContract].Hash, + c.Contracts[morphUtil.FrostfsIDContract].Hash, nnsCs.Hash, "container") - case frostfsIDContract: + case morphUtil.FrostfsIDContract: var ( h util.Uint160 found bool @@ -569,9 +556,9 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an if found { items = append(items, h) } else { - items = append(items, c.Contracts[proxyContract].Hash) + items = append(items, c.Contracts[morphUtil.ProxyContract].Hash) } - case netmapContract: + case morphUtil.NetmapContract: md := getDefaultNetmapContractConfigMap() if method == updateMethodName { if err := c.mergeNetmapConfig(md); err != nil { @@ -585,14 +572,14 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an } items = append(items, - c.Contracts[balanceContract].Hash, - c.Contracts[containerContract].Hash, + c.Contracts[morphUtil.BalanceContract].Hash, + c.Contracts[morphUtil.ContainerContract].Hash, keysParam, configParam) - case proxyContract: + case morphUtil.ProxyContract: items = nil - case policyContract: - items = append(items, c.Contracts[proxyContract].Hash) + case morphUtil.PolicyContract: + items = append(items, c.Contracts[morphUtil.ProxyContract].Hash) default: panic(fmt.Sprintf("invalid contract name: %s", ctrName)) } @@ -605,7 +592,7 @@ func (c *initializeContext) getFrostfsIDAdminFromContract() (util.Uint160, bool, if err != nil { return util.Uint160{}, false, fmt.Errorf("get nns contract: %w", err) } - fidHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(frostfsIDContract)) + fidHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(morphUtil.FrostfsIDContract)) if err != nil { return util.Uint160{}, false, fmt.Errorf("resolve frostfsid contract hash: %w", err) } @@ -634,7 +621,7 @@ func (c *initializeContext) getNetConfigFromNetmapContract() ([]stackitem.Item, if err != nil { return nil, fmt.Errorf("get nns contract: %w", err) } - nmHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(netmapContract)) + nmHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(morphUtil.NetmapContract)) if err != nil { return nil, fmt.Errorf("can't get netmap contract hash: %w", err) } @@ -667,8 +654,8 @@ func (c *initializeContext) mergeNetmapConfig(md map[string]any) error { func (c *initializeContext) getAlphabetDeployItems(i, n int) []any { items := make([]any, 5) - items[0] = c.Contracts[netmapContract].Hash - items[1] = c.Contracts[proxyContract].Hash + items[0] = c.Contracts[morphUtil.NetmapContract].Hash + items[1] = c.Contracts[morphUtil.ProxyContract].Hash items[2] = innerring.GlagoliticLetter(i).String() items[3] = int64(i) items[4] = int64(n) diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go b/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go index 8267fd04d..7b0bc8197 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go @@ -55,7 +55,7 @@ func (c *initializeContext) setNNS() error { } } - alphaCs := c.getContract(alphabetContract) + alphaCs := c.getContract(morphUtil.AlphabetContract) for i, acc := range c.Accounts { alphaCs.Hash = state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name) @@ -139,7 +139,7 @@ func (c *initializeContext) emitUpdateNNSGroupScript(bw *io.BufBinWriter, nnsHas } func getAlphabetNNSDomain(i int) string { - return alphabetContract + strconv.FormatUint(uint64(i), 10) + ".frostfs" + return morphUtil.AlphabetContract + strconv.FormatUint(uint64(i), 10) + ".frostfs" } // wrapRegisterScriptWithPrice wraps a given script with `getPrice`/`setPrice` calls for NNS. diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_register.go b/cmd/frostfs-adm/internal/modules/morph/initialize_register.go index 78c160ec2..04afd7c77 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_register.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_register.go @@ -123,7 +123,7 @@ func (c *initializeContext) transferNEOToAlphabetContracts() error { return err } - cs := c.getContract(alphabetContract) + cs := c.getContract(morphUtil.AlphabetContract) amount := initialAlphabetNEOAmount / len(c.Wallets) bw := io.NewBufBinWriter() diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_transfer.go b/cmd/frostfs-adm/internal/modules/morph/initialize_transfer.go index 90e216486..a24d3a6f6 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_transfer.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_transfer.go @@ -144,7 +144,7 @@ func (c *initializeContext) multiSign(tx *transaction.Transaction, accType strin } func (c *initializeContext) transferGASToProxy() error { - proxyCs := c.getContract(proxyContract) + proxyCs := c.getContract(morphUtil.ProxyContract) r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash) bal, err := r.BalanceOf(proxyCs.Hash) diff --git a/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go b/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go index 623f1d9ae..c09ba8b8d 100644 --- a/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go +++ b/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go @@ -21,7 +21,7 @@ func listNetmapCandidatesNodes(cmd *cobra.Command, _ []string) { cs, err := r.GetContractByID(1) commonCmd.ExitOnErr(cmd, "can't get NNS contract info: %w", err) - nmHash, err := util.NNSResolveHash(inv, cs.Hash, util.DomainOf(netmapContract)) + nmHash, err := util.NNSResolveHash(inv, cs.Hash, util.DomainOf(util.NetmapContract)) commonCmd.ExitOnErr(cmd, "can't get netmap contract hash: %w", err) res, err := inv.Call(nmHash, "netmapCandidates") diff --git a/cmd/frostfs-adm/internal/modules/morph/proxy.go b/cmd/frostfs-adm/internal/modules/morph/proxy.go index 5ae4ae041..9e973b0de 100644 --- a/cmd/frostfs-adm/internal/modules/morph/proxy.go +++ b/cmd/frostfs-adm/internal/modules/morph/proxy.go @@ -47,7 +47,7 @@ func processAccount(cmd *cobra.Command, addr util.Uint160, method string) error return fmt.Errorf("can't get NNS contract info: %w", err) } - proxyHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(proxyContract)) + proxyHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(util2.ProxyContract)) if err != nil { return fmt.Errorf("can't get proxy contract hash: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/remove_node.go b/cmd/frostfs-adm/internal/modules/morph/remove_node.go index 75c486e03..678bcc7ee 100644 --- a/cmd/frostfs-adm/internal/modules/morph/remove_node.go +++ b/cmd/frostfs-adm/internal/modules/morph/remove_node.go @@ -41,7 +41,7 @@ func removeNodesCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(netmapContract)) + nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(util.NetmapContract)) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/util/const.go b/cmd/frostfs-adm/internal/modules/morph/util/const.go index d6e5dbc98..bf71b067f 100644 --- a/cmd/frostfs-adm/internal/modules/morph/util/const.go +++ b/cmd/frostfs-adm/internal/modules/morph/util/const.go @@ -17,4 +17,15 @@ const ( SingleAccountName = "single" CommitteeAccountName = "committee" + + NNSContract = "nns" + FrostfsContract = "frostfs" // not deployed in side-chain. + ProcessingContract = "processing" // not deployed in side-chain. + AlphabetContract = "alphabet" + BalanceContract = "balance" + ContainerContract = "container" + FrostfsIDContract = "frostfsid" + NetmapContract = "netmap" + PolicyContract = "policy" + ProxyContract = "proxy" )