Skip to content

[custom channels]: refactor channel JSON, add more custom data parsers #1441

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

Merged
merged 6 commits into from
Apr 1, 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
13 changes: 11 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:

GO_VERSION: '1.23.6'

LITD_ITEST_BRANCH: 'lnd-19'
LITD_ITEST_BRANCH: 'closedchannel-data'

jobs:
#######################
Expand Down Expand Up @@ -266,6 +266,9 @@ jobs:
name: run itests
runs-on: ubuntu-latest
steps:
- name: cleanup space
run: rm -rf /opt/hostedtoolcache

- name: git checkout
uses: actions/checkout@v4

Expand Down Expand Up @@ -306,6 +309,9 @@ jobs:
name: run itests postgres
runs-on: ubuntu-latest
steps:
- name: cleanup space
run: rm -rf /opt/hostedtoolcache

- name: git checkout
uses: actions/checkout@v4

Expand Down Expand Up @@ -347,6 +353,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: cleanup space
run: rm -rf /opt/hostedtoolcache

- name: git checkout
uses: actions/checkout@v4

Expand Down Expand Up @@ -391,7 +400,7 @@ jobs:
# Notify about the completion of all coverage collecting jobs.
finish:
if: ${{ always() }}
needs: [unit-test]
needs: [ unit-test ]
runs-on: ubuntu-latest
steps:
- uses: coverallsapp/github-action@v2
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/basic-price-oracle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ require (
github.com/lightninglabs/neutrino v0.16.1 // indirect
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect
github.com/lightningnetwork/lnd v0.19.0-beta.rc1 // indirect
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f // indirect
github.com/lightningnetwork/lnd/cert v1.2.2 // indirect
github.com/lightningnetwork/lnd/clock v1.1.1 // indirect
github.com/lightningnetwork/lnd/fn/v2 v2.0.8 // indirect
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/basic-price-oracle/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display h1:Y2WiPkBS
github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
github.com/lightningnetwork/lnd v0.19.0-beta.rc1 h1:FJvsdw4PZ41ykrHi7vNGit9IIohE+IlKpVwL5/1+L+0=
github.com/lightningnetwork/lnd v0.19.0-beta.rc1/go.mod h1:BP+neeFpmeAA7o5hu3zp3FwOEl26idSyPV9zBOavp6E=
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f h1:+Bejv2Ij/ryUjLacBd5au0acMH0AYs0lhb7ki5rx9ms=
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f/go.mod h1:BP+neeFpmeAA7o5hu3zp3FwOEl26idSyPV9zBOavp6E=
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2
github.com/lightninglabs/lndclient v0.19.0-3
github.com/lightninglabs/neutrino/cache v1.1.2
github.com/lightningnetwork/lnd v0.19.0-beta.rc1
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f
github.com/lightningnetwork/lnd/cert v1.2.2
github.com/lightningnetwork/lnd/clock v1.1.1
github.com/lightningnetwork/lnd/fn/v2 v2.0.8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display h1:Y2WiPkBS
github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
github.com/lightningnetwork/lnd v0.19.0-beta.rc1 h1:FJvsdw4PZ41ykrHi7vNGit9IIohE+IlKpVwL5/1+L+0=
github.com/lightningnetwork/lnd v0.19.0-beta.rc1/go.mod h1:BP+neeFpmeAA7o5hu3zp3FwOEl26idSyPV9zBOavp6E=
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f h1:+Bejv2Ij/ryUjLacBd5au0acMH0AYs0lhb7ki5rx9ms=
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f/go.mod h1:BP+neeFpmeAA7o5hu3zp3FwOEl26idSyPV9zBOavp6E=
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=
Expand Down
13 changes: 6 additions & 7 deletions rfq/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ func (m *Manager) addScidAlias(scidAlias uint64, assetSpecifier asset.Specifier,
}

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

for _, chanAsset := range jsonAssets {
gen := chanAsset.AssetInfo.AssetGenesis
assetIDBytes, err := hex.DecodeString(
gen.AssetID,
)
fundingAssets := jsonChannel.FundingAssets
for _, chanAsset := range fundingAssets {
gen := chanAsset.AssetGenesis
assetIDBytes, err := hex.DecodeString(gen.AssetID)
if err != nil {
return false, fmt.Errorf("error decoding asset ID: %w",
err)
Expand Down
30 changes: 15 additions & 15 deletions rfqmsg/custom_channel_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ type JsonAssetUtxo struct {
DecimalDisplay uint8 `json:"decimal_display"`
}

// JsonAssetChanInfo is a struct that represents the channel information of a
// single asset within a channel.
type JsonAssetChanInfo struct {
AssetInfo JsonAssetUtxo `json:"asset_utxo"`
Capacity uint64 `json:"capacity"`
LocalBalance uint64 `json:"local_balance"`
RemoteBalance uint64 `json:"remote_balance"`
}

// JsonAssetChannel is a struct that represents the channel information of all
// assets within a channel.
type JsonAssetChannel struct {
Assets []JsonAssetChanInfo `json:"assets"`
FundingAssets []JsonAssetUtxo `json:"funding_assets"`
LocalAssets []JsonAssetTranche `json:"local_assets"`
RemoteAssets []JsonAssetTranche `json:"remote_assets"`
OutgoingHtlcs []JsonAssetTranche `json:"outgoing_htlcs"`
IncomingHtlcs []JsonAssetTranche `json:"incoming_htlcs"`
Capacity uint64 `json:"capacity"`
LocalBalance uint64 `json:"local_balance"`
RemoteBalance uint64 `json:"remote_balance"`
OutgoingHtlcBalance uint64 `json:"outgoing_htlc_balance"`
IncomingHtlcBalance uint64 `json:"incoming_htlc_balance"`
}

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

// JsonHtlcBalance is a struct that represents the balance of a single asset
// HTLC.
type JsonHtlcBalance struct {
// JsonAssetTranche is a struct that represents the balance of a single asset
// tranche.
type JsonAssetTranche struct {
AssetID string `json:"asset_id"`
Amount uint64 `json:"amount"`
}

// JsonHtlc is a struct that represents the asset information that can be
// transferred via an HTLC.
type JsonHtlc struct {
Balances []*JsonHtlcBalance `json:"balances"`
RfqID string `json:"rfq_id"`
Balances []*JsonAssetTranche `json:"balances"`
RfqID string `json:"rfq_id"`
}
4 changes: 2 additions & 2 deletions rfqmsg/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ func (h *Htlc) ToCustomRecords() (lnwire.CustomRecords, error) {
// AsJson returns the Htlc record as a JSON blob.
func (h *Htlc) AsJson() ([]byte, error) {
j := &JsonHtlc{
Balances: make([]*JsonHtlcBalance, len(h.Balances())),
Balances: make([]*JsonAssetTranche, len(h.Balances())),
}

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

for idx, balance := range h.Balances() {
j.Balances[idx] = &JsonHtlcBalance{
j.Balances[idx] = &JsonAssetTranche{
AssetID: hex.EncodeToString(balance.AssetID.Val[:]),
Amount: balance.Amount.Val,
}
Expand Down
18 changes: 3 additions & 15 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8036,7 +8036,7 @@ type channelWithSpecifier struct {
channelInfo lndclient.ChannelInfo

// assetInfo contains the asset related info of the channel.
assetInfo rfqmsg.JsonAssetChanInfo
assetInfo rfqmsg.JsonAssetChannel
}

// computeChannelAssetBalance computes the total local and remote balance for
Expand Down Expand Up @@ -8066,29 +8066,17 @@ func (r *rpcServer) computeChannelAssetBalance(ctx context.Context,
// Check if the assets of this channel match the provided
// specifier.
pass, err := r.cfg.RfqManager.ChannelCompatible(
ctx, assetData.Assets, specifier,
ctx, assetData, specifier,
)
if err != nil {
return nil, err
}

if pass {
// Since the assets of the channel passed the above
// filter, we're safe to aggregate their info to be
// represented as a single entity.
var aggrInfo rfqmsg.JsonAssetChanInfo

// TODO(george): refactor when JSON gets fixed
for _, info := range assetData.Assets {
aggrInfo.Capacity += info.Capacity
aggrInfo.LocalBalance += info.LocalBalance
aggrInfo.RemoteBalance += info.RemoteBalance
}

channels = append(channels, channelWithSpecifier{
specifier: specifier,
channelInfo: openChan,
assetInfo: aggrInfo,
assetInfo: assetData,
})
}
}
Expand Down
Loading
Loading