mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 14:40:30 +01:00
itest: fix channel open and close ntfn test
Because we now get one more update per channel when closing it, we need to update our test that looks at the close notifications sent by the SubscribeChannelEvent RPC.
This commit is contained in:
parent
bb4c754504
commit
f7943448b9
2 changed files with 48 additions and 32 deletions
|
@ -1486,6 +1486,7 @@ func verifyCloseUpdate(chanUpdate *lnrpc.ChannelEventUpdate,
|
||||||
lnrpc.ChannelEventUpdate_INACTIVE_CHANNEL,
|
lnrpc.ChannelEventUpdate_INACTIVE_CHANNEL,
|
||||||
chanUpdate.Type)
|
chanUpdate.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *lnrpc.ChannelEventUpdate_ClosedChannel:
|
case *lnrpc.ChannelEventUpdate_ClosedChannel:
|
||||||
if chanUpdate.Type !=
|
if chanUpdate.Type !=
|
||||||
lnrpc.ChannelEventUpdate_CLOSED_CHANNEL {
|
lnrpc.ChannelEventUpdate_CLOSED_CHANNEL {
|
||||||
|
@ -1507,6 +1508,13 @@ func verifyCloseUpdate(chanUpdate *lnrpc.ChannelEventUpdate,
|
||||||
update.ClosedChannel.CloseInitiator)
|
update.ClosedChannel.CloseInitiator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case *lnrpc.ChannelEventUpdate_FullyResolvedChannel:
|
||||||
|
if chanUpdate.Type != lnrpc.ChannelEventUpdate_FULLY_RESOLVED_CHANNEL {
|
||||||
|
return fmt.Errorf("update type mismatch: expected %v, got %v",
|
||||||
|
lnrpc.ChannelEventUpdate_FULLY_RESOLVED_CHANNEL,
|
||||||
|
chanUpdate.Type)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("channel update channel of wrong type, "+
|
return fmt.Errorf("channel update channel of wrong type, "+
|
||||||
"expected closed channel, got %T",
|
"expected closed channel, got %T",
|
||||||
|
|
|
@ -276,8 +276,8 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe
|
||||||
aliceChanSub := subscribeChannelNotifications(ctxb, t, net.Alice)
|
aliceChanSub := subscribeChannelNotifications(ctxb, t, net.Alice)
|
||||||
defer close(aliceChanSub.quit)
|
defer close(aliceChanSub.quit)
|
||||||
|
|
||||||
// Open the channel between Alice and Bob, asserting that the
|
// Open the channels between Alice and Bob, asserting that the channels
|
||||||
// channel has been properly open on-chain.
|
// have been properly opened on-chain.
|
||||||
chanPoints := make([]*lnrpc.ChannelPoint, numChannels)
|
chanPoints := make([]*lnrpc.ChannelPoint, numChannels)
|
||||||
for i := 0; i < numChannels; i++ {
|
for i := 0; i < numChannels; i++ {
|
||||||
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
|
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
|
||||||
|
@ -291,11 +291,10 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe
|
||||||
|
|
||||||
// Since each of the channels just became open, Bob and Alice should
|
// Since each of the channels just became open, Bob and Alice should
|
||||||
// each receive an open and an active notification for each channel.
|
// each receive an open and an active notification for each channel.
|
||||||
var numChannelUpds int
|
const numExpectedOpenUpdates = 3 * numChannels
|
||||||
const totalNtfns = 3 * numChannels
|
|
||||||
verifyOpenUpdatesReceived := func(sub channelSubscription) error {
|
verifyOpenUpdatesReceived := func(sub channelSubscription) error {
|
||||||
numChannelUpds = 0
|
numChannelUpds := 0
|
||||||
for numChannelUpds < totalNtfns {
|
for numChannelUpds < numExpectedOpenUpdates {
|
||||||
select {
|
select {
|
||||||
case update := <-sub.updateChan:
|
case update := <-sub.updateChan:
|
||||||
switch update.Type {
|
switch update.Type {
|
||||||
|
@ -327,30 +326,32 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe
|
||||||
update.Type)
|
update.Type)
|
||||||
}
|
}
|
||||||
numChannelUpds++
|
numChannelUpds++
|
||||||
|
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
return fmt.Errorf("timeout waiting for channel "+
|
return fmt.Errorf("timeout waiting for channel "+
|
||||||
"notifications, only received %d/%d "+
|
"notifications, only received %d/%d "+
|
||||||
"chanupds", numChannelUpds,
|
"chanupds", numChannelUpds,
|
||||||
totalNtfns)
|
numExpectedOpenUpdates)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := verifyOpenUpdatesReceived(bobChanSub); err != nil {
|
require.NoError(
|
||||||
t.Fatalf("error verifying open updates: %v", err)
|
t.t, verifyOpenUpdatesReceived(bobChanSub), "bob open channels",
|
||||||
}
|
)
|
||||||
if err := verifyOpenUpdatesReceived(aliceChanSub); err != nil {
|
require.NoError(
|
||||||
t.Fatalf("error verifying open updates: %v", err)
|
t.t, verifyOpenUpdatesReceived(aliceChanSub), "alice open "+
|
||||||
}
|
"channels",
|
||||||
|
)
|
||||||
|
|
||||||
// Close the channel between Alice and Bob, asserting that the channel
|
// Close the channels between Alice and Bob, asserting that the channels
|
||||||
// has been properly closed on-chain.
|
// have been properly closed on-chain.
|
||||||
for i, chanPoint := range chanPoints {
|
for i, chanPoint := range chanPoints {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), defaultTimeout)
|
ctx, _ := context.WithTimeout(context.Background(), defaultTimeout)
|
||||||
|
|
||||||
// Force close half of the channels.
|
// Force close the first of the two channels.
|
||||||
force := i%2 == 0
|
force := i%2 == 0
|
||||||
closeChannelAndAssert(ctx, t, net, net.Alice, chanPoint, force)
|
closeChannelAndAssert(ctx, t, net, net.Alice, chanPoint, force)
|
||||||
if force {
|
if force {
|
||||||
|
@ -360,20 +361,21 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe
|
||||||
|
|
||||||
// verifyCloseUpdatesReceived is used to verify that Alice and Bob
|
// verifyCloseUpdatesReceived is used to verify that Alice and Bob
|
||||||
// receive the correct channel updates in order.
|
// receive the correct channel updates in order.
|
||||||
|
const numExpectedCloseUpdates = 3 * numChannels
|
||||||
verifyCloseUpdatesReceived := func(sub channelSubscription,
|
verifyCloseUpdatesReceived := func(sub channelSubscription,
|
||||||
forceType lnrpc.ChannelCloseSummary_ClosureType,
|
forceType lnrpc.ChannelCloseSummary_ClosureType,
|
||||||
closeInitiator lnrpc.Initiator) error {
|
closeInitiator lnrpc.Initiator) error {
|
||||||
|
|
||||||
// Ensure one inactive and one closed notification is received for each
|
// Ensure one inactive and one closed notification is received
|
||||||
// closed channel.
|
// for each closed channel.
|
||||||
numChannelUpds := 0
|
numChannelUpds := 0
|
||||||
for numChannelUpds < 2*numChannels {
|
for numChannelUpds < numExpectedCloseUpdates {
|
||||||
expectedCloseType := lnrpc.ChannelCloseSummary_COOPERATIVE_CLOSE
|
expectedCloseType := lnrpc.ChannelCloseSummary_COOPERATIVE_CLOSE
|
||||||
|
|
||||||
// Every other channel should be force closed. If this
|
// Every other channel should be force closed. If this
|
||||||
// channel was force closed, set the expected close type
|
// channel was force closed, set the expected close type
|
||||||
// the the type passed in.
|
// to the type passed in.
|
||||||
force := (numChannelUpds/2)%2 == 0
|
force := (numChannelUpds/3)%2 == 0
|
||||||
if force {
|
if force {
|
||||||
expectedCloseType = forceType
|
expectedCloseType = forceType
|
||||||
}
|
}
|
||||||
|
@ -389,13 +391,15 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe
|
||||||
}
|
}
|
||||||
|
|
||||||
numChannelUpds++
|
numChannelUpds++
|
||||||
|
|
||||||
case err := <-sub.errChan:
|
case err := <-sub.errChan:
|
||||||
return err
|
return err
|
||||||
|
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
return fmt.Errorf("timeout waiting "+
|
return fmt.Errorf("timeout waiting "+
|
||||||
"for channel notifications, only "+
|
"for channel notifications, only "+
|
||||||
"received %d/%d chanupds",
|
"received %d/%d chanupds",
|
||||||
numChannelUpds, 2*numChannels)
|
numChannelUpds, numChannelUpds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,19 +410,23 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe
|
||||||
// receive a remote force close notification for force closed channels.
|
// receive a remote force close notification for force closed channels.
|
||||||
// All channels (cooperatively and force closed) should have a remote
|
// All channels (cooperatively and force closed) should have a remote
|
||||||
// close initiator because Alice closed the channels.
|
// close initiator because Alice closed the channels.
|
||||||
if err := verifyCloseUpdatesReceived(bobChanSub,
|
require.NoError(
|
||||||
lnrpc.ChannelCloseSummary_REMOTE_FORCE_CLOSE,
|
t.t, verifyCloseUpdatesReceived(
|
||||||
lnrpc.Initiator_INITIATOR_REMOTE); err != nil {
|
bobChanSub,
|
||||||
t.Fatalf("errored verifying close updates: %v", err)
|
lnrpc.ChannelCloseSummary_REMOTE_FORCE_CLOSE,
|
||||||
}
|
lnrpc.Initiator_INITIATOR_REMOTE,
|
||||||
|
), "verifying bob close updates",
|
||||||
|
)
|
||||||
|
|
||||||
// Verify Alice receives all closed channel notifications. She should
|
// Verify Alice receives all closed channel notifications. She should
|
||||||
// receive a remote force close notification for force closed channels.
|
// receive a remote force close notification for force closed channels.
|
||||||
// All channels (cooperatively and force closed) should have a local
|
// All channels (cooperatively and force closed) should have a local
|
||||||
// close initiator because Alice closed the channels.
|
// close initiator because Alice closed the channels.
|
||||||
if err := verifyCloseUpdatesReceived(aliceChanSub,
|
require.NoError(
|
||||||
lnrpc.ChannelCloseSummary_LOCAL_FORCE_CLOSE,
|
t.t, verifyCloseUpdatesReceived(
|
||||||
lnrpc.Initiator_INITIATOR_LOCAL); err != nil {
|
aliceChanSub,
|
||||||
t.Fatalf("errored verifying close updates: %v", err)
|
lnrpc.ChannelCloseSummary_LOCAL_FORCE_CLOSE,
|
||||||
}
|
lnrpc.Initiator_INITIATOR_LOCAL,
|
||||||
|
), "verifying alice close updates",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue