-
Notifications
You must be signed in to change notification settings - Fork 405
Low level anchor transaction build support #1055
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
Low level anchor transaction build support #1055
Conversation
Another motivation for this is that Lightning Signer needs this for adding anchor support, since we depend on LDK for transaction construction. |
Codecov Report
@@ Coverage Diff @@
## main #1055 +/- ##
==========================================
+ Coverage 90.82% 92.04% +1.22%
==========================================
Files 65 65
Lines 32890 37896 +5006
==========================================
+ Hits 29872 34883 +5011
+ Misses 3018 3013 -5
Continue to review full report at Codecov.
|
a498feb
to
8bc9ce5
Compare
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.
Concept ACK.
This is a far cleaner approach than #725, as the need-to-include-anchor detection is wrapped inside the CommitmentTransaction
interface.
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.
Concept ACK. It would be nice at least have some kind of test or something for this code.
This is a script builder to generate anchor output ones. They can be satisfied either by a signature for the committed funding pubkey or anyone after CSV delay expiration. This is used at anchor output addition while generating commitment transaction.
502e19a
to
7e115ed
Compare
Done. But this is the first unit test for |
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.
Done. But this is the first unit test for CommitmentTransaction - not sure if we want to have something more extensive.
I think its fine enough, would be good to check the output scripts but it doesn't matter hugely and once we ship anchor we'll have more extensive tests of that anyway.
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.
Otherwise good to me!
keys.clone(), 1, | ||
&mut htlcs_with_aux, &channel_parameters.as_holder_broadcastable() | ||
); | ||
assert_eq!(tx.built.transaction.output.len(), 2); |
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.
I think there is a missing test case when we have !htlcs_with_aux.is_empty()
?
diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs
index 20734f95..e226dc84 100644
--- a/lightning/src/ln/chan_utils.rs
+++ b/lightning/src/ln/chan_utils.rs
@@ -1268,7 +1268,8 @@ mod tests {
use super::CounterpartyCommitmentSecrets;
use ::{hex, chain};
use prelude::*;
- use ln::chan_utils::{CommitmentTransaction, TxCreationKeys, ChannelTransactionParameters, CounterpartyChannelTransactionParameters};
+ use ln::PaymentHash;
+ use ln::chan_utils::{CommitmentTransaction, TxCreationKeys, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, HTLCOutputInCommitment};
use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1};
use util::test_utils;
use chain::keysinterface::{KeysInterface, BaseSign};
@@ -1298,6 +1299,14 @@ mod tests {
funding_outpoint: Some(chain::transaction::OutPoint { txid: Default::default(), index: 0 })
};
+ let payment_hash = PaymentHash([42; 32]);
+ let htlc_info = HTLCOutputInCommitment {
+ offered: false,
+ amount_msat: 1,
+ cltv_expiry: 100,
+ payment_hash,
+ transaction_output_index: Some(3),
+ };
let mut htlcs_with_aux: Vec<(_, ())> = Vec::new();
let tx = CommitmentTransaction::new_with_auxiliary_htlc_data(
@@ -1337,6 +1346,15 @@ mod tests {
&mut htlcs_with_aux, &channel_parameters.as_holder_broadcastable()
);
assert_eq!(tx.built.transaction.output.len(), 2);
+ let tx = CommitmentTransaction::new_with_auxiliary_htlc_data(
+ 0, 3000, 0,
+ true,
+ holder_pubkeys.funding_pubkey,
+ counterparty_pubkeys.funding_pubkey,
+ keys.clone(), 1,
+ &mut vec![(htlc_info, ())], &channel_parameters.as_holder_broadcastable()
+ );
+ assert_eq!(tx.built.transaction.output.len(), 4);
}
#[test]
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.
Good point. Slightly modified the test to generate a non-dust HTLC output (in case we start sanity checking that in the future) and pass None
for the HTLC tx index (it should be populated by the commitment tx constructor, but we don't check if already set).
The anchor ouputs pair is added if there are pending HTLCs. Or a a per-party anchor is added if the party has a pending balance.
7e115ed
to
8275698
Compare
Code Review ACK 8275698 |
This pulls out changes to
CommitmentTransaction
from #725.Note that the approach is slightly different from @ariard's original implementation. We can already tell whether an anchor needs inclusion by whether the party's output is non-zero or there are HTLCs. We just need to know the value of
opt_anchors
and the funding pubkeys.This does not yet add anchor support in
Channel
.