Skip to content

Commit b0230d4

Browse files
authored
Merge pull request #995 from GeorgeTsagk/tapd-groupkeys
Custom channels itest: Use group keys on some payments & invoices
2 parents c0fba9a + 91e5c85 commit b0230d4

File tree

5 files changed

+217
-54
lines changed

5 files changed

+217
-54
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ require (
2828
github.com/lightninglabs/pool v0.6.5-beta.0.20250305125211-4e860ec4e77f
2929
github.com/lightninglabs/pool/auctioneerrpc v1.1.3-0.20250305125211-4e860ec4e77f
3030
github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f
31-
github.com/lightninglabs/taproot-assets v0.5.2-0.20250401150538-a9ea76a9ed3c
31+
github.com/lightninglabs/taproot-assets v0.5.2-0.20250416114205-2da076df4b4e
3232
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

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,8 @@ github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f h1:5p
11811181
github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f/go.mod h1:lGs2hSVZ+GFpdv3btaIl9icG5/gz7BBRfvmD2iqqNl0=
11821182
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display h1:w7FM5LH9Z6CpKxl13mS48idsu6F+cEZf0lkyiV+Dq9g=
11831183
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
1184-
github.com/lightninglabs/taproot-assets v0.5.2-0.20250401150538-a9ea76a9ed3c h1:Rebx5DVZx3u327vKRrueFjZNlei1RzdGzFmOZmenkiQ=
1185-
github.com/lightninglabs/taproot-assets v0.5.2-0.20250401150538-a9ea76a9ed3c/go.mod h1:e3SjXbbi4xKhOzq54c672Z/j9UTRq5DLJGx/URgVTJo=
1184+
github.com/lightninglabs/taproot-assets v0.5.2-0.20250416114205-2da076df4b4e h1:37sk9Wmkh9QFjnqR8eHIhCi8x0uIQL0F2fpcQI25I9g=
1185+
github.com/lightninglabs/taproot-assets v0.5.2-0.20250416114205-2da076df4b4e/go.mod h1:e3SjXbbi4xKhOzq54c672Z/j9UTRq5DLJGx/URgVTJo=
11861186
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY=
11871187
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
11881188
github.com/lightningnetwork/lnd v0.19.0-beta.rc1.0.20250327183348-eb822a5e117f h1:+Bejv2Ij/ryUjLacBd5au0acMH0AYs0lhb7ki5rx9ms=

itest/assets_test.go

+67-5
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,12 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
741741
opt(cfg)
742742
}
743743

744+
// Nullify assetID if group key is set. RPC methods won't accept both so
745+
// let's prioritize the group key if set.
746+
if len(cfg.groupKey) > 0 {
747+
assetID = nil
748+
}
749+
744750
ctxb := context.Background()
745751
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
746752
defer cancel()
@@ -770,6 +776,7 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
770776
stream, err := srcTapd.SendPayment(ctxt, &tchrpc.SendPaymentRequest{
771777
AssetId: assetID,
772778
AssetAmount: amt,
779+
GroupKey: cfg.groupKey,
773780
PaymentRequest: sendReq,
774781
})
775782
require.NoError(t, err)
@@ -942,6 +949,7 @@ type payConfig struct {
942949
payStatus lnrpc.Payment_PaymentStatus
943950
failureReason lnrpc.PaymentFailureReason
944951
rfq fn.Option[rfqmsg.ID]
952+
groupKey []byte
945953
}
946954

