mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-17 04:11:42 +02:00
lntest: update zero-conf tests to account for zeroconfacceptor
This commit is contained in:
parent
4ab80b012d
commit
48912560e2
@ -1063,6 +1063,18 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
)
|
)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
// If we are testing zero-conf channels, setup a
|
||||||
|
// ChannelAcceptor for the fundee.
|
||||||
|
var cancel context.CancelFunc
|
||||||
|
if testCase.zeroConf {
|
||||||
|
// Setup a ChannelAcceptor.
|
||||||
|
var ctxc context.Context
|
||||||
|
ctxc, cancel = context.WithCancel(ctxb)
|
||||||
|
acceptStream, err := to.ChannelAcceptor(ctxc)
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
go acceptChannel(t, true, acceptStream)
|
||||||
|
}
|
||||||
|
|
||||||
var fundingShim *lnrpc.FundingShim
|
var fundingShim *lnrpc.FundingShim
|
||||||
if testCase.commitmentType == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
|
if testCase.commitmentType == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
|
||||||
_, minerHeight, err := net.Miner.Client.GetBestBlock()
|
_, minerHeight, err := net.Miner.Client.GetBestBlock()
|
||||||
@ -1085,6 +1097,11 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
t, net, from, to, params,
|
t, net, from, to, params,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Remove the ChannelAcceptor.
|
||||||
|
if testCase.zeroConf {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for both sides to see the opened channel.
|
// Wait for both sides to see the opened channel.
|
||||||
err = dave.WaitForNetworkChannelOpen(chanPoint)
|
err = dave.WaitForNetworkChannelOpen(chanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -265,6 +265,23 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
net, t, alice, bob, chanAmt, thawHeight, true,
|
net, t, alice, bob, chanAmt, thawHeight, true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a zero-conf channel is being opened, the nodes are signalling the
|
||||||
|
// zero-conf feature bit. Setup a ChannelAcceptor for the fundee.
|
||||||
|
ctxb := context.Background()
|
||||||
|
|
||||||
|
var (
|
||||||
|
cancel context.CancelFunc
|
||||||
|
ctxc context.Context
|
||||||
|
)
|
||||||
|
|
||||||
|
if zeroConf {
|
||||||
|
ctxc, cancel = context.WithCancel(ctxb)
|
||||||
|
acceptStream, err := bob.ChannelAcceptor(ctxc)
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
go acceptChannel(t, true, acceptStream)
|
||||||
|
}
|
||||||
|
|
||||||
aliceChanPoint := openChannelAndAssert(
|
aliceChanPoint := openChannelAndAssert(
|
||||||
t, net, alice, bob,
|
t, net, alice, bob,
|
||||||
lntest.OpenChannelParams{
|
lntest.OpenChannelParams{
|
||||||
@ -275,6 +292,11 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Remove the ChannelAcceptor for Bob.
|
||||||
|
if zeroConf {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
|
||||||
err := alice.WaitForNetworkChannelOpen(aliceChanPoint)
|
err := alice.WaitForNetworkChannelOpen(aliceChanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("alice didn't report channel: %v", err)
|
t.Fatalf("alice didn't report channel: %v", err)
|
||||||
@ -320,6 +342,16 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
net, t, bob, carol, chanAmt, thawHeight, true,
|
net, t, bob, carol, chanAmt, thawHeight, true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup a ChannelAcceptor for Carol if a zero-conf channel open is
|
||||||
|
// being attempted.
|
||||||
|
if zeroConf {
|
||||||
|
ctxc, cancel = context.WithCancel(ctxb)
|
||||||
|
acceptStream, err := carol.ChannelAcceptor(ctxc)
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
go acceptChannel(t, true, acceptStream)
|
||||||
|
}
|
||||||
|
|
||||||
bobChanPoint := openChannelAndAssert(
|
bobChanPoint := openChannelAndAssert(
|
||||||
t, net, bob, carol,
|
t, net, bob, carol,
|
||||||
lntest.OpenChannelParams{
|
lntest.OpenChannelParams{
|
||||||
@ -329,6 +361,12 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
ZeroConf: zeroConf,
|
ZeroConf: zeroConf,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Remove the ChannelAcceptor for Carol.
|
||||||
|
if zeroConf {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
|
||||||
err = bob.WaitForNetworkChannelOpen(bobChanPoint)
|
err = bob.WaitForNetworkChannelOpen(bobChanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("alice didn't report channel: %v", err)
|
t.Fatalf("alice didn't report channel: %v", err)
|
||||||
|
@ -19,6 +19,8 @@ import (
|
|||||||
// testZeroConfChannelOpen tests that opening a zero-conf channel works and
|
// testZeroConfChannelOpen tests that opening a zero-conf channel works and
|
||||||
// sending payments also works.
|
// sending payments also works.
|
||||||
func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
||||||
|
ctxb := context.Background()
|
||||||
|
|
||||||
// Since option-scid-alias is opt-in, the provided harness nodes will
|
// Since option-scid-alias is opt-in, the provided harness nodes will
|
||||||
// not have the feature bit set. Also need to set anchors as those are
|
// not have the feature bit set. Also need to set anchors as those are
|
||||||
// default-off in itests.
|
// default-off in itests.
|
||||||
@ -44,7 +46,6 @@ func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Wait for both Bob and Carol to view the channel as active.
|
// Wait for both Bob and Carol to view the channel as active.
|
||||||
ctxb := context.Background()
|
|
||||||
err := net.Bob.WaitForNetworkChannelOpen(fundingPoint)
|
err := net.Bob.WaitForNetworkChannelOpen(fundingPoint)
|
||||||
require.NoError(t.t, err, "bob didn't report channel")
|
require.NoError(t.t, err, "bob didn't report channel")
|
||||||
err = carol.WaitForNetworkChannelOpen(fundingPoint)
|
err = carol.WaitForNetworkChannelOpen(fundingPoint)
|
||||||
@ -60,6 +61,12 @@ func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Ensure that both Carol and Dave are connected.
|
// Ensure that both Carol and Dave are connected.
|
||||||
net.EnsureConnected(t.t, carol, dave)
|
net.EnsureConnected(t.t, carol, dave)
|
||||||
|
|
||||||
|
// Setup a ChannelAcceptor for Dave.
|
||||||
|
ctxc, cancel := context.WithCancel(ctxb)
|
||||||
|
acceptStream, err := dave.ChannelAcceptor(ctxc)
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
go acceptChannel(t, true, acceptStream)
|
||||||
|
|
||||||
// Open a private zero-conf anchors channel of 1M satoshis.
|
// Open a private zero-conf anchors channel of 1M satoshis.
|
||||||
params := lntest.OpenChannelParams{
|
params := lntest.OpenChannelParams{
|
||||||
Amt: chanAmt,
|
Amt: chanAmt,
|
||||||
@ -69,6 +76,9 @@ func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
}
|
}
|
||||||
chanOpenUpdate := openChannelStream(t, net, carol, dave, params)
|
chanOpenUpdate := openChannelStream(t, net, carol, dave, params)
|
||||||
|
|
||||||
|
// Remove the ChannelAcceptor.
|
||||||
|
cancel()
|
||||||
|
|
||||||
// We should receive the OpenStatusUpdate_ChanOpen update without
|
// We should receive the OpenStatusUpdate_ChanOpen update without
|
||||||
// having to mine any blocks.
|
// having to mine any blocks.
|
||||||
fundingPoint2, err := net.WaitForChannelOpen(chanOpenUpdate)
|
fundingPoint2, err := net.WaitForChannelOpen(chanOpenUpdate)
|
||||||
@ -153,10 +163,19 @@ func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Give Eve some coins to fund the channel.
|
// Give Eve some coins to fund the channel.
|
||||||
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, eve)
|
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, eve)
|
||||||
|
|
||||||
|
// Setup a ChannelAcceptor.
|
||||||
|
ctxc, cancel = context.WithCancel(ctxb)
|
||||||
|
acceptStream, err = carol.ChannelAcceptor(ctxc)
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
go acceptChannel(t, true, acceptStream)
|
||||||
|
|
||||||
// We'll open a public zero-conf anchors channel of 1M satoshis.
|
// We'll open a public zero-conf anchors channel of 1M satoshis.
|
||||||
params.Private = false
|
params.Private = false
|
||||||
chanOpenUpdate2 := openChannelStream(t, net, eve, carol, params)
|
chanOpenUpdate2 := openChannelStream(t, net, eve, carol, params)
|
||||||
|
|
||||||
|
// Remove the ChannelAcceptor.
|
||||||
|
cancel()
|
||||||
|
|
||||||
// Wait to receive the OpenStatusUpdate_ChanOpen update.
|
// Wait to receive the OpenStatusUpdate_ChanOpen update.
|
||||||
fundingPoint3, err := net.WaitForChannelOpen(chanOpenUpdate2)
|
fundingPoint3, err := net.WaitForChannelOpen(chanOpenUpdate2)
|
||||||
require.NoError(t.t, err, "error while waiting for channel open")
|
require.NoError(t.t, err, "error while waiting for channel open")
|
||||||
@ -581,6 +600,12 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
err = dave.WaitForNetworkChannelOpen(fundingPoint)
|
err = dave.WaitForNetworkChannelOpen(fundingPoint)
|
||||||
require.NoError(t.t, err, "dave didn't report channel")
|
require.NoError(t.t, err, "dave didn't report channel")
|
||||||
|
|
||||||
|
// Setup a ChannelAcceptor for Dave.
|
||||||
|
ctxc, cancel := context.WithCancel(ctxb)
|
||||||
|
acceptStream, err := dave.ChannelAcceptor(ctxc)
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
go acceptChannel(t, zeroConf, acceptStream)
|
||||||
|
|
||||||
// Open a private channel, optionally specifying a channel-type.
|
// Open a private channel, optionally specifying a channel-type.
|
||||||
params := lntest.OpenChannelParams{
|
params := lntest.OpenChannelParams{
|
||||||
Amt: chanAmt,
|
Amt: chanAmt,
|
||||||
@ -592,6 +617,9 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
}
|
}
|
||||||
chanOpenUpdate := openChannelStream(t, net, carol, dave, params)
|
chanOpenUpdate := openChannelStream(t, net, carol, dave, params)
|
||||||
|
|
||||||
|
// Remove the ChannelAcceptor.
|
||||||
|
cancel()
|
||||||
|
|
||||||
if !zeroConf {
|
if !zeroConf {
|
||||||
// If this is not a zero-conf channel, mine a single block to
|
// If this is not a zero-conf channel, mine a single block to
|
||||||
// confirm the channel.
|
// confirm the channel.
|
||||||
|
@ -493,3 +493,21 @@ func getOutputIndex(t *harnessTest, miner *lntest.HarnessMiner,
|
|||||||
|
|
||||||
return p2trOutputIndex
|
return p2trOutputIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// acceptChannel is used to accept a single channel that comes across. This
|
||||||
|
// should be run in a goroutine and is used to test nodes with the zero-conf
|
||||||
|
// feature bit.
|
||||||
|
func acceptChannel(t *harnessTest, zeroConf bool,
|
||||||
|
stream lnrpc.Lightning_ChannelAcceptorClient) {
|
||||||
|
|
||||||
|
req, err := stream.Recv()
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
|
||||||
|
resp := &lnrpc.ChannelAcceptResponse{
|
||||||
|
Accept: true,
|
||||||
|
PendingChanId: req.PendingChanId,
|
||||||
|
ZeroConf: zeroConf,
|
||||||
|
}
|
||||||
|
err = stream.Send(resp)
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user