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

Break HTTP routes into multiple servers #1087

Merged
merged 12 commits into from
Aug 18, 2023
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
32 changes: 30 additions & 2 deletions cmd/juno/juno.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,65 @@ Juno is a Go implementation of a Starknet full-node client created by Nethermind
const (
configF = "config"
logLevelF = "log-level"
httpF = "http"
httpPortF = "http-port"
wsF = "ws"
wsPortF = "ws-port"
dbPathF = "db-path"
networkF = "network"
ethNodeF = "eth-node"
pprofF = "pprof"
pprofPortF = "pprof-port"
colourF = "colour"
pendingPollIntervalF = "pending-poll-interval"
p2pF = "p2p"
p2pAddrF = "p2p-addr"
p2pBootPeersF = "p2p-boot-peers"
metricsF = "metrics"
metricsPortF = "metrics-port"
grpcF = "grpc"
grpcPortF = "grpc-port"

defaultConfig = ""
defaultHTTP = false
defaultHTTPPort = 6060
defaultWS = false
defaultWSPort = 6061
defaultDBPath = ""
defaultEthNode = ""
defaultPprof = false
defaultPprofPort = 6062
defaultColour = true
defaultPendingPollInterval = time.Duration(0)
defaultP2p = false
defaultP2pAddr = ""
defaultP2pBootPeers = ""
defaultMetrics = false
defaultMetricsPort = 9090
defaultGRPC = false
defaultGRPCPort = 6064

configFlagUsage = "The yaml configuration file."
logLevelFlagUsage = "Options: debug, info, warn, error."
httpUsage = "Enables the HTTP RPC server on the default port."
httpPortUsage = "The port on which the HTTP server will listen for requests."
wsUsage = "Enables the Websocket RPC server on the default port."
wsPortUsage = "The port on which the websocket server will listen for requests."
dbPathUsage = "Location of the database files."
networkUsage = "Options: mainnet, goerli, goerli2, integration."
pprofUsage = "Enables the pprof endpoint."
pprofUsage = "Enables the pprof endpoint on the default port."
pprofPortUsage = "The port on which the pprof HTTP server will listen for requests."
colourUsage = "Uses --colour=false command to disable colourized outputs (ANSI Escape Codes)."
ethNodeUsage = "Websocket endpoint of the Ethereum node. In order to verify the correctness of the L2 chain, " +
"Juno must connect to an Ethereum node and parse events in the Starknet contract."
pendingPollIntervalUsage = "Sets how frequently pending block will be updated (disabled by default)"
p2pUsage = "enable p2p server"
p2PAddrUsage = "specify p2p source address as multiaddr"
p2pBootPeersUsage = "specify list of p2p boot peers splitted by a comma"
metricsUsage = "enable prometheus endpoint"
metricsUsage = "Enables the prometheus metrics endpoint on the default port."
metricsPortUsage = "The port on which the prometheus endpoint will listen for requests."
grpcUsage = "Enable the HTTP GRPC server on the default port."
grpcPortUsage = "The port on which the GRPC server will listen for requests."
)

var Version string
Expand Down Expand Up @@ -157,17 +178,24 @@ func NewCmd(config *node.Config, run func(*cobra.Command, []string) error) *cobr

junoCmd.Flags().StringVar(&cfgFile, configF, defaultConfig, configFlagUsage)
junoCmd.Flags().Var(&defaultLogLevel, logLevelF, logLevelFlagUsage)
junoCmd.Flags().Bool(httpF, defaultHTTP, httpUsage)
junoCmd.Flags().Uint16(httpPortF, defaultHTTPPort, httpPortUsage)
junoCmd.Flags().Bool(wsF, defaultWS, wsUsage)
junoCmd.Flags().Uint16(wsPortF, defaultWSPort, wsPortUsage)
junoCmd.Flags().String(dbPathF, defaultDBPath, dbPathUsage)
junoCmd.Flags().Var(&defaultNetwork, networkF, networkUsage)
junoCmd.Flags().String(ethNodeF, defaultEthNode, ethNodeUsage)
junoCmd.Flags().Bool(pprofF, defaultPprof, pprofUsage)
junoCmd.Flags().Uint16(pprofPortF, defaultPprofPort, pprofPortUsage)
junoCmd.Flags().Bool(colourF, defaultColour, colourUsage)
junoCmd.Flags().Duration(pendingPollIntervalF, defaultPendingPollInterval, pendingPollIntervalUsage)
junoCmd.Flags().Bool(p2pF, defaultP2p, p2pUsage)
junoCmd.Flags().String(p2pAddrF, defaultP2pAddr, p2PAddrUsage)
junoCmd.Flags().String(p2pBootPeersF, defaultP2pBootPeers, p2pBootPeersUsage)
junoCmd.Flags().Bool(metricsF, defaultMetrics, metricsUsage)
junoCmd.Flags().Uint16(metricsPortF, defaultMetricsPort, metricsPortUsage)
junoCmd.Flags().Bool(grpcF, defaultGRPC, grpcUsage)
junoCmd.Flags().Uint16(grpcPortF, defaultGRPCPort, grpcPortUsage)

