Skip to content

Commit

Permalink
fix(lightning): use min0ConfTxFee only for orders with 0 client balan…
Browse files Browse the repository at this point in the history
…ce (#1542)
  • Loading branch information
pwltr authored Feb 9, 2024
1 parent e86372f commit 52fbd29
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/screens/Lightning/CustomSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ const CustomSetup = ({
}

const getChannelOpenCost = async (): Promise<void> => {
if (amount === 0) {
return;
}
const res = await estimateOrderFee({
lspBalanceSat: amount,
channelExpiryWeeks: DEFAULT_CHANNEL_DURATION,
Expand Down
31 changes: 20 additions & 11 deletions src/store/utils/blocktank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { err, ok, Result } from '@synonymdev/result';

import { resetSendTransaction, updateSendTransaction } from '../actions/wallet';
import { setLightningSetupStep } from '../slices/user';
import { getBlocktankStore, getWalletStore, dispatch } from '../helpers';
import {
getBlocktankStore,
getWalletStore,
dispatch,
getFeesStore,
} from '../helpers';
import * as blocktank from '../../utils/blocktank';
import {
createOrder,
Expand Down Expand Up @@ -276,14 +281,20 @@ export const startChannelPurchase = async ({
}

const { onchainBalance } = getBalance({ selectedNetwork, selectedWallet });
const min0ConfTxFee = await getMin0ConfTxFee(orderData.value.id);
if (min0ConfTxFee.isErr()) {
return err(min0ConfTxFee.error.message);

// Get transaction fee
const fees = getFeesStore().onchain;
let satPerVByteFee = fees.fast;
if (remoteBalance === 0) {
// For orders with 0 client balance, we use the min 0-conf tx fee from BT to get a turbo channel.
const min0ConfTxFee = await getMin0ConfTxFee(orderData.value.id);
if (min0ConfTxFee.isErr()) {
return err(min0ConfTxFee.error.message);
}
satPerVByteFee = Math.ceil(min0ConfTxFee.value.satPerVByte); // might be float
}
const satPerVByteFee = Math.ceil(min0ConfTxFee.value.satPerVByte); // might be float
let txFeeInSats = getTotalFee({
satsPerByte: satPerVByteFee,
});

let txFeeInSats = getTotalFee({ satsPerByte: satPerVByteFee });
const buyChannelDataFeeSat = Math.ceil(buyChannelData.feeSat);
const buyChannelDataClientBalanceFeeSat = Math.ceil(
buyChannelData.clientBalanceSat,
Expand Down Expand Up @@ -316,9 +327,7 @@ export const startChannelPurchase = async ({
},
});

const feeRes = updateFee({
satsPerByte: satPerVByteFee,
});
const feeRes = updateFee({ satsPerByte: satPerVByteFee });
if (feeRes.isErr()) {
return err(feeRes.error.message);
}
Expand Down

0 comments on commit 52fbd29

Please sign in to comment.