Skip to content

Commit

Permalink
feat(swaps): check if rHash exists (#642)
Browse files Browse the repository at this point in the history
This checks if the rHash for a swap request has been used for a previous
swap, and rejects the swap request if so. rHash values should not be
reused as we rely on them to uniquely identify swap they jeopardize the
atomicity of the swap.

Closes #547.
  • Loading branch information
ImmanuelSegol authored and sangaman committed Nov 14, 2018
1 parent 27ec3c2 commit ef2beb2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/swaps/Swaps.ts
Expand Up @@ -304,7 +304,11 @@ class Swaps extends EventEmitter {
// TODO: max cltv to limit routes
// TODO: consider the time gap between taking the routes and using them.
// TODO: multi route support (currently only 1)
// TODO: check to make sure we don't already have a deal for the requested payment hash

if (this.usedHashes.has(requestPacket.body!.rHash)) {
this.sendErrorToPeer(peer, requestPacket.body!.rHash, 'this rHash already exists', requestPacket.header.id);
return false;
}
const requestBody = requestPacket.body!;

const { quantity, price, isBuy } = orderToAccept;
Expand Down

0 comments on commit ef2beb2

Please sign in to comment.