Skip to content

Commit 5c59312

Browse files
authored
Merge pull request #1056 from lightninglabs/group-key-support-balance-fixes
custom channels: add coop close balance assertions for grouped asset channels
2 parents c050f67 + ab3eb92 commit 5c59312

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ require (
2929
github.com/lightninglabs/pool v0.6.5-beta.0.20250305125211-4e860ec4e77f
3030
github.com/lightninglabs/pool/auctioneerrpc v1.1.3-0.20250305125211-4e860ec4e77f
3131
github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f
32-
github.com/lightninglabs/taproot-assets v0.5.2-0.20250506181734-e63f1a4f4597
33-
github.com/lightninglabs/taproot-assets/taprpc v1.0.1
32+
github.com/lightninglabs/taproot-assets v0.5.2-0.20250508000445-bb5a2a6f154a
33+
github.com/lightninglabs/taproot-assets/taprpc v1.0.2
3434
github.com/lightningnetwork/lnd v0.19.0-beta.rc3
3535
github.com/lightningnetwork/lnd/cert v1.2.2
3636
github.com/lightningnetwork/lnd/clock v1.1.1

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,10 @@ github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f h1:5p
506506
github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f/go.mod h1:lGs2hSVZ+GFpdv3btaIl9icG5/gz7BBRfvmD2iqqNl0=
507507
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display h1:w7FM5LH9Z6CpKxl13mS48idsu6F+cEZf0lkyiV+Dq9g=
508508
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
509-
github.com/lightninglabs/taproot-assets v0.5.2-0.20250506181734-e63f1a4f4597 h1:2gdwdH9HAPWnHk/1gnU7g1imofiw56KAEuLVBmMeoyQ=
510-
github.com/lightninglabs/taproot-assets v0.5.2-0.20250506181734-e63f1a4f4597/go.mod h1:OdeFcj2bnJf6aaYjBB5c8KdNI3aDaEMQpsSu2EqvMlw=
511-
github.com/lightninglabs/taproot-assets/taprpc v1.0.1 h1:aSlCWdJkagx9xa8DqK/pzHYCtY7PokU6wASse3dWayc=
512-
github.com/lightninglabs/taproot-assets/taprpc v1.0.1/go.mod h1:Ccq0t2GsXzOtC8qF0U1ux/yTF5HcBbVrhCb0tb/jObM=
509+
github.com/lightninglabs/taproot-assets v0.5.2-0.20250508000445-bb5a2a6f154a h1:Jd2ned2248idCMgHirLYOtgJQp54GSNMFfOPH8bVSj0=
510+
github.com/lightninglabs/taproot-assets v0.5.2-0.20250508000445-bb5a2a6f154a/go.mod h1:OdeFcj2bnJf6aaYjBB5c8KdNI3aDaEMQpsSu2EqvMlw=
511+
github.com/lightninglabs/taproot-assets/taprpc v1.0.2 h1:LcK62+X7UYGFEwUgGwnKXLdoTOsBPFc6FOYXm7jiFFU=
512+
github.com/lightninglabs/taproot-assets/taprpc v1.0.2/go.mod h1:Ccq0t2GsXzOtC8qF0U1ux/yTF5HcBbVrhCb0tb/jObM=
513513
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY=
514514
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
515515
github.com/lightningnetwork/lnd v0.19.0-beta.rc3 h1:XWMlyZvBrp69AnQqrshLOOPZjOl4hFWR1RD4ceCXt9k=

itest/assets_test.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,10 @@ func defaultCoOpCloseBalanceCheck(t *testing.T, local, remote *HarnessNode,
18441844
assetIDs [][]byte, groupKey []byte, universeTap *tapClient,
18451845
remoteBtcBalance, remoteAssetBalance bool) {
18461846

1847+
ctxb := context.Background()
1848+
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
1849+
defer cancel()
1850+
18471851
// With the channel closed, we'll now assert that the co-op close
18481852
// transaction was inserted into the local universe.
18491853
//
@@ -1941,10 +1945,34 @@ func defaultCoOpCloseBalanceCheck(t *testing.T, local, remote *HarnessNode,
19411945
closeTx.TxOut[localAssetIndex].PkScript,
19421946
)
19431947

1948+
// Because we don't exactly know what asset IDs made it into the close
1949+
// transaction, we need to fetch the closed channel to find that out.
1950+
closedChans, err := local.ClosedChannels(
1951+
ctxt, &lnrpc.ClosedChannelsRequest{
1952+
Cooperative: true,
1953+
},
1954+
)
1955+
require.NoError(t, err)
1956+
require.NotEmpty(t, closedChans.Channels)
1957+
1958+
var closedJsonChannel *rfqmsg.JsonAssetChannel
1959+
for _, closedChan := range closedChans.Channels {
1960+
if closedChan.ClosingTxHash == closeTx.TxHash().String() {
1961+
closedJsonChannel = &rfqmsg.JsonAssetChannel{}
1962+
err = json.Unmarshal(
1963+
closedChan.CustomChannelData, closedJsonChannel,
1964+
)
1965+
require.NoError(t, err)
1966+
1967+
break
1968+
}
1969+
}
1970+
require.NotNil(t, closedJsonChannel)
1971+
19441972
// We now verify the arrival of the local balance asset proof at the
19451973
// universe server.
19461974
var localAssetCloseOut rfqmsg.JsonCloseOutput
1947-
err := json.Unmarshal(
1975+
err = json.Unmarshal(
19481976
localCloseOut.CustomChannelData, &localAssetCloseOut,
19491977
)
19501978
require.NoError(t, err)
@@ -1956,6 +1984,19 @@ func defaultCoOpCloseBalanceCheck(t *testing.T, local, remote *HarnessNode,
19561984

19571985
require.Contains(t, assetIDStrings, assetIDStr)
19581986

1987+
// We only check for a proof if an asset of that asset ID was
1988+
// actually in the close output, which might not always be the
1989+
// case in grouped asset channels.
1990+
localAssetIDs := fn.NewSet[string](fn.Map(
1991+
func(t rfqmsg.JsonAssetTranche) string {
1992+
return t.AssetID
1993+
},
1994+
closedJsonChannel.LocalAssets,
1995+
)...)
1996+
if !localAssetIDs.Contains(assetIDStr) {
1997+
continue
1998+
}
1999+
19592000
assetID, err := hex.DecodeString(assetIDStr)
19602001
require.NoError(t, err)
19612002

@@ -1995,6 +2036,19 @@ func defaultCoOpCloseBalanceCheck(t *testing.T, local, remote *HarnessNode,
19952036

19962037
require.Contains(t, assetIDStrings, assetIDStr)
19972038

2039+
// We only check for a proof if an asset of that asset ID was
2040+
// actually in the close output, which might not always be the
2041+
// case in grouped asset channels.
2042+
remoteAssetIDs := fn.NewSet[string](fn.Map(
2043+
func(t rfqmsg.JsonAssetTranche) string {
2044+
return t.AssetID
2045+
},
2046+
closedJsonChannel.RemoteAssets,
2047+
)...)
2048+
if !remoteAssetIDs.Contains(assetIDStr) {
2049+
continue
2050+
}
2051+
19982052
assetID, err := hex.DecodeString(assetIDStr)
19992053
require.NoError(t, err)
20002054

itest/litd_custom_channels_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,10 +1308,7 @@ func testCustomChannelsGroupTranchesForceClose(ctx context.Context,
13081308
closeAssetChannelAndAssert(
13091309
t, net, charlie, dave, chanPointCD,
13101310
[][]byte{assetID1, assetID2}, groupKey, universeTap,
1311-
// TODO(guggero): replace this with
1312-
// assertDefaultCoOpCloseBalance(true, true) once we have the
1313-
// ability to check the custom data in the closed channel list.
1314-
noOpCoOpCloseBalanceCheck,
1311+
assertDefaultCoOpCloseBalance(true, true),
13151312
)
13161313

13171314
assertSpendableBalance(

0 commit comments

Comments
 (0)