From cf48e82242ded5ad1f539491ccd57ed945e1c292 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 13 Aug 2020 12:01:18 +0300 Subject: [PATCH] consensus: exit if wrong password is provided in configuration --- pkg/consensus/consensus.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index 7fcc1d35e..7e14d8e22 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -18,6 +18,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/mempool" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "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/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" @@ -121,6 +122,19 @@ func NewService(cfg Config) (Service, error) { return nil, err } + // Check that wallet password is correct for at least one account. + var ok bool + for _, acc := range srv.wallet.Accounts { + err := acc.Decrypt(srv.Config.Wallet.Password) + if err == nil { + ok = true + break + } + } + if !ok { + return nil, errors.New("no account with provided password was found") + } + defer srv.wallet.Close() srv.dbft = dbft.New( @@ -325,7 +339,8 @@ func (s *service) getKeyPair(pubs []crypto.PublicKey) (int, crypto.PrivateKey, c key, err := keys.NEP2Decrypt(acc.EncryptedWIF, s.Config.Wallet.Password) if err != nil { - continue + s.log.Fatal("can't unlock account", zap.String("address", address.Uint160ToString(sh))) + break } return i, &privateKey{PrivateKey: key}, &publicKey{PublicKey: key.PublicKey()}