wallet-core: always use batch withdrawal

This commit is contained in:
Florian Dold 2023-08-22 16:37:27 +02:00
parent b9f908db58
commit 0a05f6d903
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
11 changed files with 4 additions and 74 deletions

View File

@ -68,7 +68,6 @@ export async function runBench1(configJson: any): Promise<void> {
} else { } else {
logger.info("not trusting exchange (validating signatures)"); logger.info("not trusting exchange (validating signatures)");
} }
const batchWithdrawal = !!process.env["TALER_WALLET_BATCH_WITHDRAWAL"];
let wallet = {} as Wallet; let wallet = {} as Wallet;
let getDbStats: () => AccessStats; let getDbStats: () => AccessStats;
@ -91,9 +90,7 @@ export async function runBench1(configJson: any): Promise<void> {
testing: { testing: {
insecureTrustExchange: trustExchange, insecureTrustExchange: trustExchange,
}, },
features: { features: {},
batchWithdrawal,
},
}, },
}); });
wallet = res.wallet; wallet = res.wallet;

View File

@ -76,8 +76,6 @@ export async function runBench3(configJson: any): Promise<void> {
} else { } else {
logger.info("not trusting exchange (validating signatures)"); logger.info("not trusting exchange (validating signatures)");
} }
const batchWithdrawal = !!process.env["TALER_WALLET_BATCH_WITHDRAWAL"];
let wallet = {} as Wallet; let wallet = {} as Wallet;
let getDbStats: () => AccessStats; let getDbStats: () => AccessStats;
@ -96,9 +94,7 @@ export async function runBench3(configJson: any): Promise<void> {
persistentStoragePath: undefined, persistentStoragePath: undefined,
httpLib: myHttpLib, httpLib: myHttpLib,
config: { config: {
features: { features: {},
batchWithdrawal,
},
testing: { testing: {
insecureTrustExchange: trustExchange, insecureTrustExchange: trustExchange,
}, },

View File

@ -103,6 +103,7 @@ import { runPaymentTemplateTest } from "./test-payment-template.js";
import { runExchangeDepositTest } from "./test-exchange-deposit.js"; import { runExchangeDepositTest } from "./test-exchange-deposit.js";
import { runPeerRepairTest } from "./test-peer-repair.js"; import { runPeerRepairTest } from "./test-peer-repair.js";
import { runPaymentShareTest } from "./test-payment-share.js"; import { runPaymentShareTest } from "./test-payment-share.js";
import { runSimplePaymentTest } from "./test-simple-payment.js";
/** /**
* Test runner. * Test runner.
@ -129,6 +130,7 @@ const allTests: TestMainFunction[] = [
runClauseSchnorrTest, runClauseSchnorrTest,
runDenomUnofferedTest, runDenomUnofferedTest,
runDepositTest, runDepositTest,
runSimplePaymentTest,
runExchangeManagementTest, runExchangeManagementTest,
runExchangeTimetravelTest, runExchangeTimetravelTest,
runFeeRegressionTest, runFeeRegressionTest,

View File

@ -258,7 +258,6 @@ async function createLocalWallet(
cryptoWorkerType: walletCliArgs.wallet.cryptoWorker as any, cryptoWorkerType: walletCliArgs.wallet.cryptoWorker as any,
config: { config: {
features: { features: {
batchWithdrawal: checkEnvFlag("TALER_WALLET_BATCH_WITHDRAWAL"),
}, },
testing: { testing: {
devModeActive: checkEnvFlag("TALER_WALLET_DEV_MODE"), devModeActive: checkEnvFlag("TALER_WALLET_DEV_MODE"),

View File

@ -710,12 +710,6 @@ async function processPlanchetGenerate(
} }
interface WithdrawalRequestBatchArgs { interface WithdrawalRequestBatchArgs {
/**
* Use the batched request on the network level.
* Not supported by older exchanges.
*/
useBatchRequest: boolean;
coinStartIndex: number; coinStartIndex: number;
batchSize: number; batchSize: number;
@ -923,7 +917,6 @@ async function processPlanchetExchangeBatchRequest(
// FIXME: handle individual error codes better! // FIXME: handle individual error codes better!
if (args.useBatchRequest) {
const reqUrl = new URL( const reqUrl = new URL(
`reserves/${withdrawalGroup.reservePub}/batch-withdraw`, `reserves/${withdrawalGroup.reservePub}/batch-withdraw`,
withdrawalGroup.exchangeBaseUrl, withdrawalGroup.exchangeBaseUrl,
@ -949,53 +942,6 @@ async function processPlanchetExchangeBatchRequest(
coinIdxs: [], coinIdxs: [],
}; };
} }
} else {
// We emulate the batch response here by making multiple individual requests
const responses: ExchangeWithdrawBatchResponse = {
ev_sigs: [],
};
const responseCoinIdxs: number[] = [];
for (let i = 0; i < batchReq.planchets.length; i++) {
try {
const p = batchReq.planchets[i];
const reqUrl = new URL(
`reserves/${withdrawalGroup.reservePub}/withdraw`,
withdrawalGroup.exchangeBaseUrl,
).href;
const resp = await ws.http.fetch(reqUrl, { method: "POST", body: p });
if (resp.status === HttpStatusCode.UnavailableForLegalReasons) {
await handleKycRequired(
ws,
withdrawalGroup,
resp,
i,
requestCoinIdxs,
);
// We still return blinded coins that we could actually withdraw.
return {
coinIdxs: responseCoinIdxs,
batchResp: responses,
};
}
const r = await readSuccessResponseJsonOrThrow(
resp,
codecForWithdrawResponse(),
);
responses.ev_sigs.push(r);
responseCoinIdxs.push(requestCoinIdxs[i]);
} catch (e) {
if (e instanceof TalerError) {
logger.warn(`withdrawing planchet failed: ${j2s(e.errorDetail)}`);
logger.warn(`planchet denom pub hash: ${batchReq.planchets[i].denom_pub_hash}`);
}
await storeCoinError(e, requestCoinIdxs[i]);
}
}
return {
coinIdxs: responseCoinIdxs,
batchResp: responses,
};
}
} }
async function processPlanchetVerifyAndStoreCoin( async function processPlanchetVerifyAndStoreCoin(
@ -1548,7 +1494,6 @@ async function processWithdrawalGroupPendingReady(
const resp = await processPlanchetExchangeBatchRequest(ws, wgContext, { const resp = await processPlanchetExchangeBatchRequest(ws, wgContext, {
batchSize: maxBatchSize, batchSize: maxBatchSize,
coinStartIndex: i, coinStartIndex: i,
useBatchRequest: ws.config.features.batchWithdrawal,
}); });
let work: Promise<void>[] = []; let work: Promise<void>[] = [];
work = []; work = [];

View File

@ -272,7 +272,6 @@ export interface WalletConfig {
* Configurations values that may be safe to show to the user * Configurations values that may be safe to show to the user
*/ */
features: { features: {
batchWithdrawal: boolean;
allowHttp: boolean; allowHttp: boolean;
}; };
} }

View File

@ -1696,7 +1696,6 @@ export class Wallet {
], ],
}, },
features: { features: {
batchWithdrawal: false,
allowHttp: false, allowHttp: false,
}, },
testing: { testing: {

View File

@ -34,7 +34,6 @@ function parse_json_or_undefined<T>(str: string | undefined): T | undefined {
export const codecForSettings = (): Codec<Settings> => export const codecForSettings = (): Codec<Settings> =>
buildCodecForObject<Settings>() buildCodecForObject<Settings>()
.property("walletAllowHttp", codecForBoolean()) .property("walletAllowHttp", codecForBoolean())
.property("walletBatchWithdrawal", codecForBoolean())
.property("injectTalerSupport", codecForBoolean()) .property("injectTalerSupport", codecForBoolean())
.property("advanceMode", codecForBoolean()) .property("advanceMode", codecForBoolean())
.property("backup", codecForBoolean()) .property("backup", codecForBoolean())

View File

@ -119,7 +119,6 @@ export const defaultSettings: Settings = {
showJsonOnError: false, showJsonOnError: false,
extendedAccountTypes: false, extendedAccountTypes: false,
walletAllowHttp: false, walletAllowHttp: false,
walletBatchWithdrawal: false,
}; };
/** /**

View File

@ -316,10 +316,6 @@ function AdvanceSettings(): VNode {
label: i18n.str`Allow HTTP connections`, label: i18n.str`Allow HTTP connections`,
description: i18n.str`Using HTTP connection may be faster but unsafe (wallet restart required)`, description: i18n.str`Using HTTP connection may be faster but unsafe (wallet restart required)`,
}, },
walletBatchWithdrawal: {
label: i18n.str`Allow batch withdrawals`,
description: i18n.str`Using the batch withdrawal API allows faster withdrawals (wallet restart required)`,
},
langSelector: { langSelector: {
label: i18n.str`Lang selector`, label: i18n.str`Lang selector`,
description: i18n.str`Allows to manually change the language of the UI. Otherwise it will be automatically selected by your browser configuration.`, description: i18n.str`Allows to manually change the language of the UI. Otherwise it will be automatically selected by your browser configuration.`,

View File

@ -332,7 +332,6 @@ async function reinitWallet(): Promise<void> {
{ {
features: { features: {
allowHttp: settings.walletAllowHttp, allowHttp: settings.walletAllowHttp,
batchWithdrawal: settings.walletBatchWithdrawal,
}, },
}, },
); );