Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeTsagk committed Nov 25, 2024
1 parent e0ab462 commit f055328
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 16 deletions.
3 changes: 3 additions & 0 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,9 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,

result, err := getAssetPaymentResult(stream, false)
require.NoError(t, err)
if result.Status == lnrpc.Payment_FAILED {
t.Logf("Failure reason: %v", result.FailureReason)
}
require.Equal(t, expectedStatus, result.Status)

expectedReason := failReason.UnwrapOr(
Expand Down
73 changes: 57 additions & 16 deletions itest/litd_custom_channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var (

shortTimeout = time.Second * 5

defaultPaymentStatus = fn.None[lnrpc.Payment_PaymentStatus]()
defaultPaymentStatusOpt = fn.None[lnrpc.Payment_PaymentStatus]()
)

var (
Expand Down Expand Up @@ -230,7 +230,7 @@ func testCustomChannelsLarge(_ context.Context, net *NetworkHarness,
)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, false,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after invoice")

Expand All @@ -245,7 +245,7 @@ func testCustomChannelsLarge(_ context.Context, net *NetworkHarness,

payInvoiceWithAssets(
t.t, fabia, erin, invoiceResp2.PaymentRequest, assetID, false,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after invoice 2")

Expand All @@ -256,7 +256,7 @@ func testCustomChannelsLarge(_ context.Context, net *NetworkHarness,
)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp3.PaymentRequest, assetID, false,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after invoice 3")

Expand Down Expand Up @@ -448,7 +448,7 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
)
payInvoiceWithAssets(
t.t, dave, charlie, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after invoice back")

Expand Down Expand Up @@ -513,7 +513,7 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after invoice")

Expand Down Expand Up @@ -558,7 +558,7 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after invoice")

Expand Down Expand Up @@ -595,7 +595,7 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after invoice")

Expand All @@ -616,7 +616,7 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after asset-to-asset")

Expand Down Expand Up @@ -952,7 +952,7 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after invoice")

Expand Down Expand Up @@ -990,7 +990,7 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after invoice")

Expand Down Expand Up @@ -1027,7 +1027,7 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after invoice")

Expand All @@ -1048,7 +1048,7 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after asset-to-asset")

Expand Down Expand Up @@ -1961,7 +1961,7 @@ func testCustomChannelsLiquidityEdgeCases(_ context.Context,

payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, false,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)

logBalance(t.t, nodes, assetID, "after big asset payment (asset "+
Expand Down Expand Up @@ -2007,7 +2007,7 @@ func testCustomChannelsLiquidityEdgeCases(_ context.Context,

payInvoiceWithAssets(
t.t, yara, dave, invoiceResp.PaymentRequest, assetID, false,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)

logBalance(t.t, nodes, assetID, "after big asset payment (asset "+
Expand Down Expand Up @@ -2051,6 +2051,47 @@ func testCustomChannelsLiquidityEdgeCases(_ context.Context,
logBalance(t.t, nodes, assetID, "after failed payment (asset "+
"invoice, strict forwarding)")

// Edge case: Fabia gets all the asset liquidity on her side. Then
// generates an asset invoice to be paid for with assets by Charlie.
// Charlie will unleash multiple shards towards Fabia, exhausting the
// liquidity in the Erin<->Fabia channel. Dave should be able to detect
// those failures and account for those cancelled HTLCs in the RFQ
// tracking mechanism. Eventually we will slosh some funds from Fabia
// back to Erin in order for Erin to be able to forward the rest of the
// HTLCs, leading to the release of the preimage.

// Erin starts by sending half of the assets to Fabia's side. He also
// sends some raw sats to be used by Fabia later for the sloshing.
sendAssetKeySendPayment(
t.t, erin, fabia, 2*bigAssetAmount, assetID,
fn.None[int64](), lnrpc.Payment_SUCCEEDED,
fn.None[lnrpc.PaymentFailureReason](),
)
sendKeySendPayment(t.t, erin, fabia, 20_000)

logBalance(t.t, nodes, assetID, "balance after 1st slosh")

invoiceResp = createAssetInvoice(t.t, erin, fabia, 1_000, assetID)

go func() {
// After a small delay (less than the payment timeout) Fabia
// sloshes back the liquidity to Erin. This should allow the
// payment by Charlie to eventually complete.
time.Sleep(time.Second * 2)
sendAssetKeySendPayment(
t.t, fabia, erin, 2_000, assetID,
fn.None[int64](), lnrpc.Payment_SUCCEEDED,
fn.None[lnrpc.PaymentFailureReason](),
)
}()

payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatusOpt,
)

logBalance(t.t, nodes, assetID, "after htlc track cancel")

// Edge case: Charlie negotiates a quote with Dave which has a low max
// amount (~170k sats). Then Charlie creates an invoice with a total
// amount slightly larger than the max allowed in the quote (200k sats).
Expand Down Expand Up @@ -2652,7 +2693,7 @@ func testCustomChannelsOraclePricing(_ context.Context,

numUnits, rate := payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, false,
defaultPaymentStatus,
defaultPaymentStatusOpt,
)
logBalance(t.t, nodes, assetID, "after invoice")

Expand Down

0 comments on commit f055328

Please sign in to comment.