From eb7b8bf7c4eabab089c500a00edee4a8d0cc26f7 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 17 Jun 2022 00:45:32 +0300 Subject: [PATCH] [#1513] node: Encode node's public key into binary format once Avoid per-iteration key encoding due to the immutability of the key. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/config.go | 17 ++++++++++------- cmd/neofs-node/netmap.go | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index dcae1dd3a..648968f18 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -77,6 +77,8 @@ type cfg struct { key *keys.PrivateKey + binPublicKey []byte + ownerIDFromKey user.ID // user ID calculated from key apiVersion version.Version @@ -269,13 +271,14 @@ func initCfg(path string) *cfg { fatalOnErr(err) c := &cfg{ - ctx: context.Background(), - appCfg: appCfg, - internalErr: make(chan error), - log: log, - wg: new(sync.WaitGroup), - key: key, - apiVersion: version.Current(), + ctx: context.Background(), + appCfg: appCfg, + internalErr: make(chan error), + log: log, + wg: new(sync.WaitGroup), + key: key, + binPublicKey: key.PublicKey().Bytes(), + apiVersion: version.Current(), cfgAccounting: cfgAccounting{ scriptHash: contractsconfig.Balance(appCfg), }, diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 8f5c58646..6174e29cf 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -288,7 +288,7 @@ func (c *cfg) netmapLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, error) { nmNodes := nm.Nodes() for i := range nmNodes { - if bytes.Equal(nmNodes[i].PublicKey(), c.key.PublicKey().Bytes()) { + if bytes.Equal(nmNodes[i].PublicKey(), c.binPublicKey) { return &nmNodes[i], nil } }