Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include funding transaction in pending closing channel message #941

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ func (api *api) ListChannels(ctx context.Context) ([]Channel, error) {
Id: channel.Id,
RemotePubkey: channel.RemotePubkey,
FundingTxId: channel.FundingTxId,
FundingTxVout: channel.FundingTxVout,
Active: channel.Active,
Public: channel.Public,
InternalChannel: channel.InternalChannel,
Expand Down
1 change: 1 addition & 0 deletions api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ type Channel struct {
Id string `json:"id"`
RemotePubkey string `json:"remotePubkey"`
FundingTxId string `json:"fundingTxId"`
FundingTxVout uint32 `json:"fundingTxVout"`
Active bool `json:"active"`
Public bool `json:"public"`
InternalChannel interface{} `json:"internalChannel"`
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/channels/ChannelDropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function ChannelDropdownMenu({
<DropdownMenuContent align="end">
<DropdownMenuItem className="flex flex-row items-center gap-2 cursor-pointer">
<ExternalLink
to={`https://mempool.space/tx/${channel.fundingTxId}`}
to={`https://mempool.space/tx/${channel.fundingTxId}#flow=&vout=${channel.fundingTxVout}`}
className="w-full flex flex-row items-center gap-2"
>
<ExternalLinkIcon className="w-4 h-4" />
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/screens/channels/Channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Bitcoin,
ChevronDown,
CopyIcon,
ExternalLinkIcon,
Heart,
Hotel,
HourglassIcon,
Expand Down Expand Up @@ -437,8 +438,16 @@ export default function Channels() {
>
{nodes.find((node) => node.public_key === details.nodeId)
?.alias || "Unknown"}
<ExternalLinkIcon className="ml-1 w-4 h-4 inline" />
</ExternalLink>{" "}
({new Intl.NumberFormat().format(details.amount)} sats)
({new Intl.NumberFormat().format(details.amount)} sats)&nbsp;
<ExternalLink
to={`https://mempool.space/tx/${details.fundingTxId}#flow=&vout=${details.fundingTxVout}`}
className="underline"
>
funding tx
<ExternalLinkIcon className="ml-1 w-4 h-4 inline" />
</ExternalLink>
{index < balances.onchain.pendingBalancesDetails.length - 1 &&
","}
</div>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export type Channel = {
remotePubkey: string;
id: string;
fundingTxId: string;
fundingTxVout: number;
active: boolean;
public: boolean;
confirmations?: number;
Expand Down Expand Up @@ -280,6 +281,8 @@ export type OnchainBalanceResponse = {
channelId: string;
nodeId: string;
amount: number;
fundingTxId: string;
fundingTxVout: number;
}[];
};

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/breez/breez-sdk-go v0.5.2
github.com/elnosh/gonuts v0.2.0
github.com/getAlby/glalby-go v0.0.0-20240621192717-95673c864d59
github.com/getAlby/ldk-node-go v0.0.0-20241223133853-4831e0855720
github.com/getAlby/ldk-node-go v0.0.0-20250106052504-d4191410486f
github.com/go-gormigrate/gormigrate/v2 v2.1.3
github.com/labstack/echo/v4 v4.12.0
github.com/nbd-wtf/go-nostr v0.42.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwV
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/getAlby/glalby-go v0.0.0-20240621192717-95673c864d59 h1:fSqdXE9uKhLcOOQaLtzN+D8RN3oEcZQkGX5E8PyiKy0=
github.com/getAlby/glalby-go v0.0.0-20240621192717-95673c864d59/go.mod h1:ViyJvjlvv0GCesTJ7mb3fBo4G+/qsujDAFN90xZ7a9U=
github.com/getAlby/ldk-node-go v0.0.0-20241223133853-4831e0855720 h1:LvoNtQgJf7rmRIkr9Yo8aFI3OtKvBIPV4cMNTUtJS2g=
github.com/getAlby/ldk-node-go v0.0.0-20241223133853-4831e0855720/go.mod h1:8BRjtKcz8E0RyYTPEbMS8VIdgredcGSLne8vHDtcRLg=
github.com/getAlby/ldk-node-go v0.0.0-20250106052504-d4191410486f h1:L9PHEhYgD4tO66KOoTPxYo/+unZC8zTTO5fS32jKG2E=
github.com/getAlby/ldk-node-go v0.0.0-20250106052504-d4191410486f/go.mod h1:8BRjtKcz8E0RyYTPEbMS8VIdgredcGSLne8vHDtcRLg=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk=
github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
Expand Down
25 changes: 15 additions & 10 deletions lnclient/ldk/ldk.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,10 @@ func (ls *LDKService) ListChannels(ctx context.Context) ([]lnclient.Channel, err

for _, ldkChannel := range ldkChannels {
fundingTxId := ""
fundingTxVout := uint32(0)
if ldkChannel.FundingTxo != nil {
fundingTxId = ldkChannel.FundingTxo.Txid
fundingTxVout = ldkChannel.FundingTxo.Vout
}

internalChannel := map[string]interface{}{}
Expand Down Expand Up @@ -829,6 +831,7 @@ func (ls *LDKService) ListChannels(ctx context.Context) ([]lnclient.Channel, err
Active: isActive,
Public: ldkChannel.IsAnnounced,
FundingTxId: fundingTxId,
FundingTxVout: fundingTxVout,
Confirmations: ldkChannel.Confirmations,
ConfirmationsRequired: ldkChannel.ConfirmationsRequired,
ForwardingFeeBaseMsat: ldkChannel.Config.ForwardingFeeBaseMsat,
Expand Down Expand Up @@ -1020,15 +1023,17 @@ func (ls *LDKService) GetOnchainBalance(ctx context.Context) (*lnclient.OnchainB
// increase pending balance from any lightning balances for channels that are pending closure
// (they do not exist in our list of open channels)
for _, balance := range balances.LightningBalances {
increasePendingBalance := func(nodeId, channelId string, amount uint64) {
increasePendingBalance := func(nodeId, channelId string, amount uint64, fundingTxId ldk_node.Txid, fundingTxIndex uint16) {
if !slices.ContainsFunc(channels, func(channel ldk_node.ChannelDetails) bool {
return channel.ChannelId == channelId
}) {
pendingBalancesFromChannelClosures += amount
pendingBalancesDetails = append(pendingBalancesDetails, lnclient.PendingBalanceDetails{
NodeId: nodeId,
ChannelId: channelId,
Amount: amount,
NodeId: nodeId,
ChannelId: channelId,
Amount: amount,
FundingTxId: fundingTxId,
FundingTxVout: uint32(fundingTxIndex),
})
}
}
Expand All @@ -1040,17 +1045,17 @@ func (ls *LDKService) GetOnchainBalance(ctx context.Context) (*lnclient.OnchainB
})
switch balanceType := (balance).(type) {
case ldk_node.LightningBalanceClaimableOnChannelClose:
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis)
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis, balanceType.FundingTxId, balanceType.FundingTxIndex)
case ldk_node.LightningBalanceClaimableAwaitingConfirmations:
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis)
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis, balanceType.FundingTxId, balanceType.FundingTxIndex)
case ldk_node.LightningBalanceContentiousClaimable:
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis)
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis, balanceType.FundingTxId, balanceType.FundingTxIndex)
case ldk_node.LightningBalanceMaybeTimeoutClaimableHtlc:
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis)
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis, balanceType.FundingTxId, balanceType.FundingTxIndex)
case ldk_node.LightningBalanceMaybePreimageClaimableHtlc:
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis)
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis, balanceType.FundingTxId, balanceType.FundingTxIndex)
case ldk_node.LightningBalanceCounterpartyRevokedOutputClaimable:
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis)
increasePendingBalance(balanceType.CounterpartyNodeId, balanceType.ChannelId, balanceType.AmountSatoshis, balanceType.FundingTxId, balanceType.FundingTxIndex)
}
}

