Skip to content
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

Miscellaneous anchor outputs preparatory changes #1685

Merged
merged 7 commits into from
Sep 13, 2022

Conversation

wpaulino
Copy link
Contributor

This PR includes a few miscellaneous changes that will be required for the integration of anchors outputs. They are standalone and should be fine to merge without the remaining changes to come to help split up the upcoming work into multiple PRs.

@wpaulino
Copy link
Contributor Author

Didn't see the CI failure locally as it only came up when running without grind_signatures. The responsible commit seems to be b765be4 as the test vectors don't use the zero fee anchors variant.

lightning/src/chain/channelmonitor.rs Outdated Show resolved Hide resolved
lightning/src/util/macro_logger.rs Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2022

Codecov Report

Base: 90.86% // Head: 90.80% // Decreases project coverage by -0.05% ⚠️

Coverage data is based on head (eddcf0f) compared to base (4ae65e8).
Patch coverage: 82.03% of modified lines in pull request are covered.

❗ Current head eddcf0f differs from pull request most recent head f3a5a72. Consider uploading reports for the commit f3a5a72 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1685      +/-   ##
==========================================
- Coverage   90.86%   90.80%   -0.06%     
==========================================
  Files          86       85       -1     
  Lines       46482    46019     -463     
  Branches    46482    46019     -463     
==========================================
- Hits        42234    41789     -445     
+ Misses       4248     4230      -18     
Impacted Files Coverage Δ
lightning/src/ln/functional_test_utils.rs 93.59% <ø> (+0.14%) ⬆️
lightning/src/util/config.rs 66.66% <ø> (ø)
lightning/src/ln/channel.rs 88.68% <70.83%> (-0.20%) ⬇️
lightning/src/ln/chan_utils.rs 94.55% <72.50%> (-0.95%) ⬇️
lightning/src/util/enforcing_trait_impls.rs 89.07% <83.33%> (-0.40%) ⬇️
lightning/src/chain/channelmonitor.rs 91.08% <88.23%> (-0.15%) ⬇️
lightning/src/ln/functional_tests.rs 96.94% <94.28%> (-0.18%) ⬇️
lightning/src/ln/payment_tests.rs 98.88% <100.00%> (+0.06%) ⬆️
lightning/src/util/macro_logger.rs 87.14% <100.00%> (+1.65%) ⬆️
lightning/src/onion_message/packet.rs 64.83% <0.00%> (-7.70%) ⬇️
... and 27 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@wpaulino
Copy link
Contributor Author

CI is green now that the test vectors are updated for the zero fee HTLC transaction anchors variant. I've also upstreamed the changes to the spec at lightning/bolts#1018.

@TheBlueMatt
Copy link
Collaborator

Basically LGTM.

@wpaulino
Copy link
Contributor Author

Pushed a new update to the HTLC trimming logic as it's only based on the dust limit for the zero fee HTLC transaction variant.

arik-so
arik-so previously approved these changes Aug 30, 2022
@TheBlueMatt
Copy link
Collaborator

Can you squash the fixups and I think we can land this.

dunxen
dunxen previously approved these changes Aug 30, 2022
@TheBlueMatt
Copy link
Collaborator

LGTM, can you squash again and I think this is good to go (again lol).

lightning/src/chain/channelmonitor.rs Show resolved Hide resolved
lightning/src/chain/channelmonitor.rs Outdated Show resolved Hide resolved
@@ -616,12 +616,17 @@ pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, conte
} else {
htlc_success_tx_weight(opt_anchors)
};
let total_fee = feerate_per_kw as u64 * weight / 1000;
let output_value = if opt_anchors {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we could a) recall opt_anchors to opt_anchors_zero_fee or document the field in ChannelTransactionParameters that we're supporting only option_anchors_zero_fee_htlc_tx variant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now documented under ChannelTransactionParameters. I'm not opposed to renaming it but it will be a large diff. Perhaps we can leave it as a follow-up PR?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, can be done in a follow-up PR.

lightning/src/ln/chan_utils.rs Show resolved Hide resolved
lightning/src/ln/chan_utils.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Show resolved Hide resolved
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM, feel free to squash.

lightning/src/util/macro_logger.rs Outdated Show resolved Hide resolved
@wpaulino
Copy link
Contributor Author

wpaulino commented Sep 6, 2022

Squashed with no further changes.

arik-so
arik-so previously approved these changes Sep 7, 2022
Copy link
Contributor

@arik-so arik-so left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM :)

