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 wallet sync bug #446

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 18 additions & 2 deletions scripts/network/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
}
}

async getBlock(blockHeight) {

Check warning on line 44 in scripts/network/network.js

View workflow job for this annotation

GitHub Actions / Run linters

'blockHeight' is defined but never used. Allowed unused args must match /^_/u
throw new Error('getBlockCount must be implemented');
}

async getTxPage(nStartHeight, addr, n) {

Check warning on line 48 in scripts/network/network.js

View workflow job for this annotation

GitHub Actions / Run linters

'nStartHeight' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 48 in scripts/network/network.js

View workflow job for this annotation

GitHub Actions / Run linters

'addr' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 48 in scripts/network/network.js

View workflow job for this annotation

GitHub Actions / Run linters

'n' is defined but never used. Allowed unused args must match /^_/u
throw new Error('getTxPage must be implemented');
}

async getNumPages(nStartHeight, addr) {

Check warning on line 52 in scripts/network/network.js

View workflow job for this annotation

GitHub Actions / Run linters

'nStartHeight' is defined but never used. Allowed unused args must match /^_/u
throw new Error('getNumPages must be implemented');
}

Expand Down Expand Up @@ -247,8 +247,24 @@
* @returns {Promise<number>}
*/
async getNumPages(nStartHeight, addr) {
const page = await this.#getPage(nStartHeight, addr, 1, 1);
return page.txs;
// 1) Find the total number of Blockbook txs
const walletTxs = (await this.#getPage(nStartHeight, addr, 1, 1)).txs;
// 2) This integer is larger than the number of pages
const nPageOverflow = walletTxs + 1;
// 3) In case of page overflow, Blockbook will return the actual last page.
const nPage = (
await this.#getPage(nStartHeight, addr, nPageOverflow, 1)
).page;

// This should not really happen, but just to be sure...
if (nPage >= nPageOverflow) {
throw new Error(
'Blockbook getNumPages failed! please contact a developer'
);
}

// Convert to pageSize = 1000
return Math.ceil(nPage / 1000);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions scripts/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,8 @@ export class Wallet {
let nStartHeight = Math.max(
...this.getTransactions().map((tx) => tx.blockHeight)
);
const txNumber =
(await cNet.getNumPages(nStartHeight, addr)) -
this.getTransactions().length;
// Compute the total pages and iterate through them until we've synced everything
const totalPages = Math.ceil(txNumber / 1000);
const totalPages = await cNet.getNumPages(nStartHeight, addr);
for (let i = totalPages; i > 0; i--) {
getEventEmitter().emit(
'transparent-sync-status-update',
Expand Down
Loading