htlcs_included: Vec<(HTLCOutputInCommitment, Option<&'a HTLCSource>)>, // the list of HTLCs (dust HTLCs *included*) which were not ignored when building the transaction
local_balance_msat: u64, // local balance before fees but considering dust limits
remote_balance_msat: u64, // remote balance before fees but considering dust limits
- preimages: Vec<PaymentPreimage>, // preimages for successful offered HTLCs since last commitment
+ outbound_htlc_preimages: Vec<PaymentPreimage>, // preimages for successful offered HTLCs since last commitment
+ inbound_htlc_preimages: Vec<PaymentPreimage>, // preimages for successful received HTLCs since last commitment
}
/// Used when calculating whether we or the remote can afford an additional HTLC.
}
}
+ let mut inbound_htlc_preimages: Vec<PaymentPreimage> = Vec::new();
+
for ref htlc in self.pending_inbound_htlcs.iter() {
let (include, state_name) = match htlc.state {
InboundHTLCState::RemoteAnnounced(_) => (!generated_by_local, "RemoteAnnounced"),
match &htlc.state {
&InboundHTLCState::LocalRemoved(ref reason) => {
if generated_by_local {
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
+ if let &InboundHTLCRemovalReason::Fulfill(preimage) = reason {
+ inbound_htlc_preimages.push(preimage);
value_to_self_msat_offset += htlc.amount_msat as i64;
}
}
}
}
- let mut preimages: Vec<PaymentPreimage> = Vec::new();
+
+ let mut outbound_htlc_preimages: Vec<PaymentPreimage> = Vec::new();
for ref htlc in self.pending_outbound_htlcs.iter() {
let (include, state_name) = match htlc.state {
};
if let Some(preimage) = preimage_opt {
- preimages.push(preimage);
+ outbound_htlc_preimages.push(preimage);
}
if include {
htlcs_included,
local_balance_msat: value_to_self_msat as u64,
remote_balance_msat: value_to_remote_msat as u64,
- preimages
+ inbound_htlc_preimages,
+ outbound_htlc_preimages,
}
}
let signature = match &self.holder_signer {
// TODO (taproot|arik): move match into calling method for Taproot
ChannelSignerType::Ecdsa(ecdsa) => {
- ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
+ ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx)
.map(|(sig, _)| sig).ok()?
},
// TODO (taproot|arik)
match &self.holder_signer {
// TODO (arik): move match into calling method for Taproot
ChannelSignerType::Ecdsa(ecdsa) => {
- let funding_signed = ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
+ let funding_signed = ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx)
.map(|(signature, _)| msgs::FundingSigned {
channel_id: self.channel_id(),
signature,
self.context.counterparty_funding_pubkey()
);
- self.context.holder_signer.as_ref().validate_holder_commitment(&holder_commitment_tx, commitment_stats.preimages)
+ self.context.holder_signer.as_ref().validate_holder_commitment(&holder_commitment_tx, commitment_stats.outbound_htlc_preimages)
.map_err(|_| ChannelError::Close("Failed to validate our commitment".to_owned()))?;
// Update state now that we've passed all the can-fail calls...
htlcs.push(htlc);
}
- let res = ecdsa.sign_counterparty_commitment(&commitment_stats.tx, commitment_stats.preimages, &self.context.secp_ctx)
- .map_err(|_| ChannelError::Ignore("Failed to get signatures for new commitment_signed".to_owned()))?;
+ let res = ecdsa.sign_counterparty_commitment(
+ &commitment_stats.tx,
+ commitment_stats.inbound_htlc_preimages,
+ commitment_stats.outbound_htlc_preimages,
+ &self.context.secp_ctx,
+ ).map_err(|_| ChannelError::Ignore("Failed to get signatures for new commitment_signed".to_owned()))?;
signature = res.0;
htlc_signatures = res.1;
let mut pending_outbound_blinding_points: Vec<Option<PublicKey>> = Vec::new();
(self.context.pending_outbound_htlcs.len() as u64).write(writer)?;
- for (idx, htlc) in self.context.pending_outbound_htlcs.iter().enumerate() {
+ for htlc in self.context.pending_outbound_htlcs.iter() {
htlc.htlc_id.write(writer)?;
htlc.amount_msat.write(writer)?;
htlc.cltv_expiry.write(writer)?;
reason.write(writer)?;
}
}
- if let Some(skimmed_fee) = htlc.skimmed_fee_msat {
- if pending_outbound_skimmed_fees.is_empty() {
- for _ in 0..idx { pending_outbound_skimmed_fees.push(None); }
- }
- pending_outbound_skimmed_fees.push(Some(skimmed_fee));
- } else if !pending_outbound_skimmed_fees.is_empty() {
- pending_outbound_skimmed_fees.push(None);
- }
+ pending_outbound_skimmed_fees.push(htlc.skimmed_fee_msat);
pending_outbound_blinding_points.push(htlc.blinding_point);
}
let mut holding_cell_skimmed_fees: Vec<Option<u64>> = Vec::new();
let mut holding_cell_blinding_points: Vec<Option<PublicKey>> = Vec::new();
(self.context.holding_cell_htlc_updates.len() as u64).write(writer)?;
- for (idx, update) in self.context.holding_cell_htlc_updates.iter().enumerate() {
+ for update in self.context.holding_cell_htlc_updates.iter() {
match update {
&HTLCUpdateAwaitingACK::AddHTLC {
ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet,
source.write(writer)?;
onion_routing_packet.write(writer)?;
- if let Some(skimmed_fee) = skimmed_fee_msat {
- if holding_cell_skimmed_fees.is_empty() {
- for _ in 0..idx { holding_cell_skimmed_fees.push(None); }
- }
- holding_cell_skimmed_fees.push(Some(skimmed_fee));
- } else if !holding_cell_skimmed_fees.is_empty() { holding_cell_skimmed_fees.push(None); }
-
+ holding_cell_skimmed_fees.push(skimmed_fee_msat);
holding_cell_blinding_points.push(blinding_point);
},
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
}
#[test]
- fn blinding_point_ser() {
- // Ensure that channel blinding points are (de)serialized properly.
+ fn blinding_point_skimmed_fee_ser() {
+ // Ensure that channel blinding points and skimmed fees are (de)serialized properly.
let feeest = LowerBoundedFeeEstimator::new(&TestFeeEstimator{fee_est: 15000});
let secp_ctx = Secp256k1::new();
let seed = [42; 32];
if idx % 2 == 0 {
htlc.blinding_point = Some(test_utils::pubkey(42 + idx as u8));
}
+ if idx % 3 == 0 {
+ htlc.skimmed_fee_msat = Some(1);
+ }
}
chan.context.pending_outbound_htlcs = pending_outbound_htlcs.clone();
holding_cell_htlc_updates.push(dummy_holding_cell_claim_htlc.clone());
} else {
let mut dummy_add = dummy_holding_cell_add_htlc.clone();
- if let HTLCUpdateAwaitingACK::AddHTLC { ref mut blinding_point, .. } = &mut dummy_add {
+ if let HTLCUpdateAwaitingACK::AddHTLC {
+ ref mut blinding_point, ref mut skimmed_fee_msat, ..
+ } = &mut dummy_add {
*blinding_point = Some(test_utils::pubkey(42 + i));
+ *skimmed_fee_msat = Some(42);
} else { panic!() }
holding_cell_htlc_updates.push(dummy_add);
}