Skip to content

Commit dbb9004

Browse files
authored
Merge pull request #1 from optimism-java/flags
feat: add git commit and do some refactor
2 parents 99ca45c + db164d7 commit dbb9004

File tree

14 files changed

+199
-29
lines changed

14 files changed

+199
-29
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ GOBIN = ./build/bin
88
GO ?= latest
99
GORUN = go run
1010

11+
GIT_COMMIT := $(shell git rev-parse HEAD)
12+
GIT_DATE := $(shell git log -1 --format=%ci | cut -d ' ' -f 1)
13+
1114
#? shisui: Build shisui
1215
shisui:
13-
go build ./cmd/shisui/main.go
16+
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
1417
mkdir -p $(GOBIN)
1518
mv main $(GOBIN)/shisui
1619
@echo "Done building."

cmd/shisui/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ import (
3232
"github.com/mattn/go-isatty"
3333
_ "github.com/mattn/go-sqlite3"
3434
"github.com/optimism-java/shisui2/beacon"
35-
"github.com/optimism-java/shisui2/debug"
3635
"github.com/optimism-java/shisui2/ethapi"
37-
"github.com/optimism-java/shisui2/flags"
3836
"github.com/optimism-java/shisui2/history"
37+
"github.com/optimism-java/shisui2/internal/debug"
38+
"github.com/optimism-java/shisui2/internal/flags"
3939
"github.com/optimism-java/shisui2/portalwire"
4040
"github.com/optimism-java/shisui2/state"
4141
"github.com/optimism-java/shisui2/storage"

cmd/shisui/utils/flags.go

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
package utils
2+
3+
import (
4+
"github.com/ethereum/go-ethereum/metrics"
5+
"github.com/ethereum/go-ethereum/node"
6+
"github.com/optimism-java/shisui2/internal/flags"
7+
"github.com/optimism-java/shisui2/portalwire"
8+
"github.com/urfave/cli/v2"
9+
)
10+
11+
var (
12+
// Metrics flags
13+
MetricsEnabledFlag = &cli.BoolFlag{
14+
Name: "metrics",
15+
Usage: "Enable metrics collection and reporting",
16+
Category: flags.MetricsCategory,
17+
}
18+
// MetricsHTTPFlag defines the endpoint for a stand-alone metrics HTTP endpoint.
19+
// Since the pprof service enables sensitive/vulnerable behavior, this allows a user
20+
// to enable a public-OK metrics endpoint without having to worry about ALSO exposing
21+
// other profiling behavior or information.
22+
MetricsHTTPFlag = &cli.StringFlag{
23+
Name: "metrics.addr",
24+
Usage: `Enable stand-alone metrics HTTP server listening interface.`,
25+
Category: flags.MetricsCategory,
26+
}
27+
MetricsPortFlag = &cli.IntFlag{
28+
Name: "metrics.port",
29+
Usage: `Metrics HTTP server listening port.
30+
Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.`,
31+
Value: metrics.DefaultConfig.Port,
32+
Category: flags.MetricsCategory,
33+
}
34+
MetricsEnableInfluxDBFlag = &cli.BoolFlag{
35+
Name: "metrics.influxdb",
36+
Usage: "Enable metrics export/push to an external InfluxDB database",
37+
Category: flags.MetricsCategory,
38+
}
39+
MetricsInfluxDBEndpointFlag = &cli.StringFlag{
40+
Name: "metrics.influxdb.endpoint",
41+
Usage: "InfluxDB API endpoint to report metrics to",
42+
Value: metrics.DefaultConfig.InfluxDBEndpoint,
43+
Category: flags.MetricsCategory,
44+
}
45+
MetricsInfluxDBDatabaseFlag = &cli.StringFlag{
46+
Name: "metrics.influxdb.database",
47+
Usage: "InfluxDB database name to push reported metrics to",
48+
Value: metrics.DefaultConfig.InfluxDBDatabase,
49+
Category: flags.MetricsCategory,
50+
}
51+
MetricsInfluxDBUsernameFlag = &cli.StringFlag{
52+
Name: "metrics.influxdb.username",
53+
Usage: "Username to authorize access to the database",
54+
Value: metrics.DefaultConfig.InfluxDBUsername,
55+
Category: flags.MetricsCategory,
56+
}
57+
MetricsInfluxDBPasswordFlag = &cli.StringFlag{
58+
Name: "metrics.influxdb.password",
59+
Usage: "Password to authorize access to the database",
60+
Value: metrics.DefaultConfig.InfluxDBPassword,
61+
Category: flags.MetricsCategory,
62+
}
63+
// Tags are part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB.
64+
// For example `host` tag could be used so that we can group all nodes and average a measurement
65+
// across all of them, but also so that we can select a specific node and inspect its measurements.
66+
// https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
67+
MetricsInfluxDBTagsFlag = &cli.StringFlag{
68+
Name: "metrics.influxdb.tags",
69+
Usage: "Comma-separated InfluxDB tags (key/values) attached to all measurements",
70+
Value: metrics.DefaultConfig.InfluxDBTags,
71+
Category: flags.MetricsCategory,
72+
}
73+
74+
MetricsEnableInfluxDBV2Flag = &cli.BoolFlag{
75+
Name: "metrics.influxdbv2",
76+
Usage: "Enable metrics export/push to an external InfluxDB v2 database",
77+
Category: flags.MetricsCategory,
78+
}
79+
80+
MetricsInfluxDBTokenFlag = &cli.StringFlag{
81+
Name: "metrics.influxdb.token",
82+
Usage: "Token to authorize access to the database (v2 only)",
83+
Value: metrics.DefaultConfig.InfluxDBToken,
84+
Category: flags.MetricsCategory,
85+
}
86+
87+
MetricsInfluxDBBucketFlag = &cli.StringFlag{
88+
Name: "metrics.influxdb.bucket",
89+
Usage: "InfluxDB bucket name to push reported metrics to (v2 only)",
90+
Value: metrics.DefaultConfig.InfluxDBBucket,
91+
Category: flags.MetricsCategory,
92+
}
93+
94+
MetricsInfluxDBOrganizationFlag = &cli.StringFlag{
95+
Name: "metrics.influxdb.organization",
96+
Usage: "InfluxDB organization name (v2 only)",
97+
Value: metrics.DefaultConfig.InfluxDBOrganization,
98+
Category: flags.MetricsCategory,
99+
}
100+
101+
PortalRPCListenAddrFlag = &cli.StringFlag{
102+
Name: "rpc.addr",
103+
Usage: "HTTP-RPC server listening interface",
104+
Category: flags.PortalNetworkCategory,
105+
}
106+
107+
PortalRPCPortFlag = &cli.IntFlag{
108+
Name: "rpc.port",
109+
Usage: "HTTP-RPC server listening port",
110+
Value: node.DefaultHTTPPort,
111+
Category: flags.PortalNetworkCategory,
112+
}
113+
114+
PortalDataDirFlag = &cli.StringFlag{
115+
Name: "data.dir",
116+
Usage: "Data dir of where the data file located",
117+
Value: "./",
118+
Category: flags.PortalNetworkCategory,
119+
}
120+
121+
PortalDataCapacityFlag = &cli.Uint64Flag{
122+
Name: "data.capacity",
123+
Usage: "The capacity of the data stored, the unit is MB",
124+
Value: 1000 * 10, // 10 GB
125+
Category: flags.PortalNetworkCategory,
126+
}
127+
128+
PortalNATFlag = &cli.StringFlag{
129+
Name: "nat",
130+
Usage: "NAT port mapping mechanism (any|none|upnp|pmp|stun|pmp:<IP>|extip:<IP>|stun:<IP>)",
131+
Value: "any",
132+
Category: flags.PortalNetworkCategory,
133+
}
134+
135+
PortalUDPListenAddrFlag = &cli.StringFlag{
136+
Name: "udp.addr",
137+
Usage: "Protocol UDP server listening interface",
138+
Value: "",
139+
Category: flags.PortalNetworkCategory,
140+
}
141+
142+
PortalUDPPortFlag = &cli.IntFlag{
143+
Name: "udp.port",
144+
Usage: "Protocol UDP server listening port",
145+
Value: node.DefaultUDPPort,
146+
Category: flags.PortalNetworkCategory,
147+
}
148+
149+
PortalLogLevelFlag = &cli.IntFlag{
150+
Name: "loglevel",
151+
Usage: "Loglevel of portal network",
152+
Value: node.DefaultLoglevel,
153+
Category: flags.PortalNetworkCategory,
154+
}
155+
156+
PortalLogFormatFlag = &cli.StringFlag{
157+
Name: "logformat",
158+
Usage: "Log format to use (json|logfmt|terminal)",
159+
Category: flags.PortalNetworkCategory,
160+
}
161+
162+
PortalPrivateKeyFlag = &cli.StringFlag{
163+
Name: "private.key",
164+
Usage: "Private key of p2p node, hex format without 0x prifix",
165+
Category: flags.PortalNetworkCategory,
166+
}
167+
168+
PortalBootNodesFlag = &cli.StringFlag{
169+
Name: "bootnodes",
170+
Usage: "Comma separated enode URLs for P2P discovery bootstrap",
171+
Category: flags.PortalNetworkCategory,
172+
}
173+
174+
PortalNetworksFlag = &cli.StringSliceFlag{
175+
Name: "networks",
176+
Usage: "Portal sub networks: history, beacon, state",
177+
Category: flags.PortalNetworkCategory,
178+
Value: cli.NewStringSlice(portalwire.History.Name()),
179+
}
180+
)
File renamed without changes.

debug/flags.go renamed to internal/debug/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
"github.com/ethereum/go-ethereum/metrics/exp"
3838
"github.com/mattn/go-colorable"
3939
"github.com/mattn/go-isatty"
40-
"github.com/optimism-java/shisui2/flags"
40+
"github.com/optimism-java/shisui2/internal/flags"
4141
"github.com/urfave/cli/v2"
4242
"gopkg.in/natefinch/lumberjack.v2"
4343
)
File renamed without changes.
File renamed without changes.

