run pending operations at least once, style fixes

This commit is contained in:
Florian Dold 2021-08-19 15:12:33 +02:00
parent defc393d6e
commit c0e6b6d0f6
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
8 changed files with 35 additions and 22 deletions

View File

@ -1065,5 +1065,6 @@ export function main() {
logger.warn("Allowing withdrawal of late denominations for debugging"); logger.warn("Allowing withdrawal of late denominations for debugging");
walletCoreDebugFlags.denomselAllowLate = true; walletCoreDebugFlags.denomselAllowLate = true;
} }
logger.trace(`running wallet-cli with`, process.argv);
walletCli.run(); walletCli.run();
} }

View File

@ -1620,6 +1620,7 @@ export class WalletCli {
const self = this; const self = this;
this._client = { this._client = {
async call(op: any, payload: any): Promise<any> { async call(op: any, payload: any): Promise<any> {
console.log("calling wallet with timetravel arg", self.timetravelArg);
const resp = await sh( const resp = await sh(
self.globalTestState, self.globalTestState,
`wallet-${self.name}`, `wallet-${self.name}`,

View File

@ -62,6 +62,7 @@ async function applyTimeTravel(
} }
if (s.wallet) { if (s.wallet) {
console.log("setting wallet time travel to", timetravelDuration);
s.wallet.setTimetravel(timetravelDuration); s.wallet.setTimetravel(timetravelDuration);
} }
} }
@ -139,6 +140,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
// Travel into the future, the deposit expiration is two years // Travel into the future, the deposit expiration is two years
// into the future. // into the future.
console.log("applying first time travel");
await applyTimeTravel(durationFromSpec({ days: 400 }), { await applyTimeTravel(durationFromSpec({ days: 400 }), {
wallet, wallet,
exchange, exchange,
@ -164,6 +166,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
// Travel into the future, the deposit expiration is two years // Travel into the future, the deposit expiration is two years
// into the future. // into the future.
console.log("applying second time travel");
await applyTimeTravel(durationFromSpec({ years: 2, months: 6 }), { await applyTimeTravel(durationFromSpec({ years: 2, months: 6 }), {
wallet, wallet,
exchange, exchange,

View File

@ -147,6 +147,7 @@ async function refreshCreateSession(
throw Error("db inconsistent: exchange of coin not found"); throw Error("db inconsistent: exchange of coin not found");
} }
const { availableAmount, availableDenoms } = await ws.db const { availableAmount, availableDenoms } = await ws.db
.mktx((x) => ({ .mktx((x) => ({
denominations: x.denominations, denominations: x.denominations,
@ -161,6 +162,7 @@ async function refreshCreateSession(
throw Error("db inconsistent: denomination for coin not found"); throw Error("db inconsistent: denomination for coin not found");
} }
// FIXME: use an index here, based on the withdrawal expiration time.
const availableDenoms: DenominationRecord[] = await tx.denominations.indexes.byExchangeBaseUrl const availableDenoms: DenominationRecord[] = await tx.denominations.indexes.byExchangeBaseUrl
.iter(exchange.baseUrl) .iter(exchange.baseUrl)
.toArray(); .toArray();
@ -913,7 +915,15 @@ export async function autoRefresh(
} }
} }
if (refreshCoins.length > 0) { if (refreshCoins.length > 0) {
await createRefreshGroup(ws, tx, refreshCoins, RefreshReason.Scheduled); const res = await createRefreshGroup(
ws,
tx,
refreshCoins,
RefreshReason.Scheduled,
);
logger.info(
`created refresh group for auto-refresh (${res.refreshGroupId})`,
);
} }
logger.info( logger.info(
`current wallet time: ${timestampToIsoString(getTimestampNow())}`, `current wallet time: ${timestampToIsoString(getTimestampNow())}`,

View File

@ -17,7 +17,6 @@
/** /**
* Imports. * Imports.
*/ */
import * as LibtoolVersion from "@gnu-taler/taler-util";
import { import {
AmountJson, AmountJson,
Amounts, Amounts,
@ -41,6 +40,7 @@ import {
WithdrawResponse, WithdrawResponse,
URL, URL,
WithdrawUriInfoResponse, WithdrawUriInfoResponse,
VersionMatchResult,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { import {
CoinRecord, CoinRecord,
@ -143,7 +143,7 @@ interface ExchangeWithdrawDetails {
* *
* Older exchanges don't return version information. * Older exchanges don't return version information.
*/ */
versionMatch: LibtoolVersion.VersionMatchResult | undefined; versionMatch: VersionMatchResult | undefined;
/** /**
* Libtool-style version string for the exchange or "unknown" * Libtool-style version string for the exchange or "unknown"
@ -693,15 +693,15 @@ export async function updateWithdrawalDenoms(
while (current < denominations.length) { while (current < denominations.length) {
const updatedDenominations: DenominationRecord[] = []; const updatedDenominations: DenominationRecord[] = [];
// Do a batch of batchSize // Do a batch of batchSize
for (let batchIdx = 0; batchIdx < batchSize; batchIdx++) { for (
current++; let batchIdx = 0;
if (current >= denominations.length) { batchIdx < batchSize && current < denominations.length;
break; batchIdx++, current++
} ) {
const denom = denominations[current]; const denom = denominations[current];
if (denom.status === DenominationStatus.Unverified) { if (denom.status === DenominationStatus.Unverified) {
logger.trace( logger.trace(
`Validation denomination (${current + 1}/${ `Validating denomination (${current + 1}/${
denominations.length denominations.length
}) signature of ${denom.denomPubHash}`, }) signature of ${denom.denomPubHash}`,
); );
@ -939,7 +939,7 @@ export async function getExchangeWithdrawalInfo(
let versionMatch; let versionMatch;
if (exchangeDetails.protocolVersion) { if (exchangeDetails.protocolVersion) {
versionMatch = LibtoolVersion.compare( versionMatch = compare(
WALLET_EXCHANGE_PROTOCOL_VERSION, WALLET_EXCHANGE_PROTOCOL_VERSION,
exchangeDetails.protocolVersion, exchangeDetails.protocolVersion,
); );

View File

@ -333,7 +333,7 @@ async function runTaskLoop(
} }
} }
if (opts.stopWhenDone && numGivingLiveness === 0) { if (opts.stopWhenDone && numGivingLiveness === 0 && iteration !== 0) {
logger.warn(`stopping, as no pending operations have lifeness`); logger.warn(`stopping, as no pending operations have lifeness`);
return; return;
} }
@ -970,15 +970,11 @@ export class Wallet {
this.ws.stop(); this.ws.stop();
} }
runRetryLoop(): Promise<void> {
return runTaskLoop(this.ws);
}
runPending(forceNow: boolean = false) { runPending(forceNow: boolean = false) {
return runPending(this.ws, forceNow); return runPending(this.ws, forceNow);
} }
runTaskLoop(opts: RetryLoopOpts) { runTaskLoop(opts?: RetryLoopOpts) {
return runTaskLoop(this.ws, opts); return runTaskLoop(this.ws, opts);
} }

View File

@ -179,7 +179,7 @@ class NativeWalletMessageHandler {
const w = await getDefaultNodeWallet(this.walletArgs); const w = await getDefaultNodeWallet(this.walletArgs);
this.maybeWallet = w; this.maybeWallet = w;
await w.handleCoreApiRequest("initWallet", "native-init", {}); await w.handleCoreApiRequest("initWallet", "native-init", {});
w.runRetryLoop().catch((e) => { w.runTaskLoop().catch((e) => {
console.error("Error during wallet retry loop", e); console.error("Error during wallet retry loop", e);
}); });
this.wp.resolve(w); this.wp.resolve(w);

View File

@ -215,8 +215,10 @@ function makeSyncWalletRedirect(
): Record<string, unknown> { ): Record<string, unknown> {
const innerUrl = new URL(chrome.extension.getURL(url)); const innerUrl = new URL(chrome.extension.getURL(url));
if (params) { if (params) {
const hParams = Object.keys(params).map(k => `${k}=${params[k]}`).join('&') const hParams = Object.keys(params)
innerUrl.hash = innerUrl.hash + '?' + hParams .map((k) => `${k}=${params[k]}`)
.join("&");
innerUrl.hash = innerUrl.hash + "?" + hParams;
} }
if (isFirefox()) { if (isFirefox()) {
// Some platforms don't support the sync redirect (yet), so fall back to // Some platforms don't support the sync redirect (yet), so fall back to
@ -272,8 +274,8 @@ async function reinitWallet(): Promise<void> {
} }
} }
}); });
wallet.runRetryLoop().catch((e) => { wallet.runTaskLoop().catch((e) => {
console.log("error during wallet retry loop", e); console.log("error during wallet task loop", e);
}); });
// Useful for debugging in the background page. // Useful for debugging in the background page.
(window as any).talerWallet = wallet; (window as any).talerWallet = wallet;