From ad2a5a655bf08febc19ae4e8491deda229da4f44 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 5 Feb 2018 12:00:29 -0600 Subject: [PATCH] proper error handling in collator.go Former-commit-id: b2b5a4602f2767dfdd8b3de3b2a9cf4994f8e2fa [formerly 1b764bc06d5d5eff79ffc197d89c3614313d7bb3] Former-commit-id: ec5a587e262d81211ba525afaf603a89fc1916f6 --- sharding/client.go | 6 +++--- sharding/collator.go | 17 ++++++++++------- sharding/collator_test.go | 0 sharding/vmc.go | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 sharding/collator_test.go diff --git a/sharding/client.go b/sharding/client.go index 7fb1c376e..316ba0a65 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -75,9 +75,9 @@ func (c *Client) Start() error { // 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). // Once that's done we can subscribe to block headers - // if err := initVMCValidator(c); err != nil { - // return err - // } + if err := initVMCValidator(c); err != nil { + return err + } // Listens to block headers from the geth node and if we are an eligible // proposer, we fetch pending transactions and propose a collation diff --git a/sharding/collator.go b/sharding/collator.go index b67fe7d7a..faa5e4306 100644 --- a/sharding/collator.go +++ b/sharding/collator.go @@ -18,7 +18,7 @@ func subscribeBlockHeaders(c *Client) error { _, err := c.client.SubscribeNewHead(context.Background(), headerChan) if err != nil { - return err + return fmt.Errorf("unable to subscribe to incoming headers. %v", err) } log.Info("listening for new headers...") @@ -31,7 +31,7 @@ func subscribeBlockHeaders(c *Client) error { // TODO: Only run this code on certain periods? err := watchShards(c, head) 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 { - return err + return fmt.Errorf("cannot unlock account. %v", err) } ops := bind.CallOpts{} count, err := c.vmc.VMCCaller.ShardCount(&ops) if err != nil { - return err + return fmt.Errorf("unable to fetch shard count. %v", err) } 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 addr, err := c.vmc.VMCCaller.GetEligibleProposer(&ops, big.NewInt(s)) 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 // clint, then we propose a new collation) if addr == accounts[0].Address { - proposeCollation() + err := proposeCollation() + if err != nil { + return fmt.Errorf("could not propose collation. %v", err) + } } s++ } @@ -75,6 +78,6 @@ func watchShards(c *Client, head *types.Header) error { return nil } -func proposeCollation() { +func proposeCollation() error { return nil } diff --git a/sharding/collator_test.go b/sharding/collator_test.go new file mode 100644 index 000000000..e69de29bb diff --git a/sharding/vmc.go b/sharding/vmc.go index 22007056f..594e767b6 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -72,7 +72,7 @@ func initVMC(c *Client) error { func initVMCValidator(c *Client) error { // 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 accounts := c.keystore.Accounts()