947955
func defaultPayConfig() *payConfig {
@@ -956,6 +964,12 @@ func defaultPayConfig() *payConfig {
956964

957965
type payOpt func(*payConfig)
958966

967+
func withGroupKey(groupKey []byte) payOpt {
968+
return func(c *payConfig) {
969+
c.groupKey = groupKey
970+
}
971+
}
972+
959973
func withSmallShards() payOpt {
960974
return func(c *payConfig) {
961975
c.smallShards = true
@@ -1010,6 +1024,12 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10101024
opt(cfg)
10111025
}
10121026

1027+
// Nullify assetID if group key is set. RPC methods won't accept both so
1028+
// let's prioritize the group key if set.
1029+
if len(cfg.groupKey) > 0 {
1030+
assetID = []byte{}
1031+
}
1032+
10131033
ctxb := context.Background()
10141034
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
10151035
defer cancel()
@@ -1041,6 +1061,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10411061
stream, err := payerTapd.SendPayment(ctxt, &tchrpc.SendPaymentRequest{
10421062
AssetId: assetID,
10431063
PeerPubkey: rfqPeer.PubKey[:],
1064+
GroupKey: cfg.groupKey,
10441065
PaymentRequest: sendReq,
10451066
RfqId: rfqBytes,
10461067
AllowOverpay: cfg.allowOverpay,
@@ -1102,6 +1123,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
11021123

11031124
type invoiceConfig struct {
11041125
errSubStr string
1126+
groupKey []byte
11051127
}
11061128

11071129
func defaultInvoiceConfig() *invoiceConfig {
@@ -1118,6 +1140,12 @@ func withInvoiceErrSubStr(errSubStr string) invoiceOpt {
11181140
}
11191141
}
11201142

1143+
func withInvGroupKey(groupKey []byte) invoiceOpt {
1144+
return func(c *invoiceConfig) {
1145+
c.groupKey = groupKey
1146+
}
1147+
}
1148+
11211149
func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11221150
assetAmount uint64, assetID []byte,
11231151
opts ...invoiceOpt) *lnrpc.AddInvoiceResponse {
@@ -1127,6 +1155,12 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11271155
opt(cfg)
11281156
}
11291157

1158+
// Nullify assetID if group key is set. RPC methods won't accept both so
1159+
// let's prioritize the group key if set.
1160+
if len(cfg.groupKey) > 0 {
1161+
assetID = []byte{}
1162+
}
1163+
11301164
ctxb := context.Background()
11311165
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
11321166
defer cancel()
@@ -1141,6 +1175,7 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11411175

11421176
resp, err := dstTapd.AddInvoice(ctxt, &tchrpc.AddInvoiceRequest{
11431177
AssetId: assetID,
1178+
GroupKey: cfg.groupKey,
11441179
AssetAmount: assetAmount,
11451180
PeerPubkey: dstRfqPeer.PubKey[:],
11461181
InvoiceRequest: &lnrpc.Invoice{
@@ -1185,7 +1220,7 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11851220
// individual HTLCs that arrived for it and that they show the correct asset
11861221
// amounts for the given ID when decoded.
11871222
func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
1188-
addedInvoice *lnrpc.AddInvoiceResponse, assetID []byte,
1223+
addedInvoice *lnrpc.AddInvoiceResponse, assetID []byte, groupID []byte,
11891224
assetAmount uint64) {
11901225

11911226
ctxb := context.Background()
@@ -1204,7 +1239,14 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
12041239

12051240
t.Logf("Asset invoice: %v", toProtoJSON(t, invoice))
12061241

1207-
targetID := hex.EncodeToString(assetID)
1242+
var targetID string
1243+
switch {
1244+
case len(groupID) > 0:
1245+
targetID = hex.EncodeToString(groupID)
1246+
1247+
case len(assetID) > 0:
1248+
targetID = hex.EncodeToString(assetID)
1249+
}
12081250

12091251
var totalAssetAmount uint64
12101252
for _, htlc := range invoice.Htlcs {
@@ -1231,7 +1273,7 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
12311273
// individual HTLCs that arrived for it and that they show the correct asset
12321274
// amounts for the given ID when decoded.
12331275
func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
1234-
assetID []byte, assetAmount uint64) {
1276+
assetID []byte, groupID []byte, assetAmount uint64) {
12351277

12361278
ctxb := context.Background()
12371279
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1252,7 +1294,14 @@ func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
12521294

12531295
t.Logf("Asset payment: %v", toProtoJSON(t, payment))
12541296

1255-
targetID := hex.EncodeToString(assetID)
1297+
var targetID string
1298+
switch {
1299+
case len(groupID) > 0:
1300+
targetID = hex.EncodeToString(groupID)
1301+
1302+
case len(assetID) > 0:
1303+
targetID = hex.EncodeToString(assetID)
1304+
}
12561305

12571306
var totalAssetAmount uint64
12581307
for _, htlc := range payment.Htlcs {
@@ -1282,7 +1331,19 @@ type assetHodlInvoice struct {
12821331
}
12831332

12841333
func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
1285-
assetAmount uint64, assetID []byte) assetHodlInvoice {
1334+
assetAmount uint64, assetID []byte,
1335+
opts ...invoiceOpt) assetHodlInvoice {
1336+
1337+
cfg := defaultInvoiceConfig()
1338+
for _, opt := range opts {
1339+
opt(cfg)
1340+
}
1341+
1342+
// Nullify assetID if group key is set. RPC methods won't accept both so
1343+
// let's prioritize the group key if set.
1344+
if len(cfg.groupKey) > 0 {
1345+
assetID = []byte{}
1346+
}
12861347

12871348
ctxb := context.Background()
12881349
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1306,6 +1367,7 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
13061367

13071368
resp, err := dstTapd.AddInvoice(ctxt, &tchrpc.AddInvoiceRequest{
13081369
AssetId: assetID,
1370+
GroupKey: cfg.groupKey,
13091371
AssetAmount: assetAmount,
13101372
PeerPubkey: dstRfqPeer.PubKey[:],
13111373
InvoiceRequest: &lnrpc.Invoice{

0 commit comments

Comments
 (0)