Skip to content

Commit b25a80b

Browse files
committed
lightning+router: add custom channel data fields
1 parent 12371de commit b25a80b

File tree

2 files changed

+65
-27
lines changed

2 files changed

+65
-27
lines changed

lightning_client.go

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ type ChannelInfo struct {
424424
// AliasScids contains a list of alias short channel identifiers that
425425
// may be used for this channel. This array can be empty.
426426
AliasScids []uint64
427+
428+
// CustomChannelData is an optional field that can be used to store
429+
// data for custom channels.
430+
CustomChannelData []byte
427431
}
428432

429433
func (s *lightningClient) newChannelInfo(channel *lnrpc.Channel) (*ChannelInfo,
@@ -465,8 +469,9 @@ func (s *lightningClient) newChannelInfo(channel *lnrpc.Channel) (*ChannelInfo,
465469
RemoteConstraints: newChannelConstraint(
466470
channel.RemoteConstraints,
467471
),
468-
ZeroConf: channel.ZeroConf,
469-
ZeroConfScid: channel.ZeroConfConfirmedScid,
472+
ZeroConf: channel.ZeroConf,
473+
ZeroConfScid: channel.ZeroConfConfirmedScid,
474+
CustomChannelData: channel.CustomChannelData,
470475
}
471476

472477
chanInfo.AliasScids = make([]uint64, len(channel.AliasScids))
@@ -834,6 +839,10 @@ type ChannelBalance struct {
834839

835840
// PendingBalance is the sum of all pending channel balances.
836841
PendingBalance btcutil.Amount
842+
843+
// CustomChannelData is an optional field that can be used to store
844+
// data for custom channels.
845+
CustomChannelData []byte
837846
}
838847

839848
// Node describes a node in the network.
@@ -1679,6 +1688,10 @@ type InvoiceHtlc struct {
16791688

16801689
// CustomRecords is list of the custom tlv records.
16811690
CustomRecords map[uint64][]byte
1691+
1692+
// CustomChannelData is an optional field that can be used to store
1693+
// data for custom channels.
1694+
CustomChannelData []byte
16821695
}
16831696

16841697
// PendingHtlc represents a HTLC that is currently pending on some channel.
@@ -1777,10 +1790,13 @@ func unmarshalInvoice(resp *lnrpc.Invoice) (*Invoice, error) {
17771790

17781791
for i, htlc := range resp.Htlcs {
17791792
invoiceHtlc := InvoiceHtlc{
1780-
ChannelID: lnwire.NewShortChanIDFromInt(htlc.ChanId),
1781-
Amount: lnwire.MilliSatoshi(htlc.AmtMsat),
1782-
CustomRecords: htlc.CustomRecords,
1783-
State: htlc.State,
1793+
ChannelID: lnwire.NewShortChanIDFromInt(
1794+
htlc.ChanId,
1795+
),
1796+
Amount: lnwire.MilliSatoshi(htlc.AmtMsat),
1797+
CustomRecords: htlc.CustomRecords,
1798+
State: htlc.State,
1799+
CustomChannelData: htlc.CustomChannelData,
17841800
}
17851801

17861802
if htlc.AcceptTime != 0 {
@@ -1971,6 +1987,10 @@ type PendingChannel struct {
19711987

19721988
// ChannelInitiator indicates which party opened the channel.
19731989
ChannelInitiator Initiator
1990+
1991+
// CustomChannelData is an optional field that can be used to store
1992+
// data for custom channels.
1993+
CustomChannelData []byte
19741994
}
19751995

19761996
// NewPendingChannel creates a pending channel from the rpc struct.
@@ -1993,12 +2013,13 @@ func NewPendingChannel(channel *lnrpc.PendingChannelsResponse_PendingChannel) (
19932013
}
19942014

19952015
return &PendingChannel{
1996-
ChannelPoint: outpoint,
1997-
PubKeyBytes: peer,
1998-
Capacity: btcutil.Amount(channel.Capacity),
1999-
LocalBalance: btcutil.Amount(channel.LocalBalance),
2000-
RemoteBalance: btcutil.Amount(channel.RemoteBalance),
2001-
ChannelInitiator: initiator,
2016+
ChannelPoint: outpoint,
2017+
PubKeyBytes: peer,
2018+
Capacity: btcutil.Amount(channel.Capacity),
2019+
LocalBalance: btcutil.Amount(channel.LocalBalance),
2020+
RemoteBalance: btcutil.Amount(channel.RemoteBalance),
2021+
ChannelInitiator: initiator,
2022+
CustomChannelData: channel.CustomChannelData,
20022023
}, nil
20032024
}
20042025

@@ -2473,6 +2494,10 @@ type Payment struct {
24732494

24742495
// SequenceNumber is a unique id for each payment.
24752496
SequenceNumber uint64
2497+
2498+
// FirstHopCustomRecords holds the custom TLV records that were sent to
2499+
// the first hop as part of the wire message.
2500+
FirstHopCustomRecords map[uint64][]byte
24762501
}
24772502

24782503
// ListPaymentsRequest contains the request parameters for a paginated
@@ -2540,9 +2565,14 @@ func (s *lightningClient) ListPayments(ctx context.Context,
25402565
PaymentRequest: payment.PaymentRequest,
25412566
Status: status,
25422567
Htlcs: payment.Htlcs,
2543-
Amount: lnwire.MilliSatoshi(payment.ValueMsat),
2544-
Fee: lnwire.MilliSatoshi(payment.FeeMsat),
2545-
SequenceNumber: payment.PaymentIndex,
2568+
Amount: lnwire.MilliSatoshi(
2569+
payment.ValueMsat,
2570+
),
2571+
Fee: lnwire.MilliSatoshi(
2572+
payment.FeeMsat,
2573+
),
2574+
SequenceNumber: payment.PaymentIndex,
2575+
FirstHopCustomRecords: payment.FirstHopCustomRecords,
25462576
}
25472577

25482578
// Add our preimage if it is known.
@@ -3454,8 +3484,11 @@ func (s *lightningClient) ChannelBalance(ctx context.Context) (*ChannelBalance,
34543484
}
34553485

34563486
return &ChannelBalance{
3457-
Balance: btcutil.Amount(resp.Balance), // nolint:staticcheck
3458-
PendingBalance: btcutil.Amount(resp.PendingOpenBalance), // nolint:staticcheck
3487+
//nolint:staticcheck
3488+
Balance: btcutil.Amount(resp.Balance),
3489+
//nolint:staticcheck
3490+
PendingBalance: btcutil.Amount(resp.PendingOpenBalance),
3491+
CustomChannelData: resp.CustomChannelData,
34593492
}, nil
34603493
}
34613494

router_client.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ type SendPaymentRequest struct {
305305
// as in-flight attempts can still settle afterward. Canceling will only
306306
// prevent further attempts from being sent.
307307
Cancelable bool
308+
309+
// FirstHopCustomRecords holds the custom TLV records should be sent to
310+
// the first hop as part of the wire message.
311+
FirstHopCustomRecords map[uint64][]byte
308312
}
309313

310314
// InterceptedHtlc contains information about a htlc that was intercepted in
@@ -415,16 +419,17 @@ func (r *routerClient) SendPayment(ctx context.Context,
415419

416420
rpcCtx := r.routerKitMac.WithMacaroonAuth(ctx)
417421
rpcReq := &routerrpc.SendPaymentRequest{
418-
FeeLimitSat: int64(request.MaxFee),
419-
FeeLimitMsat: int64(request.MaxFeeMsat),
420-
PaymentRequest: request.Invoice,
421-
TimeoutSeconds: int32(request.Timeout.Seconds()),
422-
MaxParts: request.MaxParts,
423-
OutgoingChanIds: request.OutgoingChanIds,
424-
AllowSelfPayment: request.AllowSelfPayment,
425-
Amp: request.AMP,
426-
TimePref: request.TimePref,
427-
Cancelable: request.Cancelable,
422+
FeeLimitSat: int64(request.MaxFee),
423+
FeeLimitMsat: int64(request.MaxFeeMsat),
424+
PaymentRequest: request.Invoice,
425+
TimeoutSeconds: int32(request.Timeout.Seconds()),
426+
MaxParts: request.MaxParts,
427+
OutgoingChanIds: request.OutgoingChanIds,
428+
AllowSelfPayment: request.AllowSelfPayment,
429+
Amp: request.AMP,
430+
TimePref: request.TimePref,
431+
Cancelable: request.Cancelable,
432+
FirstHopCustomRecords: request.FirstHopCustomRecords,
428433
}
429434
if request.MaxCltv != nil {
430435
rpcReq.CltvLimit = *request.MaxCltv

0 commit comments

Comments
 (0)