Skip to content

Commit

Permalink
Enable and fix unused issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jshufro committed Apr 17, 2024
1 parent a49f6ff commit c235da8
Show file tree
Hide file tree
Showing 22 changed files with 2 additions and 390 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# args: --issues-exit-code=0

# For now, Smart Node will only enforce goimports linting
args: --disable-all --enable goimports --enable staticcheck --enable ineffassign --enable gosimple
args: --disable-all --enable goimports --enable staticcheck --enable ineffassign --enable gosimple --enable unused

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
Expand Down
14 changes: 0 additions & 14 deletions rocketpool-cli/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"

"github.com/alessio/shellescape"
"github.com/rocket-pool/node-manager-core/api/types"
"github.com/rocket-pool/smartnode/v2/shared/config"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -98,16 +97,3 @@ func SaveConfig(cfg *config.SmartNodeConfig, directory string, filename string)

return nil
}

// Parse and augment the status of a client into a human-readable format
func getClientStatusString(clientStatus types.ClientStatus) string {
if clientStatus.IsSynced {
return "synced and ready"
}

if clientStatus.IsWorking {
return fmt.Sprintf("syncing (%.2f%%)", SyncRatioToPercent(clientStatus.SyncProgress))
}

return fmt.Sprintf("unavailable (%s)", clientStatus.Error)
}
77 changes: 0 additions & 77 deletions rocketpool-cli/commands/node/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"
"github.com/mitchellh/go-homedir"
"github.com/rocket-pool/node-manager-core/beacon"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v2"

"github.com/rocket-pool/node-manager-core/eth"
nmc_utils "github.com/rocket-pool/node-manager-core/utils"
"github.com/rocket-pool/node-manager-core/utils/math"
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/client"
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/utils"
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/utils/tx"
"github.com/rocket-pool/smartnode/v2/shared/config"
"github.com/rocket-pool/smartnode/v2/shared/types/api"
)

const (
Expand Down Expand Up @@ -324,77 +318,6 @@ func promptMinNodeFee(networkCurrentNodeFee, networkMinNodeFee float64) float64

}

// Prompt for the password to a solo validator key as part of migration
func promptForSoloKeyPassword(cfg *config.SmartNodeConfig, pubkey beacon.ValidatorPubkey) (string, error) {

// Check for the custom key directory
customKeyDir, err := homedir.Expand(cfg.GetCustomKeyPath())
if err != nil {
return "", fmt.Errorf("error expanding custom keys directory: %w", err)
}
info, err := os.Stat(customKeyDir)
if os.IsNotExist(err) || !info.IsDir() {
return "", nil
}

// Get the custom keystore files
files, err := os.ReadDir(customKeyDir)
if err != nil {
return "", fmt.Errorf("error enumerating custom keystores: %w", err)
}
if len(files) == 0 {
return "", nil
}

// Get the pubkeys for the custom keystores
pubkeyPasswords := map[string]string{}
for _, file := range files {
// Read the file
bytes, err := os.ReadFile(filepath.Join(customKeyDir, file.Name()))
if err != nil {
return "", fmt.Errorf("error reading custom keystore %s: %w", file.Name(), err)
}

// Deserialize it
keystore := api.ValidatorKeystore{}
err = json.Unmarshal(bytes, &keystore)
if err != nil {
return "", fmt.Errorf("error deserializing custom keystore %s: %w", file.Name(), err)
}

if keystore.Pubkey == pubkey {
// Found it, prompt for the password
password := utils.PromptPassword(
fmt.Sprintf("Please enter the password that the keystore for %s was encrypted with:", pubkey.Hex()), "^.*$", "",
)

formattedPubkey := strings.ToUpper(nmc_utils.RemovePrefix(pubkey.Hex()))
pubkeyPasswords[formattedPubkey] = password

fmt.Println()
break
}
}

if len(pubkeyPasswords) == 0 {
return "", fmt.Errorf("couldn't find the keystore for validator %s in the custom-keys directory; if you want to import this key into the Smartnode stack, you will need to put its keystore file into custom-keys first", pubkey.HexWithPrefix())
}

// Store it in the file
fileBytes, err := yaml.Marshal(pubkeyPasswords)
if err != nil {
return "", fmt.Errorf("error serializing keystore passwords file: %w", err)
}
passwordFile := cfg.GetCustomKeyPasswordFilePath()
err = os.WriteFile(passwordFile, fileBytes, 0600)
if err != nil {
return "", fmt.Errorf("error writing keystore passwords file: %w", err)
}

return passwordFile, nil

}

