proper error handling in collator.go

Former-commit-id: b2b5a4602f2767dfdd8b3de3b2a9cf4994f8e2fa [formerly 1b764bc06d5d5eff79ffc197d89c3614313d7bb3]
Former-commit-id: ec5a587e262d81211ba525afaf603a89fc1916f6
This commit is contained in:
Raul Jordan 2018-02-05 12:00:29 -06:00
parent 6314e30738
commit ad2a5a655b
4 changed files with 14 additions and 11 deletions

View File

@ -75,9 +75,9 @@ func (c *Client) Start() error {
// Deposit 100ETH into the validator set in the VMC. Checks if account // Deposit 100ETH into the validator set in the VMC. Checks if account
// is already a validator in the VMC (in the case the client restarted). // is already a validator in the VMC (in the case the client restarted).
// Once that's done we can subscribe to block headers // Once that's done we can subscribe to block headers
// if err := initVMCValidator(c); err != nil { if err := initVMCValidator(c); err != nil {
// return err return err
// } }
// Listens to block headers from the geth node and if we are an eligible // Listens to block headers from the geth node and if we are an eligible
// proposer, we fetch pending transactions and propose a collation // proposer, we fetch pending transactions and propose a collation

View File

@ -18,7 +18,7 @@ func subscribeBlockHeaders(c *Client) error {
_, err := c.client.SubscribeNewHead(context.Background(), headerChan) _, err := c.client.SubscribeNewHead(context.Background(), headerChan)
if err != nil { if err != nil {
return err return fmt.Errorf("unable to subscribe to incoming headers. %v", err)
} }
log.Info("listening for new headers...") log.Info("listening for new headers...")
@ -31,7 +31,7 @@ func subscribeBlockHeaders(c *Client) error {
// TODO: Only run this code on certain periods? // TODO: Only run this code on certain periods?
err := watchShards(c, head) err := watchShards(c, head)
if err != nil { if err != nil {
return err return fmt.Errorf("unable to watch shards. %v", err)
} }
} }
} }
@ -48,13 +48,13 @@ func watchShards(c *Client, head *types.Header) error {
} }
if err := c.unlockAccount(accounts[0]); err != nil { if err := c.unlockAccount(accounts[0]); err != nil {
return err return fmt.Errorf("cannot unlock account. %v", err)
} }
ops := bind.CallOpts{} ops := bind.CallOpts{}
count, err := c.vmc.VMCCaller.ShardCount(&ops) count, err := c.vmc.VMCCaller.ShardCount(&ops)
if err != nil { if err != nil {
return err return fmt.Errorf("unable to fetch shard count. %v", err)
} }
s := 0 s := 0
@ -62,12 +62,15 @@ func watchShards(c *Client, head *types.Header) error {
// Checks if we are an eligible proposer according to the VMC // Checks if we are an eligible proposer according to the VMC
addr, err := c.vmc.VMCCaller.GetEligibleProposer(&ops, big.NewInt(s)) addr, err := c.vmc.VMCCaller.GetEligibleProposer(&ops, big.NewInt(s))
if err != nil { if err != nil {
return err return fmt.Errorf("cannot fetch eligible collation proposer. %v", err)
} }
// if the address is the coinbase addr (current node running the sharding // if the address is the coinbase addr (current node running the sharding
// clint, then we propose a new collation) // clint, then we propose a new collation)
if addr == accounts[0].Address { if addr == accounts[0].Address {
proposeCollation() err := proposeCollation()
if err != nil {
return fmt.Errorf("could not propose collation. %v", err)
}
} }
s++ s++
} }
@ -75,6 +78,6 @@ func watchShards(c *Client, head *types.Header) error {
return nil return nil
} }
func proposeCollation() { func proposeCollation() error {
return nil return nil
} }

View File

View File

@ -72,7 +72,7 @@ func initVMC(c *Client) error {
func initVMCValidator(c *Client) error { func initVMCValidator(c *Client) error {
// TODO: Check if account is already in validator set. Fetch this From // TODO: Check if account is already in validator set. Fetch this From
// the VMC contract's validator set. // the VMC contract's validator set
// Unlocks the current account from the keystore // Unlocks the current account from the keystore
accounts := c.keystore.Accounts() accounts := c.keystore.Accounts()