diff options
| author | Florian Dold <florian@dold.me> | 2021-08-06 16:27:18 +0200 | 
|---|---|---|
| committer | Florian Dold <florian@dold.me> | 2021-08-06 16:27:18 +0200 | 
| commit | 05e52d4e116222728d9bcba3bcbf9e441bb4e4ed (patch) | |
| tree | 6ef9da262ea2e88379878db52d2a1dbd022acd59 /packages | |
| parent | 97de6321ac9a4047c36c9000b93989967ad36013 (diff) | |
perf and logging improvements
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/taler-wallet-cli/src/lint.ts | 5 | ||||
| -rw-r--r-- | packages/taler-wallet-core/src/headless/helpers.ts | 1 | ||||
| -rw-r--r-- | packages/taler-wallet-core/src/operations/exchanges.ts | 12 | ||||
| -rw-r--r-- | packages/taler-wallet-core/src/operations/withdraw.ts | 82 | 
4 files changed, 59 insertions, 41 deletions
| diff --git a/packages/taler-wallet-cli/src/lint.ts b/packages/taler-wallet-cli/src/lint.ts index f88865952..4b9633871 100644 --- a/packages/taler-wallet-cli/src/lint.ts +++ b/packages/taler-wallet-cli/src/lint.ts @@ -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 }; diff --git a/packages/taler-wallet-core/src/headless/helpers.ts b/packages/taler-wallet-core/src/headless/helpers.ts index cb788e2bd..f29dfd69c 100644 --- a/packages/taler-wallet-core/src/headless/helpers.ts +++ b/packages/taler-wallet-core/src/headless/helpers.ts @@ -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; diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index 86a518671..64821a7b1 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -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, diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 55f39b6bf..99d8d7d39 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -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`, +  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}`,          ); -        denom.status = DenominationStatus.VerifiedBad; -      } else { -        denom.status = DenominationStatus.VerifiedGood; +        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( | 
