Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add git commit and do some refactor #1

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions cmd/shisui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
180 changes: 180 additions & 0 deletions cmd/shisui/utils/flags.go
Original file line number Diff line number Diff line change
@@ -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:<IP>|extip:<IP>|stun:<IP>)",
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()),
}
)
File renamed without changes.
2 changes: 1 addition & 1 deletion debug/flags.go → internal/debug/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 0 additions & 14 deletions flags/categories.go → internal/flags/categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 1 addition & 10 deletions flags/helpers.go → internal/flags/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions version/vcs.go → internal/version/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package version

import (
"fmt"
"runtime/debug"
"time"
)
Expand All @@ -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
Expand Down
File renamed without changes.
8 changes: 7 additions & 1 deletion web3/api.go
Original file line number Diff line number Diff line change
@@ -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
}