-
Notifications
You must be signed in to change notification settings - Fork 411
Fix in checking channel_reserve #189
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
Conversation
@@ -2609,8 +2609,8 @@ impl Channel { | |||
if htlc_outbound_value_msat + amount_msat > self.their_max_htlc_value_in_flight_msat { | |||
return Err(HandleError{err: "Cannot send value that would put us over our max HTLC value in flight", action: None}); | |||
} | |||
// Check their_channel_reserve_satoshis: | |||
if htlc_inbound_value_msat + htlc_outbound_value_msat + amount_msat + (self.channel_value_satoshis * 1000 - self.value_to_self_msat) > (self.channel_value_satoshis - self.their_channel_reserve_satoshis) * 1000 { |
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 previous eqn seems double counting htlc_inbound_value_msat and htlc_outbound_value_msat?
Hmm, we definitely need to be subtracting pending HTLCs from the value_to_self_msat here (since any pending HTLCs can't count towards channel reserve and aren't included in value_to_self_msat), though it looks pretty awkward and I'd buy that its wrong. Can you add a test either way? |
c8fef0b
to
a3e103c
Compare
Since value_to_self_msat is adjusted when revoke_and_ack'd, when evaluating this condition, value_to_self contains pending outgoing htlc values, so, yes, they need to be subtracted. But pending incoming htlc values have nothing to do with value_to_self_msat at this point. New conditions are the same except not including value for incoming HTLC to be subtracted from value_to_self_msat. The conditions are just tighter (more money available). Also, I added outgoing value in the pending_cell. Hard to figure a good test for this. |
Hmm, ok, yes, I buy that the new version is correct, but really needs tests. One thing you could do it add a debug_assert in build_commitment_transaction that the finally-calculated value_to_self and value_to_remote match channel reserves (which is broader than revoke_and_ack), though I don't like relying on fuzz testing for that as the full_stack_target is still way too broad to reliably find things like that. If you did that and also added a number of tests which tested sending one less than and one more than the limit in the ChannelManager network tests (incl various states like awaiting-revoke, etc) then we'd probably be OK. Testing the holding cell updates is going to be much harder, I think, though, cause free_holding_cell_htlcs handles the error case instead of sending the new HTLC. |
src/ln/channel.rs
Outdated
} | ||
} | ||
|
||
// Check self.their_channel_reserve_satoshis (i.e our channel reserve): |
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.
Not sure that that is any more clear...maybe s/our channel reserve/the amount we must keep as reserve for them to have something to claim if we misbehave/?
a3e103c
to
af89dc1
Compare
still need another test involving holding cell. |
I'm not clear about this. HTLCUpdateAwaitingACK::FailHTLC won't be affecting to_self_value_msat ever? |
and max_htlc_value_in_flight_msat
ab13c24
to
0000294
Compare
added a test scenario with holding cell. |
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! Changes look good and I tried to falsify the tests a bit and they caught it.
src/ln/channel.rs
Outdated
@@ -2725,7 +2763,7 @@ impl Channel { | |||
return Err(HandleError{err: "Cannot send an HTLC while disconnected", action: Some(ErrorAction::IgnoreError)}); | |||
} | |||
|
|||
let (_, outbound_htlc_count, htlc_outbound_value_msat, htlc_inbound_value_msat) = self.get_pending_htlc_stats(false); | |||
let (_, outbound_htlc_count, htlc_outbound_value_msat, _) = self.get_pending_htlc_stats(false); |
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.
Oops, with this and the change to split up pending_htlcs into two vecs it probably makes sense to get rid of get_pending_htlc_stats - currently all callsites make it iterate over both HTLC vecs but only care about the results from one.
src/ln/channelmanager.rs
Outdated
use ln::msgs::HandleError; | ||
|
||
macro_rules! get_channel_value_stat { | ||
($node: expr, $channel_id: expr) => {{ |
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: indentation is wrong around here.
src/ln/channelmanager.rs
Outdated
macro_rules! get_route_and_payment_hash { | ||
($recv_value: expr) => {{ | ||
let route = nodes[0].router.get_route(&nodes.last().unwrap().node.get_our_node_id(), None, &Vec::new(), $recv_value, TEST_FINAL_CLTV).unwrap(); | ||
let payment_preimage = [*nodes[0].network_payment_count.borrow(); 32]; |
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 be able to use get_payment_preimage_hash!!
You can also take the change at TheBlueMatt@1f31e03 if you want, its a pretty aggressive check but once it gets adapted to udpate_fee/etc it may make sense to have something more aggressive like that. |
to get_inbound_pending_htlc_stats and get_outbound_pending_htlc_stats
0000294
to
5f1b366
Compare
Took TheBlueMatt/rust-lightning@1f31e03 and others fixed. |
Will take as #206. |
No description provided.