impl HTLCCandidate {
fn new(amount_msat: u64, origin: HTLCInitiator) -> Self {
- Self {
- amount_msat,
- origin,
- }
+ Self { amount_msat, origin }
+ }
+ fn non_dust(origin: HTLCInitiator) -> Self {
+ Self { amount_msat: 21_000_000 * 1_0000_0000, origin }
}
}
pub fn get_inbound_outbound_available_balance_msat(&self) -> (u64, u64, u64) {
// Note that we have to handle overflow due to the above case.
let outbound_stats = self.get_outbound_pending_htlc_stats(None);
+ let extra_htlc_commitment_fee_msat = self.outbound_htlc_spike_buffer_commitment_tx_fee_msat(HTLCCandidate::non_dust(HTLCInitiator::LocalOffered)) as i64;
let outbound_capacity_msat = cmp::max(self.value_to_self_msat as i64
- outbound_stats.pending_htlcs_value_msat as i64
- self.counterparty_selected_channel_reserve_satoshis.unwrap_or(0) as i64 * 1000,
- self.holder_selected_channel_reserve_satoshis as i64 * 1000,
0) as u64,
outbound_capacity_msat,
- cmp::max(cmp::min(outbound_capacity_msat as i64,
- self.counterparty_max_htlc_value_in_flight_msat as i64
- - outbound_stats.pending_htlcs_value_msat as i64),
+ cmp::max(cmp::min(cmp::min(
+ outbound_capacity_msat as i64,
+ self.counterparty_max_htlc_value_in_flight_msat as i64
+ - outbound_stats.pending_htlcs_value_msat as i64
+ - extra_htlc_commitment_fee_msat)
+ - extra_htlc_commitment_fee_msat,
+ if outbound_stats.pending_htlcs + 1 > self.counterparty_max_accepted_htlcs as u32 { i64::max_value() /*XXX0*/ } else { i64::max_value() }
+ ),
+ // TODO: self.counterparty_htlc_maximum_msat as i64),
+ // TODO: Capture feerate avoidance policy
+ // TODO: Capture HTLC count limit
0) as u64
)
}
}
+ fn outbound_htlc_spike_buffer_commitment_tx_fee_msat(&self, htlc_candidate: HTLCCandidate) -> u64 {
+ if self.is_outbound() {
+ FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE * self.next_local_commit_tx_fee_msat(htlc_candidate, Some(()))
+ } else { 0 }
+ }
+
// Send stuff to our remote peers:
/// Adds a pending outbound HTLC to this channel, note that you probably want
}
// `2 *` and extra HTLC are for the fee spike buffer.
- let commit_tx_fee_msat = if self.is_outbound() {
- let htlc_candidate = HTLCCandidate::new(amount_msat, HTLCInitiator::LocalOffered);
- FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE * self.next_local_commit_tx_fee_msat(htlc_candidate, Some(()))
- } else { 0 };
+ let htlc_candidate = HTLCCandidate::new(amount_msat, HTLCInitiator::LocalOffered);
+ let commit_tx_fee_msat = self.outbound_htlc_spike_buffer_commitment_tx_fee_msat(htlc_candidate);
if holder_balance_msat - amount_msat < commit_tx_fee_msat {
return Err(ChannelError::Ignore(format!("Cannot send value that would not leave enough to pay for fees. Pending value to self: {}. local_commit_tx_fee {}", holder_balance_msat, commit_tx_fee_msat)));
}
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 0, InitFeatures::known(), InitFeatures::known());
let max_accepted_htlcs = nodes[1].node.channel_state.lock().unwrap().by_id.get(&chan.2).unwrap().counterparty_max_accepted_htlcs as u64;
+ let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100000);
for i in 0..max_accepted_htlcs {
let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100000);
let payment_event = {
expect_pending_htlcs_forwardable!(nodes[1]);
expect_payment_received!(nodes[1], our_payment_hash, our_payment_secret, 100000);
}
- let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100000);
+ // XXX: check that we fail to get a route now!
unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret)), true, APIError::ChannelUnavailable { ref err },
assert!(regex::Regex::new(r"Cannot push more than their max accepted HTLCs \(\d+\)").unwrap().is_match(err)));