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:
Eduard S
2020-12-29 17:21:45 +01:00
parent 88f924e9dd
commit 42791181a1
12 changed files with 253 additions and 56 deletions

View File

@@ -65,7 +65,10 @@ type ClientConfig struct {
// NewClient creates a new Client to interact with Ethereum and the Hermez smart contracts.
func NewClient(client *ethclient.Client, account *accounts.Account, ks *ethKeystore.KeyStore, cfg *ClientConfig) (*Client, error) {
ethereumClient := NewEthereumClient(client, account, ks, &cfg.Ethereum)
ethereumClient, err := NewEthereumClient(client, account, ks, &cfg.Ethereum)
if err != nil {
return nil, tracerr.Wrap(err)
}
auctionClient, err := NewAuctionClient(ethereumClient, cfg.Auction.Address, cfg.Auction.TokenHEZ)
if err != nil {
return nil, tracerr.Wrap(err)

View File

@@ -73,6 +73,7 @@ type EthereumConfig struct {
// EthereumClient is an ethereum client to call Smart Contract methods and check blockchain information.
type EthereumClient struct {
client *ethclient.Client
chainID *big.Int
account *accounts.Account
ks *ethKeystore.KeyStore
ReceiptTimeout time.Duration
@@ -82,7 +83,7 @@ type EthereumClient struct {
// NewEthereumClient creates a EthereumClient instance. The account is not mandatory (it can
// be nil). If the account is nil, CallAuth will fail with ErrAccountNil.
func NewEthereumClient(client *ethclient.Client, account *accounts.Account, ks *ethKeystore.KeyStore, config *EthereumConfig) *EthereumClient {
func NewEthereumClient(client *ethclient.Client, account *accounts.Account, ks *ethKeystore.KeyStore, config *EthereumConfig) (*EthereumClient, error) {
if config == nil {
config = &EthereumConfig{
CallGasLimit: defaultCallGasLimit,
@@ -92,7 +93,7 @@ func NewEthereumClient(client *ethclient.Client, account *accounts.Account, ks *
IntervalReceiptLoop: defaultIntervalReceiptLoop,
}
}
return &EthereumClient{
c := &EthereumClient{
client: client,
account: account,
ks: ks,
@@ -100,6 +101,12 @@ func NewEthereumClient(client *ethclient.Client, account *accounts.Account, ks *
config: config,
opts: newCallOpts(),
}
chainID, err := c.EthChainID()
if err != nil {
return nil, tracerr.Wrap(err)
}
c.chainID = chainID
return c, nil
}
// EthChainID returns the ChainID of the ethereum network
@@ -147,8 +154,7 @@ func (c *EthereumClient) CallAuth(gasLimit uint64,
gasPrice.Add(gasPrice, inc)
log.Debugw("Transaction metadata", "gasPrice", gasPrice)
// TODO: Set the correct chainID
auth, err := bind.NewKeyStoreTransactorWithChainID(c.ks, *c.account, big.NewInt(0))
auth, err := bind.NewKeyStoreTransactorWithChainID(c.ks, *c.account, c.chainID)
if err != nil {
return nil, tracerr.Wrap(err)
}

View File

@@ -11,7 +11,8 @@ import (
func TestEthERC20(t *testing.T) {
ethClient, err := ethclient.Dial(ethClientDialURL)
require.Nil(t, err)
client := NewEthereumClient(ethClient, auxAccount, ks, nil)
client, err := NewEthereumClient(ethClient, auxAccount, ks, nil)
require.Nil(t, err)
consts, err := client.EthERC20Consts(tokenHEZAddressConst)
require.Nil(t, err)

View File

@@ -164,7 +164,10 @@ func TestMain(m *testing.M) {
}
// Controllable Governance Address
ethereumClientGov := NewEthereumClient(ethClient, governanceAccount, ks, nil)
ethereumClientGov, err := NewEthereumClient(ethClient, governanceAccount, ks, nil)
if err != nil {
log.Fatal(err)
}
auctionClient, err = NewAuctionClient(ethereumClientGov, auctionAddressConst, tokenHEZ)
if err != nil {
log.Fatal(err)
@@ -186,10 +189,22 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}
ethereumClientEmergencyCouncil = NewEthereumClient(ethClient, emergencyCouncilAccount, ks, nil)
ethereumClientAux = NewEthereumClient(ethClient, auxAccount, ks, nil)
ethereumClientAux2 = NewEthereumClient(ethClient, aux2Account, ks, nil)
ethereumClientHermez = NewEthereumClient(ethClient, hermezRollupTestAccount, ks, nil)
ethereumClientEmergencyCouncil, err = NewEthereumClient(ethClient, emergencyCouncilAccount, ks, nil)
if err != nil {
log.Fatal(err)
}
ethereumClientAux, err = NewEthereumClient(ethClient, auxAccount, ks, nil)
if err != nil {
log.Fatal(err)
}
ethereumClientAux2, err = NewEthereumClient(ethClient, aux2Account, ks, nil)
if err != nil {
log.Fatal(err)
}
ethereumClientHermez, err = NewEthereumClient(ethClient, hermezRollupTestAccount, ks, nil)
if err != nil {
log.Fatal(err)
}
exitVal = m.Run()
}