mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01: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:
|
||||
// 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
|
||||
if testCase.commitmentType == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
|
||||
_, minerHeight, err := net.Miner.Client.GetBestBlock()
|
||||
@ -1085,6 +1097,11 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
|
||||
t, net, from, to, params,
|
||||
)
|
||||
|
||||
// Remove the ChannelAcceptor.
|
||||
if testCase.zeroConf {
|
||||
cancel()
|
||||
}
|
||||
|
||||
// Wait for both sides to see the opened channel.
|
||||
err = dave.WaitForNetworkChannelOpen(chanPoint)
|
||||
if err != nil {
|
||||
|
@ -265,6 +265,23 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
||||
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(
|
||||
t, net, alice, bob,
|
||||
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)
|
||||
if err != nil {
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
||||
// 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(
|
||||
t, net, bob, carol,
|
||||
lntest.OpenChannelParams{
|
||||
@ -329,6 +361,12 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
||||
ZeroConf: zeroConf,
|
||||
},
|
||||
)
|
||||
|
||||
// Remove the ChannelAcceptor for Carol.
|
||||
if zeroConf {
|
||||
cancel()
|
||||
}
|
||||
|
||||
err = bob.WaitForNetworkChannelOpen(bobChanPoint)
|
||||
if err != nil {
|
||||
t.Fatalf("alice didn't report channel: %v", err)
|
||||
|
@ -19,6 +19,8 @@ import (
|
||||
// testZeroConfChannelOpen tests that opening a zero-conf channel works and
|
||||
// sending payments also works.
|
||||
func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
ctxb := context.Background()
|
||||
|
||||
// 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
|
||||
// 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.
|
||||
ctxb := context.Background()
|
||||
err := net.Bob.WaitForNetworkChannelOpen(fundingPoint)
|
||||
require.NoError(t.t, err, "bob didn't report channel")
|
||||
err = carol.WaitForNetworkChannelOpen(fundingPoint)
|
||||
@ -60,6 +61,12 @@ func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
// Ensure that both Carol and Dave are connected.
|
||||
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.
|
||||
params := lntest.OpenChannelParams{
|
||||
Amt: chanAmt,
|
||||
@ -69,6 +76,9 @@ func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
}
|
||||
chanOpenUpdate := openChannelStream(t, net, carol, dave, params)
|
||||
|
||||
// Remove the ChannelAcceptor.
|
||||
cancel()
|
||||
|
||||
// We should receive the OpenStatusUpdate_ChanOpen update without
|
||||
// having to mine any blocks.
|
||||
fundingPoint2, err := net.WaitForChannelOpen(chanOpenUpdate)
|
||||
@ -153,10 +163,19 @@ func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
// Give Eve some coins to fund the channel.
|
||||
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.
|
||||
params.Private = false
|
||||
chanOpenUpdate2 := openChannelStream(t, net, eve, carol, params)
|
||||
|
||||
// Remove the ChannelAcceptor.
|
||||
cancel()
|
||||
|
||||
// Wait to receive the OpenStatusUpdate_ChanOpen update.
|
||||
fundingPoint3, err := net.WaitForChannelOpen(chanOpenUpdate2)
|
||||
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)
|
||||
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.
|
||||
params := lntest.OpenChannelParams{
|
||||
Amt: chanAmt,
|
||||
@ -592,6 +617,9 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
|
||||
}
|
||||
chanOpenUpdate := openChannelStream(t, net, carol, dave, params)
|
||||
|
||||
// Remove the ChannelAcceptor.
|
||||
cancel()
|
||||
|
||||
if !zeroConf {
|
||||
// If this is not a zero-conf channel, mine a single block to
|
||||
// confirm the channel.
|
||||
|
@ -493,3 +493,21 @@ func getOutputIndex(t *harnessTest, miner *lntest.HarnessMiner,
|
||||
|
||||
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…
Reference in New Issue
Block a user