Skip to content

Commit

Permalink
Refactored network settings loading to be at app start for headless m…
Browse files Browse the repository at this point in the history
…ode support
  • Loading branch information
jclapis committed Jul 23, 2024
1 parent 55064c6 commit 2310d7c
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 156 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,6 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

require github.com/d4l3k/messagediff v1.2.1 // indirect

replace github.com/wealdtech/go-merkletree v1.0.1-0.20190605192610-2bb163c2ea2a => github.com/rocket-pool/go-merkletree v1.0.1-0.20220406020931-c262d9b976dd
58 changes: 29 additions & 29 deletions install/deploy/networks/devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ networkResources:
txWatchUrl: https://holesky.etherscan.io/tx
flashbotsProtectUrl: https://rpc-holesky.flashbots.net/
smartNodeResources:
stakeUrl: "TBD"
storageAddress: 0xf04de123993761Bb9F08c9C39112b0E0b0eccE50
rethAddress: 0x4be7161080b5d890500194cee2c40B1428002Bd3
rplTokenAddress: 0x59A1a7AebCbF103B3C4f85261fbaC166117E1979
v1_0_0_RewardsPoolAddress: null
v1_0_0_ClaimNodeAddress: null
v1_0_0_ClaimTrustedNodeAddress: null
v1_0_0_MinipoolManagerAddress: null
v1_1_0_NetworkPricesAddress: null
v1_1_0_NodeStakingAddress: null
v1_1_0_NodeDepositAddress: null
v1_1_0_MinipoolQueueAddress: null
v1_1_0_MinipoolFactoryAddress: null
v1_2_0_NetworkPricesAddress: 0xBba3FBCD4Bdbfc79118B1B31218602E5A71B426c
v1_2_0_NetworkBalancesAddress: 0xBe8Dc8CA5f339c196Aef634DfcDFbA61E30DC743
snapshotDelegationAddress: null
snapshotApiDomain: ""
previousRewardsPoolAddresses:
- 0x4d581a552490fb6fce5F978e66560C8b7E481818
PreviousProtocolDaoVerifierAddresses: []
OptimismPriceMessengerAddress: null
PolygonPriceMessengerAddress: null
ArbitrumPriceMessengerAddress: null
ArbitrumPriceMessengerAddressV2: null
ZkSyncEraPriceMessengerAddress: null
BasePriceMessengerAddress: null
ScrollPriceMessengerAddress: null
ScrollFeeEstimatorAddress: null
RplTwapPoolAddress: 0x7bb10d2a3105ed5cc150c099a06cafe43d8aa15d
stakeUrl: TBD
storageAddress: 0xf04de123993761Bb9F08c9C39112b0E0b0eccE50
rethAddress: 0x4be7161080b5d890500194cee2c40B1428002Bd3
rplTokenAddress: 0x59A1a7AebCbF103B3C4f85261fbaC166117E1979
v1_0_0_RewardsPoolAddress: null
v1_0_0_ClaimNodeAddress: null
v1_0_0_ClaimTrustedNodeAddress: null
v1_0_0_MinipoolManagerAddress: null
v1_1_0_NetworkPricesAddress: null
v1_1_0_NodeStakingAddress: null
v1_1_0_NodeDepositAddress: null
v1_1_0_MinipoolQueueAddress: null
v1_1_0_MinipoolFactoryAddress: null
v1_2_0_NetworkPricesAddress: 0xBba3FBCD4Bdbfc79118B1B31218602E5A71B426c
v1_2_0_NetworkBalancesAddress: 0xBe8Dc8CA5f339c196Aef634DfcDFbA61E30DC743
snapshotDelegationAddress: null
snapshotApiDomain: ""
previousRewardsPoolAddresses:
- 0x4d581a552490fb6fce5F978e66560C8b7E481818
previousProtocolDaoVerifierAddresses: []
optimismPriceMessengerAddress: null
polygonPriceMessengerAddress: null
arbitrumPriceMessengerAddress: null
arbitrumPriceMessengerAddressV2: null
zkSyncEraPriceMessengerAddress: null
basePriceMessengerAddress: null
scrollPriceMessengerAddress: null
scrollFeeEstimatorAddress: null
rplTwapPoolAddress: 0x7bb10d2a3105ed5cc150c099a06cafe43d8aa15d
58 changes: 29 additions & 29 deletions install/deploy/networks/holesky.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ networkResources:
txWatchUrl: https://holesky.etherscan.io/tx
flashbotsProtectUrl: https://rpc-holesky.flashbots.net/
smartNodeResources:
stakeUrl: "https://testnet.rocketpool.net"
storageAddress: 0x594Fb75D3dc2DFa0150Ad03F99F97817747dd4E1
rethAddress: 0x7322c24752f79c05FFD1E2a6FCB97020C1C264F1
rplTokenAddress: 0x1Cc9cF5586522c6F483E84A19c3C2B0B6d027bF0
v1_0_0_RewardsPoolAddress: null
v1_0_0_ClaimNodeAddress: null
v1_0_0_ClaimTrustedNodeAddress: null
v1_0_0_MinipoolManagerAddress: null
v1_1_0_NetworkPricesAddress: null
v1_1_0_NodeStakingAddress: null
v1_1_0_NodeDepositAddress: null
v1_1_0_MinipoolQueueAddress: null
v1_1_0_MinipoolFactoryAddress: null
v1_2_0_NetworkPricesAddress: 0x029d946F28F93399a5b0D09c879FC8c94E596AEb
v1_2_0_NetworkBalancesAddress: 0x9294Fc6F03c64Cc217f5BE8697EA3Ed2De77e2F8
snapshotDelegationAddress: null
snapshotApiDomain: ""
previousRewardsPoolAddresses:
- 0x4a625C617a44E60F74E3fe3bf6d6333b63766e91
PreviousProtocolDaoVerifierAddresses: []
OptimismPriceMessengerAddress: null
PolygonPriceMessengerAddress: null
ArbitrumPriceMessengerAddress: null
ArbitrumPriceMessengerAddressV2: null
ZkSyncEraPriceMessengerAddress: null
BasePriceMessengerAddress: null
ScrollPriceMessengerAddress: null
ScrollFeeEstimatorAddress: null
RplTwapPoolAddress: 0x7bb10d2a3105ed5cc150c099a06cafe43d8aa15d
stakeUrl: "https://testnet.rocketpool.net"
storageAddress: 0x594Fb75D3dc2DFa0150Ad03F99F97817747dd4E1
rethAddress: 0x7322c24752f79c05FFD1E2a6FCB97020C1C264F1
rplTokenAddress: 0x1Cc9cF5586522c6F483E84A19c3C2B0B6d027bF0
v1_0_0_RewardsPoolAddress: null
v1_0_0_ClaimNodeAddress: null
v1_0_0_ClaimTrustedNodeAddress: null
v1_0_0_MinipoolManagerAddress: null
v1_1_0_NetworkPricesAddress: null
v1_1_0_NodeStakingAddress: null
v1_1_0_NodeDepositAddress: null
v1_1_0_MinipoolQueueAddress: null
v1_1_0_MinipoolFactoryAddress: null
v1_2_0_NetworkPricesAddress: 0x029d946F28F93399a5b0D09c879FC8c94E596AEb
v1_2_0_NetworkBalancesAddress: 0x9294Fc6F03c64Cc217f5BE8697EA3Ed2De77e2F8
snapshotDelegationAddress: null
snapshotApiDomain: ""
previousRewardsPoolAddresses:
- 0x4a625C617a44E60F74E3fe3bf6d6333b63766e91
previousProtocolDaoVerifierAddresses: []
optimismPriceMessengerAddress: null
polygonPriceMessengerAddress: null
arbitrumPriceMessengerAddress: null
arbitrumPriceMessengerAddressV2: null
zkSyncEraPriceMessengerAddress: null
basePriceMessengerAddress: null
scrollPriceMessengerAddress: null
scrollFeeEstimatorAddress: null
rplTwapPoolAddress: 0x7bb10d2a3105ed5cc150c099a06cafe43d8aa15d
58 changes: 29 additions & 29 deletions install/deploy/networks/mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ networkResources:
txWatchUrl: https://etherscan.io/tx
flashbotsProtectUrl: https://rpc.flashbots.net/
smartNodeResources:
stakeUrl: "https://stake.rocketpool.net"
storageAddress: 0x1d8f8f00cfa6758d7bE78336684788Fb0ee0Fa46
rethAddress: 0xae78736Cd615f374D3085123A210448E74Fc6393
rplTokenAddress: 0xD33526068D116cE69F19A9ee46F0bd304F21A51f
v1_0_0_RewardsPoolAddress: 0xA3a18348e6E2d3897B6f2671bb8c120e36554802
v1_0_0_ClaimNodeAddress: 0x899336A2a86053705E65dB61f52C686dcFaeF548
v1_0_0_ClaimTrustedNodeAddress: 0x6af730deB0463b432433318dC8002C0A4e9315e8
v1_0_0_MinipoolManagerAddress: 0x6293B8abC1F36aFB22406Be5f96D893072A8cF3a
v1_1_0_NetworkPricesAddress: 0xd3f500F550F46e504A4D2153127B47e007e11166
v1_1_0_NodeStakingAddress: 0xA73ec45Fe405B5BFCdC0bF4cbc9014Bb32a01cd2
v1_1_0_NodeDepositAddress: 0x1Cc9cF5586522c6F483E84A19c3C2B0B6d027bF0
v1_1_0_MinipoolQueueAddress: 0x5870dA524635D1310Dc0e6F256Ce331012C9C19E
v1_1_0_MinipoolFactoryAddress: 0x54705f80D7C51Fcffd9C659ce3f3C9a7dCCf5788
v1_2_0_NetworkPricesAddress: 0x751826b107672360b764327631cC5764515fFC37
v1_2_0_NetworkBalancesAddress: 0x07FCaBCbe4ff0d80c2b1eb42855C0131b6cba2F4
snapshotDelegationAddress: 0x469788fE6E9E9681C6ebF3bF78e7Fd26Fc015446
snapshotApiDomain: "hub.snapshot.org"
previousRewardsPoolAddresses:
- 0x594Fb75D3dc2DFa0150Ad03F99F97817747dd4E1
PreviousProtocolDaoVerifierAddresses: []
OptimismPriceMessengerAddress: 0xdddcf2c25d50ec22e67218e873d46938650d03a7
PolygonPriceMessengerAddress: 0xb1029Ac2Be4e08516697093e2AFeC435057f3511
ArbitrumPriceMessengerAddress: 0x05330300f829AD3fC8f33838BC88CFC4093baD53
ArbitrumPriceMessengerAddressV2: 0x312FcFB03eC9B1Ea38CB7BFCd26ee7bC3b505aB1
ZkSyncEraPriceMessengerAddress: 0x6cf6CB29754aEBf88AF12089224429bD68b0b8c8
BasePriceMessengerAddress: 0x64A5856869C06B0188C84A5F83d712bbAc03517d
ScrollPriceMessengerAddress: 0x0f22dc9b9c03757d4676539203d7549c8f22c15c
ScrollFeeEstimatorAddress: 0x0d7E906BD9cAFa154b048cFa766Cc1E54E39AF9B
RplTwapPoolAddress: 0xe42318ea3b998e8355a3da364eb9d48ec725eb45
stakeUrl: "https://stake.rocketpool.net"
storageAddress: 0x1d8f8f00cfa6758d7bE78336684788Fb0ee0Fa46
rethAddress: 0xae78736Cd615f374D3085123A210448E74Fc6393
rplTokenAddress: 0xD33526068D116cE69F19A9ee46F0bd304F21A51f
v1_0_0_RewardsPoolAddress: 0xA3a18348e6E2d3897B6f2671bb8c120e36554802
v1_0_0_ClaimNodeAddress: 0x899336A2a86053705E65dB61f52C686dcFaeF548
v1_0_0_ClaimTrustedNodeAddress: 0x6af730deB0463b432433318dC8002C0A4e9315e8
v1_0_0_MinipoolManagerAddress: 0x6293B8abC1F36aFB22406Be5f96D893072A8cF3a
v1_1_0_NetworkPricesAddress: 0xd3f500F550F46e504A4D2153127B47e007e11166
v1_1_0_NodeStakingAddress: 0xA73ec45Fe405B5BFCdC0bF4cbc9014Bb32a01cd2
v1_1_0_NodeDepositAddress: 0x1Cc9cF5586522c6F483E84A19c3C2B0B6d027bF0
v1_1_0_MinipoolQueueAddress: 0x5870dA524635D1310Dc0e6F256Ce331012C9C19E
v1_1_0_MinipoolFactoryAddress: 0x54705f80D7C51Fcffd9C659ce3f3C9a7dCCf5788
v1_2_0_NetworkPricesAddress: 0x751826b107672360b764327631cC5764515fFC37
v1_2_0_NetworkBalancesAddress: 0x07FCaBCbe4ff0d80c2b1eb42855C0131b6cba2F4
snapshotDelegationAddress: 0x469788fE6E9E9681C6ebF3bF78e7Fd26Fc015446
snapshotApiDomain: "hub.snapshot.org"
previousRewardsPoolAddresses:
- 0x594Fb75D3dc2DFa0150Ad03F99F97817747dd4E1
previousProtocolDaoVerifierAddresses: []
optimismPriceMessengerAddress: 0xdddcf2c25d50ec22e67218e873d46938650d03a7
polygonPriceMessengerAddress: 0xb1029Ac2Be4e08516697093e2AFeC435057f3511
arbitrumPriceMessengerAddress: 0x05330300f829AD3fC8f33838BC88CFC4093baD53
arbitrumPriceMessengerAddressV2: 0x312FcFB03eC9B1Ea38CB7BFCd26ee7bC3b505aB1
zkSyncEraPriceMessengerAddress: 0x6cf6CB29754aEBf88AF12089224429bD68b0b8c8
basePriceMessengerAddress: 0x64A5856869C06B0188C84A5F83d712bbAc03517d
scrollPriceMessengerAddress: 0x0f22dc9b9c03757d4676539203d7549c8f22c15c
scrollFeeEstimatorAddress: 0x0d7E906BD9cAFa154b048cFa766Cc1E54E39AF9B
rplTwapPoolAddress: 0xe42318ea3b998e8355a3da364eb9d48ec725eb45
18 changes: 3 additions & 15 deletions rocketpool-cli/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,13 @@ func (c *Client) LoadConfig() (*config.SmartNodeConfig, bool, error) {
return c.cfg, c.isNewCfg, nil
}

// Load the network settings
settingsList, err := config.LoadSettingsFiles(c.Context.NetworksDir)
if err != nil {
return nil, false, fmt.Errorf("error loading network settings: %w", err)
}

// Load the config
settingsFilePath := filepath.Join(c.Context.ConfigPath, SettingsFile)
expandedPath, err := homedir.Expand(settingsFilePath)
if err != nil {
return nil, false, fmt.Errorf("error expanding settings file path: %w", err)
}
cfg, err := LoadConfigFromFile(expandedPath, settingsList)
cfg, err := LoadConfigFromFile(expandedPath, c.Context.NetworkSettings)
if err != nil {
return nil, false, err
}
Expand All @@ -51,7 +45,7 @@ func (c *Client) LoadConfig() (*config.SmartNodeConfig, bool, error) {
}

// Config wasn't loaded, but there was no error- we should create one.
cfg, err = config.NewSmartNodeConfig(c.Context.ConfigPath, c.Context.NativeMode, settingsList)
cfg, err = config.NewSmartNodeConfig(c.Context.ConfigPath, c.Context.NativeMode, c.Context.NetworkSettings)
if err != nil {
return nil, false, fmt.Errorf("error creating new Smart Node config: %w", err)
}
Expand All @@ -68,13 +62,7 @@ func (c *Client) LoadBackupConfig() (*config.SmartNodeConfig, error) {
return nil, fmt.Errorf("error expanding backup settings file path: %w", err)
}

