Skip to content

Commit

Permalink
Check validator private key only for validators
Browse files Browse the repository at this point in the history
  • Loading branch information
lumos42 committed Oct 2, 2023
1 parent de86a58 commit 568016d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 4 additions & 3 deletions plugin/evm/orderbook/tx_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 568016d

Please sign in to comment.