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

Add ability for MPW to run explorer-less #427

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
14 changes: 8 additions & 6 deletions scripts/dashboard/WalletBalance.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import { cChainParams, COIN } from '../chain_params.js';
import { translation } from '../i18n';
import { translation, tr } from '../i18n';
import { ref, computed, toRefs } from 'vue';
import { beautifyNumber } from '../misc';
import { getEventEmitter } from '../event_bus';
Expand Down Expand Up @@ -130,11 +130,13 @@ const emit = defineEmits([

getEventEmitter().on(
'transparent-sync-status-update',
(i, totalPages, finished) => {
const str = tr(translation.syncStatusHistoryProgress, [
{ current: totalPages - i + 1 },
{ total: totalPages },
]);
(i, totalPages, finished, message) => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(i, totalPages, finished, message) => {
(i, totalPages, finished, error) => {

Can you call this error/warning?

const str =
message ||
tr(translation.syncStatusHistoryProgress, [
{ current: totalPages - i + 1 },
{ total: totalPages },
]);
const progress = ((totalPages - i) / totalPages) * 100;
syncTStr.value = str;
transparentProgressSyncing.value = progress;
Expand Down
32 changes: 29 additions & 3 deletions scripts/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,29 @@ export class Wallet {
// This is just to be sure since blockbook (as we know)
// usually does not return txs of the actual last block.
this.#lastProcessedBlock = blockCount - 5;
await this.#transparentSync();
// Transparent sync is inherently less stable than Shield since it requires heavy
// explorer indexing, so we'll attempt once asynchronously, and if it fails, set a
// recurring "background" sync interval until it's finally successful.
try {
await this.#transparentSync();
} catch {
// We'll set a 5s interval sync until it's finally successful, then nuke the 'thread'.
const cThread = new AsyncInterval(async () => {
Copy link
Member

Choose a reason for hiding this comment

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

You cannot use AsyncInterval: the function sync() has to be blocked until transparentSync() is succesful, otherwise we end up in a state where the wallet is marked as synced, this.#isSynced = true, even if it isn't.

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue with blocking it is Shield then becomes unusable unless Transparent syncs (right now, Shield can be used even if Transparent is unable).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally we would split the state so that we have transparentSynced and shieldSynced, so they are operable independently.

try {
await this.#transparentSync(true);
cThread.clearInterval();
} catch {
// Emit a transparent sync warning
getEventEmitter().emit(
'transparent-sync-status-update',
0,
0,
false,
'Explorers are unreachable, your wallet may not be fully synced!'
);
}
}, 5000);
}
if (this.hasShield()) {
await this.#syncShield();
}
Expand All @@ -712,8 +734,12 @@ export class Wallet {
getEventEmitter().emit('new-tx');
});

async #transparentSync() {
if (!this.isLoaded() || this.#isSynced) return;
/**
* Synchronise UTXOs via xpub/address from the current explorer.
* @param {boolean} [force=false] - Force transparent sync, regardless of state
*/
async #transparentSync(force = false) {
if ((!this.isLoaded() || this.#isSynced) && !force) return;
Comment on lines +740 to +741
Copy link
Member

Choose a reason for hiding this comment

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

Move the loadedCheck and synced in the sync function, so we can remove the force param.

Suggested change
async #transparentSync(force = false) {
if ((!this.isLoaded() || this.#isSynced) && !force) return;
async #transparentSync() {

It's only going to be called by sync anyways

const cNet = getNetwork();
const addr = this.getKeyToExport();
let nStartHeight = Math.max(
Expand Down
Loading