From a5e952cc72695608e556117d81603d80fa2efae2 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 3 Dec 2021 12:01:30 +0300 Subject: [PATCH] [#1006] neofs-adm: skip missing entries in `dump-hashes` We have `subnet` contract in list, but it isn't currently deployed. This commit skips missing NNS entries to handle such situation. In future we may optimize this to be done in 1 round-trip. As a nice side-effect, dump-hashes for notary-enabled environment works even if notary is disabled -- it just prints zero hash for proxy contract. Signed-off-by: Evgenii Stratonikov --- cmd/neofs-adm/internal/modules/morph/dump.go | 37 +++++++++----------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/dump.go b/cmd/neofs-adm/internal/modules/morph/dump.go index 9743506c..253abb16 100644 --- a/cmd/neofs-adm/internal/modules/morph/dump.go +++ b/cmd/neofs-adm/internal/modules/morph/dump.go @@ -42,21 +42,6 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { infos := []contractDumpInfo{{name: nnsContract, hash: cs.Hash}} - bw := io.NewBufBinWriter() - for _, ctrName := range contractList { - emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly, - ctrName+".neofs", int64(nns.TXT)) - } - - res, err := c.InvokeScript(bw.Bytes(), nil) - if err != nil { - return fmt.Errorf("can't fetch info from NNS: %w", err) - } - - if len(res.Stack) != len(contractList) { - return errors.New("invalid response from NNS contract: length mismatch") - } - irSize := 0 for ; irSize < lastGlagoliticLetter; irSize++ { ok, err := c.NNSIsAvailable(cs.Hash, getAlphabetNNSDomain(irSize)) @@ -68,6 +53,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { } buf := bytes.NewBuffer(nil) + bw := io.NewBufBinWriter() if irSize != 0 { bw.Reset() @@ -91,10 +77,21 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { } } - for i := range contractList { - info := contractDumpInfo{name: contractList[i]} - if h, err := parseNNSResolveResult(res.Stack[i]); err == nil { - info.hash = h + for _, ctrName := range contractList { + bw.Reset() + emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly, + ctrName+".neofs", int64(nns.TXT)) + + res, err := c.InvokeScript(bw.Bytes(), nil) + if err != nil { + return fmt.Errorf("can't fetch info from NNS: %w", err) + } + + info := contractDumpInfo{name: ctrName} + if len(res.Stack) != 0 { + if h, err := parseNNSResolveResult(res.Stack[0]); err == nil { + info.hash = h + } } infos = append(infos, info) } @@ -108,7 +105,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { } } - res, err = c.InvokeScript(bw.Bytes(), nil) + res, err := c.InvokeScript(bw.Bytes(), nil) if err != nil { return fmt.Errorf("can't fetch info from NNS: %w", err) }