slightly more sane logging
This commit is contained in:
parent
23e72ce25c
commit
d4021a9d17
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
You should have received a copy of the GNU General Public License along with
|
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/>
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web worker for crypto operations.
|
* Web worker for crypto operations.
|
||||||
|
@ -140,7 +140,7 @@ export class CryptoApi {
|
|||||||
*/
|
*/
|
||||||
private stopped: boolean = false;
|
private stopped: boolean = false;
|
||||||
|
|
||||||
public enableTracing = true;
|
static enableTracing = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminate all worker threads.
|
* Terminate all worker threads.
|
||||||
@ -148,7 +148,7 @@ export class CryptoApi {
|
|||||||
terminateWorkers() {
|
terminateWorkers() {
|
||||||
for (let worker of this.workers) {
|
for (let worker of this.workers) {
|
||||||
if (worker.w) {
|
if (worker.w) {
|
||||||
this.enableTracing && console.log("terminating worker");
|
CryptoApi.enableTracing && console.log("terminating worker");
|
||||||
worker.w.terminate();
|
worker.w.terminate();
|
||||||
if (worker.terminationTimerHandle) {
|
if (worker.terminationTimerHandle) {
|
||||||
worker.terminationTimerHandle.clear();
|
worker.terminationTimerHandle.clear();
|
||||||
@ -173,7 +173,7 @@ export class CryptoApi {
|
|||||||
*/
|
*/
|
||||||
wake(ws: WorkerState, work: WorkItem): void {
|
wake(ws: WorkerState, work: WorkItem): void {
|
||||||
if (this.stopped) {
|
if (this.stopped) {
|
||||||
this.enableTracing && console.log("not waking, as cryptoApi is stopped");
|
CryptoApi.enableTracing && console.log("not waking, as cryptoApi is stopped");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ws.currentWorkItem !== null) {
|
if (ws.currentWorkItem !== null) {
|
||||||
@ -268,7 +268,7 @@ export class CryptoApi {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.enableTracing &&
|
CryptoApi.enableTracing &&
|
||||||
console.log(
|
console.log(
|
||||||
`rpc ${currentWorkItem.operation} took ${timer.performanceNow() -
|
`rpc ${currentWorkItem.operation} took ${timer.performanceNow() -
|
||||||
currentWorkItem.startTime}ms`,
|
currentWorkItem.startTime}ms`,
|
||||||
@ -299,7 +299,7 @@ export class CryptoApi {
|
|||||||
priority: number,
|
priority: number,
|
||||||
...args: any[]
|
...args: any[]
|
||||||
): Promise<T> {
|
): 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 p: Promise<T> = new Promise<T>((resolve, reject) => {
|
||||||
const rpcId = this.nextRpcId++;
|
const rpcId = this.nextRpcId++;
|
||||||
const workItem: WorkItem = {
|
const workItem: WorkItem = {
|
||||||
|
@ -131,6 +131,6 @@ export class SynchronousCryptoWorker {
|
|||||||
* Forcibly terminate the worker thread.
|
* Forcibly terminate the worker thread.
|
||||||
*/
|
*/
|
||||||
terminate() {
|
terminate() {
|
||||||
console.log("terminating synchronous worker (no-op)");
|
// This is a no-op.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,15 +14,12 @@ export function openTalerDb(
|
|||||||
): Promise<IDBDatabase> {
|
): Promise<IDBDatabase> {
|
||||||
console.log("in openTalerDb");
|
console.log("in openTalerDb");
|
||||||
return new Promise<IDBDatabase>((resolve, reject) => {
|
return new Promise<IDBDatabase>((resolve, reject) => {
|
||||||
console.log("calling factory.open");
|
|
||||||
const req = idbFactory.open(DB_NAME, WALLET_DB_VERSION);
|
const req = idbFactory.open(DB_NAME, WALLET_DB_VERSION);
|
||||||
console.log("after factory.open");
|
|
||||||
req.onerror = e => {
|
req.onerror = e => {
|
||||||
console.log("taler database error", e);
|
console.log("taler database error", e);
|
||||||
reject(e);
|
reject(e);
|
||||||
};
|
};
|
||||||
req.onsuccess = e => {
|
req.onsuccess = e => {
|
||||||
console.log("in openTalerDb onsuccess");
|
|
||||||
req.result.onversionchange = (evt: IDBVersionChangeEvent) => {
|
req.result.onversionchange = (evt: IDBVersionChangeEvent) => {
|
||||||
console.log(
|
console.log(
|
||||||
`handling live db version change from ${evt.oldVersion} to ${
|
`handling live db version change from ${evt.oldVersion} to ${
|
||||||
@ -35,7 +32,6 @@ export function openTalerDb(
|
|||||||
resolve(req.result);
|
resolve(req.result);
|
||||||
};
|
};
|
||||||
req.onupgradeneeded = e => {
|
req.onupgradeneeded = e => {
|
||||||
console.log("in openTalerDb onupgradeneeded");
|
|
||||||
const db = req.result;
|
const db = req.result;
|
||||||
console.log(
|
console.log(
|
||||||
`DB: upgrade needed: oldVersion=${e.oldVersion}, newVersion=${
|
`DB: upgrade needed: oldVersion=${e.oldVersion}, newVersion=${
|
||||||
|
@ -173,8 +173,6 @@ export async function getDefaultNodeWallet(
|
|||||||
|
|
||||||
shimIndexedDB(myBridgeIdbFactory);
|
shimIndexedDB(myBridgeIdbFactory);
|
||||||
|
|
||||||
console.log("opening taler DB");
|
|
||||||
|
|
||||||
const myDb = await openTalerDb(
|
const myDb = await openTalerDb(
|
||||||
myIdbFactory,
|
myIdbFactory,
|
||||||
myVersionChange,
|
myVersionChange,
|
||||||
|
@ -19,16 +19,27 @@ import os = require("os");
|
|||||||
import { getDefaultNodeWallet, withdrawTestBalance } from "./helpers";
|
import { getDefaultNodeWallet, withdrawTestBalance } from "./helpers";
|
||||||
import { MerchantBackendConnection } from "./merchant";
|
import { MerchantBackendConnection } from "./merchant";
|
||||||
import { runIntegrationTest } from "./integrationtest";
|
import { runIntegrationTest } from "./integrationtest";
|
||||||
|
import { Wallet } from "../wallet";
|
||||||
|
|
||||||
const program = new commander.Command();
|
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";
|
const walletDbPath = os.homedir + "/" + ".talerwalletdb.json";
|
||||||
|
|
||||||
|
function applyVerbose(verbose: boolean) {
|
||||||
|
if (verbose) {
|
||||||
|
console.log("enabled verbose logging");
|
||||||
|
Wallet.enableTracing = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("test-withdraw")
|
.command("test-withdraw")
|
||||||
.description("withdraw test currency from the test bank")
|
.description("withdraw test currency from the test bank")
|
||||||
.action(async () => {
|
.action(async () => {
|
||||||
|
applyVerbose(program.verbose)
|
||||||
console.log("test-withdraw command called");
|
console.log("test-withdraw command called");
|
||||||
const wallet = await getDefaultNodeWallet({
|
const wallet = await getDefaultNodeWallet({
|
||||||
persistentStoragePath: walletDbPath,
|
persistentStoragePath: walletDbPath,
|
||||||
@ -41,6 +52,7 @@ program
|
|||||||
.command("balance")
|
.command("balance")
|
||||||
.description("show wallet balance")
|
.description("show wallet balance")
|
||||||
.action(async () => {
|
.action(async () => {
|
||||||
|
applyVerbose(program.verbose)
|
||||||
console.log("balance command called");
|
console.log("balance command called");
|
||||||
const wallet = await getDefaultNodeWallet({
|
const wallet = await getDefaultNodeWallet({
|
||||||
persistentStoragePath: walletDbPath,
|
persistentStoragePath: walletDbPath,
|
||||||
@ -63,6 +75,7 @@ program
|
|||||||
.option('-s, --spend-amount <spend-amt>', 'amount to spend', "TESTKUDOS:5")
|
.option('-s, --spend-amount <spend-amt>', 'amount to spend', "TESTKUDOS:5")
|
||||||
.description("Run integration test with bank, exchange and merchant.")
|
.description("Run integration test with bank, exchange and merchant.")
|
||||||
.action(async (cmdObj) => {
|
.action(async (cmdObj) => {
|
||||||
|
applyVerbose(program.verbose)
|
||||||
|
|
||||||
await runIntegrationTest({
|
await runIntegrationTest({
|
||||||
amountToSpend: cmdObj.spendAmount,
|
amountToSpend: cmdObj.spendAmount,
|
||||||
|
@ -328,7 +328,7 @@ export class Wallet {
|
|||||||
* IndexedDB database used by the wallet.
|
* IndexedDB database used by the wallet.
|
||||||
*/
|
*/
|
||||||
db: IDBDatabase;
|
db: IDBDatabase;
|
||||||
private enableTracing = false;
|
static enableTracing = false;
|
||||||
private http: HttpRequestLibrary;
|
private http: HttpRequestLibrary;
|
||||||
private badge: Badge;
|
private badge: Badge;
|
||||||
private notifier: Notifier;
|
private notifier: Notifier;
|
||||||
@ -385,7 +385,7 @@ export class Wallet {
|
|||||||
console.log("defaults already applied");
|
console.log("defaults already applied");
|
||||||
};
|
};
|
||||||
const onFalse = (r: QueryRoot) => {
|
const onFalse = (r: QueryRoot) => {
|
||||||
console.log("applying defaults");
|
Wallet.enableTracing && console.log("applying defaults");
|
||||||
r.put(Stores.config, { key: "currencyDefaultsApplied", value: true })
|
r.put(Stores.config, { key: "currencyDefaultsApplied", value: true })
|
||||||
.putAll(Stores.currencies, builtinCurrencies)
|
.putAll(Stores.currencies, builtinCurrencies)
|
||||||
.finish();
|
.finish();
|
||||||
@ -1105,6 +1105,7 @@ export class Wallet {
|
|||||||
console.warn(
|
console.warn(
|
||||||
`Failed to deplete reserve, trying again in ${retryDelayMs} ms`,
|
`Failed to deplete reserve, trying again in ${retryDelayMs} ms`,
|
||||||
);
|
);
|
||||||
|
Wallet.enableTracing && console.info("Cause for retry was:", e);
|
||||||
this.timerGroup.after(retryDelayMs, () =>
|
this.timerGroup.after(retryDelayMs, () =>
|
||||||
processReserveInternal(nextDelay),
|
processReserveInternal(nextDelay),
|
||||||
);
|
);
|
||||||
@ -1144,10 +1145,9 @@ export class Wallet {
|
|||||||
this.processPreCoinConcurrent >= 4 ||
|
this.processPreCoinConcurrent >= 4 ||
|
||||||
this.processPreCoinThrottle[preCoin.exchangeBaseUrl]
|
this.processPreCoinThrottle[preCoin.exchangeBaseUrl]
|
||||||
) {
|
) {
|
||||||
this.enableTracing && console.log("delaying processPreCoin");
|
const timeout = Math.min(retryDelayMs * 2, 5 * 60 * 1000);
|
||||||
this.timerGroup.after(retryDelayMs, () =>
|
Wallet.enableTracing && console.log(`throttling processPreCoin of ${preCoinPub} for ${timeout}ms`);
|
||||||
processPreCoinInternal(Math.min(retryDelayMs * 2, 5 * 60 * 1000)),
|
this.timerGroup.after(retryDelayMs, () => processPreCoinInternal());
|
||||||
);
|
|
||||||
return op.promise;
|
return op.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1498,6 +1498,8 @@ export class Wallet {
|
|||||||
reqUrl.query({ reserve_pub: reservePub });
|
reqUrl.query({ reserve_pub: reservePub });
|
||||||
const resp = await this.http.get(reqUrl.href());
|
const resp = await this.http.get(reqUrl.href());
|
||||||
if (resp.status !== 200) {
|
if (resp.status !== 200) {
|
||||||
|
Wallet.enableTracing &&
|
||||||
|
console.warn(`reserve/status returned ${resp.status}`);
|
||||||
throw Error();
|
throw Error();
|
||||||
}
|
}
|
||||||
const reserveInfo = ReserveStatus.checked(resp.responseJson);
|
const reserveInfo = ReserveStatus.checked(resp.responseJson);
|
||||||
@ -1575,7 +1577,6 @@ export class Wallet {
|
|||||||
if (denom.status === DenominationStatus.VerifiedGood) {
|
if (denom.status === DenominationStatus.VerifiedGood) {
|
||||||
return Amounts.add(denom.feeWithdraw, denom.value).amount;
|
return Amounts.add(denom.feeWithdraw, denom.value).amount;
|
||||||
}
|
}
|
||||||
console.log(`verifying denom ${denom.denomPub.substr(0, 15)}`);
|
|
||||||
const valid = await this.cryptoApi.isValidDenom(
|
const valid = await this.cryptoApi.isValidDenom(
|
||||||
denom,
|
denom,
|
||||||
exchange.masterPublicKey,
|
exchange.masterPublicKey,
|
||||||
@ -1630,7 +1631,6 @@ export class Wallet {
|
|||||||
selectedDenoms = getWithdrawDenomList(amount, possibleDenoms);
|
selectedDenoms = getWithdrawDenomList(amount, possibleDenoms);
|
||||||
for (const denom of selectedDenoms || []) {
|
for (const denom of selectedDenoms || []) {
|
||||||
if (denom.status === DenominationStatus.Unverified) {
|
if (denom.status === DenominationStatus.Unverified) {
|
||||||
console.log(`verifying denom ${denom.denomPub.substr(0, 15)}`);
|
|
||||||
const valid = await this.cryptoApi.isValidDenom(
|
const valid = await this.cryptoApi.isValidDenom(
|
||||||
denom,
|
denom,
|
||||||
exchange.masterPublicKey,
|
exchange.masterPublicKey,
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/amounts.ts",
|
"src/amounts.ts",
|
||||||
|
"src/android/index.ts",
|
||||||
"src/checkable.ts",
|
"src/checkable.ts",
|
||||||
"src/crypto/browserWorkerEntry.ts",
|
"src/crypto/browserWorkerEntry.ts",
|
||||||
"src/crypto/cryptoApi-test.ts",
|
"src/crypto/cryptoApi-test.ts",
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Subproject commit ebf2b43fb00f057643d69abf34b54a1b6087dfcd
|
|
Loading…
Reference in New Issue
Block a user