Skip to content

Commit e89f936

Browse files
committed
fix(swaps): ignore swap failed for inactive swaps
This ignores any swap failed packets received for deals that are not active. Attempting to fail a completed deal would throw an assertion error that could crash `xud`.
1 parent 59aa8ff commit e89f936

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/swaps/Swaps.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,16 @@ class Swaps extends EventEmitter {
725725
private handleSwapFailed = (packet: packets.SwapFailedPacket) => {
726726
const { rHash, errorMessage, failureReason } = packet.body!;
727727
const deal = this.getDeal(rHash);
728+
// TODO: penalize for unexpected swap failed packets
728729
if (!deal) {
729-
this.logger.error(`received swap error for unknown deal payment hash ${rHash}`);
730+
this.logger.warn(`received swap failed packet for unknown deal with payment hash ${rHash}`);
730731
return;
731732
}
733+
if (deal.state !== SwapState.Active) {
734+
this.logger.warn(`received swap failed packet for inactive deal with payment hash ${rHash}`);
735+
return;
736+
}
737+
732738
this.failDeal(deal, failureReason, errorMessage);
733739
return this.persistDeal(deal);
734740
}

0 commit comments

Comments
 (0)