return junoCmd
}
113 changes: 106 additions & 7 deletions cmd/juno/juno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ func TestConfigPrecedence(t *testing.T) {
// checks on the config, those will be checked by the StarknetNode
// implementation.
defaultLogLevel := utils.INFO
defaultHTTP := false
defaultHTTPPort := uint16(6060)
defaultWS := false
defaultWSPort := uint16(6061)
defaultDBPath := ""
defaultNetwork := utils.MAINNET
defaultPprof := false
defaultPprofPort := uint16(6062)
defaultMetrics := false
defaultMetricsPort := uint16(9090)
defaultGRPC := false
defaultGRPCPort := uint16(6064)
defaultColour := true
defaultPendingPollInterval := time.Duration(0)

Expand All @@ -40,10 +48,18 @@ func TestConfigPrecedence(t *testing.T) {
inputArgs: []string{""},
expectedConfig: &node.Config{
LogLevel: defaultLogLevel,
HTTP: defaultHTTP,
HTTPPort: defaultHTTPPort,
Websocket: defaultWS,
WebsocketPort: defaultWSPort,
DatabasePath: defaultDBPath,
Network: defaultNetwork,
Pprof: defaultPprof,
PprofPort: defaultPprofPort,
GRPC: defaultGRPC,
GRPCPort: defaultGRPCPort,
Metrics: defaultMetrics,
MetricsPort: defaultMetricsPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
},
Expand All @@ -52,10 +68,18 @@ func TestConfigPrecedence(t *testing.T) {
inputArgs: []string{"--config", ""},
expectedConfig: &node.Config{
LogLevel: defaultLogLevel,
HTTP: defaultHTTP,
HTTPPort: defaultHTTPPort,
Websocket: defaultWS,
WebsocketPort: defaultWSPort,
GRPC: defaultGRPC,
GRPCPort: defaultGRPCPort,
Metrics: defaultMetrics,
MetricsPort: defaultMetricsPort,
DatabasePath: defaultDBPath,
Network: defaultNetwork,
Pprof: defaultPprof,
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
},
Expand All @@ -69,10 +93,19 @@ func TestConfigPrecedence(t *testing.T) {
cfgFileContents: "\n",
expectedConfig: &node.Config{
LogLevel: defaultLogLevel,
HTTP: defaultHTTP,
HTTPPort: defaultHTTPPort,
Websocket: defaultWS,
WebsocketPort: defaultWSPort,
GRPC: defaultGRPC,
GRPCPort: defaultGRPCPort,
Metrics: defaultMetrics,
MetricsPort: defaultMetricsPort,
Network: defaultNetwork,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
Pprof: defaultPprof,
PprofPort: defaultPprofPort,
},
},
"config file with all settings but without any other flags": {
Expand All @@ -85,10 +118,18 @@ pprof: true
`,
expectedConfig: &node.Config{
LogLevel: utils.DEBUG,
HTTP: defaultHTTP,
HTTPPort: 4576,
Websocket: defaultWS,
WebsocketPort: defaultWSPort,
GRPC: defaultGRPC,
GRPCPort: defaultGRPCPort,
Metrics: defaultMetrics,
MetricsPort: defaultMetricsPort,
DatabasePath: "/home/.juno",
Network: utils.GOERLI2,
Pprof: true,
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
},
Expand All @@ -100,10 +141,18 @@ http-port: 4576
`,
expectedConfig: &node.Config{
LogLevel: utils.DEBUG,
HTTP: defaultHTTP,
HTTPPort: 4576,
Websocket: defaultWS,
WebsocketPort: defaultWSPort,
GRPC: defaultGRPC,
GRPCPort: defaultGRPCPort,
Metrics: defaultMetrics,
MetricsPort: defaultMetricsPort,
DatabasePath: defaultDBPath,
Network: defaultNetwork,
Pprof: defaultPprof,
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
},
Expand All @@ -114,12 +163,20 @@ http-port: 4576
"--db-path", "/home/.juno", "--network", "goerli", "--pprof",
},
expectedConfig: &node.Config{
LogLevel: utils.DEBUG,
HTTPPort: 4576,
DatabasePath: "/home/.juno",
Network: utils.GOERLI,
Pprof: true,
Colour: defaultColour,
LogLevel: utils.DEBUG,
HTTP: defaultHTTP,
HTTPPort: 4576,
Websocket: defaultWS,
WebsocketPort: defaultWSPort,
GRPC: defaultGRPC,
GRPCPort: defaultGRPCPort,
Metrics: defaultMetrics,
MetricsPort: defaultMetricsPort,
DatabasePath: "/home/.juno",
Network: utils.GOERLI,
Pprof: true,
PprofPort: defaultPprofPort,
Colour: defaultColour,
},
},
"some flags without config file": {
Expand All @@ -129,32 +186,58 @@ http-port: 4576
},
expectedConfig: &node.Config{
LogLevel: utils.DEBUG,
HTTP: defaultHTTP,
HTTPPort: 4576,
Websocket: defaultWS,
WebsocketPort: defaultWSPort,
GRPC: defaultGRPC,
GRPCPort: defaultGRPCPort,
Metrics: defaultMetrics,
MetricsPort: defaultMetricsPort,
DatabasePath: "/home/.juno",
Network: utils.INTEGRATION,
Pprof: defaultPprof,
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
},
},
"all setting set in both config file and flags": {
cfgFile: true,
cfgFileContents: `log-level: debug
http: true
http-port: 4576
ws: true
ws-port: 4576
metrics: true
metrics-port: 4576
grpc: true
grpc-port: 4576
db-path: /home/config-file/.juno
network: goerli
pprof: true
pprof-port: 6064
pending-poll-interval: 5s
`,
inputArgs: []string{
"--log-level", "error", "--http-port", "4577",
"--log-level", "error", "--http", "--http-port", "4577", "--ws", "--ws-port", "4577",
"--grpc", "--grpc-port", "4577", "--metrics", "--metrics-port", "4577",
"--db-path", "/home/flag/.juno", "--network", "integration", "--pprof", "--pending-poll-interval", time.Millisecond.String(),
},
expectedConfig: &node.Config{
LogLevel: utils.ERROR,
HTTP: true,
HTTPPort: 4577,
Websocket: true,
WebsocketPort: 4577,
Metrics: true,
MetricsPort: 4577,
GRPC: true,
GRPCPort: 4577,
DatabasePath: "/home/flag/.juno",
Network: utils.INTEGRATION,
Pprof: true,
PprofPort: 6064,
Colour: defaultColour,
PendingPollInterval: time.Millisecond,
},
Expand All @@ -168,10 +251,18 @@ network: goerli
inputArgs: []string{"--db-path", "/home/flag/.juno"},
expectedConfig: &node.Config{
LogLevel: utils.WARN,
HTTP: defaultHTTP,
HTTPPort: 4576,
Websocket: defaultWS,
WebsocketPort: defaultWSPort,
GRPC: defaultGRPC,
GRPCPort: defaultGRPCPort,
Metrics: defaultMetrics,
MetricsPort: defaultMetricsPort,
DatabasePath: "/home/flag/.juno",
Network: utils.GOERLI,
Pprof: defaultPprof,
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
},
Expand All @@ -182,10 +273,18 @@ network: goerli
inputArgs: []string{"--db-path", "/home/flag/.juno", "--pprof"},
expectedConfig: &node.Config{
LogLevel: defaultLogLevel,
HTTP: defaultHTTP,
HTTPPort: defaultHTTPPort,
Websocket: defaultWS,
WebsocketPort: defaultWSPort,
GRPC: defaultGRPC,
GRPCPort: defaultGRPCPort,
Metrics: defaultMetrics,
MetricsPort: defaultMetricsPort,
DatabasePath: "/home/flag/.juno",
Network: utils.GOERLI2,
Pprof: true,
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
},
Expand Down
17 changes: 13 additions & 4 deletions docs/docs/example_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,24 @@ db-path: /home/<user>/.local/share/juno
# If using Infura, it looks something like `wss://mainnet.infura.io/ws/v3/your-infura-project-id`
eth-node: ""

# Port on which the HTTP server will listen for requests.
# Enables the HTTP RPC server.
http: false
# Port on which the HTTP RPC server will listen for requests.
http-port: 6060

# The options below are similar to the HTTP RPC options above.
ws: false # Websocket RPC server
ws-port: 6061
pprof: false
pprof-port: 6062
metrics: false
metrics-port: 9090
grpc: false
grpc-port: 6064

# Options: debug, info, warn, error
log-level: info

# Enable prometheus endpoint.
metrics: false

# Options: mainnet, goerli, goerli2, integration
network: mainnet

Expand Down
15 changes: 0 additions & 15 deletions docs/docs/http.md

This file was deleted.

Loading