Expand Down
11 changes: 9 additions & 2 deletions lnclient/lnd/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func (svc *LNDService) ListChannels(ctx context.Context) ([]lnclient.Channel, er
Active: lndChannel.Active,
Public: !lndChannel.Private,
FundingTxId: channelPoint.GetFundingTxidStr(),
FundingTxVout: channelPoint.GetOutputIndex(),
Confirmations: &confirmations,
ConfirmationsRequired: &confirmationsRequired,
UnspendablePunishmentReserve: lndChannel.LocalConstraints.ChanReserveSat,
Expand Down Expand Up @@ -863,9 +864,15 @@ func (svc *LNDService) GetOnchainBalance(ctx context.Context) (*lnclient.Onchain
for _, closingChannel := range pendingChannels.WaitingCloseChannels {
pendingBalancesFromChannelClosures += uint64(closingChannel.LimboBalance)
if closingChannel.Channel != nil {
channelPoint, err := svc.parseChannelPoint(closingChannel.Channel.ChannelPoint)
if err != nil {
return nil, err
}
pendingBalancesDetails = append(pendingBalancesDetails, lnclient.PendingBalanceDetails{
NodeId: closingChannel.Channel.RemoteNodePub,
Amount: uint64(closingChannel.LimboBalance),
NodeId: closingChannel.Channel.RemoteNodePub,
Amount: uint64(closingChannel.LimboBalance),
FundingTxId: channelPoint.GetFundingTxidStr(),
FundingTxVout: channelPoint.GetOutputIndex(),
})
}
}
Expand Down
9 changes: 6 additions & 3 deletions lnclient/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type Channel struct {
Id string
RemotePubkey string
FundingTxId string
FundingTxVout uint32
Active bool
Public bool
InternalChannel interface{}
Expand Down Expand Up @@ -135,9 +136,11 @@ type CloseChannelResponse struct {
}

type PendingBalanceDetails struct {
ChannelId string `json:"channelId"`
NodeId string `json:"nodeId"`
Amount uint64 `json:"amount"`
ChannelId string `json:"channelId"`
NodeId string `json:"nodeId"`
Amount uint64 `json:"amount"`
FundingTxId string `json:"fundingTxId"`
FundingTxVout uint32 `json:"fundingTxVout"`
}

type OnchainBalanceResponse struct {
Expand Down
Loading