Skip to content

Commit a9ea76a

Browse files
authored
Merge pull request #1441 from lightninglabs/more-custom-channel-data
[custom channels]: refactor channel JSON, add more custom data parsers
2 parents 6bb7f1c + 9d8d52f commit a9ea76a

File tree

13 files changed

+597
-168
lines changed

13 files changed

+597
-168
lines changed

.github/workflows/main.yaml

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ env:
2121

2222
GO_VERSION: '1.23.6'
2323

24-
LITD_ITEST_BRANCH: 'lnd-19'
24+
LITD_ITEST_BRANCH: 'closedchannel-data'
2525

2626
jobs:
2727
#######################
@@ -266,6 +266,9 @@ jobs:
266266
name: run itests
267267
runs-on: ubuntu-latest
268268
steps:
269+
- name: cleanup space
270+
run: rm -rf /opt/hostedtoolcache
271+
269272
- name: git checkout
270273
uses: actions/checkout@v4
271274

@@ -306,6 +309,9 @@ jobs:
306309
name: run itests postgres
307310
runs-on: ubuntu-latest
308311
steps:
312+
- name: cleanup space
313+
run: rm -rf /opt/hostedtoolcache
314+
309315
- name: git checkout
310316
uses: actions/checkout@v4
311317

@@ -347,6 +353,9 @@ jobs:
347353
runs-on: ubuntu-latest
348354

349355
steps:
356+
- name: cleanup space
357+
run: rm -rf /opt/hostedtoolcache
358+
350359
- name: git checkout
351360
uses: actions/checkout@v4
352361

@@ -391,7 +400,7 @@ jobs:
391400
# Notify about the completion of all coverage collecting jobs.
392401
finish:
393402
if: ${{ always() }}
394-
needs: [unit-test]
403+
needs: [ unit-test ]
395404
runs-on: ubuntu-latest
396405
steps:
397406
- uses: coverallsapp/github-action@v2

