From ce83d2f04f579e152ebeaa9cdb60a9543170c792 Mon Sep 17 00:00:00 2001 From: Rodrigo Sanchez Date: Wed, 31 May 2023 17:52:37 +0200 Subject: [PATCH] Changed output virtual size calculation --- src/Services/LightningService.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Services/LightningService.cs b/src/Services/LightningService.cs index ff697a21..8619dd7b 100644 --- a/src/Services/LightningService.cs +++ b/src/Services/LightningService.cs @@ -192,10 +192,11 @@ public async Task OpenChannel(ChannelOperationRequest channelOperationRequest) try { - var virtualSize=combinedPSBT.GetGlobalTransaction().GetVirtualSize()+22; //22 bytes for the 1 segwit output + // 8 value + 1 script pub key size + 34 script pub key hash (Segwit output 2-0f-2 multisig) + var outputVirtualSize = combinedPSBT.GetGlobalTransaction().GetVirtualSize() + 43; var feeRateResult = await LightningHelper.GetFeeRateResult(network, _nbXplorerService); - var totalFees = new Money(virtualSize * feeRateResult.FeeRate.SatoshiPerByte, MoneyUnit.Satoshi); + var totalFees = new Money(outputVirtualSize * feeRateResult.FeeRate.SatoshiPerByte, MoneyUnit.Satoshi); long fundingAmount = channelOperationRequest.Changeless ? channelOperationRequest.SatsAmount - totalFees : channelOperationRequest.SatsAmount; //We prepare the request (shim) with the base PSBT we had presigned with the UTXOs to fund the channel @@ -930,8 +931,8 @@ public void CancelPendingChannel(Node source, byte[] pendingChannelId, IUnmockab //Hack, see https://github.com/MetacoSA/NBitcoin/issues/1112 for details foreach (var input in result.Item1.Inputs) { - input.WitnessUtxo = originalPSBT.Inputs.FirstOrDefault(x=> x.PrevOut == input.PrevOut)?.WitnessUtxo; - input.NonWitnessUtxo = originalPSBT.Inputs.FirstOrDefault(x=> x.PrevOut == input.PrevOut)?.NonWitnessUtxo; + input.WitnessUtxo = originalPSBT.Inputs.FirstOrDefault(x => x.PrevOut == input.PrevOut)?.WitnessUtxo; + input.NonWitnessUtxo = originalPSBT.Inputs.FirstOrDefault(x => x.PrevOut == input.PrevOut)?.NonWitnessUtxo; input.SighashType = SigHash.None; }