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

View File

@@ -1,11 +1,19 @@
package sharding package sharding
import ( import (
"github.com/ethereum/go-ethereum/common/hexutil"
"sync"
"testing" "testing"
) )
func TestDeposit(t *testing.T) { // FakeEthService based on implementation of internal/ethapi.Client
if 0 != 0 { type FakeEthService struct {
t.Errorf("test incorrect") 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 { if err != nil {
return fmt.Errorf("unable to deposit eth and become a validator: %v", err) return fmt.Errorf("unable to deposit eth and become a validator: %v", err)
} }