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(coinjoin): do not ban inputs locally after unsuccessful round #8855

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading