Skip to content

Commit

Permalink
Improve receiver distribution to avoid that legacy BM gets outputs if…
Browse files Browse the repository at this point in the history
… some outputs fall below the min. amount limit.

Signed-off-by: HenrikJannsen <[email protected]>
  • Loading branch information
HenrikJannsen committed Nov 27, 2022
1 parent e757dbd commit 25f89e5
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,24 @@ public List<Tuple2<Long, String>> getReceivers(int burningManSelectionHeight,
// We only use outputs > 1000 sat or at least 2 times the cost for the output (32 bytes).
// If we remove outputs it will be spent as miner fee.
long minOutputAmount = Math.max(DPT_MIN_OUTPUT_AMOUNT, txFeePerVbyte * 32 * 2);
// We accumulate small amounts which gets filtered out and subtract it from 1 to get an adjustment factor
// used later to be applied to the remaining burningmen share.
double adjustment = 1 - burningManCandidates.stream()
.filter(candidate -> candidate.getMostRecentAddress().isPresent())
.mapToDouble(candidate -> {
double cappedBurnAmountShare = candidate.getCappedBurnAmountShare();
long amount = Math.round(cappedBurnAmountShare * spendableAmount);
return amount < minOutputAmount ? cappedBurnAmountShare : 0d;
})
.sum();

List<Tuple2<Long, String>> receivers = burningManCandidates.stream()
.filter(candidate -> candidate.getMostRecentAddress().isPresent())
.map(candidate -> new Tuple2<>(Math.round(candidate.getCappedBurnAmountShare() * spendableAmount),
candidate.getMostRecentAddress().get()))
.map(candidate -> {
double cappedBurnAmountShare = candidate.getCappedBurnAmountShare() / adjustment;
return new Tuple2<>(Math.round(cappedBurnAmountShare * spendableAmount),
candidate.getMostRecentAddress().get());
})
.filter(tuple -> tuple.first >= minOutputAmount)
.sorted(Comparator.<Tuple2<Long, String>, Long>comparing(tuple -> tuple.first)
.thenComparing(tuple -> tuple.second))
Expand Down

0 comments on commit 25f89e5

Please sign in to comment.