-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
fix: non consistent keyring #10844
Merged
Merged
fix: non consistent keyring #10844
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e7d339b
resolved conflists
swelf19 1000063
fixed code comment
swelf19 bfad545
Merge branch 'master' into fix/non-consistent-keyring
d83bdae
improved errors processing
swelf19 c8a5ee9
updated changelog
swelf19 d507980
Merge branch 'master' into fix/non-consistent-keyring
swelf19 781f365
Merge branch 'master' into fix/non-consistent-keyring
swelf19 2aed285
Merge branch 'master' into fix/non-consistent-keyring
likhita-809 f7c43a4
Merge branch 'master' into fix/non-consistent-keyring
tac0turtle bcff89a
Merge branch 'master' into fix/non-consistent-keyring
mergify[bot] e74bd12
Merge branch 'master' into fix/non-consistent-keyring
likhita-809 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -808,20 +808,32 @@ func (ks keystore) writeRecord(k *Record) error { | |||||
return nil | ||||||
} | ||||||
|
||||||
|
||||||
// existsInDb returns (true, nil) if either addr or name exist is in keystore DB. | ||||||
// On the other hand, it returns (false, error) if Get method returns error different from keyring.ErrKeyNotFound | ||||||
// In case of inconsistent keyring, it recovers it automatically. | ||||||
func (ks keystore) existsInDb(addr sdk.Address, name string) (bool, error) { | ||||||
|
||||||
if _, err := ks.db.Get(addrHexKeyAsString(addr)); err == nil { | ||||||
return true, nil // address lookup succeeds - info exists | ||||||
} else if err != keyring.ErrKeyNotFound { | ||||||
return false, err // received unexpected error - returns error | ||||||
_, errAddr := ks.db.Get(addrHexKeyAsString(addr)) | ||||||
if errAddr != nil && errAddr != keyring.ErrKeyNotFound { | ||||||
return false, errAddr // received unexpected error - returns error | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
if _, err := ks.db.Get(name); err == nil { | ||||||
_, errInfo := ks.db.Get(infoKey(name)) | ||||||
if errInfo == nil { | ||||||
return true, nil // uid lookup succeeds - info exists | ||||||
} else if err != keyring.ErrKeyNotFound { | ||||||
return false, err // received unexpected error - returns | ||||||
} else if errInfo != keyring.ErrKeyNotFound { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto: |
||||||
return false, errInfo // received unexpected error - returns | ||||||
} | ||||||
|
||||||
// looking for an issue, record with meta (getByAddress) exists, but record with public key itself does not | ||||||
if errAddr == nil && errors.Is(errInfo, keyring.ErrKeyNotFound) { | ||||||
fmt.Fprintf(os.Stderr, "address \"%s\" exists but pubkey itself does not\n", hex.EncodeToString(addr.Bytes())) | ||||||
fmt.Fprintln(os.Stderr, "recreating pubkey record") | ||||||
err := ks.db.Remove(addrHexKeyAsString(addr)) | ||||||
if err != nil { | ||||||
return true, err | ||||||
} | ||||||
return false, nil | ||||||
} | ||||||
|
||||||
// both lookups failed, info does not exist | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: we should use the
errors.Is
call here.