Commit 0affae4c authored by zeroleak's avatar zeroleak
Browse files

last mustMix: verify enough miner-fees to pay the mix

parent 0c703530
......@@ -251,7 +251,7 @@ public class Mix {
return getInputs()
.parallelStream()
.filter(input -> !input.getRegisteredInput().isLiquidity())
.map(input -> input.getRegisteredInput().getOutPoint().getValue() - pool.getDenomination())
.map(input -> input.getRegisteredInput().computeMinerFees(pool))
.reduce(0L, Long::sum);
}
......
......@@ -18,6 +18,10 @@ public class RegisteredInput {
this.lastUserHash = lastUserHash;
}
public long computeMinerFees(Pool pool) {
return getOutPoint().getValue() - pool.getDenomination();
}
public String getUsername() {
return username;
}
......
......@@ -130,6 +130,37 @@ public class MixService {
throw new QueueInputException(
"Current mix is full for mustMix", registeredInput, pool.getPoolId());
}
// last mustMix: verify enough miner-fees to pay the mix
if (liquiditySlotsAvailable == pool.getMinLiquidity()) {
long inputMinerFees = registeredInput.computeMinerFees(pool);
long minerFeeAccumulated = mix.computeMinerFeeAccumulated();
long missingMinerFees =
whirlpoolServerConfig.getMinerFees().getMinerFeeMix()
- (minerFeeAccumulated + inputMinerFees);
if (missingMinerFees > 0) {
logMixStatus(mix);
log.warn(
"["
+ pool.getPoolId()
+ "] Queueing last mustMix: insufficient minerFees, "
+ missingMinerFees
+ " sats missing. "
+ registeredInput);
throw new QueueInputException(
"Not enough minerFee for last mustMix slot", registeredInput, pool.getPoolId());
} else {
if (log.isDebugEnabled()) {
log.debug(
"["
+ pool.getPoolId()
+ "] Accepting last mustMix: sufficient minerFees, "
+ (-1 * missingMinerFees)
+ " sats excess. "
+ registeredInput);
}
}
}
}
// verify unique userHash
......
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