From 76a880a30ef8689f69f7189fd6a348c7dbbd5c58 Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Mon, 23 Dec 2024 18:04:07 +0900 Subject: [PATCH] Disable lightning payments histogram (#6518) --- BTCPayServer.Tests/GreenfieldAPITests.cs | 23 ++++----- .../Services/LightningHistogramService.cs | 49 ++----------------- 2 files changed, 15 insertions(+), 57 deletions(-) diff --git a/BTCPayServer.Tests/GreenfieldAPITests.cs b/BTCPayServer.Tests/GreenfieldAPITests.cs index dcdb05514..70e19d20b 100644 --- a/BTCPayServer.Tests/GreenfieldAPITests.cs +++ b/BTCPayServer.Tests/GreenfieldAPITests.cs @@ -3029,17 +3029,18 @@ namespace BTCPayServer.Tests var info = await client.GetLightningNodeInfo(user.StoreId, "BTC"); Assert.Single(info.NodeURIs); Assert.NotEqual(0, info.BlockHeight); - - // balance - await TestUtils.EventuallyAsync(async () => - { - var balance = await client.GetLightningNodeBalance(user.StoreId, "BTC"); - var histogram = await client.GetLightningNodeHistogram(user.StoreId, "BTC"); - var localBalance = balance.OffchainBalance.Local.ToDecimal(LightMoneyUnit.BTC); - Assert.Equal(histogram.Balance, histogram.Series.Last()); - Assert.Equal(localBalance, histogram.Balance); - Assert.Equal(localBalance, histogram.Series.Last()); - }); + + // Disable for now see #6518 + //// balance + //await TestUtils.EventuallyAsync(async () => + //{ + // var balance = await client.GetLightningNodeBalance(user.StoreId, "BTC"); + // var localBalance = balance.OffchainBalance.Local.ToDecimal(LightMoneyUnit.BTC); + // var histogram = await client.GetLightningNodeHistogram(user.StoreId, "BTC"); + // Assert.Equal(histogram.Balance, histogram.Series.Last()); + // Assert.Equal(localBalance, histogram.Balance); + // Assert.Equal(localBalance, histogram.Series.Last()); + //}); // As admin, can use the internal node through our store. await user.MakeAdmin(true); diff --git a/BTCPayServer/Services/LightningHistogramService.cs b/BTCPayServer/Services/LightningHistogramService.cs index 52b693553..3dec4822f 100644 --- a/BTCPayServer/Services/LightningHistogramService.cs +++ b/BTCPayServer/Services/LightningHistogramService.cs @@ -27,52 +27,9 @@ public class LightningHistogramService var ticks = (to - from).Ticks; var interval = TimeSpan.FromTicks(ticks / pointCount); - try - { - // general balance - var lnBalance = await lightningClient.GetBalance(cancellationToken); - var total = lnBalance.OffchainBalance.Local; - var totalBtc = total.ToDecimal(LightMoneyUnit.BTC); - // prepare transaction data - var lnInvoices = await lightningClient.ListInvoices(cancellationToken); - var lnPayments = await lightningClient.ListPayments(cancellationToken); - var lnTransactions = lnInvoices - .Where(inv => inv.Status == LightningInvoiceStatus.Paid && inv.PaidAt >= from) - .Select(inv => new LnTx { Amount = inv.Amount.ToDecimal(LightMoneyUnit.BTC), Settled = inv.PaidAt.GetValueOrDefault() }) - .Concat(lnPayments - .Where(pay => pay.Status == LightningPaymentStatus.Complete && pay.CreatedAt >= from) - .Select(pay => new LnTx { Amount = pay.Amount.ToDecimal(LightMoneyUnit.BTC) * -1, Settled = pay.CreatedAt.GetValueOrDefault() })) - .OrderByDescending(tx => tx.Settled) - .ToList(); - // assemble graph data going backwards - var series = new List(pointCount); - var labels = new List(pointCount); - var balance = totalBtc; - for (var i = pointCount; i > 0; i--) - { - var txs = lnTransactions.Where(t => - t.Settled.Ticks >= from.Ticks + interval.Ticks * i && - t.Settled.Ticks < from.Ticks + interval.Ticks * (i + 1)); - var sum = txs.Sum(tx => tx.Amount); - balance -= sum; - series.Add(balance); - labels.Add(from + interval * (i - 1)); - } - // reverse the lists - series.Reverse(); - labels.Reverse(); - return new HistogramData - { - Type = type, - Balance = totalBtc, - Series = series, - Labels = labels - }; - } - catch (Exception) - { - return null; - } + // TODO: We can't just list all invoices and payments, we need to filter them by date + // but the client doesn't support that yet so let's just disable this for now. See #6518 + return null; } private class LnTx