Skip to content

Commit

Permalink
itest: fix flake in update_pending_open_channels
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Nov 20, 2024
1 parent ef62625 commit 2c92455
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
8 changes: 6 additions & 2 deletions itest/list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,12 @@ var allTestCases = []*lntest.TestCase{
TestFunc: testChannelUtxoSelection,
},
{
Name: "update pending open channels",
TestFunc: testUpdateOnPendingOpenChannels,
Name: "update pending open channels on funder side",
TestFunc: testUpdateOnFunderPendingOpenChannels,
},
{
Name: "update pending open channels on fundee side",
TestFunc: testUpdateOnFundeePendingOpenChannels,
},
{
Name: "blinded payment htlc re-forward",
Expand Down
30 changes: 6 additions & 24 deletions itest/lnd_open_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package itest
import (
"fmt"
"strings"
"testing"

"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
Expand Down Expand Up @@ -486,27 +485,6 @@ func runBasicChannelCreationAndUpdates(ht *lntest.HarnessTest,
)
}

// testUpdateOnPendingOpenChannels checks that `update_add_htlc` followed by
// `channel_ready` is properly handled. In specific, when a node is in a state
// that it's still processing a remote `channel_ready` message, meanwhile an
// `update_add_htlc` is received, this HTLC message is cached and settled once
// processing `channel_ready` is complete.
func testUpdateOnPendingOpenChannels(ht *lntest.HarnessTest) {
// Test funder's behavior. Funder sees the channel pending, but fundee
// sees it active and sends an HTLC.
ht.Run("pending on funder side", func(t *testing.T) {
st := ht.Subtest(t)
testUpdateOnFunderPendingOpenChannels(st)
})

// Test fundee's behavior. Fundee sees the channel pending, but funder
// sees it active and sends an HTLC.
ht.Run("pending on fundee side", func(t *testing.T) {
st := ht.Subtest(t)
testUpdateOnFundeePendingOpenChannels(st)
})
}

// testUpdateOnFunderPendingOpenChannels checks that when the fundee sends an
// `update_add_htlc` followed by `channel_ready` while the funder is still
// processing the fundee's `channel_ready`, the HTLC will be cached and
Expand All @@ -530,7 +508,8 @@ func testUpdateOnFunderPendingOpenChannels(ht *lntest.HarnessTest) {
Amt: funding.MaxBtcFundingAmount,
PushAmt: funding.MaxBtcFundingAmount / 2,
}
ht.OpenChannelAssertPending(alice, bob, params)
pending := ht.OpenChannelAssertPending(alice, bob, params)
chanPoint := lntest.ChanPointFromPendingUpdate(pending)

// Alice and Bob should both consider the channel pending open.
ht.AssertNumPendingOpenChannels(alice, 1)
Expand All @@ -548,6 +527,7 @@ func testUpdateOnFunderPendingOpenChannels(ht *lntest.HarnessTest) {
// Bob will consider the channel open as there's no wait time to send
// and receive Alice's channel_ready message.
ht.AssertNumPendingOpenChannels(bob, 0)
ht.AssertChannelInGraph(bob, chanPoint)

// Alice and Bob now have different view of the channel. For Bob,
// since the channel_ready messages are processed, he will have a
Expand Down Expand Up @@ -604,7 +584,8 @@ func testUpdateOnFundeePendingOpenChannels(ht *lntest.HarnessTest) {
params := lntest.OpenChannelParams{
Amt: funding.MaxBtcFundingAmount,
}
ht.OpenChannelAssertPending(alice, bob, params)
pending := ht.OpenChannelAssertPending(alice, bob, params)
chanPoint := lntest.ChanPointFromPendingUpdate(pending)

// Alice and Bob should both consider the channel pending open.
ht.AssertNumPendingOpenChannels(alice, 1)
Expand All @@ -616,6 +597,7 @@ func testUpdateOnFundeePendingOpenChannels(ht *lntest.HarnessTest) {
// Alice will consider the channel open as there's no wait time to send
// and receive Bob's channel_ready message.
ht.AssertNumPendingOpenChannels(alice, 0)
ht.AssertChannelInGraph(alice, chanPoint)

// TODO(yy): we've prematurely marked the channel as open before
// processing channel ready messages. We need to mark it as open after
Expand Down

0 comments on commit 2c92455

Please sign in to comment.