Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into shield_activity_f…
Browse files Browse the repository at this point in the history
…inal
  • Loading branch information
panleone committed Nov 19, 2024
2 parents 98c00ed + a44f5f0 commit ead84d0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions scripts/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ import { guiToggleReceiveType } from './contacts-book.js';
import { TransactionBuilder } from './transaction_builder.js';
import { createAlert } from './alerts/alert.js';
import { AsyncInterval } from './async_interval.js';
import { debugError, debugLog, DebugTopics } from './debug.js';
import {
debugError,
debugLog,
debugTimerEnd,
debugTimerStart,
DebugTopics,
} from './debug.js';
import { OrderedArray } from './ordered_array.js';

/**
Expand Down Expand Up @@ -773,7 +779,9 @@ export class Wallet {
this.#lastProcessedBlock = blockCount - 5;
await this.#transparentSync();
if (this.hasShield()) {
debugTimerStart(DebugTopics.WALLET, 'syncShield');
await this.#syncShield();
debugTimerEnd(DebugTopics.WALLET, 'syncShield');
}
this.#isSynced = true;
// At this point download the last missing blocks in the range (blockCount -5, blockCount]
Expand Down Expand Up @@ -844,7 +852,9 @@ export class Wallet {
* @type {{txs: string[]; height: number; time: number}[]}
*/
let blocksArray = [];
let handleBlocksTime = 0;
const handleAllBlocks = async () => {
const start = performance.now();
// Process the current batch of blocks before starting to parse the next one
if (blocksArray.length) {
const ownTxs = await this.#shield.handleBlocks(blocksArray);
Expand All @@ -862,6 +872,7 @@ export class Wallet {
}
}
}
handleBlocksTime += performance.now() - start;
blocksArray = [];
// Emit status update
getEventEmitter().emit(
Expand Down Expand Up @@ -895,11 +906,15 @@ export class Wallet {
// This is neither a block or a tx.
throw new Error('Failed to parse shield binary');
}
if (blocksArray.length > 50) {
if (blocksArray.length >= 10) {
await handleAllBlocks();
}
}
await handleAllBlocks();
debugLog(
DebugTopics.WALLET,
`syncShield rust internal ${handleBlocksTime} ms`
);
// At this point it should be safe to assume that shield is ready to use
await this.saveShieldOnDisk();
} catch (e) {
Expand Down

0 comments on commit ead84d0

Please sign in to comment.