Skip to content

Commit

Permalink
Merge pull request #186 from Elenpay/changed-output-size-calc
Browse files Browse the repository at this point in the history
Changed output virtual size calculation
  • Loading branch information
Jossec101 authored May 31, 2023
2 parents 8b3a83b + ce83d2f commit 2d337c5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Services/LightningService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 2d337c5

Please sign in to comment.