diff --git a/sharding/collator/collator.go b/sharding/collator/collator.go index 9f5e00da4..8361ddd87 100644 --- a/sharding/collator/collator.go +++ b/sharding/collator/collator.go @@ -56,21 +56,22 @@ func subscribeBlockHeaders(c client.Client) error { // conditions are met func checkSMCForCollator(c client.Client, head *types.Header) error { log.Info("Checking if we are an eligible collation collator for a shard...") - period := big.NewInt(0).Div(head.Number, big.NewInt(sharding.PeriodLength)) for s := int64(0); s < sharding.ShardCount; s++ { // Checks if we are an eligible collator according to the SMC - addr, err := c.SMCCaller().GetEligibleCollator(&bind.CallOpts{}, big.NewInt(s), period) + for i := int64(0); i < sharding.NotaryCommitSize; s++ { + addr, err := c.SMCCaller().GetNotaryInCommittee(&bind.CallOpts{}, big.NewInt(s), i) - if err != nil { - return err - } - - // If output is non-empty and the addr == coinbase - if addr == c.Account().Address { - log.Info(fmt.Sprintf("Selected as collator on shard: %d", s)) - err := submitCollation(s) if err != nil { - return fmt.Errorf("could not add collation. %v", err) + return err + } + + // If output is non-empty and the addr == coinbase + if addr == c.Account().Address { + log.Info(fmt.Sprintf("Selected as collator on shard: %d", s)) + err := submitCollation(s) + if err != nil { + return fmt.Errorf("could not add collation. %v", err) + } } } } @@ -85,11 +86,11 @@ func checkSMCForCollator(c client.Client, head *types.Header) error { func isAccountInCollatorPool(c client.Client) (bool, error) { account := c.Account() // Checks if our deposit has gone through according to the SMC - b, err := c.SMCCaller().IsCollatorDeposited(&bind.CallOpts{}, account.Address) - if !b && err != nil { + b, err := c.SMCCaller().NotaryRegistry(&bind.CallOpts{}, account.Address) + if !b.Deposited && err != nil { log.Warn(fmt.Sprintf("Account %s not in collator pool.", account.Address.String())) } - return b, err + return b.Deposited, err } // submitCollation interacts with the SMC directly to add a collation header @@ -132,7 +133,7 @@ func joinCollatorPool(c client.Client) error { return fmt.Errorf("unable to intiate the deposit transaction: %v", err) } - tx, err := c.SMCTransactor().Deposit(txOps) + tx, err := c.SMCTransactor().RegisterNotary(txOps) if err != nil { return fmt.Errorf("unable to deposit eth and become a collator: %v", err) } diff --git a/sharding/collator/collator_test.go b/sharding/collator/collator_test.go index 2843607f2..d0a82cefd 100644 --- a/sharding/collator/collator_test.go +++ b/sharding/collator/collator_test.go @@ -87,7 +87,7 @@ func TestIsAccountInCollatorPool(t *testing.T) { txOpts := transactOpts() // deposit in collator pool, then it should return true txOpts.Value = sharding.NotaryDeposit - if _, err := smc.Deposit(txOpts); err != nil { + if _, err := smc.RegisterNotary(txOpts); err != nil { t.Fatalf("Failed to deposit: %v", err) } backend.Commit() @@ -105,7 +105,7 @@ func TestJoinCollatorPool(t *testing.T) { client := &mockClient{smc, t} // There should be no collators initially - numCollators, err := smc.NumCollators(&bind.CallOpts{}) + numCollators, err := smc.NotaryPoolLength(&bind.CallOpts{}) if err != nil { t.Fatal(err) } @@ -120,7 +120,7 @@ func TestJoinCollatorPool(t *testing.T) { backend.Commit() // Now there should be one collator - numCollators, err = smc.NumCollators(&bind.CallOpts{}) + numCollators, err = smc.NotaryPoolLength(&bind.CallOpts{}) if err != nil { t.Fatal(err) }