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

fix(extension): #207: fix resetting the fullSyncHeight in local storage after cache clearing #217

Merged
merged 5 commits into from
Oct 22, 2024

Conversation

VanishMax
Copy link
Contributor

Fixes #207

I understand that the issue was bigger but at least this PR fixes the symptom of incorrect cache clearing, which is the sync bar getting stuck in the incorrect state.

Read Tal's comment #207 (comment) on the "data objects could not be cloned" error – we should perhaps plan the specific set tasks to deal with it.

However, for now I decided that it might not hurt to add a "reload page" button next to the error messages in Minifront: penumbra-zone/web#1861


const handleCacheClear = () => {
setLoading(true);

void (async function () {
await setFullSyncHeight(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Does a height synced of 0 mean that the genesis state has been synced? I actually think the data structure is more like:

fullSyncHeight = undefined --> no syncing has been completed
fullSyncHeight = 0 --> genesis state synced
fullSyncHeight = <number> --> that block number has been synced

Can you validate this? May help checking the logic of the loading bar to see what text shows under which condition.

Copy link
Contributor Author

@VanishMax VanishMax Oct 17, 2024

Choose a reason for hiding this comment

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

Both 0 and undefined mean loading, number means syncing, and latestKnownBlockHeight - fullSyncHeight <= 10 means synced

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated zeros to undefined

@VanishMax VanishMax requested a review from grod220 October 17, 2024 16:33
@TalDerei TalDerei self-requested a review October 17, 2024 17:10
Copy link
Contributor

@TalDerei TalDerei left a comment

Choose a reason for hiding this comment

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

to reiterate, this sufficiently addresses the symptom, but doesn't fully resolve the issue as the root cause is deeper. Alternatively, we could modify the promise in the message listener with await Promise.allSettled([localExtStorage.remove('params'), indexedDb.clear(), chrome.storage.local.remove('fullSyncHeight')]), but they're functionally identical.

Specifically, the deeper problem lies in the fact that the listeners responsible for initializing the content scripts are blocked by the service worker while it synchronizes the genesis block. I believe there's no way to persist the wallet's connection state across page refreshes or extension reloads because the MessagePort is an in-memory object. So when the service worker restarts via chrome.runtime.reload(), it's waiting for the MessagePort to be initialized, and redirects to the onboarding screen until that's finished.


const handleCacheClear = () => {
setLoading(true);

void (async function () {
await setFullSyncHeight(undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: I don't think this will work as doing chrome.storage.set({ "fullSyncHeight": undefined }) is a no-op. Can you confirm with a test? May help reviewing the docs as well: https://developer.chrome.com/docs/extensions/reference/api/storage#type-StorageArea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Truly has some problems, reverted to the Tal's initial solution with allSettled

@VanishMax VanishMax merged commit 3ee1ff6 into main Oct 22, 2024
3 checks passed
@VanishMax VanishMax deleted the fix/#207-clearing-cache branch October 22, 2024 06:46
await Promise.allSettled([
localExtStorage.remove('params'),
indexedDb.clear(),
chrome.storage.local.remove('fullSyncHeight'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, unfortunately using the chrome storage api directly is not typesafe and could cause bugs with old Prax versions that have not undergone db migrations. Can you follow up with a PR to do:

- chrome.storage.local.remove('fullSyncHeight'),
+ localExtStorage.remove('fullSyncHeight'),

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.

Clearing cache & block sync state
3 participants