@TheBlueMatt
Copy link
Collaborator

Let's hold this until 0.0.112. I'm not 100% sure how the 0fee HTLC change will impact VLS (and the CLN folks aren't responding), but given the CLN folks haven't responded I'm fine with just shipping it.

@TheBlueMatt
Copy link
Collaborator

I believe #1685 (comment) still needs addressing.

Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM 168e76b

Thanks for documenting f43a7e8, make it easier to detect wrong script detection.

lightning/src/ln/chan_utils.rs Show resolved Hide resolved
@wpaulino
Copy link
Contributor Author

Force pushed to address final comments:

diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs
index 57496058..df037893 100644
--- a/lightning/src/ln/chan_utils.rs
+++ b/lightning/src/ln/chan_utils.rs
@@ -44,7 +44,8 @@ use util::crypto::sign;
 pub(crate) const MAX_HTLCS: u16 = 483;
 pub(crate) const OFFERED_HTLC_SCRIPT_WEIGHT: usize = 133;
 pub(crate) const OFFERED_HTLC_SCRIPT_WEIGHT_ANCHORS: usize = 136;
-// The weight range for `accepted_htlc_script` encompasses both the non-anchors and anchors variants.
+// The weight of `accepted_htlc_script` can vary in function of its CLTV argument value. We define a
+// range that encompasses both its non-anchors and anchors variants.
 pub(crate) const MIN_ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 136;
 pub(crate) const MAX_ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 143;
 
diff --git a/lightning/src/util/macro_logger.rs b/lightning/src/util/macro_logger.rs
index 45c02583..01a0d3ff 100644
--- a/lightning/src/util/macro_logger.rs
+++ b/lightning/src/util/macro_logger.rs
@@ -91,7 +91,7 @@ impl<'a> core::fmt::Display for DebugTx<'a> {
 	fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
 		if self.0.input.len() >= 1 && self.0.input.iter().any(|i| !i.witness.is_empty()) {
 			let first_input = &self.0.input[0];
-			let witness_script_len = first_input.witness.last().unwrap().len();
+			let witness_script_len = first_input.witness.last().unwrap_or(&[]).len();
 			if self.0.input.len() == 1 && witness_script_len == 71 &&
 					(first_input.sequence.0 >> 8*3) as u8 == 0x80 {
 				write!(f, "commitment tx ")?;
@@ -115,7 +115,7 @@ impl<'a> core::fmt::Display for DebugTx<'a> {
 					}
 				}
 				if num_preimage > 0 || num_timeout > 0 || num_revoked > 0 {
-					write!(f, "HTLC claim tx ({} preimage, {} timeout, {} 2 revoked)",
+					write!(f, "HTLC claim tx ({} preimage, {} timeout, {} revoked)",
 						num_preimage, num_timeout, num_revoked)?;
 				}
 			}

TheBlueMatt
TheBlueMatt previously approved these changes Sep 13, 2022
@TheBlueMatt
Copy link
Collaborator

Oops, ugh, needs rebase :(

There's no need to broadcast our local commitment transaction if we've
already seen a confirmed one as it'll be immediately rejected as a
duplicate/conflict.

This will also help prevent dispatching spurious events for bumping
commitment and HTLC transactions through anchor outputs (once
implemented in future work) and the dispatch for said events follows the
same flow as our usual commitment broadcast.
HTLC transactions from anchor channels are constrained by a CSV of 1
block, so broadcasting them along with the unconfirmed commitment
tranasction will result in them being immediately rejected as premature.
This is based on the assumption that we only support the zero HTLC
transaction fee variant of anchor channels.
With the zero fee HTLC transaction anchors variant, HTLCs can no longer
be trimmed due to their amount being too low to have a mempool valid
HTLC transaction. Now they can only be trimmed based on the dust limit
of each party within the channel.
Each test featuring HTLCs had a minimum and maximum feerate case. This
is no longer necessary for the zero HTLC transaction anchors variant as
the commitment feerate does not impact whether HTLCs can be trimmed or
not, only the dust limit does.
@TheBlueMatt TheBlueMatt merged commit 71f4749 into lightningdevkit:main Sep 13, 2022
@wpaulino wpaulino deleted the anchors-prep branch September 13, 2022 21:35
devrandom added a commit to lightning-signer/vls that referenced this pull request Mar 22, 2023
non-zero-fee anchor support was broken by LDK in lightningdevkit/rust-lightning#1685 and fix was later submitted by us
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants