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"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/status-im/status-go/geth"
|
|
||||||
"github.com/status-im/status-go/geth/params"
|
"github.com/status-im/status-go/geth/params"
|
||||||
"gopkg.in/urfave/cli.v1"
|
"gopkg.in/urfave/cli.v1"
|
||||||
)
|
)
|
||||||
|
@ -34,26 +33,15 @@ var (
|
||||||
// NetworkIDFlag defines network ID
|
// NetworkIDFlag defines network ID
|
||||||
NetworkIDFlag = cli.IntFlag{
|
NetworkIDFlag = cli.IntFlag{
|
||||||
Name: "networkid",
|
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,
|
Value: params.TestNetworkID,
|
||||||
}
|
}
|
||||||
|
|
||||||
// LightEthEnabledFlag flags whether LES is enabled or not
|
// BootClusterConfigFileFlag allows to switch boot cluster nodes
|
||||||
LightEthEnabledFlag = cli.BoolFlag{
|
BootClusterConfigFileFlag = cli.StringFlag{
|
||||||
Name: "les",
|
Name: "bootcluster",
|
||||||
Usage: "LES protocol enabled",
|
Usage: "Boot cluster config file",
|
||||||
}
|
Value: params.BootClusterConfigFile,
|
||||||
|
|
||||||
// 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",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTPEnabledFlag defines whether HTTP RPC endpoint should be opened or not
|
// HTTPEnabledFlag defines whether HTTP RPC endpoint should be opened or not
|
||||||
|
@ -85,24 +73,19 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// setup the app
|
// setup the app
|
||||||
app.Action = statusd
|
app.Action = cli.ShowAppHelp
|
||||||
app.HideVersion = true // separate command prints version
|
app.HideVersion = true // separate command prints version
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
versionCommand,
|
versionCommand,
|
||||||
|
faucetCommand,
|
||||||
wnodeCommand,
|
wnodeCommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
NodeKeyFileFlag,
|
NodeKeyFileFlag,
|
||||||
DataDirFlag,
|
DataDirFlag,
|
||||||
NetworkIDFlag,
|
NetworkIDFlag,
|
||||||
LightEthEnabledFlag,
|
|
||||||
WhisperEnabledFlag,
|
|
||||||
SwarmEnabledFlag,
|
|
||||||
HTTPEnabledFlag,
|
|
||||||
HTTPPortFlag,
|
|
||||||
IPCEnabledFlag,
|
|
||||||
LogLevelFlag,
|
LogLevelFlag,
|
||||||
|
BootClusterConfigFileFlag,
|
||||||
}
|
}
|
||||||
app.Before = func(ctx *cli.Context) error {
|
app.Before = func(ctx *cli.Context) error {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
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.
|
// makeApp creates an app with sane defaults.
|
||||||
func makeApp(gitCommit string) *cli.App {
|
func makeApp(gitCommit string) *cli.App {
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
|
@ -174,6 +114,34 @@ func makeApp(gitCommit string) *cli.App {
|
||||||
if gitCommit != "" {
|
if gitCommit != "" {
|
||||||
app.Version += "-" + gitCommit[:8]
|
app.Version += "-" + gitCommit[:8]
|
||||||
}
|
}
|
||||||
app.Usage = "Status CLI"
|
app.Usage = "CLI for Status nodes management"
|
||||||
return app
|
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 (
|
var (
|
||||||
versionCommand = cli.Command{
|
versionCommand = cli.Command{
|
||||||
Action: version,
|
Action: versionCommandHandler,
|
||||||
Name: "version",
|
Name: "version",
|
||||||
Usage: "Print app version",
|
Usage: "Print app version",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// version displays app version
|
// versionCommandHandler displays app version
|
||||||
func version(ctx *cli.Context) error {
|
func versionCommandHandler(ctx *cli.Context) error {
|
||||||
fmt.Println(strings.Title(params.ClientIdentifier))
|
fmt.Println(strings.Title(params.ClientIdentifier))
|
||||||
fmt.Println("Version:", params.Version)
|
fmt.Println("Version:", params.Version)
|
||||||
if gitCommit != "" {
|
if gitCommit != "" {
|
||||||
|
@ -35,5 +35,7 @@ func version(ctx *cli.Context) error {
|
||||||
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
|
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
|
||||||
fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
|
fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
|
||||||
|
|
||||||
|
printNodeConfig(ctx)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -413,6 +413,11 @@ func (m *NodeManager) onNodeStarted() {
|
||||||
|
|
||||||
// PopulateStaticPeers connects current node with our publicly available LES/SHH/Swarm cluster
|
// PopulateStaticPeers connects current node with our publicly available LES/SHH/Swarm cluster
|
||||||
func (m *NodeManager) PopulateStaticPeers() {
|
func (m *NodeManager) PopulateStaticPeers() {
|
||||||
|
if !m.node.config.BootClusterConfig.Enabled {
|
||||||
|
log.Info("bootcluster is disabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
enodes, err := m.node.config.LoadBootClusterNodes()
|
enodes, err := m.node.config.LoadBootClusterNodes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("can not load boot nodes: %v", err)
|
Fatalf("can not load boot nodes: %v", err)
|
||||||
|
|
|
@ -235,6 +235,7 @@ func NewNodeConfig(dataDir string, networkID uint64) (*NodeConfig, error) {
|
||||||
DatabaseCache: DatabaseCache,
|
DatabaseCache: DatabaseCache,
|
||||||
},
|
},
|
||||||
BootClusterConfig: &BootClusterConfig{
|
BootClusterConfig: &BootClusterConfig{
|
||||||
|
Enabled: true,
|
||||||
ConfigFile: BootClusterConfigFile,
|
ConfigFile: BootClusterConfigFile,
|
||||||
},
|
},
|
||||||
WhisperConfig: &WhisperConfig{
|
WhisperConfig: &WhisperConfig{
|
||||||
|
@ -365,6 +366,7 @@ func (c *NodeConfig) LoadBootClusterNodes() ([]string, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
filename := c.BootClusterConfig.ConfigFile
|
filename := c.BootClusterConfig.ConfigFile
|
||||||
|
log.Info("loading boot nodes", "source", filename)
|
||||||
if _, err = os.Stat(filename); os.IsNotExist(err) { // load from static resources
|
if _, err = os.Stat(filename); os.IsNotExist(err) { // load from static resources
|
||||||
configData, err = static.Asset("bootcluster/" + filename)
|
configData, err = static.Asset("bootcluster/" + filename)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
"LogLevel": "INFO",
|
"LogLevel": "INFO",
|
||||||
"LogToStderr": true,
|
"LogToStderr": true,
|
||||||
"BootClusterConfig": {
|
"BootClusterConfig": {
|
||||||
"Enabled": false,
|
"Enabled": true,
|
||||||
"ConfigFile": "ropsten.dev.json"
|
"ConfigFile": "ropsten.dev.json"
|
||||||
},
|
},
|
||||||
"LightEthConfig": {
|
"LightEthConfig": {
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
"LogLevel": "INFO",
|
"LogLevel": "INFO",
|
||||||
"LogToStderr": true,
|
"LogToStderr": true,
|
||||||
"BootClusterConfig": {
|
"BootClusterConfig": {
|
||||||
"Enabled": false,
|
"Enabled": true,
|
||||||
"ConfigFile": "ropsten.dev.json"
|
"ConfigFile": "ropsten.dev.json"
|
||||||
},
|
},
|
||||||
"LightEthConfig": {
|
"LightEthConfig": {
|
||||||
|
|
|
@ -97,7 +97,7 @@ func scriptsReadmeMd() (*asset, error) {
|
||||||
return nil, err
|
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}
|
a := &asset{bytes: bytes, info: info}
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ func scriptsWeb3Js() (*asset, error) {
|
||||||
return nil, err
|
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}
|
a := &asset{bytes: bytes, info: info}
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ func configLinter_exclude_listTxt() (*asset, error) {
|
||||||
return nil, err
|
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}
|
a := &asset{bytes: bytes, info: info}
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@ func keysFirebaseauthkey() (*asset, error) {
|
||||||
return nil, err
|
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}
|
a := &asset{bytes: bytes, info: info}
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
@ -357,7 +357,7 @@ func keysWnodekey() (*asset, error) {
|
||||||
return nil, err
|
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}
|
a := &asset{bytes: bytes, info: info}
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ func keysWnodepassword() (*asset, error) {
|
||||||
return nil, err
|
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}
|
a := &asset{bytes: bytes, info: info}
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue