Skip to content

Commit

Permalink
fix: LDK mark channel as inactive and show error if counterparty forw…
Browse files Browse the repository at this point in the history
…arding info missing (#267)

fix: mark channel as inactive and show error if counterparty forwarding info missing
  • Loading branch information
rolznz authored Jul 13, 2024
1 parent 350c5ea commit 7a3a8a2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
18 changes: 11 additions & 7 deletions frontend/src/screens/channels/Channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,17 @@ export default function Channels() {
channel.localBalance + channel.remoteBalance;

let channelWarning = "";
if (channel.localSpendableBalance < capacity * 0.1) {
channelWarning =
"Spending balance low. You may have trouble sending payments through this channel.";
}
if (channel.localSpendableBalance > capacity * 0.9) {
channelWarning =
"Receiving capacity low. You may have trouble receiving payments through this channel.";
if (channel.error) {
channelWarning = channel.error;
} else {
if (channel.localSpendableBalance < capacity * 0.1) {
channelWarning =
"Spending balance low. You may have trouble sending payments through this channel.";
}
if (channel.localSpendableBalance > capacity * 0.9) {
channelWarning =
"Receiving capacity low. You may have trouble receiving payments through this channel.";
}
}

return (
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export type Channel = {
forwardingFeeBaseMsat: number;
unspendablePunishmentReserve: number;
counterpartyUnspendablePunishmentReserve: number;
error?: string;
};

export type UpdateChannelRequest = {
Expand Down
13 changes: 12 additions & 1 deletion lnclient/ldk/ldk.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,21 +833,32 @@ func (ls *LDKService) ListChannels(ctx context.Context) ([]lnclient.Channel, err
unspendablePunishmentReserve = *ldkChannel.UnspendablePunishmentReserve
}

var channelError *string

if ldkChannel.CounterpartyForwardingInfoFeeBaseMsat == nil {
// if we don't have this, routing will not work (LND <-> LDK interoperability bug - https://github.com/lightningnetwork/lnd/issues/6870 )
channelErrorValue := "Counterparty forwarding info not available. Please contact [email protected]"
channelError = &channelErrorValue
}

isActive := ldkChannel.IsUsable /* superset of ldkChannel.IsReady */ && channelError == nil

channels = append(channels, lnclient.Channel{
InternalChannel: internalChannel,
LocalBalance: int64(ldkChannel.ChannelValueSats*1000 - ldkChannel.InboundCapacityMsat - ldkChannel.CounterpartyUnspendablePunishmentReserve*1000),
LocalSpendableBalance: int64(ldkChannel.OutboundCapacityMsat),
RemoteBalance: int64(ldkChannel.InboundCapacityMsat),
RemotePubkey: ldkChannel.CounterpartyNodeId,
Id: ldkChannel.UserChannelId, // CloseChannel takes the UserChannelId
Active: ldkChannel.IsUsable, // superset of ldkChannel.IsReady
Active: isActive,
Public: ldkChannel.IsPublic,
FundingTxId: fundingTxId,
Confirmations: ldkChannel.Confirmations,
ConfirmationsRequired: ldkChannel.ConfirmationsRequired,
ForwardingFeeBaseMsat: ldkChannel.Config.ForwardingFeeBaseMsat(),
UnspendablePunishmentReserve: unspendablePunishmentReserve,
CounterpartyUnspendablePunishmentReserve: ldkChannel.CounterpartyUnspendablePunishmentReserve,
Error: channelError,
})
}

Expand Down
1 change: 1 addition & 0 deletions lnclient/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type Channel struct {
ForwardingFeeBaseMsat uint32 `json:"forwardingFeeBaseMsat"`
UnspendablePunishmentReserve uint64 `json:"unspendablePunishmentReserve"`
CounterpartyUnspendablePunishmentReserve uint64 `json:"counterpartyUnspendablePunishmentReserve"`
Error *string `json:"error"`
}

type NodeStatus struct {
Expand Down

0 comments on commit 7a3a8a2

Please sign in to comment.