Commit 7ff201a4 authored by zeroleak's avatar zeroleak
Browse files

add config: server.register-input.max-inputs-same-user-hash

parent 301daa15
......@@ -51,6 +51,7 @@ server.register-input.liquidity-interval = 10: liquidities are added by batch at
### UTXO rules
```
server.register-input.max-inputs-same-hash: max inputs with same hash (same origin tx) allowed to register to a mix
server.register-input.max-inputs-same-user-hash: max inputs with same user-hash (same mixing client) allowed to register to a mix
```
### SCodes
......
......@@ -147,6 +147,7 @@ public class WhirlpoolServerConfig {
private int minConfirmationsMustMix;
private int minConfirmationsLiquidity;
private int maxInputsSameHash;
private int maxInputsSameUserHash;
private long liquidityInterval;
public int getMinConfirmationsMustMix() {
......@@ -173,6 +174,14 @@ public class WhirlpoolServerConfig {
this.maxInputsSameHash = maxInputsSameHash;
}
public int getMaxInputsSameUserHash() {
return maxInputsSameUserHash;
}
public void setMaxInputsSameUserHash(int maxInputsSameUserHash) {
this.maxInputsSameUserHash = maxInputsSameUserHash;
}
public long getLiquidityInterval() {
return liquidityInterval;
}
......@@ -597,6 +606,8 @@ public class WhirlpoolServerConfig {
configInfo.put(
"registerInput.maxInputsSameHash", String.valueOf(registerInput.maxInputsSameHash));
configInfo.put(
"registerInput.maxInputsSameUserHash", String.valueOf(registerInput.maxInputsSameUserHash));
configInfo.put(
"registerInput.minConfirmations",
"liquidity="
......
......@@ -126,13 +126,6 @@ public class MixService {
throw new QueueInputException("Current mix is full", registeredInput, pool.getPoolId());
}
// verify input not already confirmed
ConfirmedInput alreadyConfirmedInput = mix.findInput(registeredInput.getOutPoint());
if (alreadyConfirmedInput != null) {
// input already confirmed => reject duplicate client
throw new IllegalInputException("Input already confirmed");
}
if (registeredInput.isLiquidity()) {
// liquidity: verify liquidities open
if (!mix.isRegisterLiquiditiesOpen()) {
......@@ -149,14 +142,21 @@ public class MixService {
}
// verify unique userHash
Optional<ConfirmedInput> inputSameUserHash =
int maxInputsSameUserHash = whirlpoolServerConfig.getRegisterInput().getMaxInputsSameUserHash();
long countInputSameUserHash =
mix.getInputs()
.parallelStream()
.filter(input -> input.getUserHash().equals(confirmedInput.getUserHash()))
.findFirst();
if (inputSameUserHash.isPresent()) {
.count();
if ((countInputSameUserHash + 1) > maxInputsSameUserHash) {
if (log.isDebugEnabled()) {
log.debug("userHash is already mixing in " + mix.getMixId() + ": " + inputSameUserHash);
log.debug(
"already "
+ countInputSameUserHash
+ " inputs with same userHash in "
+ mix.getMixId()
+ ": "
+ confirmedInput.getUserHash());
}
throw new QueueInputException(
"Your wallet already registered for this mix", registeredInput, pool.getPoolId());
......@@ -184,6 +184,13 @@ public class MixService {
throw new QueueInputException(
"Current mix is full for inputs with same address", registeredInput, pool.getPoolId());
}
// verify input not already confirmed
ConfirmedInput alreadyConfirmedInput = mix.findInput(registeredInput.getOutPoint());
if (alreadyConfirmedInput != null) {
// input already confirmed => reject duplicate client
throw new IllegalInputException("Input already confirmed");
}
}
public synchronized byte[] confirmInput(
......@@ -397,7 +404,8 @@ public class MixService {
// there were input spent
for (ConfirmedInput spentInput : spentInputs) {
log.warn("Removing confirmed input spent in meantime", spentInput);
log.warn(
"Found " + spentInputs.size() + " confirmed input(s) spent in meantime!", spentInput);
// remove spent input
mix.unregisterInput(spentInput);
......
......@@ -98,7 +98,7 @@ public class JSONRpcClientServiceImpl implements RpcClientService {
public boolean isTxOutUnspent(String txid, long index) {
try {
// getTxOut only returns unspent outputs
BitcoindRpcClient.TxOut txOut = rpcClient.getTxOut(txid, index);
BitcoindRpcClient.TxOut txOut = rpcClient.getTxOut(txid, index, true);
if (txOut != null) {
return true;
}
......
......@@ -27,6 +27,7 @@ server.rpc-client.mock-tx-broadcast = false
server.register-input.min-confirmations-must-mix = 0
server.register-input.min-confirmations-liquidity = 0
server.register-input.max-inputs-same-hash = 1
server.register-input.max-inputs-same-user-hash = 1
server.register-input.liquidity-interval = 10
server.register-output.timeout = 120
......
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