2018-01-15 00:10:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-05-22 12:47:35 +00:00
|
|
|
"fmt"
|
|
|
|
|
2018-01-15 00:10:02 +00:00
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
2018-05-22 12:47:35 +00:00
|
|
|
"github.com/ethereum/go-ethereum/sharding"
|
|
|
|
"github.com/ethereum/go-ethereum/sharding/node"
|
|
|
|
"github.com/ethereum/go-ethereum/sharding/notary"
|
|
|
|
"github.com/ethereum/go-ethereum/sharding/proposer"
|
2018-01-15 00:10:02 +00:00
|
|
|
cli "gopkg.in/urfave/cli.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2018-05-20 22:47:47 +00:00
|
|
|
shardingCommand = cli.Command{
|
|
|
|
Action: utils.MigrateFlags(shardingClient),
|
|
|
|
Name: "sharding",
|
|
|
|
Usage: "Start a sharding-enabled node",
|
2018-01-21 00:07:41 +00:00
|
|
|
ArgsUsage: "[endpoint]",
|
2018-05-22 12:47:35 +00:00
|
|
|
Flags: []cli.Flag{utils.ProtocolFlag, utils.DataDirFlag, utils.PasswordFileFlag, utils.NetworkIdFlag, utils.IPCPathFlag, utils.DepositFlag},
|
2018-01-21 00:07:41 +00:00
|
|
|
Category: "SHARDING COMMANDS",
|
|
|
|
Description: `
|
2018-05-22 15:33:46 +00:00
|
|
|
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.
|
2018-01-21 00:07:41 +00:00
|
|
|
`,
|
2018-01-15 00:10:02 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2018-05-20 22:47:47 +00:00
|
|
|
func shardingClient(ctx *cli.Context) error {
|
|
|
|
// configures a sharding-enabled node using the cli's context.
|
2018-05-22 12:47:35 +00:00
|
|
|
shardingNode := node.NewNode(ctx)
|
|
|
|
registerShardingServices(shardingNode)
|
|
|
|
defer shardingNode.Close()
|
2018-05-22 13:11:16 +00:00
|
|
|
// starts a connection to a geth node and kicks off every registered service.
|
2018-05-20 22:47:47 +00:00
|
|
|
return shardingNode.Start()
|
2018-01-15 00:10:02 +00:00
|
|
|
}
|
2018-03-06 05:57:42 +00:00
|
|
|
|
2018-05-22 12:47:35 +00:00
|
|
|
// registerShardingServices sets up either a notary or proposer
|
|
|
|
// sharding service dependent on the ClientType cli flag. We should be defining
|
|
|
|
// the services we want to register here, as this is the geth command entry point
|
|
|
|
// for sharding.
|
|
|
|
func registerShardingServices(n node.Node) error {
|
|
|
|
protocolFlag := n.Context().GlobalString(utils.ProtocolFlag.Name)
|
|
|
|
|
|
|
|
err := n.Register(func(ctx *cli.Context) (sharding.Service, error) {
|
|
|
|
// TODO(terenc3t): handle case when we just want to start an observer node.
|
|
|
|
if protocolFlag == "notary" {
|
|
|
|
return notary.NewNotary(n.Context(), n)
|
|
|
|
}
|
|
|
|
return proposer.NewProposer(n.Context(), n)
|
|
|
|
})
|
2018-05-20 22:47:47 +00:00
|
|
|
|
2018-05-22 12:47:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to register the main sharding services: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(prestonvanloon) registers the shardp2p service.
|
|
|
|
// we can do n.Register and initialize a shardp2p.NewServer() or something like that.
|
|
|
|
return nil
|
|
|
|
}
|