-
Notifications
You must be signed in to change notification settings - Fork 419
0FC tests round 1 #4089
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
0FC tests round 1 #4089
Changes from all commits
67ed89d
bb3eeed
74c11a8
7a9d713
df0df2f
1ebc270
2eb7d31
175a3e3
25fce0a
0c54c51
6a697b1
1618c77
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 |
---|---|---|
|
@@ -69,10 +69,10 @@ pub fn max_htlcs(channel_type: &ChannelTypeFeatures) -> u16 { | |
483 | ||
} | ||
} | ||
/// The weight of a BIP141 witnessScript for a BOLT3's "offered HTLC output" on a commitment transaction, non-anchor variant. | ||
/// The weight of a BIP141 witnessScript for a BOLT3's "offered HTLC output" on a commitment transaction, non-anchor and p2a anchor variant. | ||
pub const OFFERED_HTLC_SCRIPT_WEIGHT: usize = 133; | ||
/// The weight of a BIP141 witnessScript for a BOLT3's "offered HTLC output" on a commitment transaction, anchor variant. | ||
pub const OFFERED_HTLC_SCRIPT_WEIGHT_ANCHORS: usize = 136; | ||
/// The weight of a BIP141 witnessScript for a BOLT3's "offered HTLC output" on a commitment transaction, keyed anchor variant. | ||
pub const OFFERED_HTLC_SCRIPT_WEIGHT_KEYED_ANCHORS: usize = 136; | ||
|
||
/// The weight of a BIP141 witnessScript for a BOLT3's "received HTLC output" can vary in function of its CLTV argument value. | ||
/// We define a range that encompasses both its non-anchors and anchors variants. | ||
|
@@ -95,12 +95,16 @@ pub const P2A_ANCHOR_INPUT_WITNESS_WEIGHT: u64 = 1; | |
/// The maximum value of a P2A anchor. | ||
pub const P2A_MAX_VALUE: u64 = 240; | ||
|
||
/// The upper bound weight of an HTLC timeout input from a commitment transaction with anchor | ||
/// outputs. | ||
pub const HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT: u64 = 288; | ||
/// The upper bound weight of an HTLC success input from a commitment transaction with anchor | ||
/// outputs. | ||
pub const HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT: u64 = 327; | ||
/// The upper bound weight of an HTLC timeout input from a commitment transaction with keyed anchor outputs. | ||
pub const HTLC_TIMEOUT_INPUT_KEYED_ANCHOR_WITNESS_WEIGHT: u64 = 288; | ||
/// The upper bound weight of an HTLC timeout input from a commitment transaction with a p2a anchor output. | ||
/// Note the corresponding outputs no longer have the 1 CSV lock. | ||
pub const HTLC_TIMEOUT_INPUT_P2A_ANCHOR_WITNESS_WEIGHT: u64 = 285; | ||
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. There is no coverage for this change. Tests pass if this is 288. 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. These are used to pass estimates of the size of witness to coin selection in |
||
/// The upper bound weight of an HTLC success input from a commitment transaction with keyed anchor outputs. | ||
pub const HTLC_SUCCESS_INPUT_KEYED_ANCHOR_WITNESS_WEIGHT: u64 = 327; | ||
/// The upper bound weight of an HTLC success input from a commitment transaction with a p2a anchor output. | ||
/// Note the corresponding outputs no longer have the 1 CSV lock. | ||
pub const HTLC_SUCCESS_INPUT_P2A_ANCHOR_WITNESS_WEIGHT: u64 = 324; | ||
carlaKC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// The size of the 2-of-2 multisig script | ||
const MULTISIG_SCRIPT_SIZE: u64 = 1 + // OP_2 | ||
|
@@ -158,7 +162,7 @@ impl HTLCClaim { | |
/// Check if a given input witness attempts to claim a HTLC. | ||
#[rustfmt::skip] | ||
pub fn from_witness(witness: &Witness) -> Option<Self> { | ||
debug_assert_eq!(OFFERED_HTLC_SCRIPT_WEIGHT_ANCHORS, MIN_ACCEPTED_HTLC_SCRIPT_WEIGHT); | ||
debug_assert_eq!(OFFERED_HTLC_SCRIPT_WEIGHT_KEYED_ANCHORS, MIN_ACCEPTED_HTLC_SCRIPT_WEIGHT); | ||
if witness.len() < 2 { | ||
return None; | ||
} | ||
|
@@ -177,7 +181,7 @@ impl HTLCClaim { | |
} else { | ||
None | ||
} | ||
} else if witness_script.len() == OFFERED_HTLC_SCRIPT_WEIGHT_ANCHORS { | ||
} else if witness_script.len() == OFFERED_HTLC_SCRIPT_WEIGHT_KEYED_ANCHORS { | ||
// It's possible for the weight of `offered_htlc_script` and `accepted_htlc_script` to | ||
// match so we check for both here. | ||
if witness.len() == 3 && second_to_last.len() == 33 { | ||
|
@@ -2202,7 +2206,8 @@ mod tests { | |
use super::{ChannelPublicKeys, CounterpartyCommitmentSecrets}; | ||
use crate::chain; | ||
use crate::ln::chan_utils::{ | ||
get_htlc_redeemscript, get_to_countersigner_keyed_anchor_redeemscript, | ||
get_htlc_redeemscript, get_keyed_anchor_redeemscript, | ||
get_to_countersigner_keyed_anchor_redeemscript, shared_anchor_script_pubkey, | ||
BuiltCommitmentTransaction, ChannelTransactionParameters, CommitmentTransaction, | ||
CounterpartyChannelTransactionParameters, HTLCOutputInCommitment, | ||
TrustedCommitmentTransaction, | ||
|
@@ -2250,7 +2255,7 @@ mod tests { | |
funding_outpoint: Some(chain::transaction::OutPoint { txid: Txid::all_zeros(), index: 0 }), | ||
splice_parent_funding_txid: None, | ||
channel_type_features: ChannelTypeFeatures::only_static_remote_key(), | ||
channel_value_satoshis: 3000, | ||
channel_value_satoshis: 4000, | ||
}; | ||
|
||
Self { | ||
|
@@ -2293,14 +2298,42 @@ mod tests { | |
let tx = builder.build(1000, 2000, Vec::new()); | ||
assert_eq!(tx.built.transaction.output.len(), 4); | ||
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersigner_keyed_anchor_redeemscript(&builder.counterparty_pubkeys.payment_point).to_p2wsh()); | ||
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_keyed_anchor_redeemscript(&builder.channel_parameters.holder_pubkeys.funding_pubkey).to_p2wsh()); | ||
assert_eq!(tx.built.transaction.output[0].value.to_sat(), 330); | ||
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_keyed_anchor_redeemscript(&builder.counterparty_pubkeys.funding_pubkey).to_p2wsh()); | ||
assert_eq!(tx.built.transaction.output[1].value.to_sat(), 330); | ||
|
||
// Generate broadcaster output and anchor | ||
let tx = builder.build(3000, 0, Vec::new()); | ||
assert_eq!(tx.built.transaction.output.len(), 2); | ||
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_keyed_anchor_redeemscript(&builder.channel_parameters.holder_pubkeys.funding_pubkey).to_p2wsh()); | ||
assert_eq!(tx.built.transaction.output[0].value.to_sat(), 330); | ||
|
||
// Generate counterparty output and anchor | ||
let tx = builder.build(0, 3000, Vec::new()); | ||
assert_eq!(tx.built.transaction.output.len(), 2); | ||
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_keyed_anchor_redeemscript(&builder.counterparty_pubkeys.funding_pubkey).to_p2wsh()); | ||
assert_eq!(tx.built.transaction.output[0].value.to_sat(), 330); | ||
|
||
// Generate broadcaster and counterparty outputs as well as a single anchor | ||
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_fee_commitments(); | ||
let tx = builder.build(1000, 2000, Vec::new()); | ||
assert_eq!(tx.built.transaction.output.len(), 3); | ||
assert_eq!(tx.built.transaction.output[2].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_point), Network::Testnet).script_pubkey()); | ||
assert_eq!(tx.built.transaction.output[0].script_pubkey, shared_anchor_script_pubkey()); | ||
assert_eq!(tx.built.transaction.output[0].value.to_sat(), 240); // remember total channel value is 4000sat | ||
|
||
// Generate broadcaster output and anchor | ||
let tx = builder.build(3000, 0, Vec::new()); | ||
assert_eq!(tx.built.transaction.output.len(), 2); | ||
assert_eq!(tx.built.transaction.output[0].script_pubkey, shared_anchor_script_pubkey()); | ||
assert_eq!(tx.built.transaction.output[0].value.to_sat(), 240); // remember total channel value is 4000sat | ||
|
||
// Generate counterparty output and anchor | ||
let tx = builder.build(0, 3000, Vec::new()); | ||
assert_eq!(tx.built.transaction.output.len(), 2); | ||
assert_eq!(tx.built.transaction.output[0].script_pubkey, shared_anchor_script_pubkey()); | ||
assert_eq!(tx.built.transaction.output[0].value.to_sat(), 240); // remember total channel value is 4000sat | ||
|
||
let received_htlc = HTLCOutputInCommitment { | ||
offered: false, | ||
|
@@ -2318,7 +2351,7 @@ mod tests { | |
transaction_output_index: None, | ||
}; | ||
|
||
// Generate broadcaster output and received and offered HTLC outputs, w/o anchors | ||
// Generate broadcaster output and received and offered HTLC outputs, w/o anchors | ||
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::only_static_remote_key(); | ||
let tx = builder.build(3000, 0, vec![received_htlc.clone(), offered_htlc.clone()]); | ||
let keys = tx.trust().keys(); | ||
|
@@ -2330,16 +2363,33 @@ mod tests { | |
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(), | ||
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d"); | ||
|
||
// Generate broadcaster output and received and offered HTLC outputs, with anchors | ||
// Generate broadcaster output and received and offered HTLC outputs, with keyed anchors | ||
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(); | ||
let tx = builder.build(3000, 0, vec![received_htlc.clone(), offered_htlc.clone()]); | ||
assert_eq!(tx.built.transaction.output.len(), 5); | ||
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_keyed_anchor_redeemscript(&builder.channel_parameters.holder_pubkeys.funding_pubkey).to_p2wsh()); | ||
assert_eq!(tx.built.transaction.output[0].value.to_sat(), 330); | ||
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_keyed_anchor_redeemscript(&builder.counterparty_pubkeys.funding_pubkey).to_p2wsh()); | ||
assert_eq!(tx.built.transaction.output[1].value.to_sat(), 330); | ||
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh()); | ||
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh()); | ||
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(), | ||
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc"); | ||
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(), | ||
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7"); | ||
|
||
// Generate broadcaster output and received and offered HTLC outputs, with P2A anchors | ||
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_fee_commitments(); | ||
let tx = builder.build(3000, 0, vec![received_htlc.clone(), offered_htlc.clone()]); | ||
carlaKC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert_eq!(tx.built.transaction.output.len(), 4); | ||
assert_eq!(tx.built.transaction.output[0].script_pubkey, shared_anchor_script_pubkey()); | ||
assert_eq!(tx.built.transaction.output[0].value.to_sat(), 0); | ||
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh()); | ||
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh()); | ||
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh().to_hex_string(), | ||
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb"); | ||
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh().to_hex_string(), | ||
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d"); | ||
} | ||
|
||
#[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.
Might also make sense to do this in
check_spends
.