func SwapRpl(c *cli.Context, rp *client.Client, amountWei *big.Int) error {
// Get the TX
response, err := rp.Api.Node.SwapRpl(amountWei)
Expand Down
14 changes: 0 additions & 14 deletions rocketpool-cli/commands/service/config/cfg-form.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@ type parameterizedFormItem struct {
item tview.FormItem
}

func registerEnableCheckbox(param *config.Parameter[bool], checkbox *tview.Checkbox, form *Form, items []*parameterizedFormItem) {
checkbox.SetChangedFunc(func(checked bool) {
param.Value = checked
if !checked {
form.Clear(true)
form.AddFormItem(checkbox)
} else {
for _, item := range items {
form.AddFormItem(item.item)
}
}
})
}

// Create a list of form items based on a set of parameters
func createParameterizedFormItems(params []config.IParameter, descriptionBox *tview.TextView) []*parameterizedFormItem {
formItems := []*parameterizedFormItem{}
Expand Down
6 changes: 0 additions & 6 deletions rocketpool-cli/commands/service/config/pseudomodal.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ type Pseudomodal struct {

// The currently selected form (for vertical layouts)
selected int

// A fixed width for the description box (0 for auto)
descriptionWidth int

// The collection of descriptions for each button, to be displayed in the description box
buttonDescriptions []string
}

// NewPseudomodal returns a new modal message window.
Expand Down
7 changes: 0 additions & 7 deletions rocketpool-cli/commands/service/config/review-native-page.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ import (
// Constants
const reviewNativePageID string = "review-native-settings"

// The changed settings review page
type ReviewNativePage struct {
md *mainDisplay
changedSettings []*config.ChangedSection
page *page
}

// Create a page to review any changes
func NewReviewNativePage(md *mainDisplay, oldConfig *snCfg.SmartNodeConfig, newConfig *snCfg.SmartNodeConfig) *ReviewPage {
var changedSettings []*config.ChangedSection
Expand Down
37 changes: 0 additions & 37 deletions rocketpool-cli/commands/service/config/step-random-bn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,6 @@ import (
const randomBnPrysmID string = "step-random-bn-prysm"
const randomBnID string = "step-random-bn"

func createRandomPrysmStep(wiz *wizard, currentStep int, totalSteps int, goodOptions []*config.ParameterOption[config.BeaconNode]) *choiceWizardStep {
helperText := "You have been randomly assigned to Prysm for your Beacon Node.\n\n[orange]NOTE: Prysm currently has a very high representation of the Beacon Chain. For the health of the network and the overall safety of your funds, please consider choosing a client with a lower representation. Please visit https://clientdiversity.org to learn more."

show := func(modal *choiceModalLayout) {
wiz.md.setPage(modal.page)
modal.focus(0)
}

done := func(buttonIndex int, buttonLabel string) {
if buttonIndex == 0 {
selectRandomBn(goodOptions, false, wiz, currentStep, totalSteps)
} else {
wiz.checkpointSyncProviderModal.show()
}
}

back := func() {
wiz.localBnModal.show()
}

return newChoiceStep(
wiz,
currentStep,
totalSteps,
helperText,
[]string{"Choose Another Random Client", "Keep Prysm"},
[]string{},
76,
"Beacon Node > Selection",
DirectionalModalHorizontal,
show,
done,
back,
randomBnPrysmID,
)
}

func createRandomBnStep(wiz *wizard, currentStep int, totalSteps int, goodOptions []*config.ParameterOption[config.BeaconNode]) *choiceWizardStep {
var selectedClientName string
selectedClient := wiz.md.Config.LocalBeaconClient.BeaconNode.Value
Expand Down
4 changes: 0 additions & 4 deletions rocketpool-cli/commands/service/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ type settingsPage interface {
handleLayoutChanged()
getPage() *page
}

type wizardStep interface {
show()
}
1 change: 0 additions & 1 deletion rocketpool-cli/commands/service/config/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type wizard struct {
// Step 5 - BN settings
localBnModal *choiceWizardStep
localBnRandomModal *choiceWizardStep
localBnRandomPrysmModal *choiceWizardStep
localBnPrysmWarning *choiceWizardStep
localBnTekuWarning *choiceWizardStep
checkpointSyncProviderModal *textBoxWizardStep
Expand Down
6 changes: 0 additions & 6 deletions rocketpool-cli/commands/service/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"math"
"strings"
"time"

"github.com/urfave/cli/v2"

Expand All @@ -22,11 +21,6 @@ func SyncRatioToPercent(in float64) float64 {
// TODO: INCORPORATE THIS
}

// Settings
const (
ethClientRecentBlockThreshold time.Duration = 5 * time.Minute
)

func printClientStatus(status *types.ClientStatus, name string) {

if status.Error != "" {
Expand Down
11 changes: 0 additions & 11 deletions rocketpool-cli/commands/wallet/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,3 @@ func promptForCustomKeyPasswords(cfg *config.SmartNodeConfig, testOnly bool) (st

return passwordFile, nil
}

// Deletes the custom key password file
func deleteCustomKeyPasswordFile(passwordFile string) error {
_, err := os.Stat(passwordFile)
if os.IsNotExist(err) {
return nil
}

err = os.Remove(passwordFile)
return err
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ type minipoolCanChangeCredsContext struct {

mnemonic string
minipoolAddress common.Address
mpMgr *minipool.MinipoolManager
mpv3 *minipool.MinipoolV3
}

Expand Down
4 changes: 0 additions & 4 deletions rocketpool-daemon/api/node/get-snapshot-proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/gorilla/mux"
batch "github.com/rocket-pool/batch-query"
"github.com/rocket-pool/rocketpool-go/v2/node"
"github.com/rocket-pool/rocketpool-go/v2/rocketpool"

"github.com/rocket-pool/node-manager-core/api/server"
"github.com/rocket-pool/node-manager-core/api/types"
Expand Down Expand Up @@ -49,10 +47,8 @@ func (f *nodeGetSnapshotProposalsContextFactory) RegisterRoute(router *mux.Route

type nodeGetSnapshotProposalsContext struct {
handler *NodeHandler
rp *rocketpool.RocketPool

activeOnly bool
node *node.Node
}

func (c *nodeGetSnapshotProposalsContext) PrepareData(data *api.NodeGetSnapshotProposalsData, opts *bind.TransactOpts) (types.ResponseStatus, error) {
Expand Down
5 changes: 0 additions & 5 deletions rocketpool-daemon/api/node/get-snapshot-voting-power.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/gorilla/mux"
"github.com/rocket-pool/rocketpool-go/v2/node"
"github.com/rocket-pool/rocketpool-go/v2/rocketpool"

"github.com/rocket-pool/node-manager-core/api/server"
"github.com/rocket-pool/node-manager-core/api/types"
Expand Down Expand Up @@ -41,9 +39,6 @@ func (f *nodeGetSnapshotVotingPowerContextFactory) RegisterRoute(router *mux.Rou

type nodeGetSnapshotVotingPowerContext struct {
handler *NodeHandler
rp *rocketpool.RocketPool

node *node.Node
}

func (c *nodeGetSnapshotVotingPowerContext) PrepareData(data *api.NodeGetSnapshotVotingPowerData, opts *bind.TransactOpts) (types.ResponseStatus, error) {
Expand Down
21 changes: 0 additions & 21 deletions rocketpool-daemon/api/pdao/get-claimable-bonds.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package pdao

import (
"context"
"fmt"
"math/big"
"net/url"
"sort"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -319,22 +317,3 @@ func isRewardedIndex(defeatIndex uint64, nodeIndex uint64) bool {
}
return false
}

func getElBlockForTimestamp(context context.Context, bc beacon.IBeaconClient, beaconCfg beacon.Eth2Config, creationTime time.Time) (*big.Int, error) {
// Get the slot number the first proposal was created on
genesisTime := time.Unix(int64(beaconCfg.GenesisTime), 0)
secondsPerSlot := time.Second * time.Duration(beaconCfg.SecondsPerSlot)
startSlot := uint64(creationTime.Sub(genesisTime) / secondsPerSlot)

// Get the Beacon block for the slot
block, exists, err := bc.GetBeaconBlock(context, fmt.Sprint(startSlot))
if err != nil {
return nil, fmt.Errorf("error getting Beacon block at slot %d: %w", startSlot, err)
}
if !exists {
return nil, fmt.Errorf("beacon block at slot %d was missing", startSlot)
}

// Get the EL block for this slot
return big.NewInt(int64(block.ExecutionBlockNumber)), nil
}
22 changes: 0 additions & 22 deletions rocketpool-daemon/api/pdao/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,3 @@ func createPollard(context context.Context, logger *slog.Logger, rp *rocketpool.
}
return blockNumber, pollard, nil
}

// Loads (or regenerates) the pollard for a proposal from a block number
func getPollard(context context.Context, logger *slog.Logger, rp *rocketpool.RocketPool, cfg *config.SmartNodeConfig, bc beacon.IBeaconClient, blockNumber uint32) ([]types.VotingTreeNode, error) {
// Create a proposal manager
propMgr, err := proposals.NewProposalManager(context, logger, cfg, rp, bc)
if err != nil {
return nil, err
}

// Get the pollard
pollardPtrs, err := propMgr.GetPollardForProposal(blockNumber)
if err != nil {
return nil, err
}

// Make a slice of nodes from their pointers
pollard := make([]types.VotingTreeNode, len(pollardPtrs))
for i := range pollardPtrs {
pollard[i] = *pollardPtrs[i]
}
return pollard, nil
}
4 changes: 1 addition & 3 deletions rocketpool-daemon/api/wallet/delete-password.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func (f *walletDeletePasswordContextFactory) RegisterRoute(router *mux.Router) {
// ===============

type walletDeletePasswordContext struct {
handler *WalletHandler
password []byte
save bool
handler *WalletHandler
}

func (c *walletDeletePasswordContext) PrepareData(data *types.SuccessData, opts *bind.TransactOpts) (types.ResponseStatus, error) {
Expand Down
Loading

0 comments on commit c235da8

Please sign in to comment.