wallet-core: trust exchange for exchange benchmark

This commit is contained in:
Florian Dold 2021-12-08 16:23:00 +01:00
parent 09aeaf753a
commit 684c53e105
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
6 changed files with 52 additions and 23 deletions

View File

@ -105,6 +105,8 @@ export async function runBench1(configJson: any): Promise<void> {
logger.info(`Finished deposit amount=10 time=${Date.now() - start}`);
}
}
wallet.stop();
}
/**

View File

@ -133,6 +133,8 @@ export interface InternalWalletState {
timerGroup: TimerGroup;
stopped: boolean;
insecureTrustExchange: boolean;
/**
* Asynchronous condition to interrupt the sleep of the
* retry loop.

View File

@ -25,7 +25,7 @@ import { CryptoWorker } from "./cryptoWorkerInterface.js";
import child_process from "child_process";
import type internal from "stream";
import { OpenedPromise, openPromise } from "../../index.js";
import { FreshCoin, Logger } from "@gnu-taler/taler-util";
import { Logger } from "@gnu-taler/taler-util";
const logger = new Logger("synchronousWorker.ts");

View File

@ -218,19 +218,24 @@ export async function acceptExchangeTermsOfService(
}
async function validateWireInfo(
ws: InternalWalletState,
versionCurrent: number,
wireInfo: ExchangeWireJson,
masterPublicKey: string,
cryptoApi: CryptoApi,
): Promise<WireInfo> {
for (const a of wireInfo.accounts) {
logger.trace("validating exchange acct");
const isValid = await cryptoApi.isValidWireAccount(
let isValid = false;
if (ws.insecureTrustExchange) {
isValid = true;
} else {
isValid = await ws.cryptoApi.isValidWireAccount(
versionCurrent,
a.payto_uri,
a.master_sig,
masterPublicKey,
);
}
if (!isValid) {
throw Error("exchange acct signature invalid");
}
@ -248,11 +253,16 @@ async function validateWireInfo(
startStamp,
wireFee: Amounts.parseOrThrow(x.wire_fee),
};
const isValid = await cryptoApi.isValidWireFee(
let isValid = false;
if (ws.insecureTrustExchange) {
isValid = true;
} else {
isValid = await ws.cryptoApi.isValidWireFee(
wireMethod,
fee,
masterPublicKey,
);
}
if (!isValid) {
throw Error("exchange wire fee signature invalid");
}
@ -488,10 +498,10 @@ async function updateExchangeFromUrlImpl(
}
const wireInfo = await validateWireInfo(
ws,
version.current,
wireInfoDownload,
keysInfo.masterPublicKey,
ws.cryptoApi,
);
logger.info("finished validating exchange /wire info");

View File

@ -777,10 +777,15 @@ export async function updateWithdrawalDenoms(
denominations.length
}) signature of ${denom.denomPubHash}`,
);
const valid = await ws.cryptoApi.isValidDenom(
let valid: boolean = false;
if (ws.insecureTrustExchange) {
valid = true;
} else {
valid = await ws.cryptoApi.isValidDenom(
denom,
exchangeDetails.masterPublicKey,
);
}
logger.trace(`Done validating ${denom.denomPubHash}`);
if (!valid) {
logger.warn(

View File

@ -1037,6 +1037,14 @@ export class Wallet {
return this._client;
}
/**
* Trust the exchange, do not validate signatures.
* Only used to benchmark the exchange.
*/
setInsecureTrustExchange() {
this.ws.insecureTrustExchange = true;
}
static async create(
db: DbAccess<typeof WalletStoresV1>,
http: HttpRequestLibrary,
@ -1089,6 +1097,8 @@ class InternalWalletStateImpl implements InternalWalletState {
merchantInfoCache: Record<string, MerchantInfo> = {};
insecureTrustExchange: boolean = false;
timerGroup: TimerGroup = new TimerGroup();
latch = new AsyncCondition();
stopped = false;