Skip to content
Draft
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
46 changes: 46 additions & 0 deletions rocketpool/node/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package node

import (
"context"
"fmt"
"log"
"net/http"

"github.com/rocket-pool/smartnode/shared/services/config"
cfgtypes "github.com/rocket-pool/smartnode/shared/types/config"
"google.golang.org/genproto/googleapis/maps/routes/v1"
)

type httpServer struct {
server *http.Server
}

func startHTTP(ctx context.Context, cfg *config.RocketPoolConfig) {
host := "127.0.0.1"
if cfg.Smartnode.OpenAPIPort.Value == cfgtypes.RPC_OpenLocalhost {
host = "0.0.0.0"
}

port, ok := cfg.Smartnode.APIPort.Value.(uint16)
if !ok {
log.Fatalf("Error getting API port: %v", err)

Check failure on line 26 in rocketpool/node/http.go

View workflow job for this annotation

GitHub Actions / build

undefined: err

Check failure on line 26 in rocketpool/node/http.go

View workflow job for this annotation

GitHub Actions / build

undefined: err
}

httpServer := &httpServer{}

server := &http.Server{
Addr: fmt.Sprintf("%s:%d", host, port),
Handler: httpServer,
}

httpServer.server = server
}

func (s *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {

w.WriteHeader(http.StatusOK)
w.Write([]byte("Hello, World!"))
}

func (s *httpServer) addRoute(r *routes.Route) {
}
9 changes: 8 additions & 1 deletion rocketpool/node/node.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package node

import (
"context"
"fmt"
"math/big"
"net/http"
Expand Down Expand Up @@ -51,7 +52,7 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
app.Commands = append(app.Commands, cli.Command{
Name: name,
Aliases: aliases,
Usage: "Run Rocket Pool node activity daemon",
Usage: "Run Rocket Pool node activity daemon/webserver",
Action: func(c *cli.Context) error {
return run(c)
},
Expand Down Expand Up @@ -119,6 +120,12 @@ func run(c *cli.Context) error {
m := state.NewNetworkStateManager(rp, cfg.Smartnode.GetStateManagerContracts(), bc, &updateLog)
stateLocker := collectors.NewStateLocker()

// Create a context for the daemon
ctx := context.Background()

// Start the HTTP server
startHTTP(ctx, cfg)

// Initialize tasks
manageFeeRecipient, err := newManageFeeRecipient(c, log.NewColorLogger(ManageFeeRecipientColor))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions rocketpool/node/routes/state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package routes
31 changes: 31 additions & 0 deletions shared/services/config/smartnode-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ type SmartnodeConfig struct {
// Threshold for automatic vote power initialization transactions
AutoInitVPThreshold config.Parameter `yaml:"autoInitVPThreshold,omitempty"`

// Port for the node's webserver
APIPort config.Parameter `yaml:"apiPort,omitempty"`

// Whether to expose the node's API port to the local network
OpenAPIPort config.Parameter `yaml:"openAPIPort,omitempty"`

///////////////////////////
// Non-editable settings //
///////////////////////////
Expand Down Expand Up @@ -413,6 +419,29 @@ func NewSmartnodeConfig(cfg *RocketPoolConfig) *SmartnodeConfig {
OverwriteOnUpgrade: true,
},

APIPort: config.Parameter{
ID: "apiPort",
Name: "API Port",
Description: "The port your Smartnode's API should listen on.",
Type: config.ParameterType_Uint16,
Default: map[config.Network]interface{}{config.Network_All: uint16(8280)},
AffectsContainers: []config.ContainerID{config.ContainerID_Node},
CanBeBlank: false,
OverwriteOnUpgrade: false,
},

OpenAPIPort: config.Parameter{
ID: "openAPIPort",
Name: "Expose API Port",
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.",
Type: config.ParameterType_Choice,
Default: map[config.Network]interface{}{config.Network_All: config.RPC_Closed},
AffectsContainers: []config.ContainerID{config.ContainerID_Node},
CanBeBlank: false,
OverwriteOnUpgrade: false,
Options: config.RestrictedPortModes(),
},

txWatchUrl: map[config.Network]string{
config.Network_Mainnet: "https://etherscan.io/tx",
config.Network_Devnet: "https://hoodi.etherscan.io/tx",
Expand Down Expand Up @@ -635,6 +664,8 @@ func (cfg *SmartnodeConfig) GetParameters() []*config.Parameter {
&cfg.ArchiveECUrl,
&cfg.WatchtowerMaxFeeOverride,
&cfg.WatchtowerPrioFeeOverride,
&cfg.APIPort,
&cfg.OpenAPIPort,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
image: {{.Smartnode.GetSmartnodeContainerTag}}
container_name: {{.Smartnode.ProjectName}}_node
restart: unless-stopped
ports: [{{.GetNodeOpenPorts}}]
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- {{.RocketPoolDirectory}}:/.rocketpool
Expand Down
13 changes: 13 additions & 0 deletions shared/types/config/port-modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,16 @@ func PortModes(warningOverride string) []ParameterOption {
Value: RPC_OpenExternal,
}}
}

func RestrictedPortModes() []ParameterOption {

return []ParameterOption{{
Name: "Closed",
Description: "Do not allow connections to the port",
Value: RPC_Closed,
}, {
Name: "Open to Localhost",
Description: "Allow connections from this host only",
Value: RPC_OpenLocalhost,
}}
}
Loading