cmd/statusd: faucet sub-command added, refs #159
This commit is contained in:
parent
9a7caa6b58
commit
88394690c2
|
@ -0,0 +1 @@
|
|||
*
|
|
@ -0,0 +1,15 @@
|
|||
FROM alpine:3.5
|
||||
|
||||
RUN \
|
||||
apk add --update go git make gcc musl-dev linux-headers ca-certificates && \
|
||||
git clone --depth 1 --branch feature/statusd-replaces-geth-on-cluster https://github.com/farazdagi/status-go && \
|
||||
(cd status-go && make) && \
|
||||
cp status-go/build/bin/statusd /statusd && \
|
||||
apk del go git make gcc musl-dev linux-headers && \
|
||||
rm -rf /status-go && rm -rf /var/cache/apk/*
|
||||
|
||||
EXPOSE 8545
|
||||
EXPOSE 30303
|
||||
EXPOSE 3001
|
||||
|
||||
ENTRYPOINT ["/statusd"]
|
|
@ -0,0 +1,62 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/status-im/status-go/geth"
|
||||
"github.com/status-im/status-go/geth/params"
|
||||
"gopkg.in/urfave/cli.v1"
|
||||
)
|
||||
|
||||
var (
|
||||
faucetCommand = cli.Command{
|
||||
Action: faucetCommandHandler,
|
||||
Name: "faucet",
|
||||
Usage: "Starts faucet node (light node used by faucet service to request Ether)",
|
||||
Flags: []cli.Flag{
|
||||
HTTPPortFlag,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// faucetCommandHandler handles `statusd faucet` command
|
||||
func faucetCommandHandler(ctx *cli.Context) error {
|
||||
config, err := parseFaucetCommandConfig(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can not parse config: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("Starting Status Faucet node..")
|
||||
if err = geth.CreateAndRunNode(config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// wait till node has been stopped
|
||||
geth.NodeManagerInstance().Node().GethStack().Wait()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// parseFaucetCommandConfig parses incoming CLI options and returns node configuration object
|
||||
func parseFaucetCommandConfig(ctx *cli.Context) (*params.NodeConfig, error) {
|
||||
nodeConfig, err := makeNodeConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// select sub-protocols
|
||||
nodeConfig.LightEthConfig.Enabled = true
|
||||
nodeConfig.WhisperConfig.Enabled = false
|
||||
nodeConfig.SwarmConfig.Enabled = false
|
||||
|
||||
// RPC configuration
|
||||
nodeConfig.APIModules = "eth"
|
||||
nodeConfig.HTTPHost = "0.0.0.0" // allow to connect from anywhere
|
||||
nodeConfig.HTTPPort = ctx.Int(HTTPPortFlag.Name)
|
||||
|
||||
// extra options
|
||||
nodeConfig.BootClusterConfig.Enabled = true
|
||||
nodeConfig.BootClusterConfig.ConfigFile = ctx.GlobalString(BootClusterConfigFileFlag.Name)
|
||||
|
||||
return nodeConfig, nil
|
||||
}
|
|
@ -6,7 +6,6 @@ import (
|
|||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/status-im/status-go/geth"
|
||||
"github.com/status-im/status-go/geth/params"
|
||||
"gopkg.in/urfave/cli.v1"
|
||||
)
|
||||
|
@ -34,26 +33,15 @@ var (
|
|||
// NetworkIDFlag defines network ID
|
||||
NetworkIDFlag = cli.IntFlag{
|
||||
Name: "networkid",
|
||||
Usage: "Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten)",
|
||||
Usage: "Network identifier (integer, 1=Homestead, 3=Ropsten, 4=Rinkeby)",
|
||||
Value: params.TestNetworkID,
|
||||
}
|
||||
|
||||
// LightEthEnabledFlag flags whether LES is enabled or not
|
||||
LightEthEnabledFlag = cli.BoolFlag{
|
||||
Name: "les",
|
||||
Usage: "LES protocol enabled",
|
||||
}
|
||||
|
||||
// WhisperEnabledFlag flags whether Whisper is enabled or not
|
||||
WhisperEnabledFlag = cli.BoolFlag{
|
||||
Name: "shh",
|
||||
Usage: "SHH protocol enabled",
|
||||
}
|
||||
|
||||
// SwarmEnabledFlag flags whether Swarm is enabled or not
|
||||
SwarmEnabledFlag = cli.BoolFlag{
|
||||
Name: "swarm",
|
||||
Usage: "Swarm protocol enabled",
|
||||
// BootClusterConfigFileFlag allows to switch boot cluster nodes
|
||||
BootClusterConfigFileFlag = cli.StringFlag{
|
||||
Name: "bootcluster",
|
||||
Usage: "Boot cluster config file",
|
||||
Value: params.BootClusterConfigFile,
|
||||
}
|
||||
|
||||
// HTTPEnabledFlag defines whether HTTP RPC endpoint should be opened or not
|
||||
|
@ -85,24 +73,19 @@ var (
|
|||
|
||||
func init() {
|
||||
// setup the app
|
||||
app.Action = statusd
|
||||
app.Action = cli.ShowAppHelp
|
||||
app.HideVersion = true // separate command prints version
|
||||
app.Commands = []cli.Command{
|
||||
versionCommand,
|
||||
faucetCommand,
|
||||
wnodeCommand,
|
||||
}
|
||||
|
||||
app.Flags = []cli.Flag{
|
||||
NodeKeyFileFlag,
|
||||
DataDirFlag,
|
||||
NetworkIDFlag,
|
||||
LightEthEnabledFlag,
|
||||
WhisperEnabledFlag,
|
||||
SwarmEnabledFlag,
|
||||
HTTPEnabledFlag,
|
||||
HTTPPortFlag,
|
||||
IPCEnabledFlag,
|
||||
LogLevelFlag,
|
||||
BootClusterConfigFileFlag,
|
||||
}
|
||||
app.Before = func(ctx *cli.Context) error {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
@ -120,49 +103,6 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
// statusd runs Status node
|
||||
func statusd(ctx *cli.Context) error {
|
||||
config, err := makeNodeConfig(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "can not parse config: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := geth.CreateAndRunNode(config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// wait till node has been stopped
|
||||
geth.NodeManagerInstance().Node().GethStack().Wait()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// makeNodeConfig parses incoming CLI options and returns node configuration object
|
||||
func makeNodeConfig(ctx *cli.Context) (*params.NodeConfig, error) {
|
||||
nodeConfig, err := params.NewNodeConfig(ctx.GlobalString(DataDirFlag.Name), ctx.GlobalUint64(NetworkIDFlag.Name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nodeConfig.NodeKeyFile = ctx.GlobalString(NodeKeyFileFlag.Name)
|
||||
if !ctx.GlobalBool(HTTPEnabledFlag.Name) {
|
||||
nodeConfig.HTTPHost = "" // HTTP RPC is disabled
|
||||
}
|
||||
nodeConfig.IPCEnabled = ctx.GlobalBool(IPCEnabledFlag.Name)
|
||||
nodeConfig.LightEthConfig.Enabled = ctx.GlobalBool(LightEthEnabledFlag.Name)
|
||||
nodeConfig.WhisperConfig.Enabled = ctx.GlobalBool(WhisperEnabledFlag.Name)
|
||||
nodeConfig.SwarmConfig.Enabled = ctx.GlobalBool(SwarmEnabledFlag.Name)
|
||||
nodeConfig.HTTPPort = ctx.GlobalInt(HTTPPortFlag.Name)
|
||||
|
||||
if logLevel := ctx.GlobalString(LogLevelFlag.Name); len(logLevel) > 0 {
|
||||
nodeConfig.LogEnabled = true
|
||||
nodeConfig.LogLevel = logLevel
|
||||
}
|
||||
|
||||
return nodeConfig, nil
|
||||
}
|
||||
|
||||
// makeApp creates an app with sane defaults.
|
||||
func makeApp(gitCommit string) *cli.App {
|
||||
app := cli.NewApp()
|
||||
|
@ -174,6 +114,34 @@ func makeApp(gitCommit string) *cli.App {
|
|||
if gitCommit != "" {
|
||||
app.Version += "-" + gitCommit[:8]
|
||||
}
|
||||
app.Usage = "Status CLI"
|
||||
app.Usage = "CLI for Status nodes management"
|
||||
return app
|
||||
}
|
||||
|
||||
// makeNodeConfig parses incoming CLI options and returns node configuration object
|
||||
func makeNodeConfig(ctx *cli.Context) (*params.NodeConfig, error) {
|
||||
nodeConfig, err := params.NewNodeConfig(ctx.GlobalString(DataDirFlag.Name), ctx.GlobalUint64(NetworkIDFlag.Name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nodeConfig.NodeKeyFile = ctx.GlobalString(NodeKeyFileFlag.Name)
|
||||
|
||||
if logLevel := ctx.GlobalString(LogLevelFlag.Name); len(logLevel) > 0 {
|
||||
nodeConfig.LogEnabled = true
|
||||
nodeConfig.LogLevel = logLevel
|
||||
}
|
||||
|
||||
return nodeConfig, nil
|
||||
}
|
||||
|
||||
// printNodeConfig prints node config
|
||||
func printNodeConfig(ctx *cli.Context) {
|
||||
nodeConfig, err := makeNodeConfig(ctx)
|
||||
if err != nil {
|
||||
fmt.Printf("Loaded Config: failed (err: %v)", err)
|
||||
return
|
||||
}
|
||||
nodeConfig.LightEthConfig.Genesis = "SKIP"
|
||||
fmt.Println("Loaded Config: ", nodeConfig)
|
||||
}
|
||||
|
|
|
@ -12,14 +12,14 @@ import (
|
|||
|
||||
var (
|
||||
versionCommand = cli.Command{
|
||||
Action: version,
|
||||
Action: versionCommandHandler,
|
||||
Name: "version",
|
||||
Usage: "Print app version",
|
||||
}
|
||||
)
|
||||
|
||||
// version displays app version
|
||||
func version(ctx *cli.Context) error {
|
||||
// versionCommandHandler displays app version
|
||||
func versionCommandHandler(ctx *cli.Context) error {
|
||||
fmt.Println(strings.Title(params.ClientIdentifier))
|
||||
fmt.Println("Version:", params.Version)
|
||||
if gitCommit != "" {
|
||||
|
@ -35,5 +35,7 @@ func version(ctx *cli.Context) error {
|
|||
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
|
||||
fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
|
||||
|
||||
printNodeConfig(ctx)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -413,6 +413,11 @@ func (m *NodeManager) onNodeStarted() {
|
|||
|
||||
// PopulateStaticPeers connects current node with our publicly available LES/SHH/Swarm cluster
|
||||
func (m *NodeManager) PopulateStaticPeers() {
|
||||
if !m.node.config.BootClusterConfig.Enabled {
|
||||
log.Info("bootcluster is disabled")
|
||||
return
|
||||
}
|
||||
|
||||
enodes, err := m.node.config.LoadBootClusterNodes()
|
||||
if err != nil {
|
||||
Fatalf("can not load boot nodes: %v", err)
|
||||
|
|
|
@ -235,6 +235,7 @@ func NewNodeConfig(dataDir string, networkID uint64) (*NodeConfig, error) {
|
|||
DatabaseCache: DatabaseCache,
|
||||
},
|
||||
BootClusterConfig: &BootClusterConfig{
|
||||
Enabled: true,
|
||||
ConfigFile: BootClusterConfigFile,
|
||||
},
|
||||
WhisperConfig: &WhisperConfig{
|
||||
|
@ -365,6 +366,7 @@ func (c *NodeConfig) LoadBootClusterNodes() ([]string, error) {
|
|||
var err error
|
||||
|
||||
filename := c.BootClusterConfig.ConfigFile
|
||||
log.Info("loading boot nodes", "source", filename)
|
||||
if _, err = os.Stat(filename); os.IsNotExist(err) { // load from static resources
|
||||
configData, err = static.Asset("bootcluster/" + filename)
|
||||
} else {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
"LogLevel": "INFO",
|
||||
"LogToStderr": true,
|
||||
"BootClusterConfig": {
|
||||
"Enabled": false,
|
||||
"Enabled": true,
|
||||
"ConfigFile": "ropsten.dev.json"
|
||||
},
|
||||
"LightEthConfig": {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
"LogLevel": "INFO",
|
||||
"LogToStderr": true,
|
||||
"BootClusterConfig": {
|
||||
"Enabled": false,
|
||||
"Enabled": true,
|
||||
"ConfigFile": "ropsten.dev.json"
|
||||
},
|
||||
"LightEthConfig": {
|
||||
|
|
|
@ -97,7 +97,7 @@ func scriptsReadmeMd() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "scripts/README.md", size: 133, mode: os.FileMode(420), modTime: time.Unix(1494793924, 0)}
|
||||
info := bindataFileInfo{name: "scripts/README.md", size: 133, mode: os.FileMode(420), modTime: time.Unix(1494795629, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ func scriptsWeb3Js() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "scripts/web3.js", size: 496165, mode: os.FileMode(420), modTime: time.Unix(1494794103, 0)}
|
||||
info := bindataFileInfo{name: "scripts/web3.js", size: 496165, mode: os.FileMode(420), modTime: time.Unix(1494795674, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ func configLinter_exclude_listTxt() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "config/linter_exclude_list.txt", size: 2258, mode: os.FileMode(420), modTime: time.Unix(1494793924, 0)}
|
||||
info := bindataFileInfo{name: "config/linter_exclude_list.txt", size: 2258, mode: os.FileMode(420), modTime: time.Unix(1494795629, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ func keysFirebaseauthkey() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "keys/firebaseauthkey", size: 153, mode: os.FileMode(420), modTime: time.Unix(1494793924, 0)}
|
||||
info := bindataFileInfo{name: "keys/firebaseauthkey", size: 153, mode: os.FileMode(420), modTime: time.Unix(1494795629, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ func keysWnodekey() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "keys/wnodekey", size: 65, mode: os.FileMode(420), modTime: time.Unix(1494793924, 0)}
|
||||
info := bindataFileInfo{name: "keys/wnodekey", size: 65, mode: os.FileMode(420), modTime: time.Unix(1494795629, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ func keysWnodepassword() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "keys/wnodepassword", size: 9, mode: os.FileMode(420), modTime: time.Unix(1494793924, 0)}
|
||||
info := bindataFileInfo{name: "keys/wnodepassword", size: 9, mode: os.FileMode(420), modTime: time.Unix(1494795629, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue