sharding: fix merge confs

Former-commit-id: 6016b3f659b6d325061f7862e2b0b7d9c882df93 [formerly 64aa7c188428e5f0415062d22f65093be73cf20a]
Former-commit-id: ba6af02c1a8cffbc36edaa04685ac7a456c03919
This commit is contained in:
Raul Jordan 2018-06-12 00:14:25 -05:00
7 changed files with 29 additions and 23 deletions

View File

@ -119,16 +119,16 @@ Concurrently, you will need to run another service that is tasked with processin
## Running a Collation Proposal Node
```
geth sharding --actor "proposer" --datadir /path/to/your/datadir --password /path/to/your/password.txt --networkid 12345
geth sharding --actor "proposer" --datadir /path/to/your/datadir --password /path/to/your/password.txt --shardid 0 --networkid 12345
```
This node is tasked with processing pending transactions into blobs within collations by serializing data into collation bodies. It is responsible for submitting proposals (collation headers) to the SMC via the `addHeader` function.
This node is tasked with processing pending transactions into blobs within collations by serializing data into collation bodies. It is responsible for submitting proposals on shard 0 (collation headers) to the SMC via the `addHeader` function.
## Running an Observer Node
geth sharding --datadir /path/to/your/datadir --password /path/to/your/password.txt --networkid 12345
geth sharding --datadir /path/to/your/datadir --password /path/to/your/password.txt --shardid 0 --networkid 12345
Omitting the `--actor` flag will launch a simple observer service attached to the sharding client that is able to listen to changes happening throughout the sharded Ethereum network.
Omitting the `--actor` flag will launch a simple observer service attached to the sharding client that is able to listen to changes happening throughout the sharded Ethereum network on shard 0.
# Making Changes

View File

@ -120,6 +120,7 @@ var (
utils.ExtraDataFlag,
utils.DepositFlag,
utils.ActorFlag,
utils.ShardIDFlag,
configFileFlag,
}

View File

