mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-29 19:22:40 +01:00
itest: refactor testExternalFundingChanPoint
This commit is contained in:
parent
1d135c1409
commit
1b741cb6cc
@ -15,4 +15,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
|
|||||||
Name: "basic funding flow",
|
Name: "basic funding flow",
|
||||||
TestFunc: testBasicChannelFunding,
|
TestFunc: testBasicChannelFunding,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "external channel funding",
|
||||||
|
TestFunc: testExternalFundingChanPoint,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
@ -460,122 +460,106 @@ func sendAllCoinsConfirm(net *lntest.NetworkHarness, node *lntest.HarnessNode,
|
|||||||
mineBlocks(t, net, 1, 1)
|
mineBlocks(t, net, 1, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
//// testExternalFundingChanPoint tests that we're able to carry out a normal
|
// testExternalFundingChanPoint tests that we're able to carry out a normal
|
||||||
//// channel funding workflow given a channel point that was constructed outside
|
// channel funding workflow given a channel point that was constructed outside
|
||||||
//// the main daemon.
|
// the main daemon.
|
||||||
func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
|
func testExternalFundingChanPoint(ht *lntemp.HarnessTest) {
|
||||||
// ctxb := context.Background()
|
// First, we'll create two new nodes that we'll use to open channel
|
||||||
|
// between for this test.
|
||||||
|
carol := ht.NewNode("carol", nil)
|
||||||
|
dave := ht.NewNode("dave", nil)
|
||||||
|
|
||||||
// // First, we'll create two new nodes that we'll use to open channel
|
// Carol will be funding the channel, so we'll send some coins over to
|
||||||
// // between for this test.
|
// her and ensure they have enough confirmations before we proceed.
|
||||||
// carol := net.NewNode(t.t, "carol", nil)
|
ht.FundCoins(btcutil.SatoshiPerBitcoin, carol)
|
||||||
// defer shutdownAndAssert(net, t, carol)
|
|
||||||
|
|
||||||
// dave := net.NewNode(t.t, "dave", nil)
|
// Before we start the test, we'll ensure both sides are connected to
|
||||||
// defer shutdownAndAssert(net, t, dave)
|
// the funding flow can properly be executed.
|
||||||
|
ht.EnsureConnected(carol, dave)
|
||||||
|
|
||||||
// // Carol will be funding the channel, so we'll send some coins over to
|
// At this point, we're ready to simulate our external channel funding
|
||||||
// // her and ensure they have enough confirmations before we proceed.
|
// flow. To start with, we'll create a pending channel with a shim for
|
||||||
// net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
|
// a transaction that will never be published.
|
||||||
|
const thawHeight uint32 = 10
|
||||||
|
const chanSize = funding.MaxBtcFundingAmount
|
||||||
|
fundingShim1, chanPoint1, _ := deriveFundingShim(
|
||||||
|
ht, carol, dave, chanSize, thawHeight, false,
|
||||||
|
)
|
||||||
|
ht.OpenChannelAssertPending(
|
||||||
|
carol, dave, lntemp.OpenChannelParams{
|
||||||
|
Amt: chanSize,
|
||||||
|
FundingShim: fundingShim1,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
ht.AssertNodesNumPendingOpenChannels(carol, dave, 1)
|
||||||
|
|
||||||
// // Before we start the test, we'll ensure both sides are connected to
|
// That channel is now pending forever and normally would saturate the
|
||||||
// // the funding flow can properly be executed.
|
// max pending channel limit for both nodes. But because the channel is
|
||||||
// net.EnsureConnected(t.t, carol, dave)
|
// externally funded, we should still be able to open another one. Let's
|
||||||
|
// do exactly that now. For this one we publish the transaction so we
|
||||||
|
// can mine it later.
|
||||||
|
fundingShim2, chanPoint2, _ := deriveFundingShim(
|
||||||
|
ht, carol, dave, chanSize, thawHeight, true,
|
||||||
|
)
|
||||||
|
|
||||||
// // At this point, we're ready to simulate our external channel funding
|
// At this point, we'll now carry out the normal basic channel funding
|
||||||
// // flow. To start with, we'll create a pending channel with a shim for
|
// test as everything should now proceed as normal (a regular channel
|
||||||
// // a transaction that will never be published.
|
// funding flow).
|
||||||
// const thawHeight uint32 = 10
|
carolChan, daveChan, _ := basicChannelFundingTest(
|
||||||
// const chanSize = funding.MaxBtcFundingAmount
|
ht, carol, dave, fundingShim2,
|
||||||
// fundingShim1, chanPoint1, _ := deriveFundingShimOld(
|
)
|
||||||
// net, t, carol, dave, chanSize, thawHeight, false,
|
|
||||||
// )
|
|
||||||
// _ = openChannelStream(
|
|
||||||
// t, net, carol, dave, lntest.OpenChannelParams{
|
|
||||||
// Amt: chanSize,
|
|
||||||
// FundingShim: fundingShim1,
|
|
||||||
// },
|
|
||||||
// )
|
|
||||||
// assertNumOpenChannelsPending(t, carol, dave, 1)
|
|
||||||
|
|
||||||
// // That channel is now pending forever and normally would saturate the
|
// Both channels should be marked as frozen with the proper thaw
|
||||||
// // max pending channel limit for both nodes. But because the channel is
|
// height.
|
||||||
// // externally funded, we should still be able to open another one. Let's
|
require.Equal(ht, thawHeight, carolChan.ThawHeight,
|
||||||
// // do exactly that now. For this one we publish the transaction so we
|
"thaw height unmatched")
|
||||||
// // can mine it later.
|
require.Equal(ht, thawHeight, daveChan.ThawHeight,
|
||||||
// fundingShim2, chanPoint2, _ := deriveFundingShimOld(
|
"thaw height unmatched")
|
||||||
// net, t, carol, dave, chanSize, thawHeight, true,
|
|
||||||
// )
|
|
||||||
|
|
||||||
// // At this point, we'll now carry out the normal basic channel funding
|
// Next, to make sure the channel functions as normal, we'll make some
|
||||||
// // test as everything should now proceed as normal (a regular channel
|
// payments within the channel.
|
||||||
// // funding flow).
|
payAmt := btcutil.Amount(100000)
|
||||||
// var carolChan, daveChan lnrpc.Channel
|
invoice := &lnrpc.Invoice{
|
||||||
// carolChan, daveChan, _, err := basicChannelFundingTest(
|
Memo: "new chans",
|
||||||
// t, net, carol, dave, fundingShim2,
|
Value: int64(payAmt),
|
||||||
// )
|
}
|
||||||
|
resp := dave.RPC.AddInvoice(invoice)
|
||||||
|
ht.CompletePaymentRequests(carol, []string{resp.PaymentRequest})
|
||||||
|
|
||||||
// // Both channels should be marked as frozen with the proper thaw
|
// Now that the channels are open, and we've confirmed that they're
|
||||||
// // height.
|
// operational, we'll now ensure that the channels are frozen as
|
||||||
// require.Equal(
|
// intended (if requested).
|
||||||
// t.t, thawHeight, carolChan.ThawHeight, "thaw height unmatched",
|
//
|
||||||
// )
|
// First, we'll try to close the channel as Carol, the initiator. This
|
||||||
// require.Equal(
|
// should fail as a frozen channel only allows the responder to
|
||||||
// t.t, thawHeight, daveChan.ThawHeight, "thaw height unmatched",
|
// initiate a channel close.
|
||||||
// )
|
ht.CloseChannelAssertErr(carol, chanPoint2, false)
|
||||||
|
|
||||||
// // Next, to make sure the channel functions as normal, we'll make some
|
// Before Dave closes the channel, he needs to check the invoice is
|
||||||
// // payments within the channel.
|
// settled to avoid an error saying cannot close channel due to active
|
||||||
// payAmt := btcutil.Amount(100000)
|
// HTLCs.
|
||||||
// invoice := &lnrpc.Invoice{
|
ht.AssertInvoiceSettled(dave, resp.PaymentAddr)
|
||||||
// Memo: "new chans",
|
|
||||||
// Value: int64(payAmt),
|
|
||||||
// }
|
|
||||||
// ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
// resp, err := dave.AddInvoice(ctxt, invoice)
|
|
||||||
// require.NoError(t.t, err)
|
|
||||||
// err = completePaymentRequests(
|
|
||||||
// carol, carol.RouterClient, []string{resp.PaymentRequest}, true,
|
|
||||||
// )
|
|
||||||
// require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// // Now that the channels are open, and we've confirmed that they're
|
// Next we'll try but this time with Dave (the responder) as the
|
||||||
// // operational, we'll now ensure that the channels are frozen as
|
// initiator. This time the channel should be closed as normal.
|
||||||
// // intended (if requested).
|
ht.CloseChannel(dave, chanPoint2, false)
|
||||||
// //
|
|
||||||
// // First, we'll try to close the channel as Carol, the initiator. This
|
|
||||||
// // should fail as a frozen channel only allows the responder to
|
|
||||||
// // initiate a channel close.
|
|
||||||
// _, _, err = net.CloseChannel(carol, chanPoint2, false)
|
|
||||||
// require.Error(t.t, err,
|
|
||||||
// "carol wasn't denied a co-op close attempt "+
|
|
||||||
// "for a frozen channel",
|
|
||||||
// )
|
|
||||||
|
|
||||||
// // Next we'll try but this time with Dave (the responder) as the
|
// As a last step, we check if we still have the pending channel
|
||||||
// // initiator. This time the channel should be closed as normal.
|
// hanging around because we never published the funding TX.
|
||||||
// closeChannelAndAssert(t, net, dave, chanPoint2, false)
|
ht.AssertNodesNumPendingOpenChannels(carol, dave, 1)
|
||||||
|
|
||||||
// // As a last step, we check if we still have the pending channel hanging
|
// Let's make sure we can abandon it.
|
||||||
// // around because we never published the funding TX.
|
carol.RPC.AbandonChannel(&lnrpc.AbandonChannelRequest{
|
||||||
// assertNumOpenChannelsPending(t, carol, dave, 1)
|
ChannelPoint: chanPoint1,
|
||||||
|
PendingFundingShimOnly: true,
|
||||||
|
})
|
||||||
|
dave.RPC.AbandonChannel(&lnrpc.AbandonChannelRequest{
|
||||||
|
ChannelPoint: chanPoint1,
|
||||||
|
PendingFundingShimOnly: true,
|
||||||
|
})
|
||||||
|
|
||||||
// // Let's make sure we can abandon it.
|
// It should now not appear in the pending channels anymore.
|
||||||
// ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ht.AssertNodesNumPendingOpenChannels(carol, dave, 0)
|
||||||
// _, err = carol.AbandonChannel(ctxt, &lnrpc.AbandonChannelRequest{
|
|
||||||
// ChannelPoint: chanPoint1,
|
|
||||||
// PendingFundingShimOnly: true,
|
|
||||||
// })
|
|
||||||
// require.NoError(t.t, err)
|
|
||||||
// ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
// _, err = dave.AbandonChannel(ctxt, &lnrpc.AbandonChannelRequest{
|
|
||||||
// ChannelPoint: chanPoint1,
|
|
||||||
// PendingFundingShimOnly: true,
|
|
||||||
// })
|
|
||||||
// require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// // It should now not appear in the pending channels anymore.
|
|
||||||
// assertNumOpenChannelsPending(t, carol, dave, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// testFundingPersistence is intended to ensure that the Funding Manager
|
// testFundingPersistence is intended to ensure that the Funding Manager
|
||||||
|
@ -287,10 +287,6 @@ var allTestCases = []*testCase{
|
|||||||
name: "immediate payment after channel opened",
|
name: "immediate payment after channel opened",
|
||||||
test: testPaymentFollowingChannelOpen,
|
test: testPaymentFollowingChannelOpen,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "external channel funding",
|
|
||||||
test: testExternalFundingChanPoint,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "psbt channel funding",
|
name: "psbt channel funding",
|
||||||
test: testPsbtChanFunding,
|
test: testPsbtChanFunding,
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||||
|
"github.com/lightningnetwork/lnd/lntemp"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
"github.com/lightningnetwork/lnd/lntest"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
@ -248,7 +249,9 @@ func nodeArgsForCommitType(commitType lnrpc.CommitmentType) []string {
|
|||||||
func calcStaticFee(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
|
func calcStaticFee(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
|
||||||
const htlcWeight = input.HTLCWeight
|
const htlcWeight = input.HTLCWeight
|
||||||
var (
|
var (
|
||||||
feePerKw = chainfee.SatPerKVByte(50000).FeePerKWeight()
|
feePerKw = chainfee.SatPerKWeight(
|
||||||
|
lntemp.DefaultFeeRateSatPerKw,
|
||||||
|
)
|
||||||
commitWeight = input.CommitWeight
|
commitWeight = input.CommitWeight
|
||||||
anchors = btcutil.Amount(0)
|
anchors = btcutil.Amount(0)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user