From de860733505ffe8986a59a643cb5b2fb385a532c Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Wed, 30 Oct 2024 18:04:50 +0100 Subject: [PATCH] itest: add itest for MinRelayFee check This commit adds an integration test for the MinRelayFee check. The test ensures that transactions with fees below the minimum relay fee are rejected. --- cmd/litcli/ln.go | 1 - go.mod | 4 +- go.sum | 8 +-- itest/litd_custom_channels_test.go | 85 ++++++++++++++++++++++++++++++ itest/litd_test_list_on_test.go | 4 ++ 5 files changed, 95 insertions(+), 7 deletions(-) diff --git a/cmd/litcli/ln.go b/cmd/litcli/ln.go index df1738756..b5c19f7c9 100644 --- a/cmd/litcli/ln.go +++ b/cmd/litcli/ln.go @@ -64,7 +64,6 @@ var fundChannelCommand = cli.Command{ Usage: "(optional) a manual fee expressed in " + "sat/vByte that should be used when crafting " + "the transaction", - Value: 1, }, cli.Uint64Flag{ Name: "push_amt", diff --git a/go.mod b/go.mod index b7de923c3..276d90c20 100644 --- a/go.mod +++ b/go.mod @@ -16,14 +16,14 @@ require ( github.com/lightninglabs/lightning-node-connect v0.3.2-alpha.0.20240822142323-ee4e7ff52f83 github.com/lightninglabs/lightning-terminal/autopilotserverrpc v0.0.1 github.com/lightninglabs/lightning-terminal/litrpc v1.0.0 - github.com/lightninglabs/lndclient v0.18.4-1 + github.com/lightninglabs/lndclient v0.18.4-3 github.com/lightninglabs/loop v0.28.8-beta.0.20241022072406-1e8ae31ddc27 github.com/lightninglabs/loop/looprpc v1.0.0 github.com/lightninglabs/loop/swapserverrpc v1.0.10 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.4.2-0.20241031160301-588e58bfae6c + github.com/lightninglabs/taproot-assets v0.4.2-0.20241101220611-e6b78bd51722 github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241025090009-615f3d633e61 github.com/lightningnetwork/lnd/cert v1.2.2 github.com/lightningnetwork/lnd/fn v1.2.3 diff --git a/go.sum b/go.sum index 5cac0df87..9a354b76d 100644 --- a/go.sum +++ b/go.sum @@ -1157,8 +1157,8 @@ github.com/lightninglabs/lightning-node-connect v0.3.2-alpha.0.20240822142323-ee github.com/lightninglabs/lightning-node-connect v0.3.2-alpha.0.20240822142323-ee4e7ff52f83/go.mod h1:+SasPOt0evcJdfApb/ALTaTz4x3a2/kWy5KqFoTpiX8= github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2 h1:Er1miPZD2XZwcfE4xoS5AILqP1mj7kqnhbBSxW9BDxY= github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2/go.mod h1:antQGRDRJiuyQF6l+k6NECCSImgCpwaZapATth2Chv4= -github.com/lightninglabs/lndclient v0.18.4-1 h1:k2UnxHGNH243NRe5/dL2sKgrxc8WMHbFQRdnCtfilwc= -github.com/lightninglabs/lndclient v0.18.4-1/go.mod h1:/HLqmZGL9MtP8F1g+laq+L9VrsugBN5tsTct3C5wWCg= +github.com/lightninglabs/lndclient v0.18.4-3 h1:Xk3ZuCQE4ZlF70jaToryL2MvRcryiE0zTfUjJbmzUBY= +github.com/lightninglabs/lndclient v0.18.4-3/go.mod h1:/HLqmZGL9MtP8F1g+laq+L9VrsugBN5tsTct3C5wWCg= github.com/lightninglabs/loop v0.28.8-beta.0.20241022072406-1e8ae31ddc27 h1:eZBvG9XvDL0zsUIqFfD7SCk+Ex8rGWEL8j5UQ/aqjco= github.com/lightninglabs/loop v0.28.8-beta.0.20241022072406-1e8ae31ddc27/go.mod h1:4B1DqrcOc5Yv9KyclAeQJY9Ah9UMX7RpI4Uru7aEzl4= github.com/lightninglabs/loop/looprpc v1.0.0 h1:xry4QPCZShPww660xJm1BVcNFj8etgNeN2vMpfsv3c4= @@ -1177,8 +1177,8 @@ 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.4.2-0.20241031160301-588e58bfae6c h1:HfU82bWD4Yk+Mf2Ax25uhcIwq0SxToTq8J8YJLReW/U= -github.com/lightninglabs/taproot-assets v0.4.2-0.20241031160301-588e58bfae6c/go.mod h1:AYq9p1FOMdwAGjEjVaT79+cDyAwcc4fj8W0YJvCU0JE= +github.com/lightninglabs/taproot-assets v0.4.2-0.20241101220611-e6b78bd51722 h1:67uNN65L8P6rcTkFAAuD+oYldQcDkSQLGK+o4Cfu/X8= +github.com/lightninglabs/taproot-assets v0.4.2-0.20241101220611-e6b78bd51722/go.mod h1:DLcxQrwsLSXLTMNr1hBY5+pJSxNJYqobPqxhflYYFp8= 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.3-beta.rc3.0.20241025090009-615f3d633e61 h1:EcBM2tz+iyspYRFaDVjUe5a2bkuBWFxOWD2mzdCraUc= diff --git a/itest/litd_custom_channels_test.go b/itest/litd_custom_channels_test.go index 82045f21a..640bb48b9 100644 --- a/itest/litd_custom_channels_test.go +++ b/itest/litd_custom_channels_test.go @@ -27,6 +27,7 @@ import ( "github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest/port" "github.com/lightningnetwork/lnd/lntest/wait" + "github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwire" "github.com/stretchr/testify/require" ) @@ -2637,3 +2638,87 @@ func testCustomChannelsOraclePricing(_ context.Context, noOpCoOpCloseBalanceCheck, ) } + +// testCustomChannelsFee tests the whether the custom channel funding process +// fails if the proposed fee rate is lower than the minimum relay fee. +func testCustomChannelsFee(_ context.Context, + net *NetworkHarness, t *harnessTest) { + + ctxb := context.Background() + lndArgs := slices.Clone(lndArgsTemplate) + litdArgs := slices.Clone(litdArgsTemplate) + + zane, err := net.NewNode( + t.t, "Zane", lndArgs, false, true, litdArgs..., + ) + require.NoError(t.t, err) + + litdArgs = append(litdArgs, fmt.Sprintf( + "--taproot-assets.proofcourieraddr=%s://%s", + proof.UniverseRpcCourierType, zane.Cfg.LitAddr(), + )) + + charlie, err := net.NewNode( + t.t, "Charlie", lndArgs, false, true, litdArgs..., + ) + require.NoError(t.t, err) + dave, err := net.NewNode(t.t, "Dave", lndArgs, false, true, litdArgs...) + require.NoError(t.t, err) + + nodes := []*HarnessNode{charlie, dave} + connectAllNodes(t.t, net, nodes) + fundAllNodes(t.t, net, nodes) + + charlieTap := newTapClient(t.t, charlie) + daveTap := newTapClient(t.t, dave) + + // Mint an assets on Charlie and sync Dave to Charlie as the universe. + mintedAssets := itest.MintAssetsConfirmBatch( + t.t, t.lndHarness.Miner.Client, charlieTap, + []*mintrpc.MintAssetRequest{ + { + Asset: itestAsset, + }, + }, + ) + cents := mintedAssets[0] + assetID := cents.AssetGenesis.AssetId + + t.Logf("Minted %d lightning cents, syncing universes...", cents.Amount) + syncUniverses(t.t, charlieTap, dave) + t.Logf("Universes synced between all nodes, distributing assets...") + + // Fund a channel with a fee rate of zero. + zeroLowFeeRate := uint32(0) + + _, err = charlieTap.FundChannel( + ctxb, &tchrpc.FundChannelRequest{ + AssetAmount: cents.Amount, + AssetId: assetID, + PeerPubkey: daveTap.node.PubKey[:], + FeeRateSatPerVbyte: zeroLowFeeRate, + PushSat: 0, + }, + ) + + errSpecifyFeerate := "fee rate must be specified" + require.ErrorContains(t.t, err, errSpecifyFeerate) + + // Fund a channel with a fee rate that is too low. + tooLowFeeRate := uint32(1) + tooLowFeeRateAmount := chainfee.SatPerVByte(tooLowFeeRate) + + _, err = charlieTap.FundChannel( + ctxb, &tchrpc.FundChannelRequest{ + AssetAmount: cents.Amount, + AssetId: assetID, + PeerPubkey: daveTap.node.PubKey[:], + FeeRateSatPerVbyte: tooLowFeeRate, + PushSat: 0, + }, + ) + + errFeeRateTooLow := fmt.Sprintf("fee rate %s too low, "+ + "min_relay_fee: ", tooLowFeeRateAmount.FeePerKWeight()) + require.ErrorContains(t.t, err, errFeeRateTooLow) +} diff --git a/itest/litd_test_list_on_test.go b/itest/litd_test_list_on_test.go index 1726b928e..6f01d736c 100644 --- a/itest/litd_test_list_on_test.go +++ b/itest/litd_test_list_on_test.go @@ -60,4 +60,8 @@ var allTestCases = []*testCase{ name: "test custom channels oracle pricing", test: testCustomChannelsOraclePricing, }, + { + name: "test custom channels fee", + test: testCustomChannelsFee, + }, }