perf and logging improvements

This commit is contained in:
Florian Dold 2021-08-06 16:27:18 +02:00
parent 97de6321ac
commit 05e52d4e11
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 60 additions and 42 deletions

View File

@ -149,10 +149,11 @@ function checkBasicConf(context: LintContext): BasicConf {
} }
const roundUnit = cfg.getAmount("taler", "currency_round_unit"); const roundUnit = cfg.getAmount("taler", "currency_round_unit");
if (!roundUnit.isDefined) { const ru = roundUnit.required();
if (ru.currency.toLowerCase() != mainCurrency.toLowerCase()) {
context.numErr++; context.numErr++;
console.log( console.log(
"error: configuration incomplete, section TALER option CURRENCY_ROUND_UNIT missing", "error: [TALER]/CURRENCY_ROUND_UNIT: currency does not match main currency",
); );
} }
return { mainCurrency }; return { mainCurrency };

View File

@ -118,6 +118,7 @@ export async function getDefaultNodeWallet(
} }
myBackend.afterCommitCallback = async () => { myBackend.afterCommitCallback = async () => {
logger.trace("committing database");
// Allow caller to stop persisting the wallet. // Allow caller to stop persisting the wallet.
if (args.persistentStoragePath === undefined) { if (args.persistentStoragePath === undefined) {
return; return;

View File

@ -341,7 +341,6 @@ async function downloadKeysInfo(
); );
logger.info("received /keys response"); logger.info("received /keys response");
logger.trace(j2s(exchangeKeysJson));
if (exchangeKeysJson.denoms.length === 0) { if (exchangeKeysJson.denoms.length === 0) {
const opErr = makeErrorDetails( const opErr = makeErrorDetails(
@ -442,18 +441,23 @@ async function updateExchangeFromUrlImpl(
const keysInfo = await downloadKeysInfo(baseUrl, ws.http, timeout); const keysInfo = await downloadKeysInfo(baseUrl, ws.http, timeout);
logger.info("updating exchange /wire info");
const wireInfoDownload = await downloadExchangeWithWireInfo( const wireInfoDownload = await downloadExchangeWithWireInfo(
baseUrl, baseUrl,
ws.http, ws.http,
timeout, timeout,
); );
logger.info("validating exchange /wire info");
const wireInfo = await validateWireInfo( const wireInfo = await validateWireInfo(
wireInfoDownload, wireInfoDownload,
keysInfo.masterPublicKey, keysInfo.masterPublicKey,
ws.cryptoApi, ws.cryptoApi,
); );
logger.info("finished validating exchange /wire info");
const tosDownload = await downloadExchangeWithTermsOfService( const tosDownload = await downloadExchangeWithTermsOfService(
baseUrl, baseUrl,
ws.http, ws.http,
@ -462,6 +466,8 @@ async function updateExchangeFromUrlImpl(
let recoupGroupId: string | undefined = undefined; let recoupGroupId: string | undefined = undefined;
logger.trace("updating exchange info in database");
const updated = await ws.db const updated = await ws.db
.mktx((x) => ({ .mktx((x) => ({
exchanges: x.exchanges, exchanges: x.exchanges,
@ -512,6 +518,7 @@ async function updateExchangeFromUrlImpl(
await tx.exchanges.put(r); await tx.exchanges.put(r);
await tx.exchangeDetails.put(details); await tx.exchangeDetails.put(details);
logger.trace("updating denominations in database");
for (const currentDenom of keysInfo.currentDenominations) { for (const currentDenom of keysInfo.currentDenominations) {
const oldDenom = await tx.denominations.get([ const oldDenom = await tx.denominations.get([
baseUrl, baseUrl,
@ -523,6 +530,7 @@ async function updateExchangeFromUrlImpl(
await tx.denominations.put(currentDenom); await tx.denominations.put(currentDenom);
} }
} }
logger.trace("done updating denominations in database");
// Handle recoup // Handle recoup
const recoupDenomList = keysInfo.recoup; const recoupDenomList = keysInfo.recoup;
@ -579,6 +587,8 @@ async function updateExchangeFromUrlImpl(
throw Error("something went wrong with updating the exchange"); throw Error("something went wrong with updating the exchange");
} }
logger.trace("done updating exchange info in database");
return { return {
exchange: updated.exchange, exchange: updated.exchange,
exchangeDetails: updated.exchangeDetails, exchangeDetails: updated.exchangeDetails,

View File

@ -675,6 +675,9 @@ export async function updateWithdrawalDenoms(
ws: InternalWalletState, ws: InternalWalletState,
exchangeBaseUrl: string, exchangeBaseUrl: string,
): Promise<void> { ): Promise<void> {
logger.trace(
`updating denominations used for withdrawal for ${exchangeBaseUrl}`,
);
const exchangeDetails = await ws.db const exchangeDetails = await ws.db
.mktx((x) => ({ .mktx((x) => ({
exchanges: x.exchanges, exchanges: x.exchanges,
@ -689,53 +692,56 @@ export async function updateWithdrawalDenoms(
} }
// First do a pass where the validity of candidate denominations // First do a pass where the validity of candidate denominations
// is checked and the result is stored in the database. // is checked and the result is stored in the database.
logger.trace("getting candidate denominations");
const denominations = await getCandidateWithdrawalDenoms(ws, exchangeBaseUrl); const denominations = await getCandidateWithdrawalDenoms(ws, exchangeBaseUrl);
for (const denom of denominations) { logger.trace(`got ${denominations.length} candidate denominations`);
if (denom.status === DenominationStatus.Unverified) { const batchSize = 500;
const valid = await ws.cryptoApi.isValidDenom( let current = 0;
denom,
exchangeDetails.masterPublicKey, while (current < denominations.length) {
); const updatedDenominations: DenominationRecord[] = [];
if (!valid) { // Do a batch of batchSize
logger.warn( for (let batchIdx = 0; batchIdx < batchSize; batchIdx++) {
`Signature check for denomination h=${denom.denomPubHash} failed`, current++;
); if (current >= denominations.length) {
denom.status = DenominationStatus.VerifiedBad; break;
} else {
denom.status = DenominationStatus.VerifiedGood;
} }
const denom = denominations[current];
if (denom.status === DenominationStatus.Unverified) {
logger.trace(
`Validation denomination (${current + 1}/${
denominations.length
}) signature of ${denom.denomPubHash}`,
);
const valid = await ws.cryptoApi.isValidDenom(
denom,
exchangeDetails.masterPublicKey,
);
logger.trace(`Done validating ${denom.denomPubHash}`);
if (!valid) {
logger.warn(
`Signature check for denomination h=${denom.denomPubHash} failed`,
);
denom.status = DenominationStatus.VerifiedBad;
} else {
denom.status = DenominationStatus.VerifiedGood;
}
updatedDenominations.push(denom);
}
}
if (updatedDenominations.length > 0) {
logger.trace("writing denomination batch to db");
await ws.db await ws.db
.mktx((x) => ({ denominations: x.denominations })) .mktx((x) => ({ denominations: x.denominations }))
.runReadWrite(async (tx) => { .runReadWrite(async (tx) => {
await tx.denominations.put(denom); for (let i = 0; i < updatedDenominations.length; i++) {
const denom = updatedDenominations[i];
await tx.denominations.put(denom);
}
}); });
logger.trace("done with DB write");
} }
} }
// FIXME: This debug info should either be made conditional on some flag
// or put into some wallet-core API.
const nextDenominations = await getCandidateWithdrawalDenoms(
ws,
exchangeBaseUrl,
);
logger.trace(
`updated withdrawable denominations for "${exchangeBaseUrl}, n=${nextDenominations.length}"`,
);
const now = getTimestampNow();
for (const denom of nextDenominations) {
const startDelay = getDurationRemaining(denom.stampStart, now);
const lastPossibleWithdraw = timestampSubtractDuraction(
denom.stampExpireWithdraw,
{ d_ms: 50 * 1000 },
);
const remaining = getDurationRemaining(lastPossibleWithdraw, now);
logger.trace(
`Denom ${denom.denomPubHash} ${denom.status} revoked ${
denom.isRevoked
} offered ${denom.isOffered} remaining ${
(remaining.d_ms as number) / 1000
}sec withdrawDelay ${(startDelay.d_ms as number) / 1000}sec`,
);
}
} }
async function incrementWithdrawalRetry( async function incrementWithdrawalRetry(