From 809928a79020e942b2e74892e76cdb35a4661db5 Mon Sep 17 00:00:00 2001 From: Oliver Weichhold Date: Sat, 10 Mar 2018 12:46:03 +0100 Subject: [PATCH] WIP --- .../Blockchain/Monero/MoneroPayoutHandler.cs | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/MiningCore/Blockchain/Monero/MoneroPayoutHandler.cs b/src/MiningCore/Blockchain/Monero/MoneroPayoutHandler.cs index 0f3390111..7582eef3e 100644 --- a/src/MiningCore/Blockchain/Monero/MoneroPayoutHandler.cs +++ b/src/MiningCore/Blockchain/Monero/MoneroPayoutHandler.cs @@ -172,8 +172,48 @@ private async Task PayoutBatch(Balance[] balances) var transferSplitResponse = await walletDaemon.ExecuteCmdSingleAsync(MWC.TransferSplit, request); - HandleTransferResponse(transferSplitResponse, balances); - return; + if (transferResponse.Error == null) + { + HandleTransferResponse(transferSplitResponse, balances); + return; + } + } + + // retry paged - unfortunately this is necessary for cases like this: https://github.com/monero-project/monero/issues/3379 + logger.Info(() => $"[{LogCategory}] Retrying paged"); + + var validBalances = balances.Where(x => x.Amount > 0).ToArray(); + var pageSize = 10; + var pageCount = (int)Math.Ceiling((double)validBalances.Length / pageSize); + + for (var i = 0; i < pageCount; i++) + { + var page = validBalances + .Skip(i * pageSize) + .Take(pageSize) + .ToArray(); + + // update request + request.Destinations = page + .Where(x => x.Amount > 0) + .Select(x => + { + ExtractAddressAndPaymentId(x.Address, out var address, out var paymentId); + + return new TransferDestination + { + Address = address, + Amount = (ulong)Math.Floor(x.Amount * MoneroConstants.SmallestUnit[poolConfig.Coin.Type]) + }; + }).ToArray(); + + logger.Info(() => $"[{LogCategory}] Page {i + 1}: Paying out {FormatAmount(page.Sum(x => x.Amount))} to {page.Length} addresses"); + + transferResponse = await walletDaemon.ExecuteCmdSingleAsync(MWC.Transfer, request); + HandleTransferResponse(transferResponse, balances); + + if (transferResponse.Error != null) + return; } }