[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-06-17 00:45:32 +03:00 committed by LeL
parent 4574ba646d
commit eb7b8bf7c4
2 changed files with 11 additions and 8 deletions

View file

@ -77,6 +77,8 @@ type cfg struct {
key *keys.PrivateKey key *keys.PrivateKey
binPublicKey []byte
ownerIDFromKey user.ID // user ID calculated from key ownerIDFromKey user.ID // user ID calculated from key
apiVersion version.Version apiVersion version.Version
@ -275,6 +277,7 @@ func initCfg(path string) *cfg {
log: log, log: log,
wg: new(sync.WaitGroup), wg: new(sync.WaitGroup),
key: key, key: key,
binPublicKey: key.PublicKey().Bytes(),
apiVersion: version.Current(), apiVersion: version.Current(),
cfgAccounting: cfgAccounting{ cfgAccounting: cfgAccounting{
scriptHash: contractsconfig.Balance(appCfg), scriptHash: contractsconfig.Balance(appCfg),

View file

@ -288,7 +288,7 @@ func (c *cfg) netmapLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, error) {
nmNodes := nm.Nodes() nmNodes := nm.Nodes()
for i := range nmNodes { 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 return &nmNodes[i], nil
} }
} }