-
Notifications
You must be signed in to change notification settings - Fork 2.3k
sweeper: relax anchor sweeping when there's no deadline pressure #7965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
535b038
091af93
460d824
e8f4880
3b49694
61ae9af
97a7a7e
06cca85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,10 +23,13 @@ import ( | |
| ) | ||
|
|
||
| // testCommitmentTransactionDeadline tests that the anchor sweep transaction is | ||
| // taking account of the deadline of the commitment transaction. It tests two | ||
| // taking account of the deadline of the commitment transaction. It tests three | ||
| // scenarios: | ||
| // 1. when the CPFP is skipped, checks that the deadline is not used. | ||
| // 2. when the CPFP is used, checks that the deadline is applied. | ||
| // 2. when the CPFP is used, checks that the deadline is NOT applied when it's | ||
| // larger than 144. | ||
| // 3. when the CPFP is used, checks that the deadline is applied when it's | ||
| // less than 144. | ||
| // | ||
| // Note that whether the deadline is used or not is implicitly checked by its | ||
| // corresponding fee rates. | ||
|
|
@@ -43,13 +46,13 @@ func testCommitmentTransactionDeadline(ht *lntest.HarnessTest) { | |
| // DefaultAnchorsCommitMaxFeeRateSatPerVByte. | ||
| feeRateDefault = 20000 | ||
|
|
||
| // finalCTLV is used when Alice sends payment to Bob. | ||
| finalCTLV = 144 | ||
| // defaultDeadline is the anchorSweepConfTarget, which is used | ||
| // when the commitment has no deadline pressure. | ||
| defaultDeadline = 144 | ||
|
|
||
| // deadline is used when Alice sweep the anchor. Notice there | ||
| // is a block padding of 3 added, such that the value of | ||
| // deadline is 147. | ||
| deadline = uint32(finalCTLV + routing.BlockPadding) | ||
| // deadline is one block below the default deadline. A forced | ||
| // anchor sweep will be performed when seeing this value. | ||
| deadline = defaultDeadline - 1 | ||
| ) | ||
|
|
||
| // feeRateSmall(sat/kw) is used when we want to skip the CPFP | ||
|
|
@@ -91,7 +94,7 @@ func testCommitmentTransactionDeadline(ht *lntest.HarnessTest) { | |
|
|
||
| // calculateSweepFeeRate runs multiple steps to calculate the fee rate | ||
| // used in sweeping the transactions. | ||
| calculateSweepFeeRate := func(expectedSweepTxNum int) int64 { | ||
| calculateSweepFeeRate := func(expectedSweepTxNum, deadline int) int64 { | ||
| // Create two nodes, Alice and Bob. | ||
| alice := setupNode("Alice") | ||
| defer ht.Shutdown(alice) | ||
|
|
@@ -110,14 +113,18 @@ func testCommitmentTransactionDeadline(ht *lntest.HarnessTest) { | |
| }, | ||
| ) | ||
|
|
||
| // Calculate the final ctlv delta based on the expected | ||
| // deadline. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Maybe add a comment that the sendpaymentv2 rpc adds the blockpadding to the finalcltv delta therefore we account for it here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't think it's |
||
| finalCltvDelta := int32(deadline - int(routing.BlockPadding)) | ||
|
|
||
| // Send a payment with a specified finalCTLVDelta, which will | ||
| // be used as our deadline later on when Alice force closes the | ||
| // channel. | ||
| req := &routerrpc.SendPaymentRequest{ | ||
| Dest: bob.PubKey[:], | ||
| Amt: 10e4, | ||
| PaymentHash: ht.Random32Bytes(), | ||
| FinalCltvDelta: finalCTLV, | ||
| FinalCltvDelta: finalCltvDelta, | ||
| TimeoutSeconds: 60, | ||
| FeeLimitMsat: noFeeLimitMsat, | ||
| } | ||
|
|
@@ -154,8 +161,27 @@ func testCommitmentTransactionDeadline(ht *lntest.HarnessTest) { | |
| // we should see only one sweep tx in the mempool. | ||
| ht.SetFeeEstimateWithConf(feeRateSmall, deadline) | ||
|
|
||
| // Calculate fee rate used. | ||
| feeRate := calculateSweepFeeRate(1) | ||
| // Calculate fee rate used and assert only the force close tx is | ||
| // broadcast. | ||
| feeRate := calculateSweepFeeRate(1, deadline) | ||
|
|
||
| // We expect the default max fee rate is used. Allow some deviation | ||
| // because weight estimates during tx generation are estimates. | ||
| require.InEpsilonf( | ||
| ht, int64(maxPerKw), feeRate, 0.01, | ||
| "expected fee rate:%d, got fee rate:%d", maxPerKw, feeRate, | ||
| ) | ||
|
|
||
| // Setup our fee estimation for the deadline. Because the fee rate is | ||
| // greater than the parent tx's fee rate, this value will be used to | ||
| // sweep the anchor transaction. However, due to the default value | ||
| // being used, we should not attempt CPFP here because we are not force | ||
| // sweeping the anchor output. | ||
| ht.SetFeeEstimateWithConf(feeRateLarge, defaultDeadline) | ||
|
|
||
| // Calculate fee rate used and assert only the force close tx is | ||
| // broadcast. | ||
| feeRate = calculateSweepFeeRate(1, defaultDeadline) | ||
|
|
||
| // We expect the default max fee rate is used. Allow some deviation | ||
| // because weight estimates during tx generation are estimates. | ||
|
|
@@ -170,8 +196,9 @@ func testCommitmentTransactionDeadline(ht *lntest.HarnessTest) { | |
| // transactions in the mempool. | ||
| ht.SetFeeEstimateWithConf(feeRateLarge, deadline) | ||
|
|
||
| // Calculate fee rate used. | ||
| feeRate = calculateSweepFeeRate(2) | ||
| // Calculate fee rate used and assert both the force close tx and the | ||
| // anchor sweeping tx are broadcast. | ||
| feeRate = calculateSweepFeeRate(2, deadline) | ||
|
|
||
| // We expect the anchor to be swept with the deadline, which has the | ||
| // fee rate of feeRateLarge. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great that we also include a Ratio Check in the Fee-Estimation, meaning that if we have a deadline sweep we do only sweep it if the new Fee is at least greater that 5% (or similar) of the original value. I saw some CPFPs which were increasing the feerate from 10.1 to 10.3 sats/vbyte which makes no sense either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah what we want to start to do there is actually use
testmempoolacceptbefore we broadcast things. So we become less "spray and pray" in general.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool yeah this will be handled by the incoming fee bumper.