diff --git a/cmd/geth/main.go b/cmd/geth/main.go index b955bd243..61c03f486 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -164,6 +164,8 @@ func init() { consoleCommand, attachCommand, javascriptCommand, + // See shardingcmd.go: + shardingClientCommand, // See misccmd.go: makecacheCommand, makedagCommand, diff --git a/cmd/geth/shardingcmd.go b/cmd/geth/shardingcmd.go new file mode 100644 index 000000000..9923c9e28 --- /dev/null +++ b/cmd/geth/shardingcmd.go @@ -0,0 +1,30 @@ +package main + +import ( + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/sharding" + + "github.com/ethereum/go-ethereum/cmd/utils" + cli "gopkg.in/urfave/cli.v1" +) + +var ( + shardingClientCommand = cli.Command{ + Action: utils.MigrateFlags(shardingClient), + Name: "shard", + Usage: "Start a sharding client", + ArgsUsage: "[endpoint]", + Category: "SHARDING COMMANDS", + Description: "TODO(prestonvanloon)- Add sharding client description", + } +) + +func shardingClient(ctx *cli.Context) error { + log.Info("hello world!") + c := sharding.MakeShardingClient(ctx) + if err := c.Start(); err != nil { + return err + } + c.Wait() + return nil +} diff --git a/sharding/client.go b/sharding/client.go new file mode 100644 index 000000000..2392bf63b --- /dev/null +++ b/sharding/client.go @@ -0,0 +1,29 @@ +package sharding + +import ( + "github.com/ethereum/go-ethereum/log" + cli "gopkg.in/urfave/cli.v1" +) + +type Client struct { +} + +func MakeShardingClient(ctx *cli.Context) *Client { + // TODO: Setup client + return &Client{} +} + +func (c *Client) Start() error { + log.Info("Starting sharding client") + // TODO: Dial to RPC + // TODO: Verify VMC + if err := c.verifyVMC(); err != nil { + return err + } + + return nil +} + +func (c *Client) Wait() { + // TODO: Blocking lock +} diff --git a/sharding/config.go b/sharding/config.go new file mode 100644 index 000000000..cc04c3cd8 --- /dev/null +++ b/sharding/config.go @@ -0,0 +1,18 @@ +package sharding + +import "math/big" + +var ( + // Number of network shards + shardCount = 100 + // Address of the validator management contract + validatorManagerAddress = "" // TODO + // Gas limit for verifying signatures + sigGasLimit = 40000 + // Number of blocks in a period + periodLength = 5 + // Number of periods to lookahead for ??? TODO(prestonvanloon) finish this comment. + lookaheadPeriods = 4 + // Required deposit size in wei + depositSize = new(big.Int).Exp(big.NewInt(10), big.NewInt(20), nil) // 100 ETH +) diff --git a/sharding/config_test.go b/sharding/config_test.go new file mode 100644 index 000000000..746ea5948 --- /dev/null +++ b/sharding/config_test.go @@ -0,0 +1,16 @@ +package sharding + +import ( + "math/big" + "testing" +) + +func TestDepositSize(t *testing.T) { + want, err := new(big.Int).SetString("100000000000000000000", 10) // 100 ETH + if !err { + t.Fatalf("Failed to setup test") + } + if depositSize.Cmp(want) != 0 { + t.Errorf("depositSize incorrect. Wanted %d, got %d", want, depositSize) + } +} diff --git a/sharding/vmc.go b/sharding/vmc.go new file mode 100644 index 000000000..a40373ad2 --- /dev/null +++ b/sharding/vmc.go @@ -0,0 +1,8 @@ +package sharding + +func (c *Client) verifyVMC() error { + // TODO: Fetch validator manager contract. + // TODO: Assert that the contract contents/ABI are as expected. + // TODO: Upload VMC if does not exist. + return nil +}