diff --git a/sharding/client.go b/sharding/client.go index 70d9d665e..639d3fad1 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -13,8 +13,7 @@ import ( ) const ( - // TODO(prestonvanloon): Can this be referenced from main.clientIdentifier? - clientIdentifier = "geth" // Client identifier to advertise over the network + clientIdentifier = "geth" // Used to determine the ipc name. ) // Client for sharding. Communicates to geth node via JSON RPC. @@ -32,7 +31,7 @@ func MakeShardingClient(ctx *cli.Context) *Client { if ctx.GlobalIsSet(utils.DataDirFlag.Name) { path = ctx.GlobalString(utils.DataDirFlag.Name) } - endpoint := fmt.Sprintf("%s/geth.ipc", path) + endpoint := fmt.Sprintf("%s/%s.ipc", path, clientIdentifier) config := &node.Config{ DataDir: path, @@ -58,7 +57,7 @@ func MakeShardingClient(ctx *cli.Context) *Client { // Start the sharding client. // * Connects to node. -// * Verifies the validator management contract. +// * Verifies or deploys the validator management contract. func (c *Client) Start() error { log.Info("Starting sharding client") rpcClient, err := dialRPC(c.endpoint) @@ -71,14 +70,14 @@ func (c *Client) Start() error { return err } - // TODO: Wait to be selected in goroutine? + // TODO: Wait to be selected as collator in goroutine? return nil } // Wait until sharding client is shutdown. func (c *Client) Wait() { - // TODO: Blocking lock + // TODO: Blocking lock. } // dialRPC endpoint to node. @@ -88,3 +87,19 @@ func dialRPC(endpoint string) (*rpc.Client, error) { } return rpc.Dial(endpoint) } + +// UnlockAccount will unlock the specified account using utils.PasswordFileFlag or empty string if unset. +func (c *Client) unlockAccount(account accounts.Account) error { + pass := "" + + if c.ctx.GlobalIsSet(utils.PasswordFileFlag.Name) { + blob, err := ioutil.ReadFile(c.ctx.GlobalString(utils.PasswordFileFlag.Name)) + if err != nil { + return fmt.Errorf("unable to read account password contents in file %s. %v", utils.PasswordFileFlag.Value, err) + } + // TODO: Use bufio.Scanner or other reader that doesn't include a trailing newline character. + pass = strings.Trim(string(blob), "\n") // Some text files end in new line, remove with strings.Trim. + } + + return c.keystore.Unlock(account, pass) +} diff --git a/sharding/vmc.go b/sharding/vmc.go index 1c03aa04c..277ade15c 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -26,7 +26,6 @@ var ( // Verify validator management contract. // Checks that the contract exists and verifies the bytecode. Otherwise, deploys a copy of the contract. func (c *Client) verifyVMC() error { - // TODO: Fetch validator manager contract. b, err := c.client.CodeAt(context.Background(), validatorManagerAddress, nil) if err != nil { return fmt.Errorf("unable to get contract code at %s. %v", validatorManagerAddress, err) @@ -50,6 +49,8 @@ func (c *Client) verifyVMC() error { } // TODO: Check contract bytecode is what we expected, otherwise return error. + // Note: The compiled byte code returned by the contract will not exactly match the original + // bytecode since the contract constructor is not saved on the chain. if !bytes.Equal(b, abiBytecode) { return fmt.Errorf("bytecode at contract address %s does not match expected bytecode", validatorManagerAddress.String()) } @@ -65,7 +66,6 @@ func (c *Client) deployVMC() (*common.Address, error) { return nil, fmt.Errorf("no accounts found") } - // TODO: call unlock only if account is actually locked. if err := c.unlockAccount(accounts[0]); err != nil { return nil, fmt.Errorf("unable to unlock account 0: %v", err) } @@ -108,18 +108,3 @@ func (c *Client) deployVMC() (*common.Address, error) { return &receipt.ContractAddress, nil } - -func (c *Client) unlockAccount(account accounts.Account) error { - pass := "" - - if c.ctx.GlobalIsSet(utils.PasswordFileFlag.Name) { - blob, err := ioutil.ReadFile(c.ctx.GlobalString(utils.PasswordFileFlag.Name)) - if err != nil { - return fmt.Errorf("unable to read account password contents in file %s. %v", utils.PasswordFileFlag.Value, err) - } - // Some text files end in new line, remove with strings.Trim. - pass = strings.Trim(string(blob), "\n") - } - - return c.keystore.Unlock(account, pass) -}