mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Load ethereum private key
Load an ethereum keystore when the node is started in coordinator mode. The private key corresponding to the forger address must be imported into the keystore before running the node in coordinator mode. You can see an examples in `cli/node/load-sk-example.sh`.
This commit is contained in:
29
node/node.go
29
node/node.go
@@ -7,6 +7,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
ethKeystore "github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/gin-contrib/cors"
|
||||
@@ -87,6 +89,8 @@ func NewNode(mode Mode, cfg *config.Node) (*Node, error) {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
var ethCfg eth.EthereumConfig
|
||||
var account *accounts.Account
|
||||
var keyStore *ethKeystore.KeyStore
|
||||
if mode == ModeCoordinator {
|
||||
ethCfg = eth.EthereumConfig{
|
||||
CallGasLimit: cfg.Coordinator.EthClient.CallGasLimit,
|
||||
@@ -95,8 +99,31 @@ func NewNode(mode Mode, cfg *config.Node) (*Node, error) {
|
||||
ReceiptTimeout: cfg.Coordinator.EthClient.ReceiptTimeout.Duration,
|
||||
IntervalReceiptLoop: cfg.Coordinator.EthClient.ReceiptLoopInterval.Duration,
|
||||
}
|
||||
|
||||
scryptN := ethKeystore.StandardScryptN
|
||||
scryptP := ethKeystore.StandardScryptP
|
||||
if cfg.Coordinator.Debug.LightScrypt {
|
||||
scryptN = ethKeystore.LightScryptN
|
||||
scryptP = ethKeystore.LightScryptP
|
||||
}
|
||||
keyStore = ethKeystore.NewKeyStore(cfg.Coordinator.EthClient.Keystore.Path,
|
||||
scryptN, scryptP)
|
||||
if !keyStore.HasAddress(cfg.Coordinator.ForgerAddress) {
|
||||
return nil, tracerr.Wrap(fmt.Errorf(
|
||||
"ethereum keystore doesn't have the key for address %v",
|
||||
cfg.Coordinator.ForgerAddress))
|
||||
}
|
||||
account = &accounts.Account{
|
||||
Address: cfg.Coordinator.ForgerAddress,
|
||||
}
|
||||
if err := keyStore.Unlock(*account,
|
||||
cfg.Coordinator.EthClient.Keystore.Password); err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
log.Infow("Forger ethereum account unlocked in the keystore",
|
||||
"addr", cfg.Coordinator.ForgerAddress)
|
||||
}
|
||||
client, err := eth.NewClient(ethClient, nil, nil, ð.ClientConfig{
|
||||
client, err := eth.NewClient(ethClient, account, keyStore, ð.ClientConfig{
|
||||
Ethereum: ethCfg,
|
||||
Rollup: eth.RollupConfig{
|
||||
Address: cfg.SmartContracts.Rollup,
|
||||
|
||||
Reference in New Issue
Block a user