Skip to content

Commit bf35fd7

Browse files
committed
update shisui dep
Signed-off-by: Chen Kai <[email protected]>
1 parent 4fcb214 commit bf35fd7

File tree

4 files changed

+175
-21
lines changed

4 files changed

+175
-21
lines changed

cmd/shisui/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818

1919
"os"
2020

21-
"github.com/ethereum/go-ethereum/cmd/utils"
2221
"github.com/ethereum/go-ethereum/common/hexutil"
2322
"github.com/ethereum/go-ethereum/core"
2423
"github.com/ethereum/go-ethereum/crypto"
@@ -31,6 +30,7 @@ import (
3130
"github.com/mattn/go-isatty"
3231
_ "github.com/mattn/go-sqlite3"
3332
"github.com/optimism-java/shisui2/beacon"
33+
"github.com/optimism-java/shisui2/cmd/shisui/utils"
3434
"github.com/optimism-java/shisui2/ethapi"
3535
"github.com/optimism-java/shisui2/history"
3636
"github.com/optimism-java/shisui2/internal/debug"

cmd/shisui/utils/flags.go

+165-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
package utils
22

33
import (
4+
"fmt"
5+
"io"
6+
"net"
7+
"os"
8+
"runtime"
9+
"strings"
10+
"time"
11+
12+
"github.com/ethereum/go-ethereum/log"
413
"github.com/ethereum/go-ethereum/metrics"
5-
"github.com/ethereum/go-ethereum/node"
14+
"github.com/ethereum/go-ethereum/metrics/exp"
15+
"github.com/ethereum/go-ethereum/metrics/influxdb"
616
"github.com/optimism-java/shisui2/internal/flags"
717
"github.com/optimism-java/shisui2/portalwire"
818
"github.com/urfave/cli/v2"
@@ -107,7 +117,7 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
107117
PortalRPCPortFlag = &cli.IntFlag{
108118
Name: "rpc.port",
109119
Usage: "HTTP-RPC server listening port",
110-
Value: node.DefaultHTTPPort,
120+
Value: 8545,
111121
Category: flags.PortalNetworkCategory,
112122
}
113123

@@ -132,24 +142,17 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
132142
Category: flags.PortalNetworkCategory,
133143
}
134144

135-
PortalUDPListenAddrFlag = &cli.StringFlag{
136-
Name: "udp.addr",
137-
Usage: "Protocol UDP server listening interface",
138-
Value: "",
139-
Category: flags.PortalNetworkCategory,
140-
}
141-
142145
PortalUDPPortFlag = &cli.IntFlag{
143146
Name: "udp.port",
144147
Usage: "Protocol UDP server listening port",
145-
Value: node.DefaultUDPPort,
148+
Value: 9009,
146149
Category: flags.PortalNetworkCategory,
147150
}
148151

149152
PortalLogLevelFlag = &cli.IntFlag{
150153
Name: "loglevel",
151154
Usage: "Loglevel of portal network",
152-
Value: node.DefaultLoglevel,
155+
Value: 3,
153156
Category: flags.PortalNetworkCategory,
154157
}
155158

@@ -178,3 +181,154 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
178181
Value: cli.NewStringSlice(portalwire.History.Name()),
179182
}
180183
)
184+
185+
func SetupMetrics(ctx *cli.Context) {
186+
if metrics.Enabled {
187+
log.Info("Enabling metrics collection")
188+
189+
var (
190+
enableExport = ctx.Bool(MetricsEnableInfluxDBFlag.Name)
191+
enableExportV2 = ctx.Bool(MetricsEnableInfluxDBV2Flag.Name)
192+
)
193+
194+
if enableExport || enableExportV2 {
195+
CheckExclusive(ctx, MetricsEnableInfluxDBFlag, MetricsEnableInfluxDBV2Flag)
196+
197+
v1FlagIsSet := ctx.IsSet(MetricsInfluxDBUsernameFlag.Name) ||
198+
ctx.IsSet(MetricsInfluxDBPasswordFlag.Name)
199+
200+
v2FlagIsSet := ctx.IsSet(MetricsInfluxDBTokenFlag.Name) ||
201+
ctx.IsSet(MetricsInfluxDBOrganizationFlag.Name) ||
202+
ctx.IsSet(MetricsInfluxDBBucketFlag.Name)
203+
204+
if enableExport && v2FlagIsSet {
205+
Fatalf("Flags --influxdb.metrics.organization, --influxdb.metrics.token, --influxdb.metrics.bucket are only available for influxdb-v2")
206+
} else if enableExportV2 && v1FlagIsSet {
207+
Fatalf("Flags --influxdb.metrics.username, --influxdb.metrics.password are only available for influxdb-v1")
208+
}
209+
}
210+
211+
var (
212+
endpoint = ctx.String(MetricsInfluxDBEndpointFlag.Name)
213+
database = ctx.String(MetricsInfluxDBDatabaseFlag.Name)
214+
username = ctx.String(MetricsInfluxDBUsernameFlag.Name)
215+
password = ctx.String(MetricsInfluxDBPasswordFlag.Name)
216+
217+
token = ctx.String(MetricsInfluxDBTokenFlag.Name)
218+
bucket = ctx.String(MetricsInfluxDBBucketFlag.Name)
219+
organization = ctx.String(MetricsInfluxDBOrganizationFlag.Name)
220+
)
221+
222+
if enableExport {
223+
tagsMap := SplitTagsFlag(ctx.String(MetricsInfluxDBTagsFlag.Name))
224+
225+
log.Info("Enabling metrics export to InfluxDB")
226+
227+
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "geth.", tagsMap)
228+
} else if enableExportV2 {
229+
tagsMap := SplitTagsFlag(ctx.String(MetricsInfluxDBTagsFlag.Name))
230+
231+
log.Info("Enabling metrics export to InfluxDB (v2)")
232+
233+
go influxdb.InfluxDBV2WithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, token, bucket, organization, "geth.", tagsMap)
234+
}
235+
236+
if ctx.IsSet(MetricsHTTPFlag.Name) {
237+
address := net.JoinHostPort(ctx.String(MetricsHTTPFlag.Name), fmt.Sprintf("%d", ctx.Int(MetricsPortFlag.Name)))
238+
log.Info("Enabling stand-alone metrics HTTP endpoint", "address", address)
239+
exp.Setup(address)
240+
} else if ctx.IsSet(MetricsPortFlag.Name) {
241+
log.Warn(fmt.Sprintf("--%s specified without --%s, metrics server will not start.", MetricsPortFlag.Name, MetricsHTTPFlag.Name))
242+
}
243+
}
244+
}
245+
246+
// CheckExclusive verifies that only a single instance of the provided flags was
247+
// set by the user. Each flag might optionally be followed by a string type to
248+
// specialize it further.
249+
func CheckExclusive(ctx *cli.Context, args ...interface{}) {
250+
set := make([]string, 0, 1)
251+
for i := 0; i < len(args); i++ {
252+
// Make sure the next argument is a flag and skip if not set
253+
flag, ok := args[i].(cli.Flag)
254+
if !ok {
255+
panic(fmt.Sprintf("invalid argument, not cli.Flag type: %T", args[i]))
256+
}
257+
// Check if next arg extends current and expand its name if so
258+
name := flag.Names()[0]
259+
260+
if i+1 < len(args) {
261+
switch option := args[i+1].(type) {
262+
case string:
263+
// Extended flag check, make sure value set doesn't conflict with passed in option
264+
if ctx.String(flag.Names()[0]) == option {
265+
name += "=" + option
266+
set = append(set, "--"+name)
267+
}
268+
// shift arguments and continue
269+
i++
270+
continue
271+
272+
case cli.Flag:
273+
default:
274+
panic(fmt.Sprintf("invalid argument, not cli.Flag or string extension: %T", args[i+1]))
275+
}
276+
}
277+
// Mark the flag if it's set
278+
if ctx.IsSet(flag.Names()[0]) {
279+
set = append(set, "--"+name)
280+
}
281+
}
282+
if len(set) > 1 {
283+
Fatalf("Flags %v can't be used at the same time", strings.Join(set, ", "))
284+
}
285+
}
286+
287+
// Fatalf formats a message to standard error and exits the program.
288+
// The message is also printed to standard output if standard error
289+
// is redirected to a different file.
290+
func Fatalf(format string, args ...interface{}) {
291+
w := io.MultiWriter(os.Stdout, os.Stderr)
292+
if runtime.GOOS == "windows" {
293+
// The SameFile check below doesn't work on Windows.
294+
// stdout is unlikely to get redirected though, so just print there.
295+
w = os.Stdout
296+
} else {
297+
outf, _ := os.Stdout.Stat()
298+
errf, _ := os.Stderr.Stat()
299+
if outf != nil && errf != nil && os.SameFile(outf, errf) {
300+
w = os.Stderr
301+
}
302+
}
303+
fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
304+
os.Exit(1)
305+
}
306+
307+
func SplitTagsFlag(tagsFlag string) map[string]string {
308+
tags := strings.Split(tagsFlag, ",")
309+
tagsMap := map[string]string{}
310+
311+
for _, t := range tags {
312+
if t != "" {
313+
kv := strings.Split(t, "=")
314+
315+
if len(kv) == 2 {
316+
tagsMap[kv[0]] = kv[1]
317+
}
318+
}
319+
}
320+
321+
return tagsMap
322+
}
323+
324+
// SplitAndTrim splits input separated by a comma
325+
// and trims excessive white space from the substrings.
326+
func SplitAndTrim(input string) (ret []string) {
327+
l := strings.Split(input, ",")
328+
for _, r := range l {
329+
if r = strings.TrimSpace(r); r != "" {
330+
ret = append(ret, r)
331+
}
332+
}
333+
return ret
334+
}

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ require (
112112
go.uber.org/multierr v1.11.0 // indirect
113113
golang.org/x/crypto v0.29.0 // indirect
114114
golang.org/x/net v0.31.0 // indirect
115-
golang.org/x/sync v0.9.0 // indirect
116-
golang.org/x/sys v0.27.0 // indirect
115+
golang.org/x/sync v0.10.0 // indirect
116+
golang.org/x/sys v0.28.0 // indirect
117117
golang.org/x/time v0.8.0 // indirect
118118
google.golang.org/protobuf v1.35.2 // indirect
119119
rsc.io/tmplfunc v0.0.3 // indirect
120120
)
121121

