-
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
Conversation
👋 Thanks for assigning @carlaKC as a reviewer! |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4089 +/- ##
==========================================
- Coverage 88.69% 88.56% -0.13%
==========================================
Files 176 180 +4
Lines 132839 134549 +1710
Branches 132839 134549 +1710
==========================================
+ Hits 117816 119168 +1352
- Misses 12330 12630 +300
- Partials 2693 2751 +58
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
b5fbb0b
to
a80c26a
Compare
🔔 1st Reminder Hey @carlaKC! This PR has been waiting for your review. |
8a20d8d
to
795a0a6
Compare
🔔 2nd Reminder Hey @carlaKC! This PR has been waiting for your review. |
795a0a6
to
3856b51
Compare
f7ca7fe
to
3692f83
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.
Nice update to the tests! Consider most comments non-blocking given the Friday deadline to get this in.
Only question I have is whether we need to worry about V3 tx size constraints.
let mut htlc_tx = Transaction { | ||
version: Version::TWO, | ||
version: if channel_type.supports_anchor_zero_fee_commitments() { | ||
Version::non_standard(3) |
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.
This seems pretty unlikely, but is it possible that we go over the 10,000 vB rule 4 restriction on TRUC transactions if we aggregate a bunch of second stage txns together?
We don't need to worry about package limits because we're still waiting for the commitment to confirm (like we would with CSV 1 regular anchors), but this limit applies to individual V3 transactions IIUC.
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.
If we're still waiting on the commitment to confirm I'm not sure we need to worry to much - the anchor spend on the commit should eventually get bumped enough to confirm it. What worries me more is if we aggregate HTLC claims into one transaction.
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 points thank you ! It seems the only reason why this is version 3 now is so that these HTLC tx's can be aggregated with the anchor spend. We are not doing this here, so we could revert the HTLC tx version to 2.
"Spending tx output didn't meet dust limit" | ||
); | ||
if outp.value < outp.script_pubkey.minimal_non_dust() { | ||
if single_output_below_dust { |
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.
Wouldn't we also want to checkshared_anchor_script_pubkey
like below?
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.
thanks I initially had the general case in mind, but we certainly don't expect any other non-p2a outputs to be below dust. Will fix.
lightning/src/ln/chan_utils.rs
Outdated
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d"); | ||
|
||
// Generate broadcaster output and received and offered HTLC outputs, with anchors | ||
// Generate broadcaster output and received and offered HTLC outputs, with keyed anchors |
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.
nit: double space after comma and on 2361
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.
thanks ! I was keeping it consistent with existing formatting, but don't see a need, will delete the extra space everywhere.
lightning/src/ln/monitor_tests.rs
Outdated
if keyed_anchors { | ||
user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; | ||
user_config.manually_accept_inbound_channels = true; | ||
} else if p2a_anchor { | ||
user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; | ||
user_config.manually_accept_inbound_channels = true; |
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.
could save a few lines in a few spots:
user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors;
user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor;
user_config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor;
do_test_lost_timeout_monitor_events(CommitmentType::RevokedCounterparty, false, false); | ||
do_test_lost_timeout_monitor_events(CommitmentType::RevokedCounterparty, true, false); | ||
do_test_lost_timeout_monitor_events(CommitmentType::PreviousCounterparty, false, false); | ||
do_test_lost_timeout_monitor_events(CommitmentType::PreviousCounterparty, true, false); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LatestCounterparty, false, false); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LatestCounterparty, true, false); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LocalWithoutLastHTLC, false, false); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LocalWithoutLastHTLC, true, false); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LocalWithLastHTLC, false, false); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LocalWithLastHTLC, true, false); | ||
|
||
do_test_lost_timeout_monitor_events(CommitmentType::RevokedCounterparty, false, true); | ||
do_test_lost_timeout_monitor_events(CommitmentType::RevokedCounterparty, true, true); | ||
do_test_lost_timeout_monitor_events(CommitmentType::PreviousCounterparty, false, true); | ||
do_test_lost_timeout_monitor_events(CommitmentType::PreviousCounterparty, true, true); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LatestCounterparty, false, true); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LatestCounterparty, true, true); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LocalWithoutLastHTLC, false, true); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LocalWithoutLastHTLC, true, true); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LocalWithLastHTLC, false, true); | ||
do_test_lost_timeout_monitor_events(CommitmentType::LocalWithLastHTLC, true, true); |
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.
DRY up a bit?
for p2a in [true, false] {
do_test_lost_timeout_monitor_events(CommitmentType::RevokedCounterparty, false, p2a);
...
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.
let me see if one of these errors fails, the backtrace would not tell us whether we failed with p2a true or false ?
lightning/src/ln/reorg_tests.rs
Outdated
mine_transactions(&nodes[0], &[&commitment_tx, &anchor_tx]); | ||
check_closed_broadcast(&nodes[0], 1, false); | ||
let reason = ClosureReason::CommitmentTxConfirmed; | ||
check_closed_event(&nodes[0], 1, reason, false, &[node_b_id], 10_000_000); | ||
check_added_monitors(&nodes[0], 1); | ||
|
||
mine_transactions(&nodes[1], &[&commitment_tx, &anchor_tx]); | ||
handle_bump_events(&nodes[1], nodes[1].connect_style.borrow().updates_best_block_first(), 1); |
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.
This can be DRY-ed up a bit - both branches are the same except the list of transactions we need to mine.
} | ||
|
||
p2a_value_test!(1,, 1); | ||
p2a_value_test!(238_000,, 238); |
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.
Perhaps we could change the macro to make invocation a little more readable - this is my best shot at it diff.
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.
A few assorted notes, otherwise basically lgtm.
.channel_type_features; | ||
let mut htlc_tx = Transaction { | ||
version: Version::TWO, | ||
version: if channel_type.supports_anchor_zero_fee_commitments() { |
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.
Is this required by the counterparty's signature? Ideally we wouldn't want to do this I think, but I'm not sure if the sig covers it.
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.
The counterparty sig does cover it, that's how I found this here :) See above comment from carla, as long as we don't aggregate HTLCs into the anchor tx, we could revert HTLC txs to V2.
} else if _script_pubkey.is_p2wpkh() { | ||
assert_eq!(&bitcoin::Address::p2wpkh(&bitcoin::CompressedPublicKey(bitcoin::PublicKey::from_slice(&input.witness.last().unwrap()).unwrap().inner), bitcoin::Network::Bitcoin).script_pubkey(), _script_pubkey); | ||
} else if _script_pubkey == &chan_utils::shared_anchor_script_pubkey() { | ||
assert!(input.witness.is_empty()); |
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
.
"Spending tx output didn't meet dust limit" | ||
); | ||
if outp.value < outp.script_pubkey.minimal_non_dust() { | ||
if single_output_below_dust { |
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.
Should we check that the output is P2A here?
assert!(total_value_out + min_fee <= total_value_in); | ||
if single_output_below_dust { | ||
assert_eq!( | ||
total_value_in, total_value_out, |
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.
This should fail, right? The P2A output can drift above dust if we have some dust HTLCs.
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.
this should be true; we are allowed a single output below dust as long as the transaction is zero fee.
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.
at 240 sats, single_output_below_dust
is false - now I realize i need to relax the branch below to allow for sub 1sat/vb txs if they have this 240sat output.
lightning/src/ln/monitor_tests.rs
Outdated
assert_eq!(timeout_htlc_txn[0].input.len(), 3); | ||
assert_eq!(timeout_htlc_txn[0].input[0].witness.last().unwrap().len(), chan_utils::OFFERED_HTLC_SCRIPT_WEIGHT_ANCHORS); | ||
assert_eq!(timeout_htlc_txn[0].input[1].witness.last().unwrap().len(), chan_utils::OFFERED_HTLC_SCRIPT_WEIGHT_ANCHORS); | ||
assert_eq!(timeout_htlc_txn[0].input[0].witness.last().unwrap().len(), if p2a_anchor { chan_utils::OFFERED_HTLC_SCRIPT_WEIGHT } else { chan_utils::OFFERED_HTLC_SCRIPT_WEIGHT_ANCHORS }); |
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.
Oh, can you update the docs on OFFERED_HTLC_SCRIPT_WEIGHT
to mention 0FC?
p2a_value_test!(240_000,, 240); | ||
p2a_value_test!(240_001,, 240); | ||
p2a_value_test!(353_000,, 240); | ||
p2a_value_test!(353_999,, 240); |
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.
Would be nice to have a test with two 353-sat HTLCs to demonstrate we never go over 240 even with multiple HTLCs.
/// 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. | ||
pub const HTLC_TIMEOUT_INPUT_P2A_ANCHOR_WITNESS_WEIGHT: u64 = 285; |
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.
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 comment
The 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 BumpTransactionEventHandler::handle_htlc_resolution
- they both break the 1% max overestimate there if you push them high enough.
3692f83
to
9e2a61a
Compare
In the very last commit, I revert HTLC transaction version to
|
Feel free to squash, imo |
9e2a61a
to
d90bfc6
Compare
Squashed with no further changes |
lightning/src/ln/chan_utils.rs
Outdated
|
||
Transaction { | ||
version, | ||
version: Version::TWO, |
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.
Grrrrrrrrrr discussed this further with @carlaKC and @instagibbs and we have to leave them v3, at least for the "consensus"/local commitment tx/SIGHASH_SINGLE case -
in theory someone can do a pinning attack by holding the HTLC preimage until the timeout is confirmable. Its kinda a weird attack and maybe doesn't matter that much but we should still keep it. In theory we can leave v3 for HTLCs claimed from a counterparty commitment tx cause they dont have a counterparty signature, but not sure if we should bother.
In any case we need to split up batches if they get too big. Probably worth just dropping the last commit here and landing this then fixing the too-big batch separately.
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.
d90bfc6
to
1618c77
Compare
Dropped the last commit: HTLC transactions remain V3 |
if p2a_output_below_dust || !is_p2a { | ||
panic!("Spending tx output didn't meet dust limit"); | ||
} | ||
p2a_output_below_dust = true; |
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.
Oh do we also want to check that the tx is v3 in this case? Its not required by policy (I think?) but in general we should only ever generate a tx that has a P2A dust output if the tx is v3 (or maybe has any P2A output, not just dust). Can be in a followup too.
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.
thank you will add to the follow-up
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.
ran the test suite with that check added, passes
Repurpose existing keyed anchor tests to p2a anchors, more to follow either in or after this PR