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");
if (!roundUnit.isDefined) {
const ru = roundUnit.required();
if (ru.currency.toLowerCase() != mainCurrency.toLowerCase()) {
context.numErr++;
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 };

View File

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

View File

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

View File

@ -675,6 +675,9 @@ export async function updateWithdrawalDenoms(
ws: InternalWalletState,
exchangeBaseUrl: string,
): Promise<void> {
logger.trace(
`updating denominations used for withdrawal for ${exchangeBaseUrl}`,
);
const exchangeDetails = await ws.db
.mktx((x) => ({
exchanges: x.exchanges,
@ -689,53 +692,56 @@ export async function updateWithdrawalDenoms(
}
// First do a pass where the validity of candidate denominations
// is checked and the result is stored in the database.
logger.trace("getting candidate denominations");
const denominations = await getCandidateWithdrawalDenoms(ws, exchangeBaseUrl);
for (const denom of denominations) {
if (denom.status === DenominationStatus.Unverified) {
const valid = await ws.cryptoApi.isValidDenom(
denom,
exchangeDetails.masterPublicKey,
);
if (!valid) {
logger.warn(
`Signature check for denomination h=${denom.denomPubHash} failed`,
);
denom.status = DenominationStatus.VerifiedBad;
} else {
denom.status = DenominationStatus.VerifiedGood;
logger.trace(`got ${denominations.length} candidate denominations`);
const batchSize = 500;
let current = 0;
while (current < denominations.length) {
const updatedDenominations: DenominationRecord[] = [];
// Do a batch of batchSize
for (let batchIdx = 0; batchIdx < batchSize; batchIdx++) {
current++;
if (current >= denominations.length) {
break;
}
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
.mktx((x) => ({ denominations: x.denominations }))
.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(