Skip to content

Commit

Permalink
Merge pull request #912 from lightninglabs/forward-traffic-shaper
Browse files Browse the repository at this point in the history
[custom channels]: test forward traffic shaper
  • Loading branch information
guggero authored Dec 10, 2024
2 parents 8371d03 + a08e051 commit 127e016
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 82 deletions.
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ require (
github.com/lightninglabs/pool v0.6.5-beta.0.20241015105339-044cb451b5df
github.com/lightninglabs/pool/auctioneerrpc v1.1.2
github.com/lightninglabs/pool/poolrpc v1.0.0
github.com/lightninglabs/taproot-assets v0.5.0-rc1.0.20241209075049-4a15eb2ab84e
github.com/lightningnetwork/lnd v0.18.4-beta.rc1
github.com/lightninglabs/taproot-assets v0.5.0-rc1.0.20241209175552-fde673202d0d
github.com/lightningnetwork/lnd v0.18.4-beta.rc1.0.20241205204908-f312064bfbd5
github.com/lightningnetwork/lnd/cert v1.2.2
github.com/lightningnetwork/lnd/fn v1.2.3
github.com/lightningnetwork/lnd/kvdb v1.4.10
Expand Down Expand Up @@ -236,6 +236,4 @@ replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-d

replace github.com/lightninglabs/lightning-terminal/litrpc => ./litrpc

replace github.com/lightninglabs/aperture => github.com/lightninglabs/aperture v0.3.4-beta

go 1.22.6
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1177,12 +1177,12 @@ github.com/lightninglabs/pool/poolrpc v1.0.0 h1:vvosrgNx9WXF4mcHGqLjZOW8wNM0q+BL
github.com/lightninglabs/pool/poolrpc v1.0.0/go.mod h1:ZqpEpBFRMMBAerMmilEjh27tqauSXDwLaLR0O3jvmMA=
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display h1:w7FM5LH9Z6CpKxl13mS48idsu6F+cEZf0lkyiV+Dq9g=
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
github.com/lightninglabs/taproot-assets v0.5.0-rc1.0.20241209075049-4a15eb2ab84e h1:dFbyAZrkQ9xALiVUf0qikLV2TabucCgPwJZ/Dc6r62Y=
github.com/lightninglabs/taproot-assets v0.5.0-rc1.0.20241209075049-4a15eb2ab84e/go.mod h1:d9GdY5DVoSh6+dEQRS4UUcjpVvZlAHgP8U2DAp4YedA=
github.com/lightninglabs/taproot-assets v0.5.0-rc1.0.20241209175552-fde673202d0d h1:7M7CAHVb2ctF9sgbOkfTJmp2eCY23+LjmwznDt8xDVw=
github.com/lightninglabs/taproot-assets v0.5.0-rc1.0.20241209175552-fde673202d0d/go.mod h1:kIjx0Nppwcpv+CZU6dTMb7iouq5SgPsS0JXhb6a+HPU=
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.18.4-beta.rc1 h1:z6hFKvtbfo8udPrIb81GbSoKlUWd06d4LRxTkD19IMQ=
github.com/lightningnetwork/lnd v0.18.4-beta.rc1/go.mod h1:nPRQzLla5uHPQFyyZn8r9Vgddkd23PBUDa9rggEPOfY=
github.com/lightningnetwork/lnd v0.18.4-beta.rc1.0.20241205204908-f312064bfbd5 h1:YJ/DPJd3YyPWmvv5b74KdpCFi3uBMdmDei54AageGpc=
github.com/lightningnetwork/lnd v0.18.4-beta.rc1.0.20241205204908-f312064bfbd5/go.mod h1:nPRQzLla5uHPQFyyZn8r9Vgddkd23PBUDa9rggEPOfY=
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
42 changes: 26 additions & 16 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,12 @@ func addRoutingFee(amt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
}

func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
assetID []byte, btcAmt fn.Option[int64],
expectedStatus lnrpc.Payment_PaymentStatus,
failReason fn.Option[lnrpc.PaymentFailureReason]) {
assetID []byte, btcAmt fn.Option[int64], opts ...payOpt) {

cfg := defaultPayConfig()
for _, opt := range opts {
opt(cfg)
}

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
Expand Down Expand Up @@ -760,12 +763,8 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
if result.Status == lnrpc.Payment_FAILED {
t.Logf("Failure reason: %v", result.FailureReason)
}
require.Equal(t, expectedStatus, result.Status)

expectedReason := failReason.UnwrapOr(
lnrpc.PaymentFailureReason_FAILURE_REASON_NONE,
)
require.Equal(t, expectedReason, result.FailureReason)
require.Equal(t, cfg.payStatus, result.Status)
require.Equal(t, cfg.failureReason, result.FailureReason)
}

func sendKeySendPayment(t *testing.T, src, dst *HarnessNode,
Expand Down Expand Up @@ -818,9 +817,7 @@ func createAndPayNormalInvoiceWithBtc(t *testing.T, src, dst *HarnessNode,
})
require.NoError(t, err)

payInvoiceWithSatoshi(
t, src, invoiceResp, lnrpc.Payment_SUCCEEDED, false,
)
payInvoiceWithSatoshi(t, src, invoiceResp)
}

func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
Expand All @@ -846,8 +843,12 @@ func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
}

func payInvoiceWithSatoshi(t *testing.T, payer *HarnessNode,
invoice *lnrpc.AddInvoiceResponse,
expectedStatus lnrpc.Payment_PaymentStatus, expectTimeout bool) {
invoice *lnrpc.AddInvoiceResponse, opts ...payOpt) {

cfg := defaultPayConfig()
for _, opt := range opts {
opt(cfg)
}

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
Expand All @@ -863,11 +864,12 @@ func payInvoiceWithSatoshi(t *testing.T, payer *HarnessNode,
require.NoError(t, err)

result, err := getPaymentResult(stream)
if expectTimeout {
if cfg.expectTimeout {
require.ErrorContains(t, err, "context deadline exceeded")
} else {
require.NoError(t, err)
require.Equal(t, expectedStatus, result.Status)
require.Equal(t, cfg.payStatus, result.Status)
require.Equal(t, cfg.failureReason, result.FailureReason)
}
}

Expand Down Expand Up @@ -910,6 +912,7 @@ func payInvoiceWithSatoshiLastHop(t *testing.T, payer *HarnessNode,

type payConfig struct {
smallShards bool
expectTimeout bool
payStatus lnrpc.Payment_PaymentStatus
failureReason lnrpc.PaymentFailureReason
rfq fn.Option[rfqmsg.ID]
Expand All @@ -918,6 +921,7 @@ type payConfig struct {
func defaultPayConfig() *payConfig {
return &payConfig{
smallShards: false,
expectTimeout: false,
payStatus: lnrpc.Payment_SUCCEEDED,
failureReason: lnrpc.PaymentFailureReason_FAILURE_REASON_NONE,
}
Expand All @@ -931,6 +935,12 @@ func withSmallShards() payOpt {
}
}

func withExpectTimeout() payOpt {
return func(c *payConfig) {
c.expectTimeout = true
}
}

func withFailure(status lnrpc.Payment_PaymentStatus,
reason lnrpc.PaymentFailureReason) payOpt {

Expand Down
Loading

0 comments on commit 127e016

Please sign in to comment.