wallet-core: fix withdrawal state machine

This commit is contained in:
Florian Dold 2022-09-23 21:47:38 +02:00
parent 8d19b80153
commit 2337ddab61
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
5 changed files with 14 additions and 1 deletions

View File

@ -84,6 +84,8 @@ export async function runWalletBackupBasicTest(t: GlobalTestState) {
await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:10" });
await wallet.runUntilDone();
await wallet.client.call(WalletApiOperation.RunBackupCycle, {});
{

View File

@ -59,6 +59,8 @@ export async function runWalletBackupDoublespendTest(t: GlobalTestState) {
await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:10" });
await wallet.runUntilDone();
await wallet.client.call(WalletApiOperation.RunBackupCycle, {});
await wallet.runUntilDone();
await wallet.client.call(WalletApiOperation.RunBackupCycle, {});

View File

@ -126,6 +126,11 @@ export enum WithdrawalGroupStatus {
*/
QueryingStatus = OperationStatusRange.ACTIVE_START + 2,
/**
* Ready for withdrawal.
*/
Ready = OperationStatusRange.ACTIVE_START + 3,
/**
* The corresponding withdraw record has been created.
* No further processing is done, unless explicitly requested

View File

@ -1023,7 +1023,7 @@ async function queryReserve(
logger.warn(`withdrawal group ${withdrawalGroupId} not found`);
return;
}
wg.status = WithdrawalGroupStatus.Finished;
wg.status = WithdrawalGroupStatus.Ready;
await tx.withdrawalGroups.put(wg);
});
@ -1138,6 +1138,9 @@ export async function processWithdrawalGroup(
case WithdrawalGroupStatus.Finished:
// We can try to withdraw, nothing needs to be done with the reserve.
break;
case WithdrawalGroupStatus.Ready:
// Continue with the actual withdrawal!
break;
default:
throw new InvariantViolatedError(
`unknown reserve record status: ${withdrawalGroup.status}`,

View File

@ -492,6 +492,7 @@ async function runTaskLoop(
ws: InternalWalletState,
opts: RetryLoopOpts = {},
): Promise<TaskLoopResult> {
logger.info(`running task loop opts=${j2s(opts)}`);
let retriesExceeded = false;
for (let iteration = 0; !ws.stopped; iteration++) {
const pending = await getPendingOperations(ws);