From b1eab1de54505281ee55eebaf23dd7f40d3cc53d Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 21 Dec 2023 13:59:46 +0300 Subject: [PATCH] [#883] adm: Add domainOf function to resolve NNS domain Signed-off-by: Alex Vanin --- cmd/frostfs-adm/internal/modules/morph/ape_util.go | 2 +- cmd/frostfs-adm/internal/modules/morph/balance.go | 4 ++-- cmd/frostfs-adm/internal/modules/morph/config.go | 4 ++-- cmd/frostfs-adm/internal/modules/morph/container.go | 4 ++-- cmd/frostfs-adm/internal/modules/morph/dump_hashes.go | 2 +- cmd/frostfs-adm/internal/modules/morph/epoch.go | 2 +- .../internal/modules/morph/initialize_deploy.go | 8 ++++++-- .../internal/modules/morph/netmap_candidates.go | 2 +- cmd/frostfs-adm/internal/modules/morph/proxy.go | 2 +- cmd/frostfs-adm/internal/modules/morph/remove_node.go | 2 +- 10 files changed, 18 insertions(+), 14 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/morph/ape_util.go b/cmd/frostfs-adm/internal/modules/morph/ape_util.go index e50522f2d..f64a7e108 100644 --- a/cmd/frostfs-adm/internal/modules/morph/ape_util.go +++ b/cmd/frostfs-adm/internal/modules/morph/ape_util.go @@ -96,7 +96,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 = nnsResolveHash(inv, nnsCs.Hash, policyContract+".frostfs") + ch, err = nnsResolveHash(inv, nnsCs.Hash, domainOf(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 9b706c7bf..0fee45a8f 100644 --- a/cmd/frostfs-adm/internal/modules/morph/balance.go +++ b/cmd/frostfs-adm/internal/modules/morph/balance.go @@ -63,7 +63,7 @@ func dumpBalances(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - nmHash, err = nnsResolveHash(inv, nnsCs.Hash, netmapContract+".frostfs") + nmHash, err = nnsResolveHash(inv, nnsCs.Hash, domainOf(netmapContract)) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } @@ -136,7 +136,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 := nnsResolveHash(inv, nnsHash, proxyContract+".frostfs") + h, err := nnsResolveHash(inv, nnsHash, domainOf(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 3c4029bca..db7d2ab8e 100644 --- a/cmd/frostfs-adm/internal/modules/morph/config.go +++ b/cmd/frostfs-adm/internal/modules/morph/config.go @@ -37,7 +37,7 @@ func dumpNetworkConfig(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - nmHash, err := nnsResolveHash(inv, cs.Hash, netmapContract+".frostfs") + nmHash, err := nnsResolveHash(inv, cs.Hash, domainOf(netmapContract)) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } @@ -95,7 +95,7 @@ func setConfigCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, netmapContract+".frostfs") + nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, domainOf(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 f3faa3044..e7a7f5466 100644 --- a/cmd/frostfs-adm/internal/modules/morph/container.go +++ b/cmd/frostfs-adm/internal/modules/morph/container.go @@ -35,7 +35,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 = nnsResolveHash(inv, nnsCs.Hash, containerContract+".frostfs") + ch, err = nnsResolveHash(inv, nnsCs.Hash, domainOf(containerContract)) if err != nil { return util.Uint160{}, err } @@ -306,7 +306,7 @@ func fetchContainerContractHash(wCtx *initializeContext) (util.Uint160, error) { return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err) } - ch, err := nnsResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, containerContract+".frostfs") + ch, err := nnsResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, domainOf(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 585de6d6d..0a112f35c 100644 --- a/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go +++ b/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go @@ -87,7 +87,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { for _, ctrName := range contractList { bw.Reset() emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly, - ctrName+".frostfs", int64(nns.TXT)) + domainOf(ctrName), int64(nns.TXT)) res, err := c.InvokeScript(bw.Bytes(), nil) if err != nil { diff --git a/cmd/frostfs-adm/internal/modules/morph/epoch.go b/cmd/frostfs-adm/internal/modules/morph/epoch.go index 453e984b0..39dbb0caf 100644 --- a/cmd/frostfs-adm/internal/modules/morph/epoch.go +++ b/cmd/frostfs-adm/internal/modules/morph/epoch.go @@ -27,7 +27,7 @@ func forceNewEpochCmd(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, netmapContract+".frostfs") + nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, domainOf(netmapContract)) if err != nil { return fmt.Errorf("can't get netmap 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 436ba93d2..61536b4d5 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go @@ -91,6 +91,10 @@ const ( deployMethodName = "deploy" ) +func domainOf(contract string) string { + return contract + ".frostfs" +} + func (c *initializeContext) deployNNS(method string) error { cs := c.getContract(nnsContract) h := cs.Hash @@ -198,7 +202,7 @@ func (c *initializeContext) deployOrUpdateContracts(w *io2.BufBinWriter, nnsHash cs := c.getContract(ctrName) method := updateMethodName - ctrHash, err := nnsResolveHash(c.ReadOnlyInvoker, nnsHash, ctrName+".frostfs") + ctrHash, err := nnsResolveHash(c.ReadOnlyInvoker, nnsHash, domainOf(ctrName)) if err != nil { if errors.Is(err, errMissingNNSRecord) { // if contract not found we deploy it instead of update @@ -595,7 +599,7 @@ func (c *initializeContext) getNetConfigFromNetmapContract() ([]stackitem.Item, if err != nil { return nil, fmt.Errorf("NNS is not yet deployed: %w", err) } - nmHash, err := nnsResolveHash(c.ReadOnlyInvoker, cs.Hash, netmapContract+".frostfs") + nmHash, err := nnsResolveHash(c.ReadOnlyInvoker, cs.Hash, domainOf(netmapContract)) if err != nil { return nil, fmt.Errorf("can't get netmap contract hash: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go b/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go index 30f7c69c4..bb1de09ca 100644 --- a/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go +++ b/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go @@ -20,7 +20,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 := nnsResolveHash(inv, cs.Hash, netmapContract+".frostfs") + nmHash, err := nnsResolveHash(inv, cs.Hash, domainOf(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 effcf0e27..802a61246 100644 --- a/cmd/frostfs-adm/internal/modules/morph/proxy.go +++ b/cmd/frostfs-adm/internal/modules/morph/proxy.go @@ -46,7 +46,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 := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, proxyContract+".frostfs") + proxyHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, domainOf(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 ba7bb90ff..ea958f2f7 100644 --- a/cmd/frostfs-adm/internal/modules/morph/remove_node.go +++ b/cmd/frostfs-adm/internal/modules/morph/remove_node.go @@ -40,7 +40,7 @@ func removeNodesCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, netmapContract+".frostfs") + nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, domainOf(netmapContract)) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } -- 2.45.2