Commit c2b5b69f authored by zeroleak's avatar zeroleak
Browse files

new setting: server.register-input.max-inputs-same-hash: max inputs with same...

new setting: server.register-input.max-inputs-same-hash: max inputs with same hash (same origin tx) allowed to register to a mix
parent 8665ae9a
......@@ -44,6 +44,11 @@ server.register-input.min-confirmations-must-mix: minimum confirmations for must
server.register-input.min-confirmations-liquidity: minimum confirmations for liquidity inputs
```
### UTXO rules
```
server.register-input.max-inputs-same-hash: max inputs with same hash (same origin tx) allowed to register to a mix
```
### Mix limits
```
server.mix.anonymity-set-target = 10
......
......@@ -113,6 +113,7 @@ public class WhirlpoolServerConfig {
public static class RegisterInputConfig {
private int minConfirmationsMustMix;
private int minConfirmationsLiquidity;
private int maxInputsSameHash;
public int getMinConfirmationsMustMix() {
return minConfirmationsMustMix;
......@@ -129,6 +130,14 @@ public class WhirlpoolServerConfig {
public void setMinConfirmationsLiquidity(int minConfirmationsLiquidity) {
this.minConfirmationsLiquidity = minConfirmationsLiquidity;
}
public int getMaxInputsSameHash() {
return maxInputsSameHash;
}
public void setMaxInputsSameHash(int maxInputsSameHash) {
this.maxInputsSameHash = maxInputsSameHash;
}
}
public static class RegisterOutputConfig {
......
......@@ -279,6 +279,10 @@ public class MixLimitsService {
// start mix if ready
mixService.checkRegisterInputReady(mix);
}
} else {
if (log.isDebugEnabled()) {
log.debug("No liquidity to add: maxAnonymitySet=" + mix.getPool().getMaxAnonymitySet() + ", nbInputs=" + mix.getNbInputs());
}
}
}
......
......@@ -112,6 +112,8 @@ public class MixService {
}
private synchronized void registerInput(Mix mix, RegisteredInput registeredInput, byte[] signedBordereauToReply, boolean isLiquidity) throws IllegalInputException, MixException, QueueInputException {
validateOnAddInput(mix, registeredInput);
// registerInput + response
doRegisterInput(mix, registeredInput, signedBordereauToReply, isLiquidity);
......@@ -122,6 +124,22 @@ public class MixService {
checkRegisterInputReady(mix);
}
/**
* Last input validations when adding it to a mix (not when queueing it)
*/
private void validateOnAddInput(Mix mix, RegisteredInput registeredInput) throws IllegalInputException {
// verify max-input-same-hash
String inputHash = registeredInput.getInput().getHash();
int maxInputsSameHash = whirlpoolServerConfig.getRegisterInput().getMaxInputsSameHash();
long countInputsSameHash = mix.getInputs().parallelStream().filter(input -> input.getInput().getHash().equals(inputHash)).count();
if ((countInputsSameHash + 1) > maxInputsSameHash) {
if (log.isDebugEnabled()) {
log.debug("already " + countInputsSameHash + " inputs with same hash: " + inputHash);
}
throw new IllegalInputException("Current mix is full for inputs with same hash, please try again on next mix");
}
}
private void doRegisterInput(Mix mix, RegisteredInput registeredInput, byte[] signedBordereauToReply, boolean isLiquidity) throws IllegalInputException, MixException, QueueInputException {
TxOutPoint input = registeredInput.getInput();
String username = registeredInput.getUsername();
......
......@@ -24,6 +24,7 @@ server.rpc-client.mock-tx-broadcast = false
server.register-input.min-confirmations-must-mix = 1
server.register-input.min-confirmations-liquidity = 1
server.register-input.max-inputs-same-hash = 1
# 240s = 4min
server.register-output.timeout = 240
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment