lntest: replace commitType type with rpc alternative
This commit is contained in:
1 parent
ad758d8499
commit
449f207217
15 files changed
+96
-132
No files matched your search
@@ -855,7 +855,10 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
"--maxbackoff=1s",
|
"--maxbackoff=1s",
|
||||||
}
|
}
|
||||||
if testCase.anchorCommit {
|
if testCase.anchorCommit {
|
||||||
nodeArgs = append(nodeArgs, commitTypeAnchors.Args()...)
|
anchorNodeArgs := nodeArgsForCommitType(
|
||||||
|
lnrpc.CommitmentType_ANCHORS,
|
||||||
|
)
|
||||||
|
nodeArgs = append(nodeArgs, anchorNodeArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, we'll create a brand new node we'll use within the test. If
|
// First, we'll create a brand new node we'll use within the test. If
|
||||||
|
|||||||
@@ -81,10 +81,10 @@ func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// As this is a single funder channel, Alice's balance should be
|
// As this is a single funder channel, Alice's balance should be
|
||||||
// exactly 0.5 BTC since now state transitions have taken place yet.
|
// exactly 0.5 BTC since now state transitions have taken place yet.
|
||||||
checkChannelBalance(net.Alice, amount-cType.calcStaticFee(0), 0)
|
checkChannelBalance(net.Alice, amount-calcStaticFee(cType, 0), 0)
|
||||||
|
|
||||||
// Ensure Bob currently has no available balance within the channel.
|
// Ensure Bob currently has no available balance within the channel.
|
||||||
checkChannelBalance(net.Bob, 0, amount-cType.calcStaticFee(0))
|
checkChannelBalance(net.Bob, 0, amount-calcStaticFee(cType, 0))
|
||||||
|
|
||||||
// Finally close the channel between Alice and Bob, asserting that the
|
// Finally close the channel between Alice and Bob, asserting that the
|
||||||
// channel has been properly closed on-chain.
|
// channel has been properly closed on-chain.
|
||||||
@@ -174,11 +174,11 @@ func testChannelUnsettledBalance(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Check alice's channel balance, which should have zero remote and zero
|
// Check alice's channel balance, which should have zero remote and zero
|
||||||
// pending balance.
|
// pending balance.
|
||||||
checkChannelBalance(net.Alice, chanAmt-cType.calcStaticFee(0), 0, 0, 0)
|
checkChannelBalance(net.Alice, chanAmt-calcStaticFee(cType, 0), 0, 0, 0)
|
||||||
|
|
||||||
// Check carol's channel balance, which should have zero local and zero
|
// Check carol's channel balance, which should have zero local and zero
|
||||||
// pending balance.
|
// pending balance.
|
||||||
checkChannelBalance(carol, 0, chanAmt-cType.calcStaticFee(0), 0, 0)
|
checkChannelBalance(carol, 0, chanAmt-calcStaticFee(cType, 0), 0, 0)
|
||||||
|
|
||||||
// Channel should be ready for payments.
|
// Channel should be ready for payments.
|
||||||
const (
|
const (
|
||||||
@@ -258,7 +258,7 @@ func testChannelUnsettledBalance(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Check alice's channel balance, which should have a remote unsettled
|
// Check alice's channel balance, which should have a remote unsettled
|
||||||
// balance that equals to the amount of invoices * payAmt. The remote
|
// balance that equals to the amount of invoices * payAmt. The remote
|
||||||
// balance remains zero.
|
// balance remains zero.
|
||||||
aliceLocal := chanAmt - cType.calcStaticFee(0) - numInvoices*payAmt
|
aliceLocal := chanAmt - calcStaticFee(cType, 0) - numInvoices*payAmt
|
||||||
checkChannelBalance(net.Alice, aliceLocal, 0, 0, numInvoices*payAmt)
|
checkChannelBalance(net.Alice, aliceLocal, 0, 0, numInvoices*payAmt)
|
||||||
|
|
||||||
// Check carol's channel balance, which should have a local unsettled
|
// Check carol's channel balance, which should have a local unsettled
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func testCommitmentTransactionDeadline(net *lntest.NetworkHarness,
|
|||||||
setupNode := func(name string) *lntest.HarnessNode {
|
setupNode := func(name string) *lntest.HarnessNode {
|
||||||
// Create the node.
|
// Create the node.
|
||||||
args := []string{"--hodl.exit-settle"}
|
args := []string{"--hodl.exit-settle"}
|
||||||
args = append(args, commitTypeAnchors.Args()...)
|
args = append(args, nodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)...)
|
||||||
node := net.NewNode(t.t, name, args)
|
node := net.NewNode(t.t, name, args)
|
||||||
|
|
||||||
// Send some coins to the node.
|
// Send some coins to the node.
|
||||||
@@ -244,9 +244,9 @@ func calculateTxnsFeeRate(t *testing.T,
|
|||||||
func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
|
func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
|
||||||
// We'll test the scenario for some of the commitment types, to ensure
|
// We'll test the scenario for some of the commitment types, to ensure
|
||||||
// outputs can be swept.
|
// outputs can be swept.
|
||||||
commitTypes := []commitType{
|
commitTypes := []lnrpc.CommitmentType{
|
||||||
commitTypeLegacy,
|
lnrpc.CommitmentType_LEGACY,
|
||||||
commitTypeAnchors,
|
lnrpc.CommitmentType_ANCHORS,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, channelType := range commitTypes {
|
for _, channelType := range commitTypes {
|
||||||
@@ -261,7 +261,7 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
success := t.t.Run(testName, func(t *testing.T) {
|
success := t.t.Run(testName, func(t *testing.T) {
|
||||||
ht := newHarnessTest(t, net)
|
ht := newHarnessTest(t, net)
|
||||||
|
|
||||||
args := channelType.Args()
|
args := nodeArgsForCommitType(channelType)
|
||||||
alice := net.NewNode(ht.t, "Alice", args)
|
alice := net.NewNode(ht.t, "Alice", args)
|
||||||
defer shutdownAndAssert(net, ht, alice)
|
defer shutdownAndAssert(net, ht, alice)
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
alice, carol *lntest.HarnessNode, channelType commitType) {
|
alice, carol *lntest.HarnessNode, channelType lnrpc.CommitmentType) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
@@ -407,7 +407,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// sweep the HTLC second level output one block earlier (than the
|
// sweep the HTLC second level output one block earlier (than the
|
||||||
// nursery that waits an additional block, and handles non-anchor
|
// nursery that waits an additional block, and handles non-anchor
|
||||||
// channels). So we set a maturity height that is one less.
|
// channels). So we set a maturity height that is one less.
|
||||||
if channelType == commitTypeAnchors {
|
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||||
htlcCsvMaturityHeight = padCLTV(
|
htlcCsvMaturityHeight = padCLTV(
|
||||||
startHeight + defaultCLTV + defaultCSV,
|
startHeight + defaultCLTV + defaultCSV,
|
||||||
)
|
)
|
||||||
@@ -495,7 +495,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// also expect the anchor sweep tx to be in the mempool.
|
// also expect the anchor sweep tx to be in the mempool.
|
||||||
expectedTxes := 1
|
expectedTxes := 1
|
||||||
expectedFeeRate := commitFeeRate
|
expectedFeeRate := commitFeeRate
|
||||||
if channelType == commitTypeAnchors {
|
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 2
|
expectedTxes = 2
|
||||||
expectedFeeRate = actualFeeRate
|
expectedFeeRate = actualFeeRate
|
||||||
}
|
}
|
||||||
@@ -528,7 +528,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
|
|
||||||
// If we expect anchors, add alice's anchor to our expected set of
|
// If we expect anchors, add alice's anchor to our expected set of
|
||||||
// reports.
|
// reports.
|
||||||
if channelType == commitTypeAnchors {
|
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||||
aliceReports[aliceAnchor.OutPoint.String()] = &lnrpc.Resolution{
|
aliceReports[aliceAnchor.OutPoint.String()] = &lnrpc.Resolution{
|
||||||
ResolutionType: lnrpc.ResolutionType_ANCHOR,
|
ResolutionType: lnrpc.ResolutionType_ANCHOR,
|
||||||
Outcome: lnrpc.ResolutionOutcome_CLAIMED,
|
Outcome: lnrpc.ResolutionOutcome_CLAIMED,
|
||||||
@@ -585,7 +585,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
"limbo")
|
"limbo")
|
||||||
}
|
}
|
||||||
expectedRecoveredBalance := int64(0)
|
expectedRecoveredBalance := int64(0)
|
||||||
if channelType == commitTypeAnchors {
|
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedRecoveredBalance = anchorSize
|
expectedRecoveredBalance = anchorSize
|
||||||
}
|
}
|
||||||
if forceClose.RecoveredBalance != expectedRecoveredBalance {
|
if forceClose.RecoveredBalance != expectedRecoveredBalance {
|
||||||
@@ -634,7 +634,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
)
|
)
|
||||||
|
|
||||||
// If we have anchors, add an anchor resolution for carol.
|
// If we have anchors, add an anchor resolution for carol.
|
||||||
if channelType == commitTypeAnchors {
|
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||||
carolReports[carolAnchor.OutPoint.String()] = &lnrpc.Resolution{
|
carolReports[carolAnchor.OutPoint.String()] = &lnrpc.Resolution{
|
||||||
ResolutionType: lnrpc.ResolutionType_ANCHOR,
|
ResolutionType: lnrpc.ResolutionType_ANCHOR,
|
||||||
Outcome: lnrpc.ResolutionOutcome_CLAIMED,
|
Outcome: lnrpc.ResolutionOutcome_CLAIMED,
|
||||||
@@ -709,7 +709,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
"limbo")
|
"limbo")
|
||||||
}
|
}
|
||||||
expectedRecoveredBalance := int64(0)
|
expectedRecoveredBalance := int64(0)
|
||||||
if channelType == commitTypeAnchors {
|
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedRecoveredBalance = anchorSize
|
expectedRecoveredBalance = anchorSize
|
||||||
}
|
}
|
||||||
if forceClose.RecoveredBalance != expectedRecoveredBalance {
|
if forceClose.RecoveredBalance != expectedRecoveredBalance {
|
||||||
@@ -943,7 +943,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
expectedTxes = numInvoices
|
expectedTxes = numInvoices
|
||||||
|
|
||||||
// In case of anchors, the timeout txs will be aggregated into one.
|
// In case of anchors, the timeout txs will be aggregated into one.
|
||||||
if channelType == commitTypeAnchors {
|
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 1
|
expectedTxes = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -961,7 +961,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// this is an anchor channel, the transactions are aggregated by the
|
// this is an anchor channel, the transactions are aggregated by the
|
||||||
// sweeper into one.
|
// sweeper into one.
|
||||||
numInputs := 1
|
numInputs := 1
|
||||||
if channelType == commitTypeAnchors {
|
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||||
numInputs = numInvoices + 1
|
numInputs = numInvoices + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1089,7 +1089,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// Advance the chain until just before the 2nd-layer CSV delays expire.
|
// Advance the chain until just before the 2nd-layer CSV delays expire.
|
||||||
// For anchor channels thhis is one block earlier.
|
// For anchor channels thhis is one block earlier.
|
||||||
numBlocks := uint32(defaultCSV - 1)
|
numBlocks := uint32(defaultCSV - 1)
|
||||||
if channelType == commitTypeAnchors {
|
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||||
numBlocks = defaultCSV - 2
|
numBlocks = defaultCSV - 2
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1320,7 +1320,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
|
|
||||||
// In addition, if this is an anchor-enabled channel, further add the
|
// In addition, if this is an anchor-enabled channel, further add the
|
||||||
// anchor size.
|
// anchor size.
|
||||||
if channelType == commitTypeAnchors {
|
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||||
carolExpectedBalance += btcutil.Amount(anchorSize)
|
carolExpectedBalance += btcutil.Amount(anchorSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,19 +29,19 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Run through the test with combinations of all the different
|
// Run through the test with combinations of all the different
|
||||||
// commitment types.
|
// commitment types.
|
||||||
allTypes := []commitType{
|
allTypes := []lnrpc.CommitmentType{
|
||||||
commitTypeLegacy,
|
lnrpc.CommitmentType_LEGACY,
|
||||||
commitTypeTweakless,
|
lnrpc.CommitmentType_STATIC_REMOTE_KEY,
|
||||||
commitTypeAnchors,
|
lnrpc.CommitmentType_ANCHORS,
|
||||||
}
|
}
|
||||||
|
|
||||||
// testFunding is a function closure that takes Carol and Dave's
|
// testFunding is a function closure that takes Carol and Dave's
|
||||||
// commitment types and test the funding flow.
|
// commitment types and test the funding flow.
|
||||||
testFunding := func(carolCommitType, daveCommitType commitType) {
|
testFunding := func(carolCommitType, daveCommitType lnrpc.CommitmentType) {
|
||||||
// Based on the current tweak variable for Carol, we'll
|
// Based on the current tweak variable for Carol, we'll
|
||||||
// preferentially signal the legacy commitment format. We do
|
// preferentially signal the legacy commitment format. We do
|
||||||
// the same for Dave shortly below.
|
// the same for Dave shortly below.
|
||||||
carolArgs := carolCommitType.Args()
|
carolArgs := nodeArgsForCommitType(carolCommitType)
|
||||||
carol := net.NewNode(t.t, "Carol", carolArgs)
|
carol := net.NewNode(t.t, "Carol", carolArgs)
|
||||||
defer shutdownAndAssert(net, t, carol)
|
defer shutdownAndAssert(net, t, carol)
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// fund the channel.
|
// fund the channel.
|
||||||
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
|
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
|
||||||
|
|
||||||
daveArgs := daveCommitType.Args()
|
daveArgs := nodeArgsForCommitType(daveCommitType)
|
||||||
dave := net.NewNode(t.t, "Dave", daveArgs)
|
dave := net.NewNode(t.t, "Dave", daveArgs)
|
||||||
defer shutdownAndAssert(net, t, dave)
|
defer shutdownAndAssert(net, t, dave)
|
||||||
|
|
||||||
@@ -81,20 +81,20 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Dave supports anchors, type will be what
|
// Dave supports anchors, type will be what
|
||||||
// Carol supports.
|
// Carol supports.
|
||||||
case commitTypeAnchors:
|
case lnrpc.CommitmentType_ANCHORS:
|
||||||
|
|
||||||
// Dave only supports tweakless, channel will
|
// Dave only supports tweakless, channel will
|
||||||
// be downgraded to this type if Carol supports
|
// be downgraded to this type if Carol supports
|
||||||
// anchors.
|
// anchors.
|
||||||
case commitTypeTweakless:
|
case lnrpc.CommitmentType_STATIC_REMOTE_KEY:
|
||||||
if expType == commitTypeAnchors {
|
if expType == lnrpc.CommitmentType_ANCHORS {
|
||||||
expType = commitTypeTweakless
|
expType = lnrpc.CommitmentType_STATIC_REMOTE_KEY
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dave only supoprts legacy type, channel will
|
// Dave only supoprts legacy type, channel will
|
||||||
// be downgraded to this type.
|
// be downgraded to this type.
|
||||||
case commitTypeLegacy:
|
case lnrpc.CommitmentType_LEGACY:
|
||||||
expType = commitTypeLegacy
|
expType = lnrpc.CommitmentType_LEGACY
|
||||||
|
|
||||||
default:
|
default:
|
||||||
t.Fatalf("invalid commit type %v", daveCommitType)
|
t.Fatalf("invalid commit type %v", daveCommitType)
|
||||||
@@ -103,13 +103,13 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Check that the signalled type matches what we
|
// Check that the signalled type matches what we
|
||||||
// expect.
|
// expect.
|
||||||
switch {
|
switch {
|
||||||
case expType == commitTypeAnchors &&
|
case expType == lnrpc.CommitmentType_ANCHORS &&
|
||||||
chansCommitType == lnrpc.CommitmentType_ANCHORS:
|
chansCommitType == lnrpc.CommitmentType_ANCHORS:
|
||||||
|
|
||||||
case expType == commitTypeTweakless &&
|
case expType == lnrpc.CommitmentType_STATIC_REMOTE_KEY &&
|
||||||
chansCommitType == lnrpc.CommitmentType_STATIC_REMOTE_KEY:
|
chansCommitType == lnrpc.CommitmentType_STATIC_REMOTE_KEY:
|
||||||
|
|
||||||
case expType == commitTypeLegacy &&
|
case expType == lnrpc.CommitmentType_LEGACY &&
|
||||||
chansCommitType == lnrpc.CommitmentType_LEGACY:
|
chansCommitType == lnrpc.CommitmentType_LEGACY:
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -221,7 +221,7 @@ func basicChannelFundingTest(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
|
|
||||||
// With the channel open, ensure that the amount specified above has
|
// With the channel open, ensure that the amount specified above has
|
||||||
// properly been pushed to Bob.
|
// properly been pushed to Bob.
|
||||||
aliceLocalBalance := chanAmt - pushAmt - cType.calcStaticFee(0)
|
aliceLocalBalance := chanAmt - pushAmt - calcStaticFee(cType, 0)
|
||||||
checkChannelBalance(
|
checkChannelBalance(
|
||||||
alice, aliceChannelBalance, aliceLocalBalance, pushAmt,
|
alice, aliceChannelBalance, aliceLocalBalance, pushAmt,
|
||||||
)
|
)
|
||||||
@@ -342,8 +342,8 @@ func testUnconfirmedChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
//
|
//
|
||||||
// Note that atm we haven't obtained the chanPoint yet, so we use the
|
// Note that atm we haven't obtained the chanPoint yet, so we use the
|
||||||
// type directly.
|
// type directly.
|
||||||
cType := commitTypeTweakless
|
cType := lnrpc.CommitmentType_STATIC_REMOTE_KEY
|
||||||
carolLocalBalance := chanAmt - pushAmt - cType.calcStaticFee(0)
|
carolLocalBalance := chanAmt - pushAmt - calcStaticFee(cType, 0)
|
||||||
checkChannelBalance(carol, 0, 0, carolLocalBalance, pushAmt)
|
checkChannelBalance(carol, 0, 0, carolLocalBalance, pushAmt)
|
||||||
|
|
||||||
// For Alice, her local/remote balances should be zero, and the
|
// For Alice, her local/remote balances should be zero, and the
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to get channel type: %v", err)
|
t.Fatalf("unable to get channel type: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
commitFee := cType.calcStaticFee(0)
|
commitFee := calcStaticFee(cType, 0)
|
||||||
assertBaseBalance := func() {
|
assertBaseBalance := func() {
|
||||||
// Alice has opened a channel with Bob with zero push amount, so
|
// Alice has opened a channel with Bob with zero push amount, so
|
||||||
// it's remote balance is zero.
|
// it's remote balance is zero.
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
// case of anchor channels, the second-level spends can also be aggregated and
|
// case of anchor channels, the second-level spends can also be aggregated and
|
||||||
// properly feebumped, so we'll check that as well.
|
// properly feebumped, so we'll check that as well.
|
||||||
func testMultiHopHtlcAggregation(net *lntest.NetworkHarness, t *harnessTest,
|
func testMultiHopHtlcAggregation(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
alice, bob *lntest.HarnessNode, c commitType) {
|
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||||
|
|
||||||
const finalCltvDelta = 40
|
const finalCltvDelta = 40
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
@@ -188,7 +188,7 @@ func testMultiHopHtlcAggregation(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// Bob's force close transaction should now be found in the mempool. If
|
// Bob's force close transaction should now be found in the mempool. If
|
||||||
// there are anchors, we also expect Bob's anchor sweep.
|
// there are anchors, we also expect Bob's anchor sweep.
|
||||||
expectedTxes := 1
|
expectedTxes := 1
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 2
|
expectedTxes = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@ func testMultiHopHtlcAggregation(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// one, the same is the case for the timeout transactions. In this case
|
// one, the same is the case for the timeout transactions. In this case
|
||||||
// Carol will also sweep her anchor output in a separate tx (since it
|
// Carol will also sweep her anchor output in a separate tx (since it
|
||||||
// will be low fee).
|
// will be low fee).
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 4
|
expectedTxes = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +298,7 @@ func testMultiHopHtlcAggregation(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// In case of anchor we expect all the timeout and success second
|
// In case of anchor we expect all the timeout and success second
|
||||||
// levels to be aggregated into one tx. For earlier channel types, they
|
// levels to be aggregated into one tx. For earlier channel types, they
|
||||||
// will be separate transactions.
|
// will be separate transactions.
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
require.Len(t.t, timeoutTxs, 1)
|
require.Len(t.t, timeoutTxs, 1)
|
||||||
require.Len(t.t, successTxs, 1)
|
require.Len(t.t, successTxs, 1)
|
||||||
} else {
|
} else {
|
||||||
@@ -374,7 +374,7 @@ func testMultiHopHtlcAggregation(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
|
|
||||||
// Mining one additional block, Bob's second level tx is mature, and he
|
// Mining one additional block, Bob's second level tx is mature, and he
|
||||||
// can sweep the output.
|
// can sweep the output.
|
||||||
case c == commitTypeAnchors:
|
case c == lnrpc.CommitmentType_ANCHORS:
|
||||||
_ = mineBlocks(t, net, 1, 1)
|
_ = mineBlocks(t, net, 1, 1)
|
||||||
|
|
||||||
// In case this is a non-anchor channel type, we must mine 2 blocks, as
|
// In case this is a non-anchor channel type, we must mine 2 blocks, as
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
// preimage via the witness beacon, we properly settle the HTLC on-chain using
|
// 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.
|
// the HTLC success transaction in order to ensure we don't lose any funds.
|
||||||
func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
alice, bob *lntest.HarnessNode, c commitType) {
|
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
@@ -86,13 +86,14 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// At this point, Bob decides that he wants to exit the channel
|
// At this point, Bob decides that he wants to exit the channel
|
||||||
// immediately, so he force closes his commitment transaction.
|
// immediately, so he force closes his commitment transaction.
|
||||||
bobForceClose := closeChannelAndAssertType(
|
bobForceClose := closeChannelAndAssertType(
|
||||||
t, net, bob, aliceChanPoint, c == commitTypeAnchors, true,
|
t, net, bob, aliceChanPoint,
|
||||||
|
c == lnrpc.CommitmentType_ANCHORS, true,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Alice will sweep her commitment output immediately. If there are
|
// Alice will sweep her commitment output immediately. If there are
|
||||||
// anchors, Alice will also sweep hers.
|
// anchors, Alice will also sweep hers.
|
||||||
expectedTxes := 1
|
expectedTxes := 1
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 2
|
expectedTxes = 2
|
||||||
}
|
}
|
||||||
_, err = waitForNTxsInMempool(
|
_, err = waitForNTxsInMempool(
|
||||||
@@ -161,7 +162,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// If there are anchors on the commitment, Bob will also sweep his
|
// If there are anchors on the commitment, Bob will also sweep his
|
||||||
// anchor.
|
// anchor.
|
||||||
expectedTxes = 2
|
expectedTxes = 2
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 3
|
expectedTxes = 3
|
||||||
}
|
}
|
||||||
txes, err := getNTxsFromMempool(
|
txes, err := getNTxsFromMempool(
|
||||||
@@ -188,7 +189,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// If this is a channel of the anchor type, we will subtract one block
|
// If this is a channel of the anchor type, we will subtract one block
|
||||||
// from the default CSV, as the Sweeper will handle the input, and the Sweeper
|
// from the default CSV, as the Sweeper will handle the input, and the Sweeper
|
||||||
// sweeps the input as soon as the lock expires.
|
// sweeps the input as soon as the lock expires.
|
||||||
case commitTypeAnchors:
|
case lnrpc.CommitmentType_ANCHORS:
|
||||||
secondLevelMaturity = defaultCSV - 1
|
secondLevelMaturity = defaultCSV - 1
|
||||||
|
|
||||||
// For non-anchor channel types, the nursery will handle sweeping the
|
// For non-anchor channel types, the nursery will handle sweeping the
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import (
|
|||||||
// canceled backwards. Once the timeout has been reached, then we should sweep
|
// canceled backwards. Once the timeout has been reached, then we should sweep
|
||||||
// it on-chain, and cancel the HTLC backwards.
|
// it on-chain, and cancel the HTLC backwards.
|
||||||
func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
|
func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
alice, bob *lntest.HarnessNode, c commitType) {
|
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// Bob's force close transaction should now be found in the mempool. If
|
// Bob's force close transaction should now be found in the mempool. If
|
||||||
// there are anchors, we also expect Bob's anchor sweep.
|
// there are anchors, we also expect Bob's anchor sweep.
|
||||||
expectedTxes := 1
|
expectedTxes := 1
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 2
|
expectedTxes = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import (
|
|||||||
// extract the preimage from the sweep transaction, and finish settling the
|
// extract the preimage from the sweep transaction, and finish settling the
|
||||||
// HTLC backwards into the route.
|
// HTLC backwards into the route.
|
||||||
func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
alice, bob *lntest.HarnessNode, c commitType) {
|
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// transaction in order to go to the chain and sweep her HTLC. If there
|
// transaction in order to go to the chain and sweep her HTLC. If there
|
||||||
// are anchors, Carol also sweeps hers.
|
// are anchors, Carol also sweeps hers.
|
||||||
expectedTxes := 1
|
expectedTxes := 1
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 2
|
expectedTxes = 2
|
||||||
}
|
}
|
||||||
_, err = getNTxsFromMempool(
|
_, err = getNTxsFromMempool(
|
||||||
@@ -150,7 +150,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// and settle the HTLC back off-chain. Bob will also sweep his anchor,
|
// and settle the HTLC back off-chain. Bob will also sweep his anchor,
|
||||||
// if present.
|
// if present.
|
||||||
expectedTxes = 2
|
expectedTxes = 2
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 3
|
expectedTxes = 3
|
||||||
}
|
}
|
||||||
txes, err := getNTxsFromMempool(
|
txes, err := getNTxsFromMempool(
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
// HTLC directly on-chain using the preimage in order to ensure that we don't
|
// HTLC directly on-chain using the preimage in order to ensure that we don't
|
||||||
// lose any funds.
|
// lose any funds.
|
||||||
func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
alice, bob *lntest.HarnessNode, c commitType) {
|
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
@@ -86,7 +86,8 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
|||||||
// immediately force close the channel by broadcast her commitment
|
// immediately force close the channel by broadcast her commitment
|
||||||
// transaction.
|
// transaction.
|
||||||
aliceForceClose := closeChannelAndAssertType(
|
aliceForceClose := closeChannelAndAssertType(
|
||||||
t, net, alice, aliceChanPoint, c == commitTypeAnchors, true,
|
t, net, alice, aliceChanPoint,
|
||||||
|
c == lnrpc.CommitmentType_ANCHORS, true,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Wait for the channel to be marked pending force close.
|
// Wait for the channel to be marked pending force close.
|
||||||
@@ -96,7 +97,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
|||||||
// After closeChannelAndAssertType returns, it has mined a block so now
|
// After closeChannelAndAssertType returns, it has mined a block so now
|
||||||
// bob will attempt to redeem his anchor commitment (if the channel
|
// bob will attempt to redeem his anchor commitment (if the channel
|
||||||
// type is of that type).
|
// type is of that type).
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
_, err = waitForNTxsInMempool(
|
_, err = waitForNTxsInMempool(
|
||||||
net.Miner.Client, 1, minerMempoolTimeout,
|
net.Miner.Client, 1, minerMempoolTimeout,
|
||||||
)
|
)
|
||||||
@@ -146,7 +147,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
|||||||
require.NoError(t.t, err)
|
require.NoError(t.t, err)
|
||||||
|
|
||||||
expectedTxes := 1
|
expectedTxes := 1
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 2
|
expectedTxes = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +187,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
|||||||
// the output is not timelocked since Carol was the one force closing.
|
// the output is not timelocked since Carol was the one force closing.
|
||||||
// If there are anchors, Bob should also sweep his.
|
// If there are anchors, Bob should also sweep his.
|
||||||
expectedTxes = 2
|
expectedTxes = 2
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 3
|
expectedTxes = 3
|
||||||
}
|
}
|
||||||
txes, err := getNTxsFromMempool(
|
txes, err := getNTxsFromMempool(
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
"github.com/lightningnetwork/lnd/lntest"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
@@ -17,7 +18,7 @@ import (
|
|||||||
// that's timed out. At this point, the node should timeout the HTLC using the
|
// that's timed out. At this point, the node should timeout the HTLC using the
|
||||||
// HTLC timeout transaction, then cancel it backwards as normal.
|
// HTLC timeout transaction, then cancel it backwards as normal.
|
||||||
func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||||
t *harnessTest, alice, bob *lntest.HarnessNode, c commitType) {
|
t *harnessTest, alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
@@ -72,7 +73,8 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// force close the Bob -> Carol channel. This should trigger contract
|
// force close the Bob -> Carol channel. This should trigger contract
|
||||||
// resolution mode for both of them.
|
// resolution mode for both of them.
|
||||||
closeChannelAndAssertType(
|
closeChannelAndAssertType(
|
||||||
t, net, bob, bobChanPoint, c == commitTypeAnchors, true,
|
t, net, bob, bobChanPoint,
|
||||||
|
c == lnrpc.CommitmentType_ANCHORS, true,
|
||||||
)
|
)
|
||||||
|
|
||||||
// At this point, Bob should have a pending force close channel as he
|
// At this point, Bob should have a pending force close channel as he
|
||||||
@@ -93,7 +95,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// We'll mine defaultCSV blocks in order to generate the sweep
|
// We'll mine defaultCSV blocks in order to generate the sweep
|
||||||
// transaction of Bob's funding output. If there are anchors, mine
|
// transaction of Bob's funding output. If there are anchors, mine
|
||||||
// Carol's anchor sweep too.
|
// Carol's anchor sweep too.
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
_, err = waitForTxInMempool(net.Miner.Client, minerMempoolTimeout)
|
_, err = waitForTxInMempool(net.Miner.Client, minerMempoolTimeout)
|
||||||
require.NoError(t.t, err)
|
require.NoError(t.t, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
// transaction once the timeout has expired. Once we sweep the transaction, we
|
// transaction once the timeout has expired. Once we sweep the transaction, we
|
||||||
// should also cancel back the initial HTLC.
|
// should also cancel back the initial HTLC.
|
||||||
func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||||
t *harnessTest, alice, bob *lntest.HarnessNode, c commitType) {
|
t *harnessTest, alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
@@ -84,7 +84,8 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// expired HTLC on Carol's version of the commitment transaction. If
|
// expired HTLC on Carol's version of the commitment transaction. If
|
||||||
// Carol has an anchor, it will be swept too.
|
// Carol has an anchor, it will be swept too.
|
||||||
closeChannelAndAssertType(
|
closeChannelAndAssertType(
|
||||||
t, net, carol, bobChanPoint, c == commitTypeAnchors, true,
|
t, net, carol, bobChanPoint,
|
||||||
|
c == lnrpc.CommitmentType_ANCHORS, true,
|
||||||
)
|
)
|
||||||
|
|
||||||
// At this point, Bob should have a pending force close channel as
|
// At this point, Bob should have a pending force close channel as
|
||||||
@@ -95,7 +96,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
|||||||
// Bob can sweep his output immediately. If there is an anchor, Bob will
|
// Bob can sweep his output immediately. If there is an anchor, Bob will
|
||||||
// sweep that as well.
|
// sweep that as well.
|
||||||
expectedTxes := 1
|
expectedTxes := 1
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
expectedTxes = 2
|
expectedTxes = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
type testCase struct {
|
type testCase struct {
|
||||||
name string
|
name string
|
||||||
test func(net *lntest.NetworkHarness, t *harnessTest, alice,
|
test func(net *lntest.NetworkHarness, t *harnessTest, alice,
|
||||||
bob *lntest.HarnessNode, c commitType)
|
bob *lntest.HarnessNode, c lnrpc.CommitmentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
subTests := []testCase{
|
subTests := []testCase{
|
||||||
@@ -68,19 +68,19 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
commitTypes := []commitType{
|
commitTypes := []lnrpc.CommitmentType{
|
||||||
commitTypeLegacy,
|
lnrpc.CommitmentType_LEGACY,
|
||||||
commitTypeAnchors,
|
lnrpc.CommitmentType_ANCHORS,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, commitType := range commitTypes {
|
for _, commitType := range commitTypes {
|
||||||
|
commitType := commitType
|
||||||
testName := fmt.Sprintf("committype=%v", commitType.String())
|
testName := fmt.Sprintf("committype=%v", commitType.String())
|
||||||
|
|
||||||
commitType := commitType
|
|
||||||
success := t.t.Run(testName, func(t *testing.T) {
|
success := t.t.Run(testName, func(t *testing.T) {
|
||||||
ht := newHarnessTest(t, net)
|
ht := newHarnessTest(t, net)
|
||||||
|
|
||||||
args := commitType.Args()
|
args := nodeArgsForCommitType(commitType)
|
||||||
alice := net.NewNode(t, "Alice", args)
|
alice := net.NewNode(t, "Alice", args)
|
||||||
defer shutdownAndAssert(net, ht, alice)
|
defer shutdownAndAssert(net, ht, alice)
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ func checkPaymentStatus(node *lntest.HarnessNode, preimage lntypes.Preimage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
||||||
alice, bob *lntest.HarnessNode, carolHodl bool, c commitType) (
|
alice, bob *lntest.HarnessNode, carolHodl bool, c lnrpc.CommitmentType) (
|
||||||
*lnrpc.ChannelPoint, *lnrpc.ChannelPoint, *lntest.HarnessNode) {
|
*lnrpc.ChannelPoint, *lnrpc.ChannelPoint, *lntest.HarnessNode) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
@@ -243,7 +243,7 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
// Next, we'll create a new node "carol" and have Bob connect to her. If
|
// Next, we'll create a new node "carol" and have Bob connect to her. If
|
||||||
// the carolHodl flag is set, we'll make carol always hold onto the
|
// the carolHodl flag is set, we'll make carol always hold onto the
|
||||||
// HTLC, this way it'll force Bob to go to chain to resolve the HTLC.
|
// HTLC, this way it'll force Bob to go to chain to resolve the HTLC.
|
||||||
carolFlags := c.Args()
|
carolFlags := nodeArgsForCommitType(c)
|
||||||
if carolHodl {
|
if carolHodl {
|
||||||
carolFlags = append(carolFlags, "--hodl.exit-settle")
|
carolFlags = append(carolFlags, "--hodl.exit-settle")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ func testCPFP(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// wallet.
|
// wallet.
|
||||||
func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
|
func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
|
||||||
// Start two nodes supporting anchor channels.
|
// Start two nodes supporting anchor channels.
|
||||||
args := commitTypeAnchors.Args()
|
args := nodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)
|
||||||
alice := net.NewNode(t.t, "Alice", args)
|
alice := net.NewNode(t.t, "Alice", args)
|
||||||
defer shutdownAndAssert(net, t, alice)
|
defer shutdownAndAssert(net, t, alice)
|
||||||
|
|
||||||
|
|||||||
+11
-55
@@ -208,45 +208,15 @@ func getChanInfo(node *lntest.HarnessNode) (*lnrpc.Channel, error) {
|
|||||||
return channelInfo.Channels[0], nil
|
return channelInfo.Channels[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// commitType is a simple enum used to run though the basic funding flow with
|
// nodeArgsForCommitType returns the command line flag to supply to enable this
|
||||||
// different commitment formats.
|
// commitment type.
|
||||||
type commitType byte
|
func nodeArgsForCommitType(commitType lnrpc.CommitmentType) []string {
|
||||||
|
switch commitType {
|
||||||
const (
|
case lnrpc.CommitmentType_LEGACY:
|
||||||
// commitTypeLegacy is the old school commitment type.
|
|
||||||
commitTypeLegacy commitType = iota
|
|
||||||
|
|
||||||
// commiTypeTweakless is the commitment type where the remote key is
|
|
||||||
// static (non-tweaked).
|
|
||||||
commitTypeTweakless
|
|
||||||
|
|
||||||
// commitTypeAnchors is the kind of commitment that has extra outputs
|
|
||||||
// used for anchoring down to commitment using CPFP.
|
|
||||||
commitTypeAnchors
|
|
||||||
)
|
|
||||||
|
|
||||||
// String returns that name of the commitment type.
|
|
||||||
func (c commitType) String() string {
|
|
||||||
switch c {
|
|
||||||
case commitTypeLegacy:
|
|
||||||
return "legacy"
|
|
||||||
case commitTypeTweakless:
|
|
||||||
return "tweakless"
|
|
||||||
case commitTypeAnchors:
|
|
||||||
return "anchors"
|
|
||||||
default:
|
|
||||||
return "invalid"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Args returns the command line flag to supply to enable this commitment type.
|
|
||||||
func (c commitType) Args() []string {
|
|
||||||
switch c {
|
|
||||||
case commitTypeLegacy:
|
|
||||||
return []string{"--protocol.legacy.committweak"}
|
return []string{"--protocol.legacy.committweak"}
|
||||||
case commitTypeTweakless:
|
case lnrpc.CommitmentType_STATIC_REMOTE_KEY:
|
||||||
return []string{}
|
return []string{}
|
||||||
case commitTypeAnchors:
|
case lnrpc.CommitmentType_ANCHORS:
|
||||||
return []string{"--protocol.anchors"}
|
return []string{"--protocol.anchors"}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +226,7 @@ func (c commitType) Args() []string {
|
|||||||
// calcStaticFee calculates appropriate fees for commitment transactions. This
|
// calcStaticFee calculates appropriate fees for commitment transactions. This
|
||||||
// function provides a simple way to allow test balance assertions to take fee
|
// function provides a simple way to allow test balance assertions to take fee
|
||||||
// calculations into account.
|
// calculations into account.
|
||||||
func (c commitType) calcStaticFee(numHTLCs int) btcutil.Amount {
|
func calcStaticFee(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
|
||||||
const htlcWeight = input.HTLCWeight
|
const htlcWeight = input.HTLCWeight
|
||||||
var (
|
var (
|
||||||
feePerKw = chainfee.SatPerKVByte(50000).FeePerKWeight()
|
feePerKw = chainfee.SatPerKVByte(50000).FeePerKWeight()
|
||||||
@@ -268,7 +238,7 @@ func (c commitType) calcStaticFee(numHTLCs int) btcutil.Amount {
|
|||||||
// the value of the two anchors to the resulting fee the initiator
|
// the value of the two anchors to the resulting fee the initiator
|
||||||
// pays. In addition the fee rate is capped at 10 sat/vbyte for anchor
|
// pays. In addition the fee rate is capped at 10 sat/vbyte for anchor
|
||||||
// channels.
|
// channels.
|
||||||
if c == commitTypeAnchors {
|
if c == lnrpc.CommitmentType_ANCHORS {
|
||||||
feePerKw = chainfee.SatPerKVByte(
|
feePerKw = chainfee.SatPerKVByte(
|
||||||
lnwallet.DefaultAnchorsCommitMaxFeeRateSatPerVByte * 1000,
|
lnwallet.DefaultAnchorsCommitMaxFeeRateSatPerVByte * 1000,
|
||||||
).FeePerKWeight()
|
).FeePerKWeight()
|
||||||
@@ -283,7 +253,7 @@ func (c commitType) calcStaticFee(numHTLCs int) btcutil.Amount {
|
|||||||
// channelCommitType retrieves the active channel commitment type for the given
|
// channelCommitType retrieves the active channel commitment type for the given
|
||||||
// chan point.
|
// chan point.
|
||||||
func channelCommitType(node *lntest.HarnessNode,
|
func channelCommitType(node *lntest.HarnessNode,
|
||||||
chanPoint *lnrpc.ChannelPoint) (commitType, error) {
|
chanPoint *lnrpc.ChannelPoint) (lnrpc.CommitmentType, error) {
|
||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
@@ -296,21 +266,7 @@ func channelCommitType(node *lntest.HarnessNode,
|
|||||||
|
|
||||||
for _, c := range channels.Channels {
|
for _, c := range channels.Channels {
|
||||||
if c.ChannelPoint == txStr(chanPoint) {
|
if c.ChannelPoint == txStr(chanPoint) {
|
||||||
switch c.CommitmentType {
|
return c.CommitmentType, nil
|
||||||
|
|
||||||
// If the anchor output size is non-zero, we are
|
|
||||||
// dealing with the anchor type.
|
|
||||||
case lnrpc.CommitmentType_ANCHORS:
|
|
||||||
return commitTypeAnchors, nil
|
|
||||||
|
|
||||||
// StaticRemoteKey means it is tweakless,
|
|
||||||
case lnrpc.CommitmentType_STATIC_REMOTE_KEY:
|
|
||||||
return commitTypeTweakless, nil
|
|
||||||
|
|
||||||
// Otherwise legacy.
|
|
||||||
default:
|
|
||||||
return commitTypeLegacy, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user