Skip to content

Commit

Permalink
fix(coinjoin): do not ban inputs locally after unsuccessful round
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonlesisz committed Jul 4, 2023
1 parent 1bb2732 commit 4253f3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions packages/coinjoin/src/client/round/endedRound.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { enumUtils } from '@trezor/utils';
import { enumUtils, getRandomNumberInRange } from '@trezor/utils';

import type { CoinjoinRound, CoinjoinRoundOptions } from '../CoinjoinRound';
import { EndRoundState, WabiSabiProtocolErrorCode } from '../../enums';
Expand Down Expand Up @@ -48,10 +48,18 @@ export const ended = (round: CoinjoinRound, { logger, network }: CoinjoinRoundOp
// not signed because of other reason however
logger.error(`Round not signed. This should never happen.`);
}
inputs.forEach(input =>
prison.detain(input, {
roundId: id,
errorCode: WabiSabiProtocolErrorCode.InputBanned,

// assume that inputs are not banned but just noted.
// all depends on the coordinator `AllowNotedInputRegistration` flag which is not visible in the Status
// https://github.com/zkSNACKs/WalletWasabi/blob/master/WalletWasabi/WabiSabi/Backend/Rounds/Arena.Partial.cs#L414
// give used inputs/outputs some random cool off time and try again,
// repeated input-registration will tell if they are really banned,
// make sure that addresses registered in round are recycled (reset Infinity sentence)
const minute = 60 * 1000;
const sentenceEnd = getRandomNumberInRange(5 * minute, 10 * minute);
[...inputs, ...addresses].forEach(vinvout =>
prison.detain(vinvout, {
sentenceEnd,
}),
);
} else if (endRoundState === EndRoundState.NotAllAlicesSign) {
Expand Down
6 changes: 3 additions & 3 deletions packages/coinjoin/tests/client/endedRound.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('ended', () => {

expect(logger.error).toBeCalledTimes(1);
expect(logger.error).toBeCalledWith(expect.stringMatching(/Missing affiliate request/));
expect(round.prison.inmates.length).toEqual(1);
expect(round.prison.inmates.length).toEqual(2); // input + output are detained
});

it('NotAllAlicesSign by this instance (missing witnesses)', () => {
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('ended', () => {

expect(logger.error).toBeCalledTimes(1);
expect(logger.error).toBeCalledWith(expect.stringMatching(/Missing signed inputs/));
expect(round.prison.inmates.length).toEqual(1);
expect(round.prison.inmates.length).toEqual(2); // input + output are detained
});

it('NotAllAlicesSign by this instance (other)', () => {
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('ended', () => {

expect(logger.error).toBeCalledTimes(1);
expect(logger.error).toBeCalledWith(expect.stringMatching(/This should never happen/));
expect(round.prison.inmates.length).toEqual(1);
expect(round.prison.inmates.length).toEqual(2); // input + output are detained
});

it('AbortedNotEnoughAlicesSigned by other instance (no blame round)', () => {
Expand Down

0 comments on commit 4253f3d

Please sign in to comment.