// Load the network settings
settingsList, err := config.LoadSettingsFiles(c.Context.NetworksDir)
if err != nil {
return nil, fmt.Errorf("error loading network settings: %w", err)
}

return LoadConfigFromFile(expandedPath, settingsList)
return LoadConfigFromFile(expandedPath, c.Context.NetworkSettings)
}

// Save the config
Expand Down
9 changes: 0 additions & 9 deletions rocketpool-cli/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ func SyncRatioToPercent(in float64) float64 {
return math.Min(99.99, in*100)
}

// Load the Smart Node settings from the network settings files on disk
func LoadSmartNodeSettings(networksDir string) ([]*config.SmartNodeSettings, error) {
settings, err := config.LoadSettingsFiles(networksDir)
if err != nil {
return nil, fmt.Errorf("error loading Smart Node settings files from [%s]: %w", networksDir, err)
}
return settings, nil
}

// Loads a config without updating it if it exists
func LoadConfigFromFile(path string, networks []*config.SmartNodeSettings) (*config.SmartNodeConfig, error) {
_, err := os.Stat(path)
Expand Down
4 changes: 2 additions & 2 deletions rocketpool-cli/commands/service/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func createFlagsFromConfigParams(prefix string, section config.IConfigSection, c
}

// Register commands
func RegisterCommands(app *cli.App, name string, aliases []string) {
func RegisterCommands(app *cli.App, name string, aliases []string, networkSettings []*snCfg.SmartNodeSettings) {
// Create config flags from parameters
cfgTemplate, _ := snCfg.NewSmartNodeConfig("", false, []*snCfg.SmartNodeSettings{})
cfgTemplate, _ := snCfg.NewSmartNodeConfig("", false, networkSettings)
network := cfgTemplate.Network.Value
configFlags := createFlagsFromConfigParams("", cfgTemplate, []cli.Flag{
installUpdateDefaultsFlag,
Expand Down
13 changes: 11 additions & 2 deletions rocketpool-cli/rocketpool-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/commands/wallet"
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/settings"
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/utils"
"github.com/rocket-pool/smartnode/v2/shared/config"
)

// allowRootFlag is the only one this file deals with- simply so it can exit early.
Expand Down Expand Up @@ -97,6 +98,14 @@ func newCliApp() *cli.App {
// Set utility flags
app.Flags = utils.AppendFlags(app.Flags)

// Load the network settings
systemSettings := settings.NewSystemSettings()
networkSettings, err := config.LoadSettingsFiles(systemSettings.NetworksDir)
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading network settings from path [%s]: %s", systemSettings.NetworksDir, err.Error())
os.Exit(1)
}

// Register commands
auction.RegisterCommands(app, "auction", []string{"a"})
minipool.RegisterCommands(app, "minipool", []string{"m"})
Expand All @@ -106,7 +115,7 @@ func newCliApp() *cli.App {
pdao.RegisterCommands(app, "pdao", []string{"p"})
queue.RegisterCommands(app, "queue", []string{"q"})
security.RegisterCommands(app, "security", []string{"c"})
service.RegisterCommands(app, "service", []string{"s"})
service.RegisterCommands(app, "service", []string{"s"}, networkSettings)
wallet.RegisterCommands(app, "wallet", []string{"w"})

var snSettings *settings.SmartNodeSettings
Expand All @@ -119,7 +128,7 @@ func newCliApp() *cli.App {
}

var err error
snSettings, err = settings.NewSmartNodeSettings(c)
snSettings, err = settings.NewSmartNodeSettings(c, systemSettings, networkSettings)
if err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
Expand Down
38 changes: 38 additions & 0 deletions rocketpool-cli/rocketpool-cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"bytes"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"

"github.com/prysmaticlabs/prysm/v5/testing/require"
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/settings"
"github.com/urfave/cli/v2"
)
Expand All @@ -34,6 +36,42 @@ func TestGlobalFlagsDefaults(t *testing.T) {
"--help",
)

// Make a system path
systemPath := filepath.Join(tempPath, "rocketpool")
err := os.MkdirAll(systemPath, 0755)
require.NoError(t, err)

// Emulating a (partial) installation by deploying a networks folder
// Other installation files can be copied here later if necessary
networkSettingsPath := filepath.Join(systemPath, "networks")
err = os.MkdirAll(networkSettingsPath, 0755)
require.NoError(t, err)

// Copy the settings files
networksSource := filepath.Join("..", "install", "deploy", "networks")
entries, err := os.ReadDir(networksSource)
require.NoError(t, err)
for _, file := range entries {
fileName := file.Name()

sourceFile, err := os.Open(filepath.Join(networksSource, fileName))
require.NoError(t, err)
defer sourceFile.Close()

targetFile, err := os.Create(filepath.Join(networkSettingsPath, fileName))
require.NoError(t, err)
defer targetFile.Close()

_, err = io.Copy(targetFile, sourceFile)
require.NoError(t, err)
err = targetFile.Sync()
require.NoError(t, err)
}

// Set the install dir env var
err = os.Setenv(settings.TestSystemDirEnvVar, systemPath)
require.NoError(t, err)

app := newCliApp()

// Capture stdout
Expand Down
Loading

0 comments on commit 2310d7c

Please sign in to comment.