Skip to content

Commit 30dc641

Browse files
committed
Add a port for node webserver/api
1 parent f5f1160 commit 30dc641

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

rocketpool/node/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
5252
app.Commands = append(app.Commands, cli.Command{
5353
Name: name,
5454
Aliases: aliases,
55-
Usage: "Run Rocket Pool node activity daemon",
55+
Usage: "Run Rocket Pool node activity daemon/webserver",
5656
Action: func(c *cli.Context) error {
5757
return run(c)
5858
},

shared/services/config/rocket-pool-config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,16 @@ func (cfg *RocketPoolConfig) GetMevBoostOpenPorts() string {
13831383
return fmt.Sprintf("\"%s\"", portMode.DockerPortMapping(port))
13841384
}
13851385

1386+
// Used by text/template to format node.yml
1387+
func (cfg *RocketPoolConfig) GetNodeOpenPorts() string {
1388+
portMode := cfg.Smartnode.OpenAPIPort.Value.(config.RPCMode)
1389+
if !portMode.Open() {
1390+
return ""
1391+
}
1392+
port := cfg.Smartnode.APIPort.Value.(uint16)
1393+
return fmt.Sprintf("\"%s\"", portMode.DockerPortMapping(port))
1394+
}
1395+
13861396
// Used by text/template to select an entrypoint based on which consensus client is used.
13871397
func (cfg *RocketPoolConfig) GetEth2Entrypoint() string {
13881398
if client, _ := cfg.GetSelectedConsensusClient(); client == config.ConsensusClient_Prysm {

shared/services/config/smartnode-config.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ type SmartnodeConfig struct {
112112
// Threshold for automatic vote power initialization transactions
113113
AutoInitVPThreshold config.Parameter `yaml:"autoInitVPThreshold,omitempty"`
114114

115+
// Port for the node's webserver
116+
APIPort config.Parameter `yaml:"apiPort,omitempty"`
117+
118+
// Whether to expose the node's API port to the local network
119+
OpenAPIPort config.Parameter `yaml:"openAPIPort,omitempty"`
120+
115121
///////////////////////////
116122
// Non-editable settings //
117123
///////////////////////////
@@ -413,6 +419,29 @@ func NewSmartnodeConfig(cfg *RocketPoolConfig) *SmartnodeConfig {
413419
OverwriteOnUpgrade: true,
414420
},
415421

422+
APIPort: config.Parameter{
423+
ID: "apiPort",
424+
Name: "API Port",
425+
Description: "The port your Smartnode's API should listen on.",
426+
Type: config.ParameterType_Uint16,
427+
Default: map[config.Network]interface{}{config.Network_All: uint16(8280)},
428+
AffectsContainers: []config.ContainerID{config.ContainerID_Node},
429+
CanBeBlank: false,
430+
OverwriteOnUpgrade: false,
431+
},
432+
433+
OpenAPIPort: config.Parameter{
434+
ID: "openAPIPort",
435+
Name: "Expose API Port",
436+
Description: "Expose the API port to other processes on your machine. For security reasons, you cannot expose the API port except to localhost. It is recommended to keep this CLOSED.",
437+
Type: config.ParameterType_Choice,
438+
Default: map[config.Network]interface{}{config.Network_All: config.RPC_Closed},
439+
AffectsContainers: []config.ContainerID{config.ContainerID_Node},
440+
CanBeBlank: false,
441+
OverwriteOnUpgrade: false,
442+
Options: config.RestrictedPortModes(),
443+
},
444+
416445
txWatchUrl: map[config.Network]string{
417446
config.Network_Mainnet: "https://etherscan.io/tx",
418447
config.Network_Devnet: "https://hoodi.etherscan.io/tx",
@@ -635,6 +664,8 @@ func (cfg *SmartnodeConfig) GetParameters() []*config.Parameter {
635664
&cfg.ArchiveECUrl,
636665
&cfg.WatchtowerMaxFeeOverride,
637666
&cfg.WatchtowerPrioFeeOverride,
667+
&cfg.APIPort,
668+
&cfg.OpenAPIPort,
638669
}
639670
}
640671

shared/services/rocketpool/assets/install/templates/node.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
image: {{.Smartnode.GetSmartnodeContainerTag}}
1111
container_name: {{.Smartnode.ProjectName}}_node
1212
restart: unless-stopped
13+
ports: [{{.GetNodeOpenPorts}}]
1314
volumes:
1415
- /var/run/docker.sock:/var/run/docker.sock
1516
- {{.RocketPoolDirectory}}:/.rocketpool

shared/types/config/port-modes.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,16 @@ func PortModes(warningOverride string) []ParameterOption {
5555
Value: RPC_OpenExternal,
5656
}}
5757
}
58+
59+
func RestrictedPortModes() []ParameterOption {
60+
61+
return []ParameterOption{{
62+
Name: "Closed",
63+
Description: "Do not allow connections to the port",
64+
Value: RPC_Closed,
65+
}, {
66+
Name: "Open to Localhost",
67+
Description: "Allow connections from this host only",
68+
Value: RPC_OpenLocalhost,
69+
}}
70+
}

0 commit comments

Comments
 (0)