Repository navigation
Conversation
| 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.
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. |
| } | ||
| } | ||
|
|
||
| // Check self.their_channel_reserve_satoshis (i.e our channel reserve): |
There was a problem hiding this comment.
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. |
TheBlueMatt
left a comment
There was a problem hiding this comment.
Nice! Changes look good and I tried to falsify the tests a bit and they caught it.
| } | ||
|
|
||
| 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.
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.
| use ln::msgs::HandleError; | ||
|
|
||
| macro_rules! get_channel_value_stat { | ||
| ($node: expr, $channel_id: expr) => {{ |
There was a problem hiding this comment.
nit: indentation is wrong around here.
| 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.
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.