mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
itest: zero-conf, scid-alias channel-type integration tests
This commit is contained in:
parent
49dd4b9e34
commit
5e0a2d3f92
@ -447,6 +447,97 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
)
|
||||
},
|
||||
},
|
||||
|
||||
// Restore the backup from the on-disk file, using the RPC
|
||||
// interface, for zero-conf anchor channels.
|
||||
{
|
||||
name: "restore from backup file for zero-conf " +
|
||||
"anchors channel",
|
||||
initiator: true,
|
||||
private: false,
|
||||
commitmentType: lnrpc.CommitmentType_ANCHORS,
|
||||
zeroConf: true,
|
||||
restoreMethod: func(oldNode *lntest.HarnessNode,
|
||||
backupFilePath string,
|
||||
mnemonic []string) (nodeRestorer, error) {
|
||||
|
||||
// Read the entire Multi backup stored within
|
||||
// this node's channels.backup file.
|
||||
multi, err := ioutil.ReadFile(backupFilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Now that we have Dave's backup file, we'll
|
||||
// create a new nodeRestorer that we'll restore
|
||||
// using the on-disk channels.backup.
|
||||
return chanRestoreViaRPC(
|
||||
net, password, mnemonic, multi,
|
||||
oldNode,
|
||||
)
|
||||
},
|
||||
},
|
||||
|
||||
// Restore the backup from the on-disk file, using the RPC
|
||||
// interface for a zero-conf script-enforced leased channel.
|
||||
{
|
||||
name: "restore from backup file zero-conf " +
|
||||
"script-enforced leased channel",
|
||||
initiator: true,
|
||||
private: false,
|
||||
commitmentType: lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE,
|
||||
zeroConf: true,
|
||||
restoreMethod: func(oldNode *lntest.HarnessNode,
|
||||
backupFilePath string,
|
||||
mnemonic []string) (nodeRestorer, error) {
|
||||
|
||||
// Read the entire Multi backup stored within
|
||||
// this node's channel.backup file.
|
||||
multi, err := ioutil.ReadFile(backupFilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Now that we have Dave's backup file, we'll
|
||||
// create a new nodeRestorer that we'll restore
|
||||
// using the on-disk channel backup.
|
||||
return chanRestoreViaRPC(
|
||||
net, password, mnemonic, multi,
|
||||
oldNode,
|
||||
)
|
||||
},
|
||||
},
|
||||
|
||||
// Restore a zero-conf anchors channel that was force closed by
|
||||
// dave just before going offline.
|
||||
{
|
||||
name: "restore force closed from backup file " +
|
||||
"anchors w/ zero-conf",
|
||||
initiator: true,
|
||||
private: false,
|
||||
commitmentType: lnrpc.CommitmentType_ANCHORS,
|
||||
localForceClose: true,
|
||||
zeroConf: true,
|
||||
restoreMethod: func(oldNode *lntest.HarnessNode,
|
||||
backupFilePath string,
|
||||
mnemonic []string) (nodeRestorer, error) {
|
||||
|
||||
// Read the entire Multi backup stored within
|
||||
// this node's channel.backup file.
|
||||
multi, err := ioutil.ReadFile(backupFilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Now that we have Dave's backup file, we'll
|
||||
// create a new nodeRestorer that we'll restore
|
||||
// using the on-disk channel backup.
|
||||
return chanRestoreViaRPC(
|
||||
net, password, mnemonic, multi,
|
||||
oldNode,
|
||||
)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// TODO(roasbeef): online vs offline close?
|
||||
@ -861,6 +952,10 @@ type chanRestoreTestCase struct {
|
||||
restoreMethod func(oldNode *lntest.HarnessNode,
|
||||
backupFilePath string,
|
||||
mnemonic []string) (nodeRestorer, error)
|
||||
|
||||
// zeroConf denotes whether the opened channel is a zero-conf channel
|
||||
// or not.
|
||||
zeroConf bool
|
||||
}
|
||||
|
||||
// testChanRestoreScenario executes a chanRestoreTestCase from end to end,
|
||||
@ -886,6 +981,13 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
|
||||
nodeArgs = append(nodeArgs, args...)
|
||||
}
|
||||
|
||||
if testCase.zeroConf {
|
||||
nodeArgs = append(
|
||||
nodeArgs, "--protocol.option-scid-alias",
|
||||
"--protocol.zero-conf",
|
||||
)
|
||||
}
|
||||
|
||||
// First, we'll create a brand new node we'll use within the test. If
|
||||
// we have a custom backup file specified, then we'll also create that
|
||||
// for use.
|
||||
@ -971,14 +1073,16 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
|
||||
net, t, from, to, chanAmt, thawHeight, true,
|
||||
)
|
||||
}
|
||||
params := lntest.OpenChannelParams{
|
||||
Amt: chanAmt,
|
||||
PushAmt: pushAmt,
|
||||
Private: testCase.private,
|
||||
FundingShim: fundingShim,
|
||||
CommitmentType: testCase.commitmentType,
|
||||
ZeroConf: testCase.zeroConf,
|
||||
}
|
||||
chanPoint = openChannelAndAssert(
|
||||
t, net, from, to, lntest.OpenChannelParams{
|
||||
Amt: chanAmt,
|
||||
PushAmt: pushAmt,
|
||||
Private: testCase.private,
|
||||
FundingShim: fundingShim,
|
||||
CommitmentType: testCase.commitmentType,
|
||||
},
|
||||
t, net, from, to, params,
|
||||
)
|
||||
|
||||
// Wait for both sides to see the opened channel.
|
||||
|
@ -23,14 +23,15 @@ import (
|
||||
// case of anchor channels, the second-level spends can also be aggregated and
|
||||
// properly feebumped, so we'll check that as well.
|
||||
func testMultiHopHtlcAggregation(net *lntest.NetworkHarness, t *harnessTest,
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType,
|
||||
zeroConf bool) {
|
||||
|
||||
const finalCltvDelta = 40
|
||||
ctxb := context.Background()
|
||||
|
||||
// First, we'll create a three hop network: Alice -> Bob -> Carol.
|
||||
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||
t, net, alice, bob, false, c,
|
||||
t, net, alice, bob, false, c, zeroConf,
|
||||
)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
|
@ -20,7 +20,8 @@ import (
|
||||
// preimage via the witness beacon, we properly settle the HTLC on-chain using
|
||||
// the HTLC success transaction in order to ensure we don't lose any funds.
|
||||
func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType,
|
||||
zeroConf bool) {
|
||||
|
||||
ctxb := context.Background()
|
||||
|
||||
@ -28,7 +29,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
||||
// Carol refusing to actually settle or directly cancel any HTLC's
|
||||
// self.
|
||||
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||
t, net, alice, bob, false, c,
|
||||
t, net, alice, bob, false, c, zeroConf,
|
||||
)
|
||||
|
||||
// Clean up carol's node when the test finishes.
|
||||
|
@ -20,7 +20,8 @@ import (
|
||||
// canceled backwards. Once the timeout has been reached, then we should sweep
|
||||
// it on-chain, and cancel the HTLC backwards.
|
||||
func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType,
|
||||
zeroConf bool) {
|
||||
|
||||
ctxb := context.Background()
|
||||
|
||||
@ -28,7 +29,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
|
||||
// Carol refusing to actually settle or directly cancel any HTLC's
|
||||
// self.
|
||||
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||
t, net, alice, bob, true, c,
|
||||
t, net, alice, bob, true, c, zeroConf,
|
||||
)
|
||||
|
||||
// Clean up carol's node when the test finishes.
|
||||
|
@ -22,7 +22,8 @@ import (
|
||||
// extract the preimage from the sweep transaction, and finish settling the
|
||||
// HTLC backwards into the route.
|
||||
func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType,
|
||||
zeroConf bool) {
|
||||
|
||||
ctxb := context.Background()
|
||||
|
||||
@ -30,7 +31,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
||||
// Carol refusing to actually settle or directly cancel any HTLC's
|
||||
// self.
|
||||
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||
t, net, alice, bob, false, c,
|
||||
t, net, alice, bob, false, c, zeroConf,
|
||||
)
|
||||
|
||||
// Clean up carol's node when the test finishes.
|
||||
|
@ -20,7 +20,8 @@ import (
|
||||
// HTLC directly on-chain using the preimage in order to ensure that we don't
|
||||
// lose any funds.
|
||||
func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType,
|
||||
zeroConf bool) {
|
||||
|
||||
ctxb := context.Background()
|
||||
|
||||
@ -28,7 +29,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
||||
// Carol refusing to actually settle or directly cancel any HTLC's
|
||||
// self.
|
||||
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||
t, net, alice, bob, false, c,
|
||||
t, net, alice, bob, false, c, zeroConf,
|
||||
)
|
||||
|
||||
// Clean up carol's node when the test finishes.
|
||||
|
@ -19,7 +19,8 @@ import (
|
||||
// that's timed out. At this point, the node should timeout the HTLC using the
|
||||
// HTLC timeout transaction, then cancel it backwards as normal.
|
||||
func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||
t *harnessTest, alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
t *harnessTest, alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType,
|
||||
zeroConf bool) {
|
||||
|
||||
ctxb := context.Background()
|
||||
|
||||
@ -27,7 +28,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||
// Carol refusing to actually settle or directly cancel any HTLC's
|
||||
// self.
|
||||
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||
t, net, alice, bob, true, c,
|
||||
t, net, alice, bob, true, c, zeroConf,
|
||||
)
|
||||
|
||||
// Clean up carol's node when the test finishes.
|
||||
|
@ -21,7 +21,8 @@ import (
|
||||
// transaction once the timeout has expired. Once we sweep the transaction, we
|
||||
// should also cancel back the initial HTLC.
|
||||
func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||
t *harnessTest, alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
t *harnessTest, alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType,
|
||||
zeroConf bool) {
|
||||
|
||||
ctxb := context.Background()
|
||||
|
||||
@ -29,7 +30,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||
// Carol refusing to actually settle or directly cancel any HTLC's
|
||||
// self.
|
||||
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
|
||||
t, net, alice, bob, true, c,
|
||||
t, net, alice, bob, true, c, zeroConf,
|
||||
)
|
||||
|
||||
// Clean up carol's node when the test finishes.
|
||||
|
@ -19,7 +19,8 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
type testCase struct {
|
||||
name string
|
||||
test func(net *lntest.NetworkHarness, t *harnessTest, alice,
|
||||
bob *lntest.HarnessNode, c lnrpc.CommitmentType)
|
||||
bob *lntest.HarnessNode, c lnrpc.CommitmentType,
|
||||
zeroConf bool)
|
||||
}
|
||||
|
||||
subTests := []testCase{
|
||||
@ -68,20 +69,51 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
},
|
||||
}
|
||||
|
||||
commitTypes := []lnrpc.CommitmentType{
|
||||
lnrpc.CommitmentType_LEGACY,
|
||||
lnrpc.CommitmentType_ANCHORS,
|
||||
lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE,
|
||||
commitWithZeroConf := []struct {
|
||||
commitType lnrpc.CommitmentType
|
||||
zeroConf bool
|
||||
}{
|
||||
{
|
||||
commitType: lnrpc.CommitmentType_LEGACY,
|
||||
zeroConf: false,
|
||||
},
|
||||
{
|
||||
commitType: lnrpc.CommitmentType_ANCHORS,
|
||||
zeroConf: false,
|
||||
},
|
||||
{
|
||||
commitType: lnrpc.CommitmentType_ANCHORS,
|
||||
zeroConf: true,
|
||||
},
|
||||
{
|
||||
commitType: lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE,
|
||||
zeroConf: false,
|
||||
},
|
||||
{
|
||||
commitType: lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE,
|
||||
zeroConf: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, commitType := range commitTypes {
|
||||
commitType := commitType
|
||||
testName := fmt.Sprintf("committype=%v", commitType.String())
|
||||
for _, typeAndConf := range commitWithZeroConf {
|
||||
typeAndConf := typeAndConf
|
||||
testName := fmt.Sprintf(
|
||||
"committype=%v zeroconf=%v",
|
||||
typeAndConf.commitType.String(), typeAndConf.zeroConf,
|
||||
)
|
||||
|
||||
success := t.t.Run(testName, func(t *testing.T) {
|
||||
ht := newHarnessTest(t, net)
|
||||
|
||||
args := nodeArgsForCommitType(commitType)
|
||||
args := nodeArgsForCommitType(typeAndConf.commitType)
|
||||
|
||||
if typeAndConf.zeroConf {
|
||||
args = append(
|
||||
args, "--protocol.option-scid-alias",
|
||||
"--protocol.zero-conf",
|
||||
)
|
||||
}
|
||||
|
||||
alice := net.NewNode(t, "Alice", args)
|
||||
defer shutdownAndAssert(net, ht, alice)
|
||||
|
||||
@ -107,7 +139,11 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
// static fee estimate.
|
||||
net.SetFeeEstimate(12500)
|
||||
|
||||
subTest.test(net, ht, alice, bob, commitType)
|
||||
subTest.test(
|
||||
net, ht, alice, bob,
|
||||
typeAndConf.commitType,
|
||||
typeAndConf.zeroConf,
|
||||
)
|
||||
})
|
||||
if !success {
|
||||
return
|
||||
@ -204,7 +240,8 @@ func checkPaymentStatus(node *lntest.HarnessNode, preimage lntypes.Preimage,
|
||||
}
|
||||
|
||||
func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
||||
alice, bob *lntest.HarnessNode, carolHodl bool, c lnrpc.CommitmentType) (
|
||||
alice, bob *lntest.HarnessNode, carolHodl bool, c lnrpc.CommitmentType,
|
||||
zeroConf bool) (
|
||||
*lnrpc.ChannelPoint, *lnrpc.ChannelPoint, *lntest.HarnessNode) {
|
||||
|
||||
net.EnsureConnected(t.t, alice, bob)
|
||||
@ -234,6 +271,7 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
||||
Amt: chanAmt,
|
||||
CommitmentType: c,
|
||||
FundingShim: aliceFundingShim,
|
||||
ZeroConf: zeroConf,
|
||||
},
|
||||
)
|
||||
|
||||
@ -254,6 +292,14 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
||||
if carolHodl {
|
||||
carolFlags = append(carolFlags, "--hodl.exit-settle")
|
||||
}
|
||||
|
||||
if zeroConf {
|
||||
carolFlags = append(
|
||||
carolFlags, "--protocol.option-scid-alias",
|
||||
"--protocol.zero-conf",
|
||||
)
|
||||
}
|
||||
|
||||
carol := net.NewNode(t.t, "Carol", carolFlags)
|
||||
|
||||
net.ConnectNodes(t.t, bob, carol)
|
||||
@ -280,6 +326,7 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
||||
Amt: chanAmt,
|
||||
CommitmentType: c,
|
||||
FundingShim: bobFundingShim,
|
||||
ZeroConf: zeroConf,
|
||||
},
|
||||
)
|
||||
err = bob.WaitForNetworkChannelOpen(bobChanPoint)
|
||||
|
@ -407,4 +407,20 @@ var allTestCases = []*testCase{
|
||||
name: "resolution handoff",
|
||||
test: testResHandoff,
|
||||
},
|
||||
{
|
||||
name: "zero conf channel open",
|
||||
test: testZeroConfChannelOpen,
|
||||
},
|
||||
{
|
||||
name: "option scid alias",
|
||||
test: testOptionScidAlias,
|
||||
},
|
||||
{
|
||||
name: "scid alias channel update",
|
||||
test: testUpdateChannelPolicyScidAlias,
|
||||
},
|
||||
{
|
||||
name: "scid alias upgrade",
|
||||
test: testOptionScidUpgrade,
|
||||
},
|
||||
}
|
||||
|
1042
lntest/itest/lnd_zero_conf_test.go
Normal file
1042
lntest/itest/lnd_zero_conf_test.go
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user