diff --git a/Makefile b/Makefile index e5017e4..16721c5 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,12 @@ GOBIN = ./build/bin GO ?= latest GORUN = go run +GIT_COMMIT := $(shell git rev-parse HEAD) +GIT_DATE := $(shell git log -1 --format=%ci | cut -d ' ' -f 1) + #? shisui: Build shisui shisui: - go build ./cmd/shisui/main.go + go build -ldflags "-X github.com/optimism-java/shisui2/internal/version.gitCommit=$(GIT_COMMIT) -X github.com/optimism-java/shisui2/internal/version.gitDate=$(GIT_DATE)" ./cmd/shisui/main.go mkdir -p $(GOBIN) mv main $(GOBIN)/shisui @echo "Done building." diff --git a/cmd/shisui/main.go b/cmd/shisui/main.go index c162831..c884619 100644 --- a/cmd/shisui/main.go +++ b/cmd/shisui/main.go @@ -32,10 +32,10 @@ import ( "github.com/mattn/go-isatty" _ "github.com/mattn/go-sqlite3" "github.com/optimism-java/shisui2/beacon" - "github.com/optimism-java/shisui2/debug" "github.com/optimism-java/shisui2/ethapi" - "github.com/optimism-java/shisui2/flags" "github.com/optimism-java/shisui2/history" + "github.com/optimism-java/shisui2/internal/debug" + "github.com/optimism-java/shisui2/internal/flags" "github.com/optimism-java/shisui2/portalwire" "github.com/optimism-java/shisui2/state" "github.com/optimism-java/shisui2/storage" diff --git a/cmd/shisui/utils/flags.go b/cmd/shisui/utils/flags.go new file mode 100644 index 0000000..4bb3f49 --- /dev/null +++ b/cmd/shisui/utils/flags.go @@ -0,0 +1,180 @@ +package utils + +import ( + "github.com/ethereum/go-ethereum/metrics" + "github.com/ethereum/go-ethereum/node" + "github.com/optimism-java/shisui2/internal/flags" + "github.com/optimism-java/shisui2/portalwire" + "github.com/urfave/cli/v2" +) + +var ( + // Metrics flags + MetricsEnabledFlag = &cli.BoolFlag{ + Name: "metrics", + Usage: "Enable metrics collection and reporting", + Category: flags.MetricsCategory, + } + // MetricsHTTPFlag defines the endpoint for a stand-alone metrics HTTP endpoint. + // Since the pprof service enables sensitive/vulnerable behavior, this allows a user + // to enable a public-OK metrics endpoint without having to worry about ALSO exposing + // other profiling behavior or information. + MetricsHTTPFlag = &cli.StringFlag{ + Name: "metrics.addr", + Usage: `Enable stand-alone metrics HTTP server listening interface.`, + Category: flags.MetricsCategory, + } + MetricsPortFlag = &cli.IntFlag{ + Name: "metrics.port", + Usage: `Metrics HTTP server listening port. +Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.`, + Value: metrics.DefaultConfig.Port, + Category: flags.MetricsCategory, + } + MetricsEnableInfluxDBFlag = &cli.BoolFlag{ + Name: "metrics.influxdb", + Usage: "Enable metrics export/push to an external InfluxDB database", + Category: flags.MetricsCategory, + } + MetricsInfluxDBEndpointFlag = &cli.StringFlag{ + Name: "metrics.influxdb.endpoint", + Usage: "InfluxDB API endpoint to report metrics to", + Value: metrics.DefaultConfig.InfluxDBEndpoint, + Category: flags.MetricsCategory, + } + MetricsInfluxDBDatabaseFlag = &cli.StringFlag{ + Name: "metrics.influxdb.database", + Usage: "InfluxDB database name to push reported metrics to", + Value: metrics.DefaultConfig.InfluxDBDatabase, + Category: flags.MetricsCategory, + } + MetricsInfluxDBUsernameFlag = &cli.StringFlag{ + Name: "metrics.influxdb.username", + Usage: "Username to authorize access to the database", + Value: metrics.DefaultConfig.InfluxDBUsername, + Category: flags.MetricsCategory, + } + MetricsInfluxDBPasswordFlag = &cli.StringFlag{ + Name: "metrics.influxdb.password", + Usage: "Password to authorize access to the database", + Value: metrics.DefaultConfig.InfluxDBPassword, + Category: flags.MetricsCategory, + } + // Tags are part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB. + // For example `host` tag could be used so that we can group all nodes and average a measurement + // across all of them, but also so that we can select a specific node and inspect its measurements. + // https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key + MetricsInfluxDBTagsFlag = &cli.StringFlag{ + Name: "metrics.influxdb.tags", + Usage: "Comma-separated InfluxDB tags (key/values) attached to all measurements", + Value: metrics.DefaultConfig.InfluxDBTags, + Category: flags.MetricsCategory, + } + + MetricsEnableInfluxDBV2Flag = &cli.BoolFlag{ + Name: "metrics.influxdbv2", + Usage: "Enable metrics export/push to an external InfluxDB v2 database", + Category: flags.MetricsCategory, + } + + MetricsInfluxDBTokenFlag = &cli.StringFlag{ + Name: "metrics.influxdb.token", + Usage: "Token to authorize access to the database (v2 only)", + Value: metrics.DefaultConfig.InfluxDBToken, + Category: flags.MetricsCategory, + } + + MetricsInfluxDBBucketFlag = &cli.StringFlag{ + Name: "metrics.influxdb.bucket", + Usage: "InfluxDB bucket name to push reported metrics to (v2 only)", + Value: metrics.DefaultConfig.InfluxDBBucket, + Category: flags.MetricsCategory, + } + + MetricsInfluxDBOrganizationFlag = &cli.StringFlag{ + Name: "metrics.influxdb.organization", + Usage: "InfluxDB organization name (v2 only)", + Value: metrics.DefaultConfig.InfluxDBOrganization, + Category: flags.MetricsCategory, + } + + PortalRPCListenAddrFlag = &cli.StringFlag{ + Name: "rpc.addr", + Usage: "HTTP-RPC server listening interface", + Category: flags.PortalNetworkCategory, + } + + PortalRPCPortFlag = &cli.IntFlag{ + Name: "rpc.port", + Usage: "HTTP-RPC server listening port", + Value: node.DefaultHTTPPort, + Category: flags.PortalNetworkCategory, + } + + PortalDataDirFlag = &cli.StringFlag{ + Name: "data.dir", + Usage: "Data dir of where the data file located", + Value: "./", + Category: flags.PortalNetworkCategory, + } + + PortalDataCapacityFlag = &cli.Uint64Flag{ + Name: "data.capacity", + Usage: "The capacity of the data stored, the unit is MB", + Value: 1000 * 10, // 10 GB + Category: flags.PortalNetworkCategory, + } + + PortalNATFlag = &cli.StringFlag{ + Name: "nat", + Usage: "NAT port mapping mechanism (any|none|upnp|pmp|stun|pmp:|extip:|stun:)", + Value: "any", + Category: flags.PortalNetworkCategory, + } + + PortalUDPListenAddrFlag = &cli.StringFlag{ + Name: "udp.addr", + Usage: "Protocol UDP server listening interface", + Value: "", + Category: flags.PortalNetworkCategory, + } + + PortalUDPPortFlag = &cli.IntFlag{ + Name: "udp.port", + Usage: "Protocol UDP server listening port", + Value: node.DefaultUDPPort, + Category: flags.PortalNetworkCategory, + } + + PortalLogLevelFlag = &cli.IntFlag{ + Name: "loglevel", + Usage: "Loglevel of portal network", + Value: node.DefaultLoglevel, + Category: flags.PortalNetworkCategory, + } + + PortalLogFormatFlag = &cli.StringFlag{ + Name: "logformat", + Usage: "Log format to use (json|logfmt|terminal)", + Category: flags.PortalNetworkCategory, + } + + PortalPrivateKeyFlag = &cli.StringFlag{ + Name: "private.key", + Usage: "Private key of p2p node, hex format without 0x prifix", + Category: flags.PortalNetworkCategory, + } + + PortalBootNodesFlag = &cli.StringFlag{ + Name: "bootnodes", + Usage: "Comma separated enode URLs for P2P discovery bootstrap", + Category: flags.PortalNetworkCategory, + } + + PortalNetworksFlag = &cli.StringSliceFlag{ + Name: "networks", + Usage: "Portal sub networks: history, beacon, state", + Category: flags.PortalNetworkCategory, + Value: cli.NewStringSlice(portalwire.History.Name()), + } +) diff --git a/debug/api.go b/internal/debug/api.go similarity index 100% rename from debug/api.go rename to internal/debug/api.go diff --git a/debug/flags.go b/internal/debug/flags.go similarity index 99% rename from debug/flags.go rename to internal/debug/flags.go index 3d95e6c..552b881 100644 --- a/debug/flags.go +++ b/internal/debug/flags.go @@ -37,7 +37,7 @@ import ( "github.com/ethereum/go-ethereum/metrics/exp" "github.com/mattn/go-colorable" "github.com/mattn/go-isatty" - "github.com/optimism-java/shisui2/flags" + "github.com/optimism-java/shisui2/internal/flags" "github.com/urfave/cli/v2" "gopkg.in/natefinch/lumberjack.v2" ) diff --git a/debug/loudpanic.go b/internal/debug/loudpanic.go similarity index 100% rename from debug/loudpanic.go rename to internal/debug/loudpanic.go diff --git a/debug/trace.go b/internal/debug/trace.go similarity index 100% rename from debug/trace.go rename to internal/debug/trace.go diff --git a/flags/categories.go b/internal/flags/categories.go similarity index 70% rename from flags/categories.go rename to internal/flags/categories.go index 21b0b7a..e2e5058 100644 --- a/flags/categories.go +++ b/internal/flags/categories.go @@ -24,24 +24,10 @@ package flags import "github.com/urfave/cli/v2" const ( - EthCategory = "ETHEREUM" - BeaconCategory = "BEACON CHAIN" - DevCategory = "DEVELOPER CHAIN" - StateCategory = "STATE HISTORY MANAGEMENT" - TxPoolCategory = "TRANSACTION POOL (EVM)" - BlobPoolCategory = "TRANSACTION POOL (BLOB)" - PerfCategory = "PERFORMANCE TUNING" - AccountCategory = "ACCOUNT" - APICategory = "API AND CONSOLE" - NetworkingCategory = "NETWORKING" - MinerCategory = "MINER" - GasPriceCategory = "GAS PRICE ORACLE" - VMCategory = "VIRTUAL MACHINE" LoggingCategory = "LOGGING AND DEBUGGING" MetricsCategory = "METRICS AND STATS" MiscCategory = "MISC" TestingCategory = "TESTING" - DeprecatedCategory = "ALIASED (deprecated)" PortalNetworkCategory = "PORTAL NETWORK" ) diff --git a/flags/flags.go b/internal/flags/flags.go similarity index 100% rename from flags/flags.go rename to internal/flags/flags.go diff --git a/flags/flags_test.go b/internal/flags/flags_test.go similarity index 100% rename from flags/flags_test.go rename to internal/flags/flags_test.go diff --git a/flags/helpers.go b/internal/flags/helpers.go similarity index 92% rename from flags/helpers.go rename to internal/flags/helpers.go index 5dd1144..e135706 100644 --- a/flags/helpers.go +++ b/internal/flags/helpers.go @@ -24,13 +24,12 @@ package flags import ( "fmt" "os" - "regexp" "sort" "strings" "github.com/ethereum/go-ethereum/log" "github.com/mattn/go-isatty" - "github.com/optimism-java/shisui2/version" + "github.com/optimism-java/shisui2/internal/version" "github.com/urfave/cli/v2" ) @@ -141,14 +140,6 @@ func doMigrateFlags(ctx *cli.Context) { } func init() { - if usecolor { - // Annotate all help categories with colors - cli.AppHelpTemplate = regexp.MustCompile("[A-Z ]+:").ReplaceAllString(cli.AppHelpTemplate, "\u001B[33m$0\u001B[0m") - - // Annotate flag categories with colors (private template, so need to - // copy-paste the entire thing here...) - cli.AppHelpTemplate = strings.ReplaceAll(cli.AppHelpTemplate, "{{template \"visibleFlagCategoryTemplate\" .}}", "{{range .VisibleFlagCategories}}\n {{if .Name}}\u001B[33m{{.Name}}\u001B[0m\n\n {{end}}{{$flglen := len .Flags}}{{range $i, $e := .Flags}}{{if eq (subtract $flglen $i) 1}}{{$e}}\n{{else}}{{$e}}\n {{end}}{{end}}{{end}}") - } cli.FlagStringer = FlagString } diff --git a/version/vcs.go b/internal/version/vcs.go similarity index 97% rename from version/vcs.go rename to internal/version/vcs.go index 0bdbcb2..2e461a7 100644 --- a/version/vcs.go +++ b/internal/version/vcs.go @@ -22,6 +22,7 @@ package version import ( + "fmt" "runtime/debug" "time" ) @@ -46,6 +47,9 @@ type VCSInfo struct { // VCS returns version control information of the current executable. func VCS() (VCSInfo, bool) { + fmt.Println("vcs") + fmt.Println(gitCommit) + fmt.Println(gitDate) if gitCommit != "" { // Use information set by the build script if present. return VCSInfo{Commit: gitCommit, Date: gitDate}, true diff --git a/version/version.go b/internal/version/version.go similarity index 100% rename from version/version.go rename to internal/version/version.go diff --git a/web3/api.go b/web3/api.go index 3ef68ea..022e18e 100644 --- a/web3/api.go +++ b/web3/api.go @@ -1,13 +1,19 @@ package web3 -import "runtime" +import ( + "runtime" + + "github.com/optimism-java/shisui2/internal/version" +) type API struct{} func (p *API) ClientVersion() string { // TODO add version + info, _ := version.VCS() name := "Shisui" name += "/" + runtime.GOOS + "-" + runtime.GOARCH name += "/" + runtime.Version() + name += "/" + info.Commit + "/" + info.Date return name }