From 0bf2fa915e55e11b5a8b3d379c260eb6b8164ec6 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 19 Aug 2020 16:55:01 +0300 Subject: [PATCH] consensus: don't decrypt the key again and again, cache it It's cached in dbft for a view anyway, so there is no big difference here from security POV. Lets us squeeze yet another 4% TPS improvement. Make the system fail if unable to decrypt the key along the way, which is a part of #1312. --- pkg/consensus/consensus.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index 928109ded..e616043b0 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -16,6 +16,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "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/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" @@ -255,9 +256,14 @@ func (s *service) getKeyPair(pubs []crypto.PublicKey) (int, crypto.PrivateKey, c continue } - key, err := keys.NEP2Decrypt(acc.EncryptedWIF, s.Config.Wallet.Password) - if err != nil { - continue + key := acc.PrivateKey() + if acc.PrivateKey() == nil { + err := acc.Decrypt(s.Config.Wallet.Password) + if err != nil { + s.log.Fatal("can't unlock account", zap.String("address", address.Uint160ToString(sh))) + break + } + key = acc.PrivateKey() } return i, &privateKey{PrivateKey: key}, &publicKey{PublicKey: key.PublicKey()}