122-
replace github.com/ethereum/go-ethereum => github.com/optimism-java/shisui v1.14.6-0.20241126041930-ee11806dd799
122+
replace github.com/ethereum/go-ethereum => github.com/optimism-java/shisui v1.14.6-0.20241209061923-db3778434a80

go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
184184
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
185185
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
186186
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
187-
github.com/optimism-java/shisui v1.14.6-0.20241126041930-ee11806dd799 h1:qlb2YLJzDmzeRVAh5lNjnGI2fSi6y30KEnPBRlO660k=
188-
github.com/optimism-java/shisui v1.14.6-0.20241126041930-ee11806dd799/go.mod h1:02nKocQx0Db9sQRY7H1PVtkboseYBhIU0ptKwR2iMIg=
187+
github.com/optimism-java/shisui v1.14.6-0.20241209061923-db3778434a80 h1:+NwWFTn9pT/rXGg7SMxapxJzTV9Tu396hf3rmKpgfV4=
188+
github.com/optimism-java/shisui v1.14.6-0.20241209061923-db3778434a80/go.mod h1:thV9bgHBOBHDkJJPtsQpaxT5hLsnEFwhYO87I8iE8UU=
189189
github.com/optimism-java/utp-go v0.0.0-20241110145701-0f0eebf881b3 h1:KfAZ//Sxrqulozmw4QoC8jY3h4I5diWXWPmZ1gptvGY=
190190
github.com/optimism-java/utp-go v0.0.0-20241110145701-0f0eebf881b3/go.mod h1:dJZNMUlyNpjM2VkUEHhmFprLei6gCg3r7U9qj9MmJNQ=
191191
github.com/optimism-java/zrnt v0.32.4-0.20240415084906-d9dbf06b32f7 h1:ZTQWXQ8xblCRUXhZs3h5qrBMSAHe8iNH7BG7a7IVFlI=
@@ -322,8 +322,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
322322
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
323323
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
324324
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
325-
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
326-
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
325+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
326+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
327327
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
328328
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
329329
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -350,8 +350,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
350350
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
351351
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
352352
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
353-
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
354-
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
353+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
354+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
355355
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
356356
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
357357
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=

0 commit comments

Comments
 (0)