propose collation called on geteligibleproposer

Former-commit-id: 0a23d54aa3006d103bb7123bcfe0ac2ca3a2b027 [formerly 7266cc53ca4d6826b4a54d30391f9c5e5b0b7d10]
Former-commit-id: 6b33ca471ede8696fc83285ae426645308a4c6fe
This commit is contained in:
Raul Jordan
2018-02-05 22:41:40 -06:00
parent 538a4ef41f
commit a9afdd90ef
3 changed files with 26 additions and 21 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"math/big"
)
// subscribeBlockHeaders checks incoming block headers and determines if
@@ -51,27 +52,23 @@ func watchShards(c *Client, head *types.Header) error {
return fmt.Errorf("cannot unlock account. %v", err)
}
ops := bind.CallOpts{}
count, err := c.vmc.VMCCaller.ShardCount(&ops)
if err != nil {
return fmt.Errorf("unable to fetch shard count. %v", err)
}
log.Info(fmt.Sprint("watching shards..."))
s := 0
for s < int(count.Int64()) {
for s < shardCount {
// 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 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 {
err := proposeCollation()
ops := bind.CallOpts{}
period := head.Number.Div(head.Number, big.NewInt(int64(periodLength)))
addr, err := c.vmc.VMCCaller.GetEligibleProposer(&ops, big.NewInt(int64(s)), period)
// If output is non-empty and the addr == coinbase
if err == nil && addr == accounts[0].Address {
log.Info(fmt.Sprintf("selected as collator on shard %d", s))
err := proposeCollation(s)
if err != nil {
return fmt.Errorf("could not propose collation. %v", err)
}
}
s++
}
@@ -104,6 +101,6 @@ func proposeCollation(shardID int) error {
// This functions will fetch the transactions in the txpool and and apply
// them to finish up the collation. It will then need to broadcast the
// collation to the main chain using JSON-RPC.
log.Info(fmt.Sprint("propose collation called"))
return nil
}

View File

@@ -1,11 +1,19 @@
package sharding
import (
"github.com/ethereum/go-ethereum/common/hexutil"
"sync"
"testing"
)
func TestDeposit(t *testing.T) {
if 0 != 0 {
t.Errorf("test incorrect")
}
// FakeEthService based on implementation of internal/ethapi.Client
type FakeEthService struct {
mu sync.Mutex
getCodeResp hexutil.Bytes
getCodeErr error
}
func TestSubscribeHeaders(t *testing.T) {
}

View File

@@ -97,7 +97,7 @@ func initVMCValidator(c *Client) error {
},
}
_, err := c.vmc.VMCTransactor.Deposit(&ops, accounts[0].Address)
_, err := c.vmc.VMCTransactor.Deposit(&ops)
if err != nil {
return fmt.Errorf("unable to deposit eth and become a validator: %v", err)
}