flags/categories.go renamed to internal/flags/categories.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,10 @@ package flags
2424
import "github.com/urfave/cli/v2"
2525

2626
const (
27-
EthCategory = "ETHEREUM"
28-
BeaconCategory = "BEACON CHAIN"
29-
DevCategory = "DEVELOPER CHAIN"
30-
StateCategory = "STATE HISTORY MANAGEMENT"
31-
TxPoolCategory = "TRANSACTION POOL (EVM)"
32-
BlobPoolCategory = "TRANSACTION POOL (BLOB)"
33-
PerfCategory = "PERFORMANCE TUNING"
34-
AccountCategory = "ACCOUNT"
35-
APICategory = "API AND CONSOLE"
36-
NetworkingCategory = "NETWORKING"
37-
MinerCategory = "MINER"
38-
GasPriceCategory = "GAS PRICE ORACLE"
39-
VMCategory = "VIRTUAL MACHINE"
4027
LoggingCategory = "LOGGING AND DEBUGGING"
4128
MetricsCategory = "METRICS AND STATS"
4229
MiscCategory = "MISC"
4330
TestingCategory = "TESTING"
44-
DeprecatedCategory = "ALIASED (deprecated)"
4531
PortalNetworkCategory = "PORTAL NETWORK"
4632
)
4733

