Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added check for peer's pairs on order invalidation #1864

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/p2p/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,11 @@ class Pool extends EventEmitter {
const orderInvalidationPacket = new packets.OrderInvalidationPacket({ id, pairId, quantity });
this.peers.forEach(async (peer) => {
if (!nodeToExclude || peer.nodePubKey !== nodeToExclude) {
await peer.sendPacket(orderInvalidationPacket);
if (peer.advertisedPairs.includes(pairId)) {
rsercano marked this conversation as resolved.
Show resolved Hide resolved
await peer.sendPacket(orderInvalidationPacket);
} else {
this.logger.trace(`skipping to send order invalidation to ${peer.address} since pair is not found`);
rsercano marked this conversation as resolved.
Show resolved Hide resolved
}
}
});

Expand Down Expand Up @@ -786,8 +790,12 @@ class Pool extends EventEmitter {
}
case PacketType.OrderInvalidation: {
const orderInvalidation = (packet as packets.OrderInvalidationPacket).body!;
this.logger.trace(`received order invalidation from ${peer.label}: ${JSON.stringify(orderInvalidation)}`);
this.emit('packet.orderInvalidation', orderInvalidation, peer.nodePubKey as string);
if (!this.nodeState.pairs.includes(orderInvalidation.pairId)) {
rsercano marked this conversation as resolved.
Show resolved Hide resolved
this.logger.trace(`received order invalidation for unrelated pair from ${peer.label}: ${JSON.stringify(orderInvalidation)}`);
rsercano marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.logger.trace(`received order invalidation from ${peer.label}: ${JSON.stringify(orderInvalidation)}`);
this.emit('packet.orderInvalidation', orderInvalidation, peer.nodePubKey as string);
}
break;
}
case PacketType.GetOrders: {
Expand Down