Skip to content

Commit

Permalink
fix(swaps): ignore swap failed for inactive swaps
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
sangaman committed Jan 8, 2019
1 parent 59aa8ff commit e89f936
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/swaps/Swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,16 @@ class Swaps extends EventEmitter {
private handleSwapFailed = (packet: packets.SwapFailedPacket) => {
const { rHash, errorMessage, failureReason } = packet.body!;
const deal = this.getDeal(rHash);
// TODO: penalize for unexpected swap failed packets
if (!deal) {
this.logger.error(`received swap error for unknown deal payment hash ${rHash}`);
this.logger.warn(`received swap failed packet for unknown deal with payment hash ${rHash}`);
return;
}
if (deal.state !== SwapState.Active) {
this.logger.warn(`received swap failed packet for inactive deal with payment hash ${rHash}`);
return;
}

this.failDeal(deal, failureReason, errorMessage);
return this.persistDeal(deal);
}
Expand Down

0 comments on commit e89f936

Please sign in to comment.