Skip to content

Commit 0d20cd3

Browse files
authored
fix: restrict reputation events in non-strict mode (#1808)
* fix: restrict reputation events in non-strict mode This ensures we only add severe and manual reputation events to peers when not running in strict mode by filtering both events that arise from the peer itself as well as those originating from other sources, such as failed swaps. Previously we only checked on events arising from the peer, which, for example, would include packet delays but not a failure to find routes. Fixes #1802 * fix: only deactivate currencies in strict mode
1 parent 743bf75 commit 0d20cd3

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

Diff for: lib/p2p/Pool.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,19 @@ class Pool extends EventEmitter {
675675
}
676676

677677
// A wrapper for [[NodeList.addReputationEvent]].
678-
public addReputationEvent = (nodePubKey: string, event: ReputationEvent) => {
679-
return this.nodes.addReputationEvent(nodePubKey, event);
678+
public addReputationEvent = async (nodePubKey: string, event: ReputationEvent) => {
679+
// when in strict mode, we add all reputation events
680+
// otherwise, we only add manual or severe reputation events to prevent unintentional bans
681+
if (this.strict
682+
|| event === ReputationEvent.ManualBan
683+
|| event === ReputationEvent.ManualUnban
684+
|| event === ReputationEvent.SwapAbuse
685+
|| event === ReputationEvent.SwapMisbehavior
686+
|| event === ReputationEvent.WireProtocolErr
687+
|| event === ReputationEvent.InvalidAuth) {
688+
this.logger.debug(`Peer (${nodePubKey}): reputation event: ${ReputationEvent[event]}`);
689+
await this.nodes.addReputationEvent(nodePubKey, event);
690+
}
680691
}
681692

682693
public sendToPeer = async (nodePubKey: string, packet: Packet) => {
@@ -931,19 +942,8 @@ class Pool extends EventEmitter {
931942
peer.once('close', () => this.handlePeerClose(peer));
932943

933944
peer.on('reputation', async (event) => {
934-
this.logger.debug(`Peer (${peer.label}): reputation event: ${ReputationEvent[event]}`);
935945
if (peer.nodePubKey) {
936-
// when in strict mode, we add all reputation events
937-
// otherwise, we only add manual or severe reputation events to prevent unintentional bans
938-
if (this.strict
939-
|| event === ReputationEvent.ManualBan
940-
|| event === ReputationEvent.ManualUnban
941-
|| event === ReputationEvent.SwapAbuse
942-
|| event === ReputationEvent.SwapMisbehavior
943-
|| event === ReputationEvent.WireProtocolErr
944-
|| event === ReputationEvent.InvalidAuth) {
945-
await this.addReputationEvent(peer.nodePubKey, event);
946-
}
946+
await this.addReputationEvent(peer.nodePubKey, event);
947947
}
948948
});
949949
}

Diff for: lib/swaps/Swaps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ class Swaps extends EventEmitter {
12201220
case SwapFailureReason.SendPaymentFailure:
12211221
case SwapFailureReason.NoRouteFound:
12221222
// something is wrong with swaps for this currency with this peer
1223-
if (failedCurrency && !this.strict) { // only deactivate currencies due to failed swaps in strict mode
1223+
if (failedCurrency && this.strict) { // only deactivate currencies due to failed swaps in strict mode
12241224
try {
12251225
this.pool.getPeer(deal.peerPubKey).deactivateCurrency(failedCurrency);
12261226
} catch (err) {

Diff for: test/integration/Swaps.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('Swaps.Integration', () => {
8585
peer.getIdentifier = () => '1234567890';
8686
// pool
8787
pool = sandbox.createStubInstance(Pool) as any;
88-
pool.addReputationEvent = () => Promise.resolve(true);
88+
pool.addReputationEvent = () => Promise.resolve();
8989
pool.getPeer = () => peer;
9090
pool.tryGetPeer = () => peer;
9191
// getRoute response

0 commit comments

Comments
 (0)