From b446299cf532d5d1233e522ec05f97f61786e68f Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Sun, 5 May 2024 16:32:52 -0400 Subject: [PATCH 1/8] Updated dependencies --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index bd401d4..44ee9bc 100644 --- a/go.mod +++ b/go.mod @@ -10,9 +10,9 @@ require ( github.com/goccy/go-json v0.10.2 github.com/google/uuid v1.6.0 github.com/gorilla/mux v1.8.1 - github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240501154944-195be498d365 + github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240505202557-6da147cd417c github.com/rocket-pool/batch-query v1.0.0 - github.com/rocket-pool/node-manager-core v0.3.0 + github.com/rocket-pool/node-manager-core v0.3.1-0.20240505144232-5b9a3ae77d47 github.com/urfave/cli/v2 v2.27.1 github.com/wealdtech/go-eth2-types/v2 v2.8.2 github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.4.1 diff --git a/go.sum b/go.sum index da0f321..8988122 100644 --- a/go.sum +++ b/go.sum @@ -236,8 +236,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= -github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240501154944-195be498d365 h1:RSunSkBjs5ILC+7syrK8bVIagrZEAvYGyyq0Ohcoa68= -github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240501154944-195be498d365/go.mod h1:65/oNCQjYcUeSr+hfb7EC1gGLNkaTJlCx6EEJhXh1N0= +github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240505202557-6da147cd417c h1:iO3G2VPQE+4SNfoiJuxI2WWRbMY1mlGIrJnKx6xBAZg= +github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240505202557-6da147cd417c/go.mod h1:SeANoYY+5vfDKEuFDsVooF4aa29kZrdvCI9Y/moet2s= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= @@ -283,8 +283,8 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rocket-pool/batch-query v1.0.0 h1:5HejmT1n1fIdLIqUhTNwbkG2PGOPl3IVjCpFQcQZ4I4= github.com/rocket-pool/batch-query v1.0.0/go.mod h1:d1CmxShzk0fioJ4yX0eFGhz2an1odnW/LZ2cp3eDGIQ= -github.com/rocket-pool/node-manager-core v0.3.0 h1:eXju+2URsEw6qaw92J3+JhqbtkHNrhE0GWNiEz7tKXo= -github.com/rocket-pool/node-manager-core v0.3.0/go.mod h1:f/w3jnzi3ipXet7acZ0pQhGbolU/g3IDVrqXcNWuHw4= +github.com/rocket-pool/node-manager-core v0.3.1-0.20240505144232-5b9a3ae77d47 h1:pp7oKe7sXwtG8UbAKA4AHsdiWqeKz5Lm2c8FYB0xRVs= +github.com/rocket-pool/node-manager-core v0.3.1-0.20240505144232-5b9a3ae77d47/go.mod h1:f/w3jnzi3ipXet7acZ0pQhGbolU/g3IDVrqXcNWuHw4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= From 095f59fda817ac694c88a0bba64339b1d393b84f Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Tue, 7 May 2024 15:21:53 -0400 Subject: [PATCH 2/8] Updated CI workflows (SN commit 607ef85) --- .github/workflows/build.yml | 4 ++-- .github/workflows/commits.yml | 2 +- .github/workflows/lint.yml | 5 +++-- .github/workflows/unit-tests.yml | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0fe7ca6..82b3be0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,8 +13,8 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: 1.21.8 - run: cd ${GITHUB_WORKSPACE} && go build . diff --git a/.github/workflows/commits.yml b/.github/workflows/commits.yml index 1c9df19..fde759a 100644 --- a/.github/workflows/commits.yml +++ b/.github/workflows/commits.yml @@ -9,6 +9,6 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Block Fixup Commit Merge uses: 13rac1/block-fixup-merge-action@v2.0.0 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index bba5b30..e8ab3b2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,10 +17,11 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version: 1.21.8 - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - run: go mod download all - name: golangci-lint uses: golangci/golangci-lint-action@v4 with: diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 8d3aa4c..b3322e4 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -13,8 +13,8 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: 1.21.8 - run: go test ./... From 07d9cbfd3743f2e593f68865c4fde693f94efa1a Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Thu, 9 May 2024 17:38:53 -0400 Subject: [PATCH 3/8] Migrated API to a network socket --- client/client.go | 8 ++-- client/nodeset.go | 6 +-- client/status.go | 6 +-- client/validator.go | 6 +-- client/wallet.go | 6 +-- go.mod | 6 ++- go.sum | 6 +-- server/server.go | 68 +++++++++++++++++++------------ shared/config/ids/stakewise.go | 1 + shared/config/settings.go | 3 +- shared/config/stakewise-config.go | 17 ++++++++ stakewise-daemon.go | 63 ++++++++++++++-------------- 12 files changed, 117 insertions(+), 79 deletions(-) diff --git a/client/client.go b/client/client.go index c111d73..b73b5a1 100644 --- a/client/client.go +++ b/client/client.go @@ -2,13 +2,15 @@ package swclient import ( "log/slog" + "net/http/httptrace" + "net/url" "github.com/rocket-pool/node-manager-core/api/client" ) // Binder for the Hyperdrive daemon API server type ApiClient struct { - context *client.RequesterContext + context client.IRequesterContext Nodeset *NodesetRequester Validator *ValidatorRequester Wallet *WalletRequester @@ -16,8 +18,8 @@ type ApiClient struct { } // Creates a new API client instance -func NewApiClient(baseRoute string, socketPath string, logger *slog.Logger) *ApiClient { - context := client.NewRequesterContext(baseRoute, socketPath, logger) +func NewApiClient(apiUrl *url.URL, logger *slog.Logger, tracer *httptrace.ClientTrace) *ApiClient { + context := client.NewNetworkRequesterContext(apiUrl, logger, tracer) client := &ApiClient{ context: context, diff --git a/client/nodeset.go b/client/nodeset.go index 7df8c4e..315eb2d 100644 --- a/client/nodeset.go +++ b/client/nodeset.go @@ -10,10 +10,10 @@ import ( ) type NodesetRequester struct { - context *client.RequesterContext + context client.IRequesterContext } -func NewNodesetRequester(context *client.RequesterContext) *NodesetRequester { +func NewNodesetRequester(context client.IRequesterContext) *NodesetRequester { return &NodesetRequester{ context: context, } @@ -25,7 +25,7 @@ func (r *NodesetRequester) GetName() string { func (r *NodesetRequester) GetRoute() string { return "nodeset" } -func (r *NodesetRequester) GetContext() *client.RequesterContext { +func (r *NodesetRequester) GetContext() client.IRequesterContext { return r.context } diff --git a/client/status.go b/client/status.go index a40caf4..04f4fb2 100644 --- a/client/status.go +++ b/client/status.go @@ -7,10 +7,10 @@ import ( ) type StatusRequester struct { - context *client.RequesterContext + context client.IRequesterContext } -func NewStatusRequester(context *client.RequesterContext) *StatusRequester { +func NewStatusRequester(context client.IRequesterContext) *StatusRequester { return &StatusRequester{ context: context, } @@ -24,7 +24,7 @@ func (r *StatusRequester) GetRoute() string { return "status" } -func (r *StatusRequester) GetContext() *client.RequesterContext { +func (r *StatusRequester) GetContext() client.IRequesterContext { return r.context } diff --git a/client/validator.go b/client/validator.go index 07204d1..b649419 100644 --- a/client/validator.go +++ b/client/validator.go @@ -10,10 +10,10 @@ import ( ) type ValidatorRequester struct { - context *client.RequesterContext + context client.IRequesterContext } -func NewValidatorRequester(context *client.RequesterContext) *ValidatorRequester { +func NewValidatorRequester(context client.IRequesterContext) *ValidatorRequester { return &ValidatorRequester{ context: context, } @@ -25,7 +25,7 @@ func (r *ValidatorRequester) GetName() string { func (r *ValidatorRequester) GetRoute() string { return "validator" } -func (r *ValidatorRequester) GetContext() *client.RequesterContext { +func (r *ValidatorRequester) GetContext() client.IRequesterContext { return r.context } diff --git a/client/wallet.go b/client/wallet.go index 2bac1a9..53d7f40 100644 --- a/client/wallet.go +++ b/client/wallet.go @@ -9,10 +9,10 @@ import ( ) type WalletRequester struct { - context *client.RequesterContext + context client.IRequesterContext } -func NewWalletRequester(context *client.RequesterContext) *WalletRequester { +func NewWalletRequester(context client.IRequesterContext) *WalletRequester { return &WalletRequester{ context: context, } @@ -24,7 +24,7 @@ func (r *WalletRequester) GetName() string { func (r *WalletRequester) GetRoute() string { return "wallet" } -func (r *WalletRequester) GetContext() *client.RequesterContext { +func (r *WalletRequester) GetContext() client.IRequesterContext { return r.context } diff --git a/go.mod b/go.mod index 44ee9bc..3d2f301 100644 --- a/go.mod +++ b/go.mod @@ -10,9 +10,9 @@ require ( github.com/goccy/go-json v0.10.2 github.com/google/uuid v1.6.0 github.com/gorilla/mux v1.8.1 - github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240505202557-6da147cd417c + github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240509213433-213850c1cd29 github.com/rocket-pool/batch-query v1.0.0 - github.com/rocket-pool/node-manager-core v0.3.1-0.20240505144232-5b9a3ae77d47 + github.com/rocket-pool/node-manager-core v0.3.1-0.20240507185958-ac96f93a88ec github.com/urfave/cli/v2 v2.27.1 github.com/wealdtech/go-eth2-types/v2 v2.8.2 github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.4.1 @@ -107,3 +107,5 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) + +replace github.com/nodeset-org/hyperdrive-daemon => ../hyperdrive-daemon diff --git a/go.sum b/go.sum index 8988122..14dc1cd 100644 --- a/go.sum +++ b/go.sum @@ -236,8 +236,6 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= -github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240505202557-6da147cd417c h1:iO3G2VPQE+4SNfoiJuxI2WWRbMY1mlGIrJnKx6xBAZg= -github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240505202557-6da147cd417c/go.mod h1:SeANoYY+5vfDKEuFDsVooF4aa29kZrdvCI9Y/moet2s= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= @@ -283,8 +281,8 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rocket-pool/batch-query v1.0.0 h1:5HejmT1n1fIdLIqUhTNwbkG2PGOPl3IVjCpFQcQZ4I4= github.com/rocket-pool/batch-query v1.0.0/go.mod h1:d1CmxShzk0fioJ4yX0eFGhz2an1odnW/LZ2cp3eDGIQ= -github.com/rocket-pool/node-manager-core v0.3.1-0.20240505144232-5b9a3ae77d47 h1:pp7oKe7sXwtG8UbAKA4AHsdiWqeKz5Lm2c8FYB0xRVs= -github.com/rocket-pool/node-manager-core v0.3.1-0.20240505144232-5b9a3ae77d47/go.mod h1:f/w3jnzi3ipXet7acZ0pQhGbolU/g3IDVrqXcNWuHw4= +github.com/rocket-pool/node-manager-core v0.3.1-0.20240507185958-ac96f93a88ec h1:0mXsnjqHxJt1KnUTUFvKu2RynotExI1Sx+flSRt5QhI= +github.com/rocket-pool/node-manager-core v0.3.1-0.20240507185958-ac96f93a88ec/go.mod h1:f/w3jnzi3ipXet7acZ0pQhGbolU/g3IDVrqXcNWuHw4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= diff --git a/server/server.go b/server/server.go index 0786430..ac2ca36 100644 --- a/server/server.go +++ b/server/server.go @@ -1,7 +1,8 @@ package server import ( - "path/filepath" + "fmt" + "sync" swcommon "github.com/nodeset-org/hyperdrive-stakewise/common" swnodeset "github.com/nodeset-org/hyperdrive-stakewise/server/nodeset" @@ -12,39 +13,54 @@ import ( "github.com/rocket-pool/node-manager-core/api/server" ) -const ( - CliOrigin string = "cli" - WebOrigin string = "net" -) +// ServerManager manages the API server run by the daemon +type ServerManager struct { + // The server for clients to interact with + apiServer *server.NetworkSocketApiServer +} + +// Creates a new server manager +func NewServerManager(sp *swcommon.StakewiseServiceProvider, ip string, port uint16, stopWg *sync.WaitGroup) (*ServerManager, error) { + // Start the API server + apiServer, err := createServer(sp, ip, port) + if err != nil { + return nil, fmt.Errorf("error creating API server: %w", err) + } + err = apiServer.Start(stopWg) + if err != nil { + return nil, fmt.Errorf("error starting API server: %w", err) + } + fmt.Printf("API server started on %s:%d\n", ip, port) -type StakewiseServer struct { - *server.ApiServer - socketPath string + // Create the manager + mgr := &ServerManager{ + apiServer: apiServer, + } + return mgr, nil } -func NewStakewiseServer(origin string, sp *swcommon.StakewiseServiceProvider) (*StakewiseServer, error) { +// Stops and shuts down the servers +func (m *ServerManager) Stop() { + err := m.apiServer.Stop() + if err != nil { + fmt.Printf("WARNING: API server didn't shutdown cleanly: %s\n", err.Error()) + } +} + +// Creates a new Hyperdrive API server +func createServer(sp *swcommon.StakewiseServiceProvider, ip string, port uint16) (*server.NetworkSocketApiServer, error) { apiLogger := sp.GetApiLogger() - subLogger := apiLogger.CreateSubLogger(origin) - ctx := subLogger.CreateContextWithLogger(sp.GetBaseContext()) + ctx := apiLogger.CreateContextWithLogger(sp.GetBaseContext()) - socketPath := filepath.Join(sp.GetUserDir(), swconfig.CliSocketFilename) handlers := []server.IHandler{ - swnodeset.NewNodesetHandler(subLogger, ctx, sp), - swvalidator.NewValidatorHandler(subLogger, ctx, sp), - swwallet.NewWalletHandler(subLogger, ctx, sp), - swstatus.NewStatusHandler(subLogger, ctx, sp), + swnodeset.NewNodesetHandler(apiLogger, ctx, sp), + swvalidator.NewValidatorHandler(apiLogger, ctx, sp), + swwallet.NewWalletHandler(apiLogger, ctx, sp), + swstatus.NewStatusHandler(apiLogger, ctx, sp), } - server, err := server.NewApiServer(subLogger.Logger, socketPath, handlers, swconfig.DaemonBaseRoute, swconfig.ApiVersion) + server, err := server.NewNetworkSocketApiServer(apiLogger.Logger, ip, port, handlers, swconfig.DaemonBaseRoute, swconfig.ApiVersion) if err != nil { return nil, err } - - return &StakewiseServer{ - ApiServer: server, - socketPath: socketPath, - }, nil -} - -func (s *StakewiseServer) GetSocketPath() string { - return s.socketPath + return server, nil } diff --git a/shared/config/ids/stakewise.go b/shared/config/ids/stakewise.go index ce0d8f4..1766c28 100644 --- a/shared/config/ids/stakewise.go +++ b/shared/config/ids/stakewise.go @@ -3,6 +3,7 @@ package ids const ( // Param IDs StakewiseEnableID string = "enable" + ApiPortID string = "apiPort" OperatorContainerTagID string = "operatorContainerTag" AdditionalOpFlagsID string = "additionalOpFlags" VerifyDepositRootsID string = "verifyDepositRoots" diff --git a/shared/config/settings.go b/shared/config/settings.go index a90a34b..05213b2 100644 --- a/shared/config/settings.go +++ b/shared/config/settings.go @@ -6,12 +6,11 @@ const ( DaemonBaseRoute string = ModuleName ApiVersion string = "1" ApiClientRoute string = DaemonBaseRoute + "/api/v" + ApiVersion - CliSocketFilename string = ModuleName + "-cli.sock" - NetSocketFilename string = ModuleName + "-net.sock" WalletFilename string = "wallet.json" PasswordFilename string = "password.txt" KeystorePasswordFile string = "secret.txt" DepositDataFile string = "deposit-data.json" + DefaultApiPort uint16 = 8180 // Logging ClientLogName string = "hd.log" diff --git a/shared/config/stakewise-config.go b/shared/config/stakewise-config.go index 009ed14..9b3cca1 100644 --- a/shared/config/stakewise-config.go +++ b/shared/config/stakewise-config.go @@ -19,6 +19,9 @@ type StakewiseConfig struct { // Toggle for enabling access to the root filesystem (for multiple disk usage metrics) Enabled config.Parameter[bool] + // Port to run the Stakewise API server on + ApiPort config.Parameter[uint16] + // Toggle for verifying deposit data Merkle roots before saving VerifyDepositsRoot config.Parameter[bool] @@ -61,6 +64,20 @@ func NewStakewiseConfig(hdCfg *hdconfig.HyperdriveConfig) *StakewiseConfig { }, }, + ApiPort: config.Parameter[uint16]{ + ParameterCommon: &config.ParameterCommon{ + ID: ids.ApiPortID, + Name: "Daemon API Port", + Description: "The port that the Stakewise daemon's API server should run on. Note this is bound to the local machine only; it cannot be accessed by other machines.", + AffectsContainers: []config.ContainerID{ContainerID_StakewiseDaemon}, + CanBeBlank: false, + OverwriteOnUpgrade: false, + }, + Default: map[config.Network]uint16{ + config.Network_All: DefaultApiPort, + }, + }, + VerifyDepositsRoot: config.Parameter[bool]{ ParameterCommon: &config.ParameterCommon{ ID: ids.VerifyDepositRootsID, diff --git a/stakewise-daemon.go b/stakewise-daemon.go index 7483a05..b3f988c 100644 --- a/stakewise-daemon.go +++ b/stakewise-daemon.go @@ -1,12 +1,11 @@ package main import ( - "errors" "fmt" - "io/fs" + "net/url" "os" "os/signal" - "path/filepath" + "strconv" "sync" "syscall" @@ -49,25 +48,45 @@ func main() { Usage: "The path to the Stakewise module data directory", Required: true, } + hyperdriveUrlFlag := &cli.StringFlag{ + Name: "hyperdrive-url", + Aliases: []string{"h"}, + Usage: "The URL of the Hyperdrive API", + Value: "http://127.0.0.1:" + strconv.FormatUint(uint64(config.DefaultApiPort), 10), + } + ipFlag := &cli.StringFlag{ + Name: "ip", + Aliases: []string{"i"}, + Usage: "The IP address to bind the API server to", + Value: "127.0.0.1", + } + portFlag := &cli.UintFlag{ + Name: "port", + Aliases: []string{"p"}, + Usage: "The port to bind the API server to", + Value: uint(swconfig.DefaultApiPort), + } app.Flags = []cli.Flag{ moduleDirFlag, + hyperdriveUrlFlag, + ipFlag, + portFlag, } app.Action = func(c *cli.Context) error { - // Get the config file + // Get the env vars moduleDir := c.String(moduleDirFlag.Name) - hyperdriveSocketPath := filepath.Join(moduleDir, config.HyperdriveCliSocketFilename) - _, err := os.Stat(hyperdriveSocketPath) - if errors.Is(err, fs.ErrNotExist) { - fmt.Printf("Hyperdrive socket not found at [%s].", hyperdriveSocketPath) - os.Exit(1) + hdUrlString := c.String(hyperdriveUrlFlag.Name) + hyperdriveUrl, err := url.Parse(hdUrlString) + if err != nil { + return fmt.Errorf("error parsing Hyperdrive URL [%s]: %w", hdUrlString, err) } // Wait group to handle the API server (separate because of error handling) stopWg := new(sync.WaitGroup) // Create the service provider - sp, err := services.NewServiceProvider(moduleDir, swconfig.ModuleName, swconfig.ClientLogName, swconfig.NewStakewiseConfig, config.ClientTimeout) + sp, err := services.NewServiceProvider(hyperdriveUrl, moduleDir, swconfig.ModuleName, swconfig.ClientLogName, swconfig.NewStakewiseConfig, config.ClientTimeout) if err != nil { return fmt.Errorf("error creating service provider: %w", err) } @@ -76,23 +95,13 @@ func main() { return fmt.Errorf("error creating Stakewise service provider: %w", err) } - // Get the owner of the Hyperdrive socket - var hdSocketStat syscall.Stat_t - err = syscall.Stat(hyperdriveSocketPath, &hdSocketStat) - if err != nil { - return fmt.Errorf("error getting Hyperdrive socket file [%s] info: %w", hyperdriveSocketPath, err) - } - // Start the server - apiServer, err := server.NewStakewiseServer(server.CliOrigin, stakewiseSp) + ip := c.String(ipFlag.Name) + port := c.Uint64(portFlag.Name) + serverMgr, err := server.NewServerManager(stakewiseSp, ip, uint16(port), stopWg) if err != nil { return fmt.Errorf("error creating Stakewise server: %w", err) } - err = apiServer.Start(stopWg, hdSocketStat.Uid, hdSocketStat.Gid) - if err != nil { - return fmt.Errorf("error starting API manager: %w", err) - } - fmt.Printf("Started daemon on %s.\n", apiServer.GetSocketPath()) // Start the task loop taskLoop := swtasks.NewTaskLoop(stakewiseSp, stopWg) @@ -101,8 +110,6 @@ func main() { return fmt.Errorf("error starting task loop: %w", err) } - // TODO: Metrics manager - // Handle process closures termListener := make(chan os.Signal, 1) signal.Notify(termListener, os.Interrupt, syscall.SIGTERM) @@ -110,11 +117,7 @@ func main() { <-termListener fmt.Println("Shutting down daemon...") stakewiseSp.CancelContextOnShutdown() - err := apiServer.Stop() - if err != nil { - fmt.Printf("WARNING: daemon didn't shutdown cleanly: %s\n", err.Error()) - stopWg.Done() - } + serverMgr.Stop() }() // Run the daemon until closed From 5d103b66c217f4759608016439d49172bb1d0484 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Thu, 9 May 2024 17:52:35 -0400 Subject: [PATCH 4/8] Added a daemon container tag param --- shared/config/ids/stakewise.go | 1 + shared/config/stakewise-config.go | 19 +++++++++++++++++++ shared/version.go | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/shared/config/ids/stakewise.go b/shared/config/ids/stakewise.go index 1766c28..6004784 100644 --- a/shared/config/ids/stakewise.go +++ b/shared/config/ids/stakewise.go @@ -4,6 +4,7 @@ const ( // Param IDs StakewiseEnableID string = "enable" ApiPortID string = "apiPort" + DaemonContainerTagID string = "daemonContainerTag" OperatorContainerTagID string = "operatorContainerTag" AdditionalOpFlagsID string = "additionalOpFlags" VerifyDepositRootsID string = "verifyDepositRoots" diff --git a/shared/config/stakewise-config.go b/shared/config/stakewise-config.go index 9b3cca1..55ffae8 100644 --- a/shared/config/stakewise-config.go +++ b/shared/config/stakewise-config.go @@ -25,6 +25,9 @@ type StakewiseConfig struct { // Toggle for verifying deposit data Merkle roots before saving VerifyDepositsRoot config.Parameter[bool] + // The Docker Hub tag for the Stakewise daemon + DaemonContainerTag config.Parameter[string] + // The Docker Hub tag for the Stakewise operator OperatorContainerTag config.Parameter[string] @@ -92,6 +95,20 @@ func NewStakewiseConfig(hdCfg *hdconfig.HyperdriveConfig) *StakewiseConfig { }, }, + DaemonContainerTag: config.Parameter[string]{ + ParameterCommon: &config.ParameterCommon{ + ID: ids.DaemonContainerTagID, + Name: "Daemon Container Tag", + Description: "The tag name of Hyperdrive's Stakewise Daemon image to use. See https://github.com/stakewise/v3-operator#using-docker for more details.", + AffectsContainers: []config.ContainerID{ContainerID_StakewiseDaemon}, + CanBeBlank: false, + OverwriteOnUpgrade: true, + }, + Default: map[config.Network]string{ + config.Network_All: daemonTag, + }, + }, + OperatorContainerTag: config.Parameter[string]{ ParameterCommon: &config.ParameterCommon{ ID: ids.OperatorContainerTagID, @@ -149,7 +166,9 @@ func (cfg *StakewiseConfig) GetTitle() string { func (cfg *StakewiseConfig) GetParameters() []config.IParameter { return []config.IParameter{ &cfg.Enabled, + &cfg.ApiPort, &cfg.VerifyDepositsRoot, + &cfg.DaemonContainerTag, &cfg.OperatorContainerTag, &cfg.AdditionalOpFlags, } diff --git a/shared/version.go b/shared/version.go index 73be91e..31ebcab 100644 --- a/shared/version.go +++ b/shared/version.go @@ -1,5 +1,5 @@ package shared const ( - StakewiseVersion string = "0.1.1" + StakewiseVersion string = "0.1.2-dev" ) From 20e2521295231004785d83d03eff743954d83106 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Thu, 9 May 2024 20:35:35 -0400 Subject: [PATCH 5/8] Removed a mod replace --- go.mod | 2 -- go.sum | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 3d2f301..55028cb 100644 --- a/go.mod +++ b/go.mod @@ -107,5 +107,3 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) - -replace github.com/nodeset-org/hyperdrive-daemon => ../hyperdrive-daemon diff --git a/go.sum b/go.sum index 14dc1cd..244e674 100644 --- a/go.sum +++ b/go.sum @@ -236,6 +236,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= +github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240509213433-213850c1cd29 h1:HbR4esVHeb5Y0EMUFYei/0h7yIADHpwCPs/kfS9F/YU= +github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240509213433-213850c1cd29/go.mod h1:zXxPJ7tzwMJYORRhWJbVsQFOWqWoDGg7rsr4IYUJVBA= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= From 580ea0a0d492db18fd7ef4fa07c3a0464f28a882 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Mon, 13 May 2024 16:18:37 -0400 Subject: [PATCH 6/8] Updated CI --- .github/workflows/build.yml | 3 +-- .github/workflows/lint.yml | 11 ++++++----- .github/workflows/unit-tests.yml | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 82b3be0..533dcac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,6 @@ on: tags: - v* branches: - - master - main pull_request: permissions: @@ -16,5 +15,5 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: 1.21.8 + go-version: 1.21.10 - run: cd ${GITHUB_WORKSPACE} && go build . diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e8ab3b2..1481911 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,25 +5,26 @@ on: tags: - v* branches: - - master - main pull_request: permissions: + # Required: allow read access to the content for analysis. contents: read # Optional: allow read access to pull request. Use with `only-new-issues` option. # pull-requests: read + # Optional: allow write access to checks to allow the action to annotate code in the PR. + checks: write jobs: golangci: name: lint runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: 1.21.8 - - uses: actions/checkout@v4 - - run: go mod download all + go-version: 1.21.10 - name: golangci-lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v6 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version version: latest diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index b3322e4..7dae02e 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -4,7 +4,6 @@ on: tags: - v* branches: - - master - main pull_request: permissions: @@ -16,5 +15,5 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: 1.21.8 + go-version: 1.21.10 - run: go test ./... From 969450d4c52163a9d094734c63cb8b51f7ee31e2 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Tue, 14 May 2024 10:48:42 -0400 Subject: [PATCH 7/8] Added a daemon container tag getter for templating --- shared/config/templating.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/config/templating.go b/shared/config/templating.go index a70ebef..a6f553e 100644 --- a/shared/config/templating.go +++ b/shared/config/templating.go @@ -35,8 +35,8 @@ func (c *StakewiseConfig) DepositDataFile() string { } // The tag for the daemon container -func (cfg *StakewiseConfig) DaemonTag() string { - return daemonTag +func (cfg *StakewiseConfig) GetDaemonContainerTag() string { + return cfg.DaemonContainerTag.Value } // Get the container tag of the selected VC From 8bdf16ee3974cf34229781e1eb8580ebc5b6857e Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Tue, 14 May 2024 11:54:19 -0400 Subject: [PATCH 8/8] Fixed a cmd line flag --- go.mod | 2 +- go.sum | 4 ++-- stakewise-daemon.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 55028cb..27d8d7e 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/goccy/go-json v0.10.2 github.com/google/uuid v1.6.0 github.com/gorilla/mux v1.8.1 - github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240509213433-213850c1cd29 + github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240514151427-1d3a507c33e8 github.com/rocket-pool/batch-query v1.0.0 github.com/rocket-pool/node-manager-core v0.3.1-0.20240507185958-ac96f93a88ec github.com/urfave/cli/v2 v2.27.1 diff --git a/go.sum b/go.sum index 244e674..a288e62 100644 --- a/go.sum +++ b/go.sum @@ -236,8 +236,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= -github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240509213433-213850c1cd29 h1:HbR4esVHeb5Y0EMUFYei/0h7yIADHpwCPs/kfS9F/YU= -github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240509213433-213850c1cd29/go.mod h1:zXxPJ7tzwMJYORRhWJbVsQFOWqWoDGg7rsr4IYUJVBA= +github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240514151427-1d3a507c33e8 h1:xMA8dJ39AYB5xSkta4qM+G/daG3Pcgl/z6Otf+0FzDw= +github.com/nodeset-org/hyperdrive-daemon v0.4.2-dev.0.20240514151427-1d3a507c33e8/go.mod h1:zXxPJ7tzwMJYORRhWJbVsQFOWqWoDGg7rsr4IYUJVBA= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= diff --git a/stakewise-daemon.go b/stakewise-daemon.go index b3f988c..e57b778 100644 --- a/stakewise-daemon.go +++ b/stakewise-daemon.go @@ -50,7 +50,7 @@ func main() { } hyperdriveUrlFlag := &cli.StringFlag{ Name: "hyperdrive-url", - Aliases: []string{"h"}, + Aliases: []string{"hd"}, Usage: "The URL of the Hyperdrive API", Value: "http://127.0.0.1:" + strconv.FormatUint(uint64(config.DefaultApiPort), 10), }