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",
|
||||
}
|
||||
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
|
||||
|
||||
@@ -81,10 +81,10 @@ func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
|
||||
// As this is a single funder channel, Alice's balance should be
|
||||
// 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.
|
||||
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
|
||||
// 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
|
||||
// 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
|
||||
// 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.
|
||||
const (
|
||||
@@ -258,7 +258,7 @@ func testChannelUnsettledBalance(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
// Check alice's channel balance, which should have a remote unsettled
|
||||
// balance that equals to the amount of invoices * payAmt. The remote
|
||||
// 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)
|
||||
|
||||
// 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 {
|
||||
// Create the node.
|
||||
args := []string{"--hodl.exit-settle"}
|
||||
args = append(args, commitTypeAnchors.Args()...)
|
||||
args = append(args, nodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)...)
|
||||
node := net.NewNode(t.t, name, args)
|
||||
|
||||
// Send some coins to the node.
|
||||
@@ -244,9 +244,9 @@ func calculateTxnsFeeRate(t *testing.T,
|
||||
func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
// We'll test the scenario for some of the commitment types, to ensure
|
||||
// outputs can be swept.
|
||||
commitTypes := []commitType{
|
||||
commitTypeLegacy,
|
||||
commitTypeAnchors,
|
||||
commitTypes := []lnrpc.CommitmentType{
|
||||
lnrpc.CommitmentType_LEGACY,
|
||||
lnrpc.CommitmentType_ANCHORS,
|
||||
}
|
||||
|
||||
for _, channelType := range commitTypes {
|
||||
@@ -261,7 +261,7 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
success := t.t.Run(testName, func(t *testing.T) {
|
||||
ht := newHarnessTest(t, net)
|
||||
|
||||
args := channelType.Args()
|
||||
args := nodeArgsForCommitType(channelType)
|
||||
alice := net.NewNode(ht.t, "Alice", args)
|
||||
defer shutdownAndAssert(net, ht, alice)
|
||||
|
||||
@@ -292,7 +292,7 @@ func testChannelForceClosure(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()
|
||||
|
||||
@@ -407,7 +407,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
||||
// sweep the HTLC second level output one block earlier (than the
|
||||
// nursery that waits an additional block, and handles non-anchor
|
||||
// channels). So we set a maturity height that is one less.
|
||||
if channelType == commitTypeAnchors {
|
||||
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||
htlcCsvMaturityHeight = padCLTV(
|
||||
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.
|
||||
expectedTxes := 1
|
||||
expectedFeeRate := commitFeeRate
|
||||
if channelType == commitTypeAnchors {
|
||||
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||
expectedTxes = 2
|
||||
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
|
||||
// reports.
|
||||
if channelType == commitTypeAnchors {
|
||||
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||
aliceReports[aliceAnchor.OutPoint.String()] = &lnrpc.Resolution{
|
||||
ResolutionType: lnrpc.ResolutionType_ANCHOR,
|
||||
Outcome: lnrpc.ResolutionOutcome_CLAIMED,
|
||||
@@ -585,7 +585,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
||||
"limbo")
|
||||
}
|
||||
expectedRecoveredBalance := int64(0)
|
||||
if channelType == commitTypeAnchors {
|
||||
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||
expectedRecoveredBalance = anchorSize
|
||||
}
|
||||
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 channelType == commitTypeAnchors {
|
||||
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||
carolReports[carolAnchor.OutPoint.String()] = &lnrpc.Resolution{
|
||||
ResolutionType: lnrpc.ResolutionType_ANCHOR,
|
||||
Outcome: lnrpc.ResolutionOutcome_CLAIMED,
|
||||
@@ -709,7 +709,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
||||
"limbo")
|
||||
}
|
||||
expectedRecoveredBalance := int64(0)
|
||||
if channelType == commitTypeAnchors {
|
||||
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||
expectedRecoveredBalance = anchorSize
|
||||
}
|
||||
if forceClose.RecoveredBalance != expectedRecoveredBalance {
|
||||
@@ -943,7 +943,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
||||
expectedTxes = numInvoices
|
||||
|
||||
// In case of anchors, the timeout txs will be aggregated into one.
|
||||
if channelType == commitTypeAnchors {
|
||||
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||
expectedTxes = 1
|
||||
}
|
||||
|
||||
@@ -961,7 +961,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
||||
// this is an anchor channel, the transactions are aggregated by the
|
||||
// sweeper into one.
|
||||
numInputs := 1
|
||||
if channelType == commitTypeAnchors {
|
||||
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||
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.
|
||||
// For anchor channels thhis is one block earlier.
|
||||
numBlocks := uint32(defaultCSV - 1)
|
||||
if channelType == commitTypeAnchors {
|
||||
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||
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
|
||||
// anchor size.
|
||||
if channelType == commitTypeAnchors {
|
||||
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||
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
|
||||
// commitment types.
|
||||
allTypes := []commitType{
|
||||
commitTypeLegacy,
|
||||
commitTypeTweakless,
|
||||
commitTypeAnchors,
|
||||
allTypes := []lnrpc.CommitmentType{
|
||||
lnrpc.CommitmentType_LEGACY,
|
||||
lnrpc.CommitmentType_STATIC_REMOTE_KEY,
|
||||
lnrpc.CommitmentType_ANCHORS,
|
||||
}
|
||||
|
||||
// testFunding is a function closure that takes Carol and Dave's
|
||||
// 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
|
||||
// preferentially signal the legacy commitment format. We do
|
||||
// the same for Dave shortly below.
|
||||
carolArgs := carolCommitType.Args()
|
||||
carolArgs := nodeArgsForCommitType(carolCommitType)
|
||||
carol := net.NewNode(t.t, "Carol", carolArgs)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
@@ -49,7 +49,7 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
// fund the channel.
|
||||
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
|
||||
|
||||
daveArgs := daveCommitType.Args()
|
||||
daveArgs := nodeArgsForCommitType(daveCommitType)
|
||||
dave := net.NewNode(t.t, "Dave", daveArgs)
|
||||
defer shutdownAndAssert(net, t, dave)
|
||||
|
||||
@@ -81,20 +81,20 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
|
||||
// Dave supports anchors, type will be what
|
||||
// Carol supports.
|
||||
case commitTypeAnchors:
|
||||
case lnrpc.CommitmentType_ANCHORS:
|
||||
|
||||
// Dave only supports tweakless, channel will
|
||||
// be downgraded to this type if Carol supports
|
||||
// anchors.
|
||||
case commitTypeTweakless:
|
||||
if expType == commitTypeAnchors {
|
||||
expType = commitTypeTweakless
|
||||
case lnrpc.CommitmentType_STATIC_REMOTE_KEY:
|
||||
if expType == lnrpc.CommitmentType_ANCHORS {
|
||||
expType = lnrpc.CommitmentType_STATIC_REMOTE_KEY
|
||||
}
|
||||
|
||||
// Dave only supoprts legacy type, channel will
|
||||
// be downgraded to this type.
|
||||
case commitTypeLegacy:
|
||||
expType = commitTypeLegacy
|
||||
case lnrpc.CommitmentType_LEGACY:
|
||||
expType = lnrpc.CommitmentType_LEGACY
|
||||
|
||||
default:
|
||||
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
|
||||
// expect.
|
||||
switch {
|
||||
case expType == commitTypeAnchors &&
|
||||
case expType == lnrpc.CommitmentType_ANCHORS &&
|
||||
chansCommitType == lnrpc.CommitmentType_ANCHORS:
|
||||
|
||||
case expType == commitTypeTweakless &&
|
||||
case expType == lnrpc.CommitmentType_STATIC_REMOTE_KEY &&
|
||||
chansCommitType == lnrpc.CommitmentType_STATIC_REMOTE_KEY:
|
||||
|
||||
case expType == commitTypeLegacy &&
|
||||
case expType == lnrpc.CommitmentType_LEGACY &&
|
||||
chansCommitType == lnrpc.CommitmentType_LEGACY:
|
||||
|
||||
default:
|
||||
@@ -221,7 +221,7 @@ func basicChannelFundingTest(t *harnessTest, net *lntest.NetworkHarness,
|
||||
|
||||
// With the channel open, ensure that the amount specified above has
|
||||
// properly been pushed to Bob.
|
||||
aliceLocalBalance := chanAmt - pushAmt - cType.calcStaticFee(0)
|
||||
aliceLocalBalance := chanAmt - pushAmt - calcStaticFee(cType, 0)
|
||||
checkChannelBalance(
|
||||
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
|
||||
// type directly.
|
||||
cType := commitTypeTweakless
|
||||
carolLocalBalance := chanAmt - pushAmt - cType.calcStaticFee(0)
|
||||
cType := lnrpc.CommitmentType_STATIC_REMOTE_KEY
|
||||
carolLocalBalance := chanAmt - pushAmt - calcStaticFee(cType, 0)
|
||||
checkChannelBalance(carol, 0, 0, carolLocalBalance, pushAmt)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
commitFee := cType.calcStaticFee(0)
|
||||
commitFee := calcStaticFee(cType, 0)
|
||||
assertBaseBalance := func() {
|
||||
// Alice has opened a channel with Bob with zero push amount, so
|
||||
// it's remote balance is zero.
|
||||
|
||||
@@ -23,7 +23,7 @@ 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 commitType) {
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
|
||||
const finalCltvDelta = 40
|
||||
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
|
||||
// there are anchors, we also expect Bob's anchor sweep.
|
||||
expectedTxes := 1
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
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
|
||||
// Carol will also sweep her anchor output in a separate tx (since it
|
||||
// will be low fee).
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
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
|
||||
// levels to be aggregated into one tx. For earlier channel types, they
|
||||
// will be separate transactions.
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
require.Len(t.t, timeoutTxs, 1)
|
||||
require.Len(t.t, successTxs, 1)
|
||||
} 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
|
||||
// can sweep the output.
|
||||
case c == commitTypeAnchors:
|
||||
case c == lnrpc.CommitmentType_ANCHORS:
|
||||
_ = mineBlocks(t, net, 1, 1)
|
||||
|
||||
// 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
|
||||
// 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 commitType) {
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
|
||||
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
|
||||
// immediately, so he force closes his commitment transaction.
|
||||
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
|
||||
// anchors, Alice will also sweep hers.
|
||||
expectedTxes := 1
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
expectedTxes = 2
|
||||
}
|
||||
_, 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
|
||||
// anchor.
|
||||
expectedTxes = 2
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
expectedTxes = 3
|
||||
}
|
||||
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
|
||||
// from the default CSV, as the Sweeper will handle the input, and the Sweeper
|
||||
// sweeps the input as soon as the lock expires.
|
||||
case commitTypeAnchors:
|
||||
case lnrpc.CommitmentType_ANCHORS:
|
||||
secondLevelMaturity = defaultCSV - 1
|
||||
|
||||
// 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
|
||||
// it on-chain, and cancel the HTLC backwards.
|
||||
func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
|
||||
alice, bob *lntest.HarnessNode, c commitType) {
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
|
||||
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
|
||||
// there are anchors, we also expect Bob's anchor sweep.
|
||||
expectedTxes := 1
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
expectedTxes = 2
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ 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 commitType) {
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
|
||||
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
|
||||
// are anchors, Carol also sweeps hers.
|
||||
expectedTxes := 1
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
expectedTxes = 2
|
||||
}
|
||||
_, 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,
|
||||
// if present.
|
||||
expectedTxes = 2
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
expectedTxes = 3
|
||||
}
|
||||
txes, err := getNTxsFromMempool(
|
||||
|
||||
@@ -20,7 +20,7 @@ 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 commitType) {
|
||||
alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
|
||||
ctxb := context.Background()
|
||||
|
||||
@@ -86,7 +86,8 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
||||
// immediately force close the channel by broadcast her commitment
|
||||
// transaction.
|
||||
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.
|
||||
@@ -96,7 +97,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
||||
// After closeChannelAndAssertType returns, it has mined a block so now
|
||||
// bob will attempt to redeem his anchor commitment (if the channel
|
||||
// type is of that type).
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
_, err = waitForNTxsInMempool(
|
||||
net.Miner.Client, 1, minerMempoolTimeout,
|
||||
)
|
||||
@@ -146,7 +147,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
||||
require.NoError(t.t, err)
|
||||
|
||||
expectedTxes := 1
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
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.
|
||||
// If there are anchors, Bob should also sweep his.
|
||||
expectedTxes = 2
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
expectedTxes = 3
|
||||
}
|
||||
txes, err := getNTxsFromMempool(
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||
"github.com/lightningnetwork/lnd/lntest"
|
||||
"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
|
||||
// HTLC timeout transaction, then cancel it backwards as normal.
|
||||
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()
|
||||
|
||||
@@ -72,7 +73,8 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||
// force close the Bob -> Carol channel. This should trigger contract
|
||||
// resolution mode for both of them.
|
||||
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
|
||||
@@ -93,7 +95,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||
// We'll mine defaultCSV blocks in order to generate the sweep
|
||||
// transaction of Bob's funding output. If there are anchors, mine
|
||||
// Carol's anchor sweep too.
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
_, err = waitForTxInMempool(net.Miner.Client, minerMempoolTimeout)
|
||||
require.NoError(t.t, err)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ 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 commitType) {
|
||||
t *harnessTest, alice, bob *lntest.HarnessNode, c lnrpc.CommitmentType) {
|
||||
|
||||
ctxb := context.Background()
|
||||
|
||||
@@ -84,7 +84,8 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||
// expired HTLC on Carol's version of the commitment transaction. If
|
||||
// Carol has an anchor, it will be swept too.
|
||||
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
|
||||
@@ -95,7 +96,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
|
||||
// Bob can sweep his output immediately. If there is an anchor, Bob will
|
||||
// sweep that as well.
|
||||
expectedTxes := 1
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
expectedTxes = 2
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
type testCase struct {
|
||||
name string
|
||||
test func(net *lntest.NetworkHarness, t *harnessTest, alice,
|
||||
bob *lntest.HarnessNode, c commitType)
|
||||
bob *lntest.HarnessNode, c lnrpc.CommitmentType)
|
||||
}
|
||||
|
||||
subTests := []testCase{
|
||||
@@ -68,19 +68,19 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
},
|
||||
}
|
||||
|
||||
commitTypes := []commitType{
|
||||
commitTypeLegacy,
|
||||
commitTypeAnchors,
|
||||
commitTypes := []lnrpc.CommitmentType{
|
||||
lnrpc.CommitmentType_LEGACY,
|
||||
lnrpc.CommitmentType_ANCHORS,
|
||||
}
|
||||
|
||||
for _, commitType := range commitTypes {
|
||||
commitType := commitType
|
||||
testName := fmt.Sprintf("committype=%v", commitType.String())
|
||||
|
||||
commitType := commitType
|
||||
success := t.t.Run(testName, func(t *testing.T) {
|
||||
ht := newHarnessTest(t, net)
|
||||
|
||||
args := commitType.Args()
|
||||
args := nodeArgsForCommitType(commitType)
|
||||
alice := net.NewNode(t, "Alice", args)
|
||||
defer shutdownAndAssert(net, ht, alice)
|
||||
|
||||
@@ -205,7 +205,7 @@ func checkPaymentStatus(node *lntest.HarnessNode, preimage lntypes.Preimage,
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
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
|
||||
// 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.
|
||||
carolFlags := c.Args()
|
||||
carolFlags := nodeArgsForCommitType(c)
|
||||
if carolHodl {
|
||||
carolFlags = append(carolFlags, "--hodl.exit-settle")
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ func testCPFP(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
// wallet.
|
||||
func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
// Start two nodes supporting anchor channels.
|
||||
args := commitTypeAnchors.Args()
|
||||
args := nodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)
|
||||
alice := net.NewNode(t.t, "Alice", args)
|
||||
defer shutdownAndAssert(net, t, alice)
|
||||
|
||||
|
||||
+11
-55
@@ -208,45 +208,15 @@ func getChanInfo(node *lntest.HarnessNode) (*lnrpc.Channel, error) {
|
||||
return channelInfo.Channels[0], nil
|
||||
}
|
||||
|
||||
// commitType is a simple enum used to run though the basic funding flow with
|
||||
// different commitment formats.
|
||||
type commitType byte
|
||||
|
||||
const (
|
||||
// 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:
|
||||
// nodeArgsForCommitType returns the command line flag to supply to enable this
|
||||
// commitment type.
|
||||
func nodeArgsForCommitType(commitType lnrpc.CommitmentType) []string {
|
||||
switch commitType {
|
||||
case lnrpc.CommitmentType_LEGACY:
|
||||
return []string{"--protocol.legacy.committweak"}
|
||||
case commitTypeTweakless:
|
||||
case lnrpc.CommitmentType_STATIC_REMOTE_KEY:
|
||||
return []string{}
|
||||
case commitTypeAnchors:
|
||||
case lnrpc.CommitmentType_ANCHORS:
|
||||
return []string{"--protocol.anchors"}
|
||||
}
|
||||
|
||||
@@ -256,7 +226,7 @@ func (c commitType) Args() []string {
|
||||
// calcStaticFee calculates appropriate fees for commitment transactions. This
|
||||
// function provides a simple way to allow test balance assertions to take fee
|
||||
// calculations into account.
|
||||
func (c commitType) calcStaticFee(numHTLCs int) btcutil.Amount {
|
||||
func calcStaticFee(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
|
||||
const htlcWeight = input.HTLCWeight
|
||||
var (
|
||||
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
|
||||
// pays. In addition the fee rate is capped at 10 sat/vbyte for anchor
|
||||
// channels.
|
||||
if c == commitTypeAnchors {
|
||||
if c == lnrpc.CommitmentType_ANCHORS {
|
||||
feePerKw = chainfee.SatPerKVByte(
|
||||
lnwallet.DefaultAnchorsCommitMaxFeeRateSatPerVByte * 1000,
|
||||
).FeePerKWeight()
|
||||
@@ -283,7 +253,7 @@ func (c commitType) calcStaticFee(numHTLCs int) btcutil.Amount {
|
||||
// channelCommitType retrieves the active channel commitment type for the given
|
||||
// chan point.
|
||||
func channelCommitType(node *lntest.HarnessNode,
|
||||
chanPoint *lnrpc.ChannelPoint) (commitType, error) {
|
||||
chanPoint *lnrpc.ChannelPoint) (lnrpc.CommitmentType, error) {
|
||||
|
||||
ctxb := context.Background()
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
@@ -296,21 +266,7 @@ func channelCommitType(node *lntest.HarnessNode,
|
||||
|
||||
for _, c := range channels.Channels {
|
||||
if c.ChannelPoint == txStr(chanPoint) {
|
||||
switch c.CommitmentType {
|
||||
|
||||
// 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
|
||||
}
|
||||
return c.CommitmentType, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user