-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Keymanager fixes for bad file writes #12284
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments on the commentary, but haven't tested this locally yet
} | ||
// | ||
// 6) Return Statuses | ||
return statuses, nil | ||
} | ||
|
||
// ImportKeypairs directly into the keymanager. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be updated. This routine does more than import directly into km
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you suggest breaking this function up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think it's already split up well. I think the comment could mention how this first attempts to save to disk then updates the keymanager rather than "imports directly into keymanager"
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
… instead update the information based on memory on hand
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
km.accountsStore.PublicKeys = append(km.accountsStore.PublicKeys, pk) | ||
km.accountsStore.PrivateKeys = append(km.accountsStore.PrivateKeys, sk) | ||
} | ||
updateAccountsStoreInMemory(km.accountsStore, privateKeys, publicKeys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't set km.accountsStore
after executing this function call. Its better to be explicit of what struct fields are being updated in this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the name to better represent this.
@@ -256,17 +264,70 @@ func (km *Keymanager) initializeAccountKeystore(ctx context.Context) error { | |||
} | |||
|
|||
// CreateAccountsKeystore creates a new keystore holding the provided keys. | |||
func (km *Keymanager) CreateAccountsKeystore( | |||
func (km *Keymanager) CreateAccountsKeystore(ctx context.Context, privateKeys [][]byte, publicKeys [][]byte) (*AccountsKeystoreRepresentation, error) { | |||
if err := km.CreateOrUpdateInMemoryAccountsStore(ctx, privateKeys, publicKeys); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this function succeeds but the one following it fails, will that cause issues ?
CreateOrUpdateInMemoryAccountsStore
updates it in memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will take a look again this is only used during the wallet creation process with 0 imports perhaps i can make this cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is used in the create wallet function, if it works but the store doesn't it should fail the write. it's only used in tests otherwise besides that.
validator/keymanager/local/import.go
Outdated
if err := km.wallet.WriteFileAtPath(ctx, AccountsPath, AccountsKeystoreFileName, encodedAccounts); err != nil { | ||
return nil, err | ||
// 5) Verify keys are indeed Imported | ||
if len(km.accountsStore.PublicKeys) < len(storeCopy.PublicKeys) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any point of this check now ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe not I can probably remove this... as the in memory already updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this locally and confirmed that the key is not deleted from the in memory keystore when the keystore is not successfully written to disk.
LGTM - but please address other comments
What type of PR is this?
Bug fix
What does this PR do? Why is it needed?
addresses concerns in #12281 by serializing the process and making sure that local data is not updated until file write is done. if the file is disrupted and cannot finish then the process will roll back.
// 1) Copy the in memory keystore
// 2) Delete the keys from copied in memory keystore
// 3) Save the copy to disk
// 4) Reinitialize account store
from diskreinitializing with copy instead// 5) Verify keys are indeed deletedremoving this step as the in memory is updated with copy instead of reading from file.// 6) Return API response
similar steps needed for Import
// 1) Copy the in memory keystore
// 2) Import the keys into copied in memory keystore
// 3) Save the copy to disk
// 4) Reinitialize account store
from diskreinitializing with copy instead// 5) Verify keys are indeed Importedremoving this step as the in memory is updated with copy instead of reading from file.// 6) Return Statuses
Which issues(s) does this PR fix?
Fixes #12281