mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-04-07 03:28:05 +02:00
lntemp+itest: move utils function into lntemp
This commit is contained in:
parent
edba938996
commit
4a9c3449a6
@ -70,7 +70,7 @@ func newChanRestoreScenario(ht *lntemp.HarnessTest, ct lnrpc.CommitmentType,
|
||||
}
|
||||
|
||||
if ct != lnrpc.CommitmentType_UNKNOWN_COMMITMENT_TYPE {
|
||||
args := nodeArgsForCommitType(ct)
|
||||
args := lntemp.NodeArgsForCommitType(ct)
|
||||
nodeArgs = append(nodeArgs, args...)
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ func newChanRestoreScenario(ht *lntemp.HarnessTest, ct lnrpc.CommitmentType,
|
||||
|
||||
// For the anchor output case we need two UTXOs for Carol so she can
|
||||
// sweep both the local and remote anchor.
|
||||
if commitTypeHasAnchors(ct) {
|
||||
if lntemp.CommitTypeHasAnchors(ct) {
|
||||
ht.FundCoins(btcutil.SatoshiPerBitcoin, carol)
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ func (c *chanRestoreScenario) testScenario(ht *lntemp.HarnessTest,
|
||||
// let's start up Carol again.
|
||||
require.NoError(ht, restartCarol(), "restart carol failed")
|
||||
|
||||
if commitTypeHasAnchors(c.params.CommitmentType) {
|
||||
if lntemp.CommitTypeHasAnchors(c.params.CommitmentType) {
|
||||
ht.AssertNumUTXOs(carol, 2)
|
||||
} else {
|
||||
ht.AssertNumUTXOs(carol, 1)
|
||||
@ -1467,7 +1467,7 @@ func assertDLPExecuted(ht *lntemp.HarnessTest,
|
||||
// Upon reconnection, the nodes should detect that Dave is out of sync.
|
||||
// Carol should force close the channel using her latest commitment.
|
||||
expectedTxes := 1
|
||||
if commitTypeHasAnchors(commitType) {
|
||||
if lntemp.CommitTypeHasAnchors(commitType) {
|
||||
expectedTxes = 2
|
||||
}
|
||||
ht.Miner.AssertNumTxsInMempool(expectedTxes)
|
||||
|
@ -72,7 +72,7 @@ func testCommitmentTransactionDeadline(ht *lntemp.HarnessTest) {
|
||||
setupNode := func(name string) *node.HarnessNode {
|
||||
// Create the node.
|
||||
args := []string{"--hodl.exit-settle"}
|
||||
args = append(args, nodeArgsForCommitType(
|
||||
args = append(args, lntemp.NodeArgsForCommitType(
|
||||
lnrpc.CommitmentType_ANCHORS)...,
|
||||
)
|
||||
node := ht.NewNode(name, args)
|
||||
@ -209,7 +209,7 @@ func testChannelForceClosure(ht *lntemp.HarnessTest) {
|
||||
success := ht.Run(testName, func(t *testing.T) {
|
||||
st := ht.Subtest(t)
|
||||
|
||||
args := nodeArgsForCommitType(channelType)
|
||||
args := lntemp.NodeArgsForCommitType(channelType)
|
||||
alice := st.NewNode("Alice", args)
|
||||
defer st.Shutdown(alice)
|
||||
|
||||
|
@ -41,14 +41,14 @@ func testBasicChannelFunding(ht *lntemp.HarnessTest) {
|
||||
// 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 := nodeArgsForCommitType(carolCommitType)
|
||||
carolArgs := lntemp.NodeArgsForCommitType(carolCommitType)
|
||||
carol := ht.NewNode("Carol", carolArgs)
|
||||
|
||||
// Each time, we'll send Carol a new set of coins in order to
|
||||
// fund the channel.
|
||||
ht.FundCoins(btcutil.SatoshiPerBitcoin, carol)
|
||||
|
||||
daveArgs := nodeArgsForCommitType(daveCommitType)
|
||||
daveArgs := lntemp.NodeArgsForCommitType(daveCommitType)
|
||||
dave := ht.NewNode("Dave", daveArgs)
|
||||
|
||||
// Before we start the test, we'll ensure both sides are
|
||||
|
@ -65,7 +65,7 @@ func runMultiHopHtlcClaimTest(ht *lntemp.HarnessTest, tester caseRunner) {
|
||||
|
||||
// Create the nodes here so that separate logs will be created
|
||||
// for Alice and Bob.
|
||||
args := nodeArgsForCommitType(typeAndConf.commitType)
|
||||
args := lntemp.NodeArgsForCommitType(typeAndConf.commitType)
|
||||
if typeAndConf.zeroConf {
|
||||
args = append(
|
||||
args, "--protocol.option-scid-alias",
|
||||
@ -171,7 +171,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntemp.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
|
||||
hasAnchors := commitTypeHasAnchors(c)
|
||||
hasAnchors := lntemp.CommitTypeHasAnchors(c)
|
||||
if hasAnchors {
|
||||
expectedTxes = 2
|
||||
}
|
||||
@ -348,7 +348,7 @@ func runMultiHopReceiverChainClaim(ht *lntemp.HarnessTest,
|
||||
// transaction in order to go to the chain and sweep her HTLC. If there
|
||||
// are anchors, Carol also sweeps hers.
|
||||
expectedTxes := 1
|
||||
hasAnchors := commitTypeHasAnchors(c)
|
||||
hasAnchors := lntemp.CommitTypeHasAnchors(c)
|
||||
if hasAnchors {
|
||||
expectedTxes = 2
|
||||
}
|
||||
@ -517,7 +517,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
|
||||
// Now that all parties have the HTLC locked in, we'll immediately
|
||||
// force close the Bob -> Carol channel. This should trigger contract
|
||||
// resolution mode for both of them.
|
||||
hasAnchors := commitTypeHasAnchors(c)
|
||||
hasAnchors := lntemp.CommitTypeHasAnchors(c)
|
||||
stream, _ := ht.CloseChannelAssertPending(bob, bobChanPoint, true)
|
||||
closeTx := ht.AssertStreamChannelForceClosed(
|
||||
bob, bobChanPoint, hasAnchors, stream,
|
||||
@ -682,7 +682,7 @@ func runMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntemp.HarnessTest,
|
||||
// transaction. This will let us exercise that Bob is able to sweep the
|
||||
// expired HTLC on Carol's version of the commitment transaction. If
|
||||
// Carol has an anchor, it will be swept too.
|
||||
hasAnchors := commitTypeHasAnchors(c)
|
||||
hasAnchors := lntemp.CommitTypeHasAnchors(c)
|
||||
closeStream, _ := ht.CloseChannelAssertPending(
|
||||
carol, bobChanPoint, true,
|
||||
)
|
||||
@ -840,7 +840,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
|
||||
|
||||
// At this point, Bob decides that he wants to exit the channel
|
||||
// immediately, so he force closes his commitment transaction.
|
||||
hasAnchors := commitTypeHasAnchors(c)
|
||||
hasAnchors := lntemp.CommitTypeHasAnchors(c)
|
||||
closeStream, _ := ht.CloseChannelAssertPending(
|
||||
bob, aliceChanPoint, true,
|
||||
)
|
||||
@ -888,7 +888,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntemp.HarnessTest,
|
||||
|
||||
// Carol's commitment transaction should now be in the mempool. If
|
||||
// there is an anchor, Carol will sweep that too.
|
||||
if commitTypeHasAnchors(c) {
|
||||
if lntemp.CommitTypeHasAnchors(c) {
|
||||
expectedTxes = 2
|
||||
}
|
||||
ht.Miner.AssertNumTxsInMempool(expectedTxes)
|
||||
@ -1135,7 +1135,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntemp.HarnessTest,
|
||||
// Next, Alice decides that she wants to exit the channel, so she'll
|
||||
// immediately force close the channel by broadcast her commitment
|
||||
// transaction.
|
||||
hasAnchors := commitTypeHasAnchors(c)
|
||||
hasAnchors := lntemp.CommitTypeHasAnchors(c)
|
||||
closeStream, _ := ht.CloseChannelAssertPending(
|
||||
alice, aliceChanPoint, true,
|
||||
)
|
||||
@ -1489,7 +1489,7 @@ func runMultiHopHtlcAggregation(ht *lntemp.HarnessTest,
|
||||
|
||||
// Bob's force close transaction should now be found in the mempool. If
|
||||
// there are anchors, we also expect Bob's anchor sweep.
|
||||
hasAnchors := commitTypeHasAnchors(c)
|
||||
hasAnchors := lntemp.CommitTypeHasAnchors(c)
|
||||
expectedTxes := 1
|
||||
if hasAnchors {
|
||||
expectedTxes = 2
|
||||
@ -1738,7 +1738,7 @@ func createThreeHopNetwork(ht *lntemp.HarnessTest,
|
||||
// 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 := nodeArgsForCommitType(c)
|
||||
carolFlags := lntemp.NodeArgsForCommitType(c)
|
||||
if carolHodl {
|
||||
carolFlags = append(carolFlags, "--hodl.exit-settle")
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ func runCPFP(ht *lntemp.HarnessTest, alice, bob *node.HarnessNode) {
|
||||
// wallet.
|
||||
func testAnchorReservedValue(ht *lntemp.HarnessTest) {
|
||||
// Start two nodes supporting anchor channels.
|
||||
args := nodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)
|
||||
args := lntemp.NodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)
|
||||
|
||||
// NOTE: we cannot reuse the standby node here as the test requires the
|
||||
// node to start with no UTXOs.
|
||||
@ -353,7 +353,7 @@ func testAnchorThirdPartySpend(ht *lntemp.HarnessTest) {
|
||||
//
|
||||
// NOTE: The itests differ here as anchors is default off vs the normal
|
||||
// lnd binary.
|
||||
args := nodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)
|
||||
args := lntemp.NodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)
|
||||
alice := ht.NewNode("Alice", args)
|
||||
defer ht.Shutdown(alice)
|
||||
|
||||
|
@ -415,7 +415,7 @@ func testPsbtChanFundingExternal(ht *lntemp.HarnessTest) {
|
||||
func testPsbtChanFundingSingleStep(ht *lntemp.HarnessTest) {
|
||||
const chanSize = funding.MaxBtcFundingAmount
|
||||
|
||||
args := nodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)
|
||||
args := lntemp.NodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)
|
||||
|
||||
// First, we'll create two new nodes that we'll use to open channels
|
||||
// between for this test. But in this case both nodes have an empty
|
||||
|
@ -38,37 +38,6 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
// commitTypeHasAnchors returns whether commitType uses anchor outputs.
|
||||
func commitTypeHasAnchors(commitType lnrpc.CommitmentType) bool {
|
||||
switch commitType {
|
||||
case lnrpc.CommitmentType_ANCHORS,
|
||||
lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 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 lnrpc.CommitmentType_STATIC_REMOTE_KEY:
|
||||
return []string{}
|
||||
case lnrpc.CommitmentType_ANCHORS:
|
||||
return []string{"--protocol.anchors"}
|
||||
case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
|
||||
return []string{
|
||||
"--protocol.anchors",
|
||||
"--protocol.script-enforced-lease",
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// calcStaticFee calculates appropriate fees for commitment transactions. This
|
||||
// function provides a simple way to allow test balance assertions to take fee
|
||||
// calculations into account.
|
||||
@ -87,7 +56,7 @@ func calcStaticFee(c lnrpc.CommitmentType, 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 commitTypeHasAnchors(c) {
|
||||
if lntemp.CommitTypeHasAnchors(c) {
|
||||
feePerKw = chainfee.SatPerKVByte(
|
||||
defaultSatPerVByte * 1000).FeePerKWeight()
|
||||
commitWeight = input.AnchorCommitWeight
|
||||
|
@ -121,3 +121,34 @@ func channelPointStr(chanPoint *lnrpc.ChannelPoint) string {
|
||||
|
||||
return cp.String()
|
||||
}
|
||||
|
||||
// CommitTypeHasAnchors returns whether commitType uses anchor outputs.
|
||||
func CommitTypeHasAnchors(commitType lnrpc.CommitmentType) bool {
|
||||
switch commitType {
|
||||
case lnrpc.CommitmentType_ANCHORS,
|
||||
lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 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 lnrpc.CommitmentType_STATIC_REMOTE_KEY:
|
||||
return []string{}
|
||||
case lnrpc.CommitmentType_ANCHORS:
|
||||
return []string{"--protocol.anchors"}
|
||||
case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
|
||||
return []string{
|
||||
"--protocol.anchors",
|
||||
"--protocol.script-enforced-lease",
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user