Skip to content

Commit

Permalink
refactor rpc pkgs into subpkgs, and re-add support for rpc v6 (#2419)
Browse files Browse the repository at this point in the history
* 1. refactor rpc pkgs into subpkgs, and 2. re-add support for rpc v6
  • Loading branch information
rianhughes authored Feb 7, 2025
1 parent 97a2d0a commit 668c093
Show file tree
Hide file tree
Showing 98 changed files with 14,723 additions and 736 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/ethereum/go-ethereum v1.14.13
github.com/fxamacker/cbor/v2 v2.7.0
github.com/go-playground/validator/v10 v10.24.0
github.com/hashicorp/go-set/v2 v2.1.0
github.com/jinzhu/copier v0.4.0
github.com/libp2p/go-libp2p v0.38.1
github.com/libp2p/go-libp2p-kad-dht v0.28.2
Expand All @@ -36,6 +37,7 @@ require (
google.golang.org/grpc v1.70.0
google.golang.org/protobuf v1.36.4
gopkg.in/yaml.v3 v3.0.1
nhooyr.io/websocket v1.8.17
)

require (
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpx
github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-set/v2 v2.1.0 h1:iERPCQWks+I+4bTgy0CT2myZsCqNgBg79ZHqwniohXo=
github.com/hashicorp/go-set/v2 v2.1.0/go.mod h1:6q4nh8UCVZODn2tJ5RbJi8+ki7pjZBsAEYGt6yaGeTo=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
Expand Down Expand Up @@ -508,6 +510,8 @@ github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWR
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shoenig/test v0.6.7 h1:k92ohN9VyRfZn0ezNfwamtIBT/5byyfLVktRmL/Jmek=
github.com/shoenig/test v0.6.7/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY=
github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM=
github.com/shurcooL/github_flavored_markdown v0.0.0-20181002035957-2122de532470/go.mod h1:2dOwnU2uBioM+SGy2aZoq1f/Sd1l9OkAeAUvjSyvgU0=
Expand Down Expand Up @@ -849,6 +853,8 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
lukechampine.com/blake3 v1.3.0 h1:sJ3XhFINmHSrYCgl958hscfIa3bw8x4DqMP3u1YvoYE=
lukechampine.com/blake3 v1.3.0/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
nhooyr.io/websocket v1.8.17 h1:KEVeLJkUywCKVsnLIDlD/5gtayKp8VoCkksHCGGfT9Y=
nhooyr.io/websocket v1.8.17/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU=
rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA=
sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck=
Expand Down
1 change: 1 addition & 0 deletions mocks/mock_synchronizer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions mocks/mock_vm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 18 additions & 7 deletions node/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func makeWSMetrics() jsonrpc.NewRequestListener {
}
}

func makeRPCMetrics(version, legacyVersion string) (jsonrpc.EventListener, jsonrpc.EventListener) {
func makeRPCMetrics(version1, version2, version3 string) (jsonrpc.EventListener, jsonrpc.EventListener, jsonrpc.EventListener) {
requests := prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "rpc",
Subsystem: "server",
Expand All @@ -130,23 +130,34 @@ func makeRPCMetrics(version, legacyVersion string) (jsonrpc.EventListener, jsonr

return &jsonrpc.SelectiveListener{
OnNewRequestCb: func(method string) {
requests.WithLabelValues(method, version).Inc()
requests.WithLabelValues(method, version1).Inc()
},
OnRequestHandledCb: func(method string, took time.Duration) {
requestLatencies.WithLabelValues(method, version).Observe(took.Seconds())
requestLatencies.WithLabelValues(method, version1).Observe(took.Seconds())
},
OnRequestFailedCb: func(method string, data any) {
failedRequests.WithLabelValues(method, version).Inc()
failedRequests.WithLabelValues(method, version1).Inc()
},
}, &jsonrpc.SelectiveListener{
OnNewRequestCb: func(method string) {
requests.WithLabelValues(method, legacyVersion).Inc()
requests.WithLabelValues(method, version2).Inc()
},
OnRequestHandledCb: func(method string, took time.Duration) {
requestLatencies.WithLabelValues(method, legacyVersion).Observe(took.Seconds())
requestLatencies.WithLabelValues(method, version2).Observe(took.Seconds())
},
OnRequestFailedCb: func(method string, data any) {
failedRequests.WithLabelValues(method, legacyVersion).Inc()
failedRequests.WithLabelValues(method, version2).Inc()
},
},
&jsonrpc.SelectiveListener{
OnNewRequestCb: func(method string) {
requests.WithLabelValues(method, version3).Inc()
},
OnRequestHandledCb: func(method string, took time.Duration) {
requestLatencies.WithLabelValues(method, version3).Observe(took.Seconds())
},
OnRequestFailedCb: func(method string, data any) {
failedRequests.WithLabelValues(method, version3).Inc()
},
}
}
Expand Down
40 changes: 24 additions & 16 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,28 +204,35 @@ func New(cfg *Config, version string, logLevel *utils.LogLevel) (*Node, error) {
syncReader = synchronizer
}

rpcHandler := rpc.New(chain, syncReader, throttledVM, version, log).WithGateway(gatewayClient).WithFeeder(client)
rpcHandler := rpc.New(chain, syncReader, throttledVM, version, log, &cfg.Network).WithGateway(gatewayClient).WithFeeder(client)
rpcHandler = rpcHandler.WithFilterLimit(cfg.RPCMaxBlockScan).WithCallMaxSteps(uint64(cfg.RPCCallMaxSteps))
services = append(services, rpcHandler)
// to improve RPC throughput we double GOMAXPROCS
maxGoroutines := 2 * runtime.GOMAXPROCS(0)
jsonrpcServer := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
methods, path := rpcHandler.Methods()
if err = jsonrpcServer.RegisterMethods(methods...); err != nil {
jsonrpcServerV08 := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
methodsV08, pathV08 := rpcHandler.MethodsV0_8()
if err = jsonrpcServerV08.RegisterMethods(methodsV08...); err != nil {
return nil, err
}
jsonrpcServerLegacy := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
legacyMethods, legacyPath := rpcHandler.MethodsV0_7()
if err = jsonrpcServerLegacy.RegisterMethods(legacyMethods...); err != nil {
jsonrpcServerV07 := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
methodsV07, pathV07 := rpcHandler.MethodsV0_7()
if err = jsonrpcServerV07.RegisterMethods(methodsV07...); err != nil {
return nil, err
}
jsonrpcServerV06 := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
methodsV06, pathV06 := rpcHandler.MethodsV0_6()
if err = jsonrpcServerV06.RegisterMethods(methodsV06...); err != nil {
return nil, err
}
rpcServers := map[string]*jsonrpc.Server{
"/": jsonrpcServer,
path: jsonrpcServer,
legacyPath: jsonrpcServerLegacy,
"/rpc": jsonrpcServer,
"/rpc" + path: jsonrpcServer,
"/rpc" + legacyPath: jsonrpcServerLegacy,
"/": jsonrpcServerV08,
pathV08: jsonrpcServerV08,
pathV07: jsonrpcServerV07,
pathV06: jsonrpcServerV06,
"/rpc": jsonrpcServerV08,
"/rpc" + pathV08: jsonrpcServerV08,
"/rpc" + pathV07: jsonrpcServerV07,
"/rpc" + pathV06: jsonrpcServerV06,
}
if cfg.HTTP {
readinessHandlers := NewReadinessHandlers(chain, synchronizer)
Expand All @@ -249,9 +256,10 @@ func New(cfg *Config, version string, logLevel *utils.LogLevel) (*Node, error) {
chain.WithListener(makeBlockchainMetrics())
makeJunoMetrics(version)
database.WithListener(makeDBMetrics())
rpcMetrics, legacyRPCMetrics := makeRPCMetrics(path, legacyPath)
jsonrpcServer.WithListener(rpcMetrics)
jsonrpcServerLegacy.WithListener(legacyRPCMetrics)
rpcMetricsV08, rpcMetricsV07, rpcMetricsV06 := makeRPCMetrics(pathV08, pathV07, pathV06)
jsonrpcServerV08.WithListener(rpcMetricsV08)
jsonrpcServerV07.WithListener(rpcMetricsV07)
jsonrpcServerV06.WithListener(rpcMetricsV06)
client.WithListener(makeFeederMetrics())
gatewayClient.WithListener(makeGatewayMetrics())
earlyServices = append(earlyServices, makeMetrics(cfg.MetricsHost, cfg.MetricsPort))
Expand Down
43 changes: 0 additions & 43 deletions rpc/estimate_fee_pkg_test.go

This file was deleted.

Loading

0 comments on commit 668c093

Please sign in to comment.