From 568016dddb777995f13932bd08ffc5e80f8b1ea5 Mon Sep 17 00:00:00 2001 From: Shubham Goyal Date: Mon, 2 Oct 2023 19:25:54 +0530 Subject: [PATCH] Check validator private key only for validators --- plugin/evm/orderbook/tx_processor.go | 7 ++++--- plugin/evm/vm.go | 14 +++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/plugin/evm/orderbook/tx_processor.go b/plugin/evm/orderbook/tx_processor.go index 1674cc97da..a80ed36f28 100644 --- a/plugin/evm/orderbook/tx_processor.go +++ b/plugin/evm/orderbook/tx_processor.go @@ -76,9 +76,6 @@ func NewLimitOrderTxProcessor(txPool *txpool.TxPool, memoryDb LimitOrderDatabase panic(err) } - if validatorPrivateKey == "" { - panic("private key is not supplied") - } validatorAddress, err := getAddressFromPrivateKey(validatorPrivateKey) if err != nil { panic("Unable to get address from validator private key") @@ -263,6 +260,10 @@ func getOrderBookContractCallMethod(tx *types.Transaction, orderBookABI abi.ABI, } func getAddressFromPrivateKey(key string) (common.Address, error) { + // blank key is allowed for non-validators + if key == "" { + return common.Address{}, nil + } privateKey, err := crypto.HexToECDSA(key) // admin private key if err != nil { return common.Address{}, err diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 9afbd3a6d4..4d7c6060d5 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -1156,9 +1156,17 @@ func attachEthService(handler *rpc.Server, apis []rpc.API, names []string) error } func (vm *VM) NewLimitOrderProcesser() LimitOrderProcesser { - validatorPrivateKey, err := loadPrivateKeyFromFile(vm.config.ValidatorPrivateKeyFile) - if err != nil { - panic(fmt.Sprint("please specify correct path for validator-private-key-file in chain.json ", err)) + var validatorPrivateKey string + var err error + if vm.config.IsValidator { + validatorPrivateKey, err = loadPrivateKeyFromFile(vm.config.ValidatorPrivateKeyFile) + if err != nil { + panic(fmt.Sprint("please specify correct path for validator-private-key-file in chain.json ", err)) + } + if validatorPrivateKey == "" { + panic("validator private key is empty") + } + } return NewLimitOrderProcesser( vm.ctx,