Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressing smartnode-issue-572 #621

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from

Conversation

SolezOfScience
Copy link
Contributor

@SolezOfScience SolezOfScience commented Aug 11, 2024

Overview

This is change 1/2 to address smartnode-issue-572.

This change includes a key-recovery-manager class which is a refactored version of the existing recover-keys. For the time being, the old version is being kept and will be removed in a follow-up PR which migrates the remaining daemon API implementations to use the new version and support the new CLI parameters.

Failure Reason Collection

The approach collects errors as it iteratively tries to recover keys. If keys have not been attempted to be processed, you won't get a publicKey -> error association. However, you will get a general error response. Once publicKeys are able to be procured, the response objects are used.

Limiting Unexpected State

Overall, this change maintains the status quo for how the API tries to manage/limit risk of unexpected state and how it's documented. At their core, these APIs will always have risk of unexpected state given the serial nature of how keys are written by the keystore manager. Without a true atomic batch-write procedure, there will always be risk of the process leaving unfinished work. This change does not intend to address this, but is acknowledged as a potential improvement in the future should it become worthwhile.

Testing

No testing has been run on this change yet. I would prefer to setup unit testing rather than try enacting manual testing. I'll be following up on this topic as the PR receives feedback.

This is commit 1/3 to address smartnode-issue-572. This commit includes changes to:
1) add an enable-partial-rebuild flag to the rebuild flow, 2) return error data per key from the API and 3) add logging to inform the user of the outcomes.

Update recover-keys.go

Update go.mod
@SolezOfScience SolezOfScience force-pushed the refactor/smartnode-issue-572-rebuild-rework branch from ec51995 to 9bd5510 Compare August 11, 2024 22:14
func (r *WalletRequester) Rebuild() (*types.ApiResponse[api.WalletRebuildData], error) {
return client.SendGetRequest[api.WalletRebuildData](r, "rebuild", "Rebuild", nil)
func (r *WalletRequester) Rebuild(enablePartialRebuild bool) (*types.ApiResponse[api.WalletRebuildData], error) {
return client.SendGetRequest[api.WalletRebuildData](r, "rebuild", "Rebuild", map[string]string{"enable-partial-rebuild": strconv.FormatBool(enablePartialRebuild)})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting. bool types are native json types- do we need to use a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I was just following convention on this one. For example, the skip-validator-key-recovery parameter uses a similar code flow to translate the string to boolean.

I could see the perspective that this is a bit silly since the parameter is a string, gets converted to a bool to call the method then is immediately converted back to a string for the payload. I also cringe at the idea of passing a string around which is serving as a boolean, so neither way is elegant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SendGetRequest method takes a map[string]string. Refactoring this down could make this more generic, but for now requires parameters as strings.

rocketpool-cli/commands/wallet/rebuild.go Outdated Show resolved Hide resolved
// Log
fmt.Println("Rebuilding node validator keystores...")
fmt.Printf("Partial rebuild enabled: %s.\n", enablePartialRebuild.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enablePartialRebuild.Name here is equal to enable-partial-rebuild per

Name: "enable-partial-rebuild",

Did you mean to printf the value of enablePartialRebuildValue instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. Frankly I found the use of these oddly confusing. For example, recover.go, it checks if the name is non-empty before using it but given the definition of the flags, I don't see how it could be empty.

Regardless, I'll definitely update this log.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that looks like a bug :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha - once you left that comment I figured that may be the case. I'll take a note.

rocketpool-cli/commands/wallet/rebuild.go Outdated Show resolved Hide resolved
rocketpool-cli/commands/wallet/rebuild.go Outdated Show resolved Hide resolved
rocketpool-cli/commands/wallet/utils.go Outdated Show resolved Hide resolved
rocketpool-daemon/common/validator/validator-manager.go Outdated Show resolved Hide resolved
… support test and partial recovery modes.

This change addresses all comments from the first draft of the PR to introduce partial recovery support. This removes multiple implementations of a KeyRecoveryManager interface and instead uses class fields to determine how to appropriately enact the recover code flow.
Copy link
Contributor

@jshufro jshufro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved, but i think we need to do some thorough testing before we land

}
fmt.Println("Validator Client restarted successfully.")
} else {
fmt.Println("No validator keys were found.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a slight preference to see this moved up to L84 and the conditional inverted. An early return can prevent the need for an else block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants