package node import ( "fmt" "log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/sharding" "github.com/ethereum/go-ethereum/sharding/mainchain" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/sharding/params" "github.com/ethereum/go-ethereum/sharding/txpool" cli "gopkg.in/urfave/cli.v1" ) // ShardEthereum is a service that is registered and started when geth is launched. // it contains APIs and fields that handle the different components of the sharded // Ethereum network. type ShardEthereum struct { shardConfig *params.ShardConfig // Holds necessary information to configure shards. txPool *txpool.ShardTxPool // Defines the sharding-specific txpool. To be designed. actor sharding.ShardingActor // Either notary, proposer, or observer. shardChainDb ethdb.Database // Access to the persistent db to store shard data. eventFeed *event.Feed // Used to enable P2P related interactions via different sharding actors. smcClient *mainchain.SMCClient // Provides bindings to the SMC deployed on the Ethereum mainchain. } // New creates a new sharding-enabled Ethereum instance. This is called in the main // geth sharding entrypoint. func New(ctx *cli.Context) (*ShardEthereum, error) { shardEthereum := &ShardEthereum{} path := node.DefaultDataDir() if ctx.GlobalIsSet(utils.DataDirFlag.Name) { path = ctx.GlobalString(utils.DataDirFlag.Name) } endpoint := ctx.Args().First() if endpoint == "" { endpoint = fmt.Sprintf("%s/%s.ipc", path, mainchain.ClientIdentifier) } if ctx.GlobalIsSet(utils.IPCPathFlag.Name) { endpoint = ctx.GlobalString(utils.IPCPathFlag.Name) } passwordFile := ctx.GlobalString(utils.PasswordFileFlag.Name) depositFlag := ctx.GlobalBool(utils.DepositFlag.Name) smcClient, err := mainchain.NewSMCClient(endpoint, path, depositFlag, passwordFile) if err != nil { return nil, err } shardEthereum.smcClient = smcClient if err := shardEthereum.registerShardingServices(); err != nil { return nil, err } return shardEthereum, nil } // Start the ShardEthereum service and kicks off the p2p and actor's main loop. func (s *ShardEthereum) Start() error { log.Println("Starting sharding service") if err := s.actor.Start(); err != nil { return err } defer s.actor.Stop() // TODO: start p2p and other relevant services. return nil } // Close handles graceful shutdown of the system. func (s *ShardEthereum) Close() error { return nil } func (s *ShardEthereum) registerShardingServices() error { return nil }