File renamed without changes.
File renamed without changes.

flags/helpers.go renamed to internal/flags/helpers.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ package flags
2424
import (
2525
"fmt"
2626
"os"
27-
"regexp"
2827
"sort"
2928
"strings"
3029

3130
"github.com/ethereum/go-ethereum/log"
3231
"github.com/mattn/go-isatty"
33-
"github.com/optimism-java/shisui2/version"
32+
"github.com/optimism-java/shisui2/internal/version"
3433
"github.com/urfave/cli/v2"
3534
)
3635

@@ -141,14 +140,6 @@ func doMigrateFlags(ctx *cli.Context) {
141140
}
142141

143142
func init() {
144-
if usecolor {
145-
// Annotate all help categories with colors
146-
cli.AppHelpTemplate = regexp.MustCompile("[A-Z ]+:").ReplaceAllString(cli.AppHelpTemplate, "\u001B[33m$0\u001B[0m")
147-
148-
// Annotate flag categories with colors (private template, so need to
149-
// copy-paste the entire thing here...)
150-
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}}")
151-
}
152143
cli.FlagStringer = FlagString
153144
}
154145

version/vcs.go renamed to internal/version/vcs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package version
2323

2424
import (
25+
"fmt"
2526
"runtime/debug"
2627
"time"
2728
)
@@ -46,6 +47,9 @@ type VCSInfo struct {
4647

4748
// VCS returns version control information of the current executable.
4849
func VCS() (VCSInfo, bool) {
50+
fmt.Println("vcs")
51+
fmt.Println(gitCommit)
52+
fmt.Println(gitDate)
4953
if gitCommit != "" {
5054
// Use information set by the build script if present.
5155
return VCSInfo{Commit: gitCommit, Date: gitDate}, true
File renamed without changes.

web3/api.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package web3
22

3-
import "runtime"
3+
import (
4+
"runtime"
5+
6+
"github.com/optimism-java/shisui2/internal/version"
7+
)
48

59
type API struct{}
610

711
func (p *API) ClientVersion() string {
812
// TODO add version
13+
info, _ := version.VCS()
914
name := "Shisui"
1015
name += "/" + runtime.GOOS + "-" + runtime.GOARCH
1116
name += "/" + runtime.Version()
17+
name += "/" + info.Commit + "/" + info.Date
1218
return name
1319
}

0 commit comments

Comments
 (0)