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

[4.18.100] utxo resync fix using addresses hash #3088

Merged
merged 5 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import BigNumber from 'bignumber.js';
import { isEqual } from 'lodash';
import ObjectHash from 'object-hash';
import type {
lf$Database, lf$Transaction,
} from 'lovefield';
Expand Down Expand Up @@ -2886,6 +2887,19 @@ async function certificateToDb(
return result;
}

function compareAndSetIfNewAddressSetHash(id: number, addresses: Array<string>): boolean {
const requestAddresseSet = new Set(addresses);
const requestAddresseHash = ObjectHash.sha1(requestAddresseSet);
const localStorageKey = `TMP/UTXO_REQUEST_ADDRESSES_HASH/${id}`;
const prevRequestAddressHash = localStorage.getItem(localStorageKey);
if (prevRequestAddressHash == null || prevRequestAddressHash !== requestAddresseHash) {
console.log('[rawUpdateUtxos] clearing utxo state.', requestAddresseHash, prevRequestAddressHash);
localStorage.setItem(localStorageKey, requestAddresseHash);
return true;
}
return false;
}

async function rawUpdateUtxos(
db: lf$Database,
dbTx: lf$Transaction,
Expand Down Expand Up @@ -2914,7 +2928,11 @@ async function rawUpdateUtxos(
utxoStorageApi.setDb(db);
utxoStorageApi.setDbTx(dbTx);

await utxoService.syncUtxoState(toRequestAddresses(addresses));
const requestAddresses = toRequestAddresses(addresses);
if (compareAndSetIfNewAddressSetHash(publicDeriver.getPublicDeriverId(), requestAddresses)) {
await utxoStorageApi.clearUtxoState();
}
await utxoService.syncUtxoState(requestAddresses);
}

function toRequestAddresses(
Expand Down
25 changes: 15 additions & 10 deletions packages/yoroi-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/yoroi-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yoroi",
"version": "4.18.0",
"version": "4.18.100",
"description": "Cardano ADA wallet",
"scripts": {
"dev:build": "rimraf dev/ && babel-node scripts/build --type=debug",
Expand Down Expand Up @@ -221,6 +221,7 @@
"mobx-react-form": "2.0.8",
"mobx-react-router": "4.1.0",
"moment": "2.29.1",
"object-hash": "3.0.0",
"path-browserify": "1.0.1",
"pbkdf2": "3.1.1",
"process": "0.11.10",
Expand Down