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

Reset database if version is 0.9.18 #4503

Merged
merged 1 commit into from
May 29, 2018
Merged

Reset database if version is 0.9.18 #4503

merged 1 commit into from
May 29, 2018

Conversation

cammellos
Copy link
Contributor

@cammellos cammellos commented May 29, 2018

fixes #4409

Summary:

The code will try to open an encrypted realm.
If it fails will try to open an unencrypted realm.

If that is successful we reset the database and create an encrypted version.

We ensure it is unencrypted as we don't want to reset the database if a IO error occurred on step 1.

Testing notes (optional):

Should ask you to reset from 0.9.18, but update cleanly from 0.9.19/nightlies

status: ready

@cammellos cammellos self-assigned this May 29, 2018
(defn unencrypted-realm?
[file-name]
(boolean
(.schemaVersion rn-dependencies/realm file-name)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you detail this function? Not sure how version and encryption are related.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are just trying to open the file, to make sure it is unencrypted, basically we only care if it's successful or not.

Copy link
Contributor

@jeluard jeluard May 29, 2018

Choose a reason for hiding this comment

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

I can think of others reason for this call to fail than just being unencrypted. Maybe we can find a better name? Or a safer method?

(try
(.schemaVersion rn-dependencies/realm file-name (to-buffer encryption-key))
(catch js/Object e
(log/info "Attempting to read encrypted file failes"))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we improve error handling? What if this fails ?
(I realize you didn't introduce this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case it's ok for us to fail, we want to detect unencrypted versions of realm, so we can reset them, once we remove the code I agree error handling should be made more robust.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about returning nil only and not logging then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean just remove the log statement? (we need the schema version if it we manage to decrypt it)

Copy link
Contributor

Choose a reason for hiding this comment

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

Right in the catch

Copy link
Contributor

Choose a reason for hiding this comment

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

Hopefully this function does not only return nil 😅

:let [migrated-realm (open-realm schema file-name encryption-key)]]
(close migrated-realm)))
(defn reset-realm [file-name schemas encryption-key]
(utils/show-popup "Important: Wallet Upgrade" "The Status Wallet will be upgraded in this release. The 12 mnemonic words will generate different addresses and whisper identities (public key). Given that we changed the algorithm used to generate keys and addresses, it will be impossible to re-import accounts created with the old algorithm in Status. Please create a new account.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this not be called outside of reset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure, it used to be there I have reintroduced it ( it seems resetting realm is a single purpouse thing, only applies for this release, should be throwaway code), but don't mind putting it outside.

Copy link
Contributor

Choose a reason for hiding this comment

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

We might find other needs for this in the future. I would not expect that kind of side effects when calling a reset function.

(let [encrypted-version (encrypted-realm-version file-name encryption-key)
;; If it's unencrypted reset schema
unencrypted? (and (not encrypted-version)
(unencrypted-realm? file-name))]
Copy link
Contributor

Choose a reason for hiding this comment

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

What will happen if this is fresh install without any previous schema - won't unencrypted? be true ?
If yes, will it work fine, or crash on the reset-realm schema (+ show confusing pop-up) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's interesting, it seems like you are right, I had tested it on my local android and worked fine, but will make sure it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weirdly enough it just works, I can't really say why from the code (possibly because opening an empty realm will succede and return a version of 0? ). But will make sure that is the case ,good shout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, opening an empty realm does not fail, and return a schema version of -1

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I know why, calling version on empty realm returns -1, I just remembered. It's probably worth documenting somewhere...

@rasom
Copy link
Contributor

rasom commented May 29, 2018

@jeluard
Copy link
Contributor

jeluard commented May 29, 2018

Can we take this opportunity to add some simple doc to realm function? This would help improving the overall quality of this ns that requires some love :)

@rasom
Copy link
Contributor

rasom commented May 29, 2018

@cammellos
Copy link
Contributor Author

@jeluard yes, I will test everything works ( is still wip, I needed an image to test on a real device), and add some docs to the namespace

@cammellos cammellos requested a review from mandrigin May 29, 2018 07:58
@cammellos
Copy link
Contributor Author

@jeluard updated with docstrings and some tests

unencrypted? (and (not encrypted-version)
(unencrypted-realm? file-name))]
(cond
encrypted-version (migrate-schemas file-name schemas encryption-key encrypted-version)
Copy link
Contributor

Choose a reason for hiding this comment

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

is it fine to call migrate-schemas if encrypted-version is -1?

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 so, I haven't changed that logic + I have tested multiple times on clean installations

Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a comment though, because it looks like this case with -1 was just forgotten.

Copy link
Contributor

@mandrigin mandrigin left a comment

Choose a reason for hiding this comment

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

LGTM

@jeluard
Copy link
Contributor

jeluard commented May 29, 2018

@cammellos Awesome thanks for the effort!

@rasom
Copy link
Contributor

rasom commented May 29, 2018

@rasom
Copy link
Contributor

rasom commented May 29, 2018

@lukaszfryc
Copy link
Contributor

@cammellos all looks good 👍
I tested upgrading from 0.9.18 (Android, iOS) as well as from develop (iOS). I also checked some scenarios around it like recovering account, creating additional new account, etc.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
@cammellos cammellos merged commit 26dd1c1 into develop May 29, 2018
@rasom rasom deleted the bug/#4409 branch May 30, 2018 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

"Realm file decryption failed" error after app upgrade from release 0.9.18 to develop version
6 participants