@ -14,7 +14,7 @@ var (
Name: "sharding",
Usage: "Start a sharding-enabled node",
ArgsUsage: "[endpoint]",
Flags: []cli.Flag{utils.ActorFlag, utils.DataDirFlag, utils.PasswordFileFlag, utils.NetworkIdFlag, utils.IPCPathFlag, utils.DepositFlag},
Flags: []cli.Flag{utils.ActorFlag, utils.DataDirFlag, utils.PasswordFileFlag, utils.NetworkIdFlag, utils.IPCPathFlag, utils.DepositFlag, utils.ShardIDFlag},
Category: "SHARDING COMMANDS",
Description: `
Launches a sharding node that manages services related to submitting collations to a Sharding Manager Contract, notary and proposer services, and shardp2p connections. This feature is a work in progress.

View File

@ -542,6 +542,10 @@ var (
Name: "actor",
Usage: `use the --actor notary or --actor proposer to start a notary or proposer service in the sharding node. If omitted, the sharding node registers an Observer service that simply observes the activity in the sharded network`,
}
ShardIDFlag = cli.IntFlag{
Name: "shardid",
Usage: `use the --shardid to determine which shard to start p2p server, listen for incoming transactions and perform proposer/observer duties`,
}
)
// MakeDataDir retrieves the currently requested data directory, terminating

View File

@ -74,6 +74,7 @@ func New(ctx *cli.Context) (*ShardEthereum, error) {
passwordFile := ctx.GlobalString(utils.PasswordFileFlag.Name)
depositFlag := ctx.GlobalBool(utils.DepositFlag.Name)
actorFlag := ctx.GlobalString(utils.ActorFlag.Name)
shardIDFlag := ctx.GlobalInt(utils.ShardIDFlag.Name)
smcClient, err := mainchain.NewSMCClient(endpoint, path, depositFlag, passwordFile)
if err != nil {
@ -99,7 +100,7 @@ func New(ctx *cli.Context) (*ShardEthereum, error) {
return nil, err
}
if err := shardEthereum.registerActorService(actorFlag); err != nil {
if err := shardEthereum.registerActorService(actorFlag, shardIDFlag); err != nil {
return nil, err
}
@ -209,7 +210,7 @@ func (s *ShardEthereum) registerTXPool(actor string) error {
}
// Registers the actor according to CLI flags. Either notary/proposer/observer.
func (s *ShardEthereum) registerActorService(actor string) error {
func (s *ShardEthereum) registerActorService(actor string, shardID int) error {
return s.Register(func(ctx *sharding.ServiceContext) (sharding.Service, error) {
var p2p *shardp2p.Server
@ -220,9 +221,8 @@ func (s *ShardEthereum) registerActorService(actor string) error {
} else if actor == "proposer" {
var txPool *txpool.ShardTXPool
ctx.RetrieveService(&txPool)
return proposer.NewProposer(s.smcClient, p2p, txPool, s.shardChainDb)
return proposer.NewProposer(s.smcClient, p2p, txPool, s.shardChainDb, shardID)
}
return observer.NewObserver(p2p, s.shardChainDb)
return observer.NewObserver(p2p, s.shardChainDb, shardID)
})
}

View File

@ -3,6 +3,8 @@
package observer
import (
"fmt"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/sharding"
@ -14,20 +16,21 @@ import (
type Observer struct {
shardp2p sharding.ShardP2P
shardChainDb ethdb.Database
shardID int
}
// NewObserver creates a new observer instance.
func NewObserver(shardp2p sharding.ShardP2P, shardChainDb ethdb.Database) (*Observer, error) {
return &Observer{shardp2p, shardChainDb}, nil
func NewObserver(shardp2p sharding.ShardP2P, shardChainDb ethdb.Database, shardID int) (*Observer, error) {
return &Observer{shardp2p, shardChainDb, shardID}, nil
}
// Start the main routine for an observer.
func (o *Observer) Start() {
log.Info("Starting shard observer service")
log.Info(fmt.Sprintf("Starting observer service in shard %d", o.shardID))
}
// Stop the main loop for observing the shard network.
func (o *Observer) Stop() error {
log.Info("Stopping shard observer service")
log.Info(fmt.Sprintf("Starting observer service in shard %d", o.shardID))
return nil
}

View File

@ -24,24 +24,25 @@ type Proposer struct {
shardp2p sharding.ShardP2P
txpool sharding.TXPool
shardChainDb ethdb.Database
shardID int
}
// NewProposer creates a struct instance of a proposer service.
// It will have access to a mainchain client, a shardp2p network,
// and a shard transaction pool.
func NewProposer(client *mainchain.SMCClient, shardp2p sharding.ShardP2P, txpool sharding.TXPool, shardChainDb ethdb.Database) (*Proposer, error) {
return &Proposer{client, shardp2p, txpool, shardChainDb}, nil
func NewProposer(client *mainchain.SMCClient, shardp2p sharding.ShardP2P, txpool sharding.TXPool, shardChainDb ethdb.Database, shardID int) (*Proposer, error) {
return &Proposer{client, shardp2p, txpool, shardChainDb, shardID}, nil
}
// Start the main loop for proposing collations.
func (p *Proposer) Start() {
log.Info("Starting proposer service")
log.Info(fmt.Sprintf("Starting proposer service in shard %d", p.shardID))
go p.proposeCollations()
}
// Stop the main loop for proposing collations.
func (p *Proposer) Stop() error {
log.Info("Stopping proposer service")
log.Info(fmt.Sprintf("Stopping proposer service in shard %d", p.shardID))
return nil
}
@ -56,9 +57,6 @@ func (p *Proposer) proposeCollations() {
nil, 0, nil, data))
}
// TODO: Create and use CLI flag for shardID
shardID := big.NewInt(0)
// Get current block number.
blockNumber, err := p.client.ChainReader().BlockByNumber(context.Background(), nil)
if err != nil {
@ -68,14 +66,14 @@ func (p *Proposer) proposeCollations() {
period := new(big.Int).Div(blockNumber.Number(), big.NewInt(sharding.PeriodLength))
// Create collation.
collation, err := createCollation(p.client, shardID, period, txs)
collation, err := createCollation(p.client, big.NewInt(int64(p.shardID)), period, txs)
if err != nil {
log.Error(fmt.Sprintf("Could not create collation: %v", err))
return
}
// Check SMC if we can submit header before addHeader
canAdd, err := checkHeaderAdded(p.client, shardID, period)
canAdd, err := checkHeaderAdded(p.client, big.NewInt(int64(p.shardID)), period)
if err != nil {
log.Error(fmt.Sprintf("Could not check if we can submit header: %v", err))
return