[#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 <alexey@nspcc.ru>
This commit is contained in:
parent
058ab0e533
commit
0bb3836e84
1 changed files with 16 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue