@@ -984,18 +984,12 @@ func assertPendingChannels(t *testing.T, node *HarnessNode,
984
984
require .NoError (t , err )
985
985
require .Len (t , pendingChannelsResp .PendingOpenChannels , numChannels )
986
986
987
- // For older versions (during the backward compatibility test), if the
988
- // channel custom data is in the old format, we can't do further checks.
989
- if node .Cfg .OldChannelFormat {
990
- return
991
- }
992
-
993
987
pendingChan := pendingChannelsResp .PendingOpenChannels [0 ]
994
- var pendingJSON rfqmsg.JsonAssetChannel
995
- err = json .Unmarshal (
996
- pendingChan .Channel .CustomChannelData , & pendingJSON ,
988
+ pendingJSON , err := parseChannelData (
989
+ node , pendingChan .Channel .CustomChannelData ,
997
990
)
998
991
require .NoError (t , err )
992
+
999
993
require .GreaterOrEqual (t , len (pendingJSON .FundingAssets ), 1 )
1000
994
1001
995
require .NotZero (t , pendingJSON .Capacity )
@@ -1040,12 +1034,6 @@ func haveFundingAsset(assetChannel *rfqmsg.JsonAssetChannel,
1040
1034
func assertAssetChan (t * testing.T , src , dst * HarnessNode , fundingAmount uint64 ,
1041
1035
channelAssets []* taprpc.Asset ) {
1042
1036
1043
- if src .Cfg .OldChannelFormat {
1044
- t .Logf ("Skipping asset channel check for %s->%s, old format" ,
1045
- src .Cfg .Name , dst .Cfg .Name )
1046
- return
1047
- }
1048
-
1049
1037
err := wait .NoError (func () error {
1050
1038
a , err := getChannelCustomData (src , dst )
1051
1039
if err != nil {
@@ -1153,8 +1141,7 @@ func getChannelCustomData(src, dst *HarnessNode) (*rfqmsg.JsonAssetChannel,
1153
1141
1154
1142
targetChan := assetChannels [0 ]
1155
1143
1156
- var assetData rfqmsg.JsonAssetChannel
1157
- err = json .Unmarshal (targetChan .CustomChannelData , & assetData )
1144
+ assetData , err := parseChannelData (src , targetChan .CustomChannelData )
1158
1145
if err != nil {
1159
1146
return nil , fmt .Errorf ("unable to unmarshal asset data: %w" ,
1160
1147
err )
@@ -1165,7 +1152,7 @@ func getChannelCustomData(src, dst *HarnessNode) (*rfqmsg.JsonAssetChannel,
1165
1152
len (assetData .FundingAssets ))
1166
1153
}
1167
1154
1168
- return & assetData , nil
1155
+ return assetData , nil
1169
1156
}
1170
1157
1171
1158
func getAssetChannelBalance (t * testing.T , node * HarnessNode , assetIDs [][]byte ,
@@ -1272,8 +1259,9 @@ func assertChannelAssetBalanceWithDelta(t *testing.T, node *HarnessNode,
1272
1259
1273
1260
targetChan := fetchChannel (t , node , chanPoint )
1274
1261
1275
- var assetBalance rfqmsg.JsonAssetChannel
1276
- err := json .Unmarshal (targetChan .CustomChannelData , & assetBalance )
1262
+ assetBalance , err := parseChannelData (
1263
+ node , targetChan .CustomChannelData ,
1264
+ )
1277
1265
require .NoError (t , err )
1278
1266
1279
1267
require .Len (t , assetBalance .FundingAssets , 1 )
@@ -1287,8 +1275,9 @@ func channelAssetBalance(t *testing.T, node *HarnessNode,
1287
1275
1288
1276
targetChan := fetchChannel (t , node , chanPoint )
1289
1277
1290
- var assetBalance rfqmsg.JsonAssetChannel
1291
- err := json .Unmarshal (targetChan .CustomChannelData , & assetBalance )
1278
+ assetBalance , err := parseChannelData (
1279
+ node , targetChan .CustomChannelData ,
1280
+ )
1292
1281
require .NoError (t , err )
1293
1282
1294
1283
require .GreaterOrEqual (t , len (assetBalance .FundingAssets ), 1 )
@@ -2312,9 +2301,8 @@ func defaultCoOpCloseBalanceCheck(t *testing.T, local, remote *HarnessNode,
2312
2301
var closedJsonChannel * rfqmsg.JsonAssetChannel
2313
2302
for _ , closedChan := range closedChans .Channels {
2314
2303
if closedChan .ClosingTxHash == closeTx .TxHash ().String () {
2315
- closedJsonChannel = & rfqmsg.JsonAssetChannel {}
2316
- err = json .Unmarshal (
2317
- closedChan .CustomChannelData , closedJsonChannel ,
2304
+ closedJsonChannel , err = parseChannelData (
2305
+ local , closedChan .CustomChannelData ,
2318
2306
)
2319
2307
require .NoError (t , err )
2320
2308
@@ -2977,8 +2965,7 @@ func newCloseExpiryInfo(t *testing.T, node *HarnessNode) forceCloseExpiryInfo {
2977
2965
cltvs [payHash ] = htlc .ExpirationHeight
2978
2966
}
2979
2967
2980
- var assetData rfqmsg.JsonAssetChannel
2981
- err = json .Unmarshal (mainChan .CustomChannelData , & assetData )
2968
+ assetData , err := parseChannelData (node , mainChan .CustomChannelData )
2982
2969
require .NoError (t , err )
2983
2970
2984
2971
return forceCloseExpiryInfo {
@@ -3092,8 +3079,9 @@ func assertPendingChannelAssetData(t *testing.T, node *HarnessNode,
3092
3079
"custom channel data" , targetChanPointStr )
3093
3080
}
3094
3081
3095
- var closeData rfqmsg.JsonAssetChannel
3096
- err = json .Unmarshal (targetChan .CustomChannelData , & closeData )
3082
+ closeData , err := parseChannelData (
3083
+ node , targetChan .CustomChannelData ,
3084
+ )
3097
3085
if err != nil {
3098
3086
return fmt .Errorf ("error unmarshalling custom channel " +
3099
3087
"data: %v" , err )
@@ -3191,8 +3179,7 @@ func assertClosedChannelAssetData(t *testing.T, node *HarnessNode,
3191
3179
require .NotNil (t , closedChan )
3192
3180
require .NotEmpty (t , closedChan .CustomChannelData )
3193
3181
3194
- var closeData rfqmsg.JsonAssetChannel
3195
- err = json .Unmarshal (closedChan .CustomChannelData , & closeData )
3182
+ closeData , err := parseChannelData (node , closedChan .CustomChannelData )
3196
3183
require .NoError (t , err )
3197
3184
3198
3185
require .GreaterOrEqual (t , len (closeData .FundingAssets ), 1 )
@@ -3643,3 +3630,53 @@ func assertForceCloseSweeps(ctx context.Context, net *NetworkHarness,
3643
3630
3644
3631
return aliceExpectedBalance , bobExpectedBalance
3645
3632
}
3633
+
3634
+ // oldJsonAssetChanInfo is a struct that represents the old channel information
3635
+ // of a single asset within a channel, as it looked for litd v0.14.1 and before.
3636
+ type oldJsonAssetChanInfo struct {
3637
+ AssetInfo rfqmsg.JsonAssetUtxo `json:"asset_utxo"`
3638
+ Capacity uint64 `json:"capacity"`
3639
+ LocalBalance uint64 `json:"local_balance"`
3640
+ RemoteBalance uint64 `json:"remote_balance"`
3641
+ }
3642
+
3643
+ // oldJsonAssetChannel is a struct that represents the old channel information
3644
+ // of all assets within a channel, as it looked for litd v0.14.1 and before.
3645
+ type oldJsonAssetChannel struct {
3646
+ Assets []oldJsonAssetChanInfo `json:"assets"`
3647
+ }
3648
+
3649
+ // parseChannelData parses the given channel data into a rfqmsg.JsonAssetChannel
3650
+ // struct. It can deal with the old (litd v0.14.1 and before) and new (litd
3651
+ // v0.15.0 and after) channel data formats.
3652
+ func parseChannelData (node * HarnessNode ,
3653
+ data []byte ) (* rfqmsg.JsonAssetChannel , error ) {
3654
+
3655
+ var closeData rfqmsg.JsonAssetChannel
3656
+ if node .Cfg .OldChannelFormat {
3657
+ var oldData oldJsonAssetChannel
3658
+ err := json .Unmarshal (data , & oldData )
3659
+ if err != nil {
3660
+ return nil , fmt .Errorf ("error unmarshalling old " +
3661
+ "channel data: %w" , err )
3662
+ }
3663
+
3664
+ oldAsset := oldData .Assets [0 ]
3665
+ closeData .FundingAssets = []rfqmsg.JsonAssetUtxo {
3666
+ oldAsset .AssetInfo ,
3667
+ }
3668
+ closeData .Capacity = oldAsset .Capacity
3669
+ closeData .LocalBalance = oldAsset .LocalBalance
3670
+ closeData .RemoteBalance = oldAsset .RemoteBalance
3671
+
3672
+ return & closeData , nil
3673
+ }
3674
+
3675
+ err := json .Unmarshal (data , & closeData )
3676
+ if err != nil {
3677
+ return nil , fmt .Errorf ("error unmarshalling channel data: %w" ,
3678
+ err )
3679
+ }
3680
+
3681
+ return & closeData , nil
3682
+ }
0 commit comments