From 9c48116a8173276307a20036978bc1c247b1660f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20A=2EP?= <53834183+Jossec101@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:11:48 +0100 Subject: [PATCH] Fix creating dust utxos and 100K utxos, now we require a min amount to be swept out of the LND hot wallet, this shall ensure that there's more than a 100K utxo in the wallet --- src/Jobs/SweepNodeWalletsJob.cs | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Jobs/SweepNodeWalletsJob.cs b/src/Jobs/SweepNodeWalletsJob.cs index 19d5f818..ca5a72d9 100644 --- a/src/Jobs/SweepNodeWalletsJob.cs +++ b/src/Jobs/SweepNodeWalletsJob.cs @@ -44,7 +44,7 @@ public SweepNodeWalletsJob(ILogger logger, INBXplorerService nbXplorerService, ILightningClientService lightningClientService) { - + _logger = logger; _nodeRepository = nodeRepository; _walletRepository = walletRepository; @@ -66,7 +66,7 @@ public async Task Execute(IJobExecutionContext context) #region Local functions async Task SweepFunds(Node node, Wallet wallet, Lightning.LightningClient lightningClient - ,List utxos) + , List utxos) { if (node == null) throw new ArgumentNullException(nameof(node)); if (wallet == null) throw new ArgumentNullException(nameof(wallet)); @@ -81,9 +81,9 @@ async Task SweepFunds(Node node, Wallet wallet, Lightning.LightningClient lightn if (node.ChannelAdminMacaroon != null) { var lndChangeAddress = await lightningClient.NewAddressAsync(new NewAddressRequest - { - Type = AddressType.UnusedWitnessPubkeyHash - }, + { + Type = AddressType.UnusedWitnessPubkeyHash + }, new Metadata { { @@ -92,21 +92,21 @@ async Task SweepFunds(Node node, Wallet wallet, Lightning.LightningClient lightn }); var totalSatsAvailable = utxos.Sum(x => x.AmountSat); - if (returningAddress != null && lndChangeAddress != null && utxos.Any() && totalSatsAvailable > requiredAnchorChannelClosingAmount) + if (returningAddress != null && lndChangeAddress != null && utxos.Any() && totalSatsAvailable > Constants.MINIMUM_SWEEP_TRANSACTION_AMOUNT_SATS) { - var sweepedFundsAmount = (long)((totalSatsAvailable - requiredAnchorChannelClosingAmount) * 0.9); // We should let requiredAnchorChannelClosingAmount sats as a UTXO in in the hot wallet for channel closings + // We need to maintain onchain balance to be at least RequiredAnchorChannelClosingAmount but also we apply a 10% buffer to pay for this sweep fees and let some more money on the wallet + var sweepedFundsAmount = (long)((totalSatsAvailable - requiredAnchorChannelClosingAmount) * 0.9); var sendManyResponse = await lightningClient.SendManyAsync(new SendManyRequest() - { - AddrToAmount = + { + AddrToAmount = { {returningAddress.Address.ToString(), sweepedFundsAmount}, //Sweeped funds - {lndChangeAddress.Address, requiredAnchorChannelClosingAmount}, }, - MinConfs = 1, - Label = $"Hot wallet Sweep tx on {DateTime.UtcNow.ToString("O")} to walletId:{wallet.Id}", - SpendUnconfirmed = false, - TargetConf = 1 // 1 for now TODO Maybe this can be set as a global env var for all the Target blocks of the FM.. - }, + MinConfs = 6, + Label = $"Hot wallet Sweep tx on {DateTime.UtcNow.ToString("O")} to walletId:{wallet.Id}", + SpendUnconfirmed = false, + TargetConf = Constants.SWEEP_CONF_TARGET + }, new Metadata { { @@ -157,9 +157,9 @@ async Task SweepFunds(Node node, Wallet wallet, Lightning.LightningClient lightn try { - + var client = _lightningClientService.GetLightningClient(node.Endpoint); - + var unspentResponse = await client.ListUnspentAsync(new ListUnspentRequest { MinConfs = 1, MaxConfs = Int32.MaxValue }, new Metadata { {