docs/examples/basic-price-oracle/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ require (
9898
github.com/lightninglabs/neutrino v0.16.1 // indirect
9999
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
100100
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect
101-
github.com/lightningnetwork/lnd v0.19.0-beta.rc1 // indirect
101+
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f // indirect
102102
github.com/lightningnetwork/lnd/cert v1.2.2 // indirect
103103
github.com/lightningnetwork/lnd/clock v1.1.1 // indirect
104104
github.com/lightningnetwork/lnd/fn/v2 v2.0.8 // indirect

docs/examples/basic-price-oracle/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display h1:Y2WiPkBS
448448
github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
449449
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY=
450450
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
451-
github.com/lightningnetwork/lnd v0.19.0-beta.rc1 h1:FJvsdw4PZ41ykrHi7vNGit9IIohE+IlKpVwL5/1+L+0=
452-
github.com/lightningnetwork/lnd v0.19.0-beta.rc1/go.mod h1:BP+neeFpmeAA7o5hu3zp3FwOEl26idSyPV9zBOavp6E=
451+
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f h1:+Bejv2Ij/ryUjLacBd5au0acMH0AYs0lhb7ki5rx9ms=
452+
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f/go.mod h1:BP+neeFpmeAA7o5hu3zp3FwOEl26idSyPV9zBOavp6E=
453453
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
454454
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
455455
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2
3030
github.com/lightninglabs/lndclient v0.19.0-3
3131
github.com/lightninglabs/neutrino/cache v1.1.2
32-
github.com/lightningnetwork/lnd v0.19.0-beta.rc1
32+
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f
3333
github.com/lightningnetwork/lnd/cert v1.2.2
3434
github.com/lightningnetwork/lnd/clock v1.1.1
3535
github.com/lightningnetwork/lnd/fn/v2 v2.0.8

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,8 @@ github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display h1:Y2WiPkBS
502502
github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
503503
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY=
504504
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
505-
github.com/lightningnetwork/lnd v0.19.0-beta.rc1 h1:FJvsdw4PZ41ykrHi7vNGit9IIohE+IlKpVwL5/1+L+0=
506-
github.com/lightningnetwork/lnd v0.19.0-beta.rc1/go.mod h1:BP+neeFpmeAA7o5hu3zp3FwOEl26idSyPV9zBOavp6E=
505+
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f h1:+Bejv2Ij/ryUjLacBd5au0acMH0AYs0lhb7ki5rx9ms=
506+
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f/go.mod h1:BP+neeFpmeAA7o5hu3zp3FwOEl26idSyPV9zBOavp6E=
507507
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
508508
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
509509
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=

rfq/manager.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func (m *Manager) addScidAlias(scidAlias uint64, assetSpecifier asset.Specifier,
575575
}
576576

577577
match, err := m.ChannelCompatible(
578-
ctxb, assetData.Assets, assetSpecifier,
578+
ctxb, assetData, assetSpecifier,
579579
)
580580
if err != nil {
581581
return err
@@ -999,14 +999,13 @@ func (m *Manager) AssetMatchesSpecifier(ctx context.Context,
999999
// if the specifier is a group key, then all assets in the channel must belong
10001000
// to that group.
10011001
func (m *Manager) ChannelCompatible(ctx context.Context,
1002-
jsonAssets []rfqmsg.JsonAssetChanInfo, specifier asset.Specifier) (bool,
1002+
jsonChannel rfqmsg.JsonAssetChannel, specifier asset.Specifier) (bool,
10031003
error) {
10041004

1005-
for _, chanAsset := range jsonAssets {
1006-
gen := chanAsset.AssetInfo.AssetGenesis
1007-
assetIDBytes, err := hex.DecodeString(
1008-
gen.AssetID,
1009-
)
1005+
fundingAssets := jsonChannel.FundingAssets
1006+
for _, chanAsset := range fundingAssets {
1007+
gen := chanAsset.AssetGenesis
1008+
assetIDBytes, err := hex.DecodeString(gen.AssetID)
10101009
if err != nil {
10111010
return false, fmt.Errorf("error decoding asset ID: %w",
10121011
err)

rfqmsg/custom_channel_data.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ type JsonAssetUtxo struct {
2828
DecimalDisplay uint8 `json:"decimal_display"`
2929
}
3030

31-
// JsonAssetChanInfo is a struct that represents the channel information of a
32-
// single asset within a channel.
33-
type JsonAssetChanInfo struct {
34-
AssetInfo JsonAssetUtxo `json:"asset_utxo"`
35-
Capacity uint64 `json:"capacity"`
36-
LocalBalance uint64 `json:"local_balance"`
37-
RemoteBalance uint64 `json:"remote_balance"`
38-
}
39-
4031
// JsonAssetChannel is a struct that represents the channel information of all
4132
// assets within a channel.
4233
type JsonAssetChannel struct {
43-
Assets []JsonAssetChanInfo `json:"assets"`
34+
FundingAssets []JsonAssetUtxo `json:"funding_assets"`
35+
LocalAssets []JsonAssetTranche `json:"local_assets"`
36+
RemoteAssets []JsonAssetTranche `json:"remote_assets"`
37+
OutgoingHtlcs []JsonAssetTranche `json:"outgoing_htlcs"`
38+
IncomingHtlcs []JsonAssetTranche `json:"incoming_htlcs"`
39+
Capacity uint64 `json:"capacity"`
40+
LocalBalance uint64 `json:"local_balance"`
41+
RemoteBalance uint64 `json:"remote_balance"`
42+
OutgoingHtlcBalance uint64 `json:"outgoing_htlc_balance"`
43+
IncomingHtlcBalance uint64 `json:"incoming_htlc_balance"`
4444
}
4545

4646
// JsonAssetChannelBalances is a struct that represents the balance information
@@ -58,16 +58,16 @@ type JsonCloseOutput struct {
5858
ScriptKeys map[string]string `json:"script_keys"`
5959
}
6060

61-
// JsonHtlcBalance is a struct that represents the balance of a single asset
62-
// HTLC.
63-
type JsonHtlcBalance struct {
61+
// JsonAssetTranche is a struct that represents the balance of a single asset
62+
// tranche.
63+
type JsonAssetTranche struct {
6464
AssetID string `json:"asset_id"`
6565
Amount uint64 `json:"amount"`
6666
}
6767

6868
// JsonHtlc is a struct that represents the asset information that can be
6969
// transferred via an HTLC.
7070
type JsonHtlc struct {
71-
Balances []*JsonHtlcBalance `json:"balances"`
72-
RfqID string `json:"rfq_id"`
71+
Balances []*JsonAssetTranche `json:"balances"`
72+
RfqID string `json:"rfq_id"`
7373
}

rfqmsg/records.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ func (h *Htlc) ToCustomRecords() (lnwire.CustomRecords, error) {
177177
// AsJson returns the Htlc record as a JSON blob.
178178
func (h *Htlc) AsJson() ([]byte, error) {
179179
j := &JsonHtlc{
180-
Balances: make([]*JsonHtlcBalance, len(h.Balances())),
180+
Balances: make([]*JsonAssetTranche, len(h.Balances())),
181181
}
182182

183183
h.RfqID.ValOpt().WhenSome(func(id ID) {
184184
j.RfqID = hex.EncodeToString(id[:])
185185
})
186186

187187
for idx, balance := range h.Balances() {
188-
j.Balances[idx] = &JsonHtlcBalance{
188+
j.Balances[idx] = &JsonAssetTranche{
189189
AssetID: hex.EncodeToString(balance.AssetID.Val[:]),
190190
Amount: balance.Amount.Val,
191191
}

rpcserver.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -8036,7 +8036,7 @@ type channelWithSpecifier struct {
80368036
channelInfo lndclient.ChannelInfo
80378037

80388038
// assetInfo contains the asset related info of the channel.
8039-
assetInfo rfqmsg.JsonAssetChanInfo
8039+
assetInfo rfqmsg.JsonAssetChannel
80408040
}
80418041

80428042
// computeChannelAssetBalance computes the total local and remote balance for
@@ -8066,29 +8066,17 @@ func (r *rpcServer) computeChannelAssetBalance(ctx context.Context,
80668066
// Check if the assets of this channel match the provided
80678067
// specifier.
80688068
pass, err := r.cfg.RfqManager.ChannelCompatible(
8069-
ctx, assetData.Assets, specifier,
8069+
ctx, assetData, specifier,
80708070
)
80718071
if err != nil {
80728072
return nil, err
80738073
}
80748074

80758075
if pass {
8076-
// Since the assets of the channel passed the above
8077-
// filter, we're safe to aggregate their info to be
8078-
// represented as a single entity.
8079-
var aggrInfo rfqmsg.JsonAssetChanInfo
8080-
8081-
// TODO(george): refactor when JSON gets fixed
8082-
for _, info := range assetData.Assets {
8083-
aggrInfo.Capacity += info.Capacity
8084-
aggrInfo.LocalBalance += info.LocalBalance
8085-
aggrInfo.RemoteBalance += info.RemoteBalance
8086-
}
8087-
80888076
channels = append(channels, channelWithSpecifier{
80898077
specifier: specifier,
80908078
channelInfo: openChan,
8091-
assetInfo: aggrInfo,
8079+
assetInfo: assetData,
80928080
})
80938081
}
80948082
}

0 commit comments

Comments
 (0)