From 71853348b996350224be00a258b91eb760fa7f5d Mon Sep 17 00:00:00 2001 From: Vladimir Domnich Date: Wed, 16 Nov 2022 16:17:12 +0300 Subject: [PATCH] [#2063] morph/client: Support new hash format in morph nns client Signed-off-by: Vladimir Domnich --- CHANGELOG.md | 1 + .../internal/modules/morph/initialize_nns.go | 2 ++ pkg/morph/client/nns.go | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ab68472a..999dd151c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Changelog for NeoFS Node - Shard can now change mode when encountering background disk errors (#2035) - Background workers and object service now use separate client caches (#2048) - `replicator.pool_size` config field to tune replicator pool size (#2049) +- Fix NNS hash parsing in morph client (#2063) ### Changed - `object lock` command reads CID and OID the same way other commands do (#1971) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go index d5dee7d72..980fc7b06 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go @@ -261,6 +261,8 @@ func parseNNSResolveResult(res stackitem.Item) (util.Uint160, error) { continue } + // We support several formats for hash encoding, this logic should be maintained in sync + // with nnsResolve from pkg/morph/client/nns.go h, err := util.Uint160DecodeStringLE(string(bs)) if err == nil { return h, nil diff --git a/pkg/morph/client/nns.go b/pkg/morph/client/nns.go index 46f7d717f..d22faf08e 100644 --- a/pkg/morph/client/nns.go +++ b/pkg/morph/client/nns.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" @@ -149,7 +150,20 @@ func nnsResolve(c *rpcclient.WSClient, nnsHash util.Uint160, domain string) (uti if err != nil { return util.Uint160{}, fmt.Errorf("malformed response: %w", err) } - return util.Uint160DecodeStringLE(string(bs)) + + // We support several formats for hash encoding, this logic should be maintained in sync + // with parseNNSResolveResult from cmd/neofs-adm/internal/modules/morph/initialize_nns.go + h, err := util.Uint160DecodeStringLE(string(bs)) + if err == nil { + return h, nil + } + + h, err = address.StringToUint160(string(bs)) + if err == nil { + return h, nil + } + + return util.Uint160{}, errors.New("no valid hashes are found") } func exists(c *rpcclient.WSClient, nnsHash util.Uint160, domain string) (bool, error) {