slightly more sane logging

This commit is contained in:
Florian Dold 2019-08-18 23:06:27 +02:00
parent 23e72ce25c
commit d4021a9d17
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
9 changed files with 30 additions and 23 deletions

View File

@ -12,7 +12,7 @@
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
*/
/**
* Web worker for crypto operations.

View File

@ -140,7 +140,7 @@ export class CryptoApi {
*/
private stopped: boolean = false;
public enableTracing = true;
static enableTracing = false;
/**
* Terminate all worker threads.
@ -148,7 +148,7 @@ export class CryptoApi {
terminateWorkers() {
for (let worker of this.workers) {
if (worker.w) {
this.enableTracing && console.log("terminating worker");
CryptoApi.enableTracing && console.log("terminating worker");
worker.w.terminate();
if (worker.terminationTimerHandle) {
worker.terminationTimerHandle.clear();
@ -173,7 +173,7 @@ export class CryptoApi {
*/
wake(ws: WorkerState, work: WorkItem): void {
if (this.stopped) {
this.enableTracing && console.log("not waking, as cryptoApi is stopped");
CryptoApi.enableTracing && console.log("not waking, as cryptoApi is stopped");
return;
}
if (ws.currentWorkItem !== null) {
@ -268,7 +268,7 @@ export class CryptoApi {
return;
}
this.enableTracing &&
CryptoApi.enableTracing &&
console.log(
`rpc ${currentWorkItem.operation} took ${timer.performanceNow() -
currentWorkItem.startTime}ms`,
@ -299,7 +299,7 @@ export class CryptoApi {
priority: number,
...args: any[]
): Promise<T> {
this.enableTracing && console.log("cryptoApi: doRpc called");
CryptoApi.enableTracing && console.log("cryptoApi: doRpc called");
const p: Promise<T> = new Promise<T>((resolve, reject) => {
const rpcId = this.nextRpcId++;
const workItem: WorkItem = {

View File

@ -131,6 +131,6 @@ export class SynchronousCryptoWorker {
* Forcibly terminate the worker thread.
*/
terminate() {
console.log("terminating synchronous worker (no-op)");
// This is a no-op.
}
}

View File

@ -14,15 +14,12 @@ export function openTalerDb(
): Promise<IDBDatabase> {
console.log("in openTalerDb");
return new Promise<IDBDatabase>((resolve, reject) => {
console.log("calling factory.open");
const req = idbFactory.open(DB_NAME, WALLET_DB_VERSION);
console.log("after factory.open");
req.onerror = e => {
console.log("taler database error", e);
reject(e);
};
req.onsuccess = e => {
console.log("in openTalerDb onsuccess");
req.result.onversionchange = (evt: IDBVersionChangeEvent) => {
console.log(
`handling live db version change from ${evt.oldVersion} to ${
@ -35,7 +32,6 @@ export function openTalerDb(
resolve(req.result);
};
req.onupgradeneeded = e => {
console.log("in openTalerDb onupgradeneeded");
const db = req.result;
console.log(
`DB: upgrade needed: oldVersion=${e.oldVersion}, newVersion=${

View File

@ -173,8 +173,6 @@ export async function getDefaultNodeWallet(
shimIndexedDB(myBridgeIdbFactory);
console.log("opening taler DB");
const myDb = await openTalerDb(
myIdbFactory,
myVersionChange,

View File

@ -19,16 +19,27 @@ import os = require("os");
import { getDefaultNodeWallet, withdrawTestBalance } from "./helpers";
import { MerchantBackendConnection } from "./merchant";
import { runIntegrationTest } from "./integrationtest";
import { Wallet } from "../wallet";
const program = new commander.Command();
program.version("0.0.1");
program
.version("0.0.1")
.option('--verbose', "enable verbose output", false);
const walletDbPath = os.homedir + "/" + ".talerwalletdb.json";
function applyVerbose(verbose: boolean) {
if (verbose) {
console.log("enabled verbose logging");
Wallet.enableTracing = true;
}
}
program
.command("test-withdraw")
.description("withdraw test currency from the test bank")
.action(async () => {
applyVerbose(program.verbose)
console.log("test-withdraw command called");
const wallet = await getDefaultNodeWallet({
persistentStoragePath: walletDbPath,
@ -41,6 +52,7 @@ program
.command("balance")
.description("show wallet balance")
.action(async () => {
applyVerbose(program.verbose)
console.log("balance command called");
const wallet = await getDefaultNodeWallet({
persistentStoragePath: walletDbPath,
@ -63,6 +75,7 @@ program
.option('-s, --spend-amount <spend-amt>', 'amount to spend', "TESTKUDOS:5")
.description("Run integration test with bank, exchange and merchant.")
.action(async (cmdObj) => {
applyVerbose(program.verbose)
await runIntegrationTest({
amountToSpend: cmdObj.spendAmount,

View File

@ -328,7 +328,7 @@ export class Wallet {
* IndexedDB database used by the wallet.
*/
db: IDBDatabase;
private enableTracing = false;
static enableTracing = false;
private http: HttpRequestLibrary;
private badge: Badge;
private notifier: Notifier;
@ -385,7 +385,7 @@ export class Wallet {
console.log("defaults already applied");
};
const onFalse = (r: QueryRoot) => {
console.log("applying defaults");
Wallet.enableTracing && console.log("applying defaults");
r.put(Stores.config, { key: "currencyDefaultsApplied", value: true })
.putAll(Stores.currencies, builtinCurrencies)
.finish();
@ -1105,6 +1105,7 @@ export class Wallet {
console.warn(
`Failed to deplete reserve, trying again in ${retryDelayMs} ms`,
);
Wallet.enableTracing && console.info("Cause for retry was:", e);
this.timerGroup.after(retryDelayMs, () =>
processReserveInternal(nextDelay),
);
@ -1144,10 +1145,9 @@ export class Wallet {
this.processPreCoinConcurrent >= 4 ||
this.processPreCoinThrottle[preCoin.exchangeBaseUrl]
) {
this.enableTracing && console.log("delaying processPreCoin");
this.timerGroup.after(retryDelayMs, () =>
processPreCoinInternal(Math.min(retryDelayMs * 2, 5 * 60 * 1000)),
);
const timeout = Math.min(retryDelayMs * 2, 5 * 60 * 1000);
Wallet.enableTracing && console.log(`throttling processPreCoin of ${preCoinPub} for ${timeout}ms`);
this.timerGroup.after(retryDelayMs, () => processPreCoinInternal());
return op.promise;
}
@ -1498,6 +1498,8 @@ export class Wallet {
reqUrl.query({ reserve_pub: reservePub });
const resp = await this.http.get(reqUrl.href());
if (resp.status !== 200) {
Wallet.enableTracing &&
console.warn(`reserve/status returned ${resp.status}`);
throw Error();
}
const reserveInfo = ReserveStatus.checked(resp.responseJson);
@ -1575,7 +1577,6 @@ export class Wallet {
if (denom.status === DenominationStatus.VerifiedGood) {
return Amounts.add(denom.feeWithdraw, denom.value).amount;
}
console.log(`verifying denom ${denom.denomPub.substr(0, 15)}`);
const valid = await this.cryptoApi.isValidDenom(
denom,
exchange.masterPublicKey,
@ -1630,7 +1631,6 @@ export class Wallet {
selectedDenoms = getWithdrawDenomList(amount, possibleDenoms);
for (const denom of selectedDenoms || []) {
if (denom.status === DenominationStatus.Unverified) {
console.log(`verifying denom ${denom.denomPub.substr(0, 15)}`);
const valid = await this.cryptoApi.isValidDenom(
denom,
exchange.masterPublicKey,

View File

@ -23,6 +23,7 @@
},
"files": [
"src/amounts.ts",
"src/android/index.ts",
"src/checkable.ts",
"src/crypto/browserWorkerEntry.ts",
"src/crypto/cryptoApi-test.ts",

@ -1 +0,0 @@
Subproject commit ebf2b43fb00f057643d69abf34b54a1b6087dfcd