From 0bb3836e84308da0c4d6e6afa3295aca4aebc92a Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 11 Feb 2021 13:44:47 +0300 Subject: [PATCH] [#383] innerring: Sort node info attributes All node info attribute transformations can't guarantee the order of attributes. However it should be consistent otherwise smart-contract won't be able to collect signatures and approve transaction. Signed-off-by: Alex Vanin --- pkg/innerring/processors/netmap/process_peers.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/innerring/processors/netmap/process_peers.go b/pkg/innerring/processors/netmap/process_peers.go index a99af3a662..974bc508b7 100644 --- a/pkg/innerring/processors/netmap/process_peers.go +++ b/pkg/innerring/processors/netmap/process_peers.go @@ -2,6 +2,8 @@ package netmap import ( "encoding/hex" + "sort" + "strings" "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-node/pkg/innerring/invoke" @@ -35,6 +37,20 @@ func (np *Processor) processAddPeer(node []byte) { return } + // sort attributes to make it consistent + a := nodeInfo.Attributes() + sort.Slice(a, func(i, j int) bool { + switch strings.Compare(a[i].Key(), a[j].Key()) { + case -1: + return true + case 1: + return false + default: + return a[i].Value() < a[j].Value() + } + }) + nodeInfo.SetAttributes(a...) + // marshal node info back to binary node, err = nodeInfo.Marshal() if err != nil {