Skip to content

Commit

Permalink
Persist update_add sender skimmed fee in Channel
Browse files Browse the repository at this point in the history
This will always be None as of this commit, but once we start setting the field
it will break backwards compat with LDK versions prior to 0.0.116.
  • Loading branch information
valentinewallace committed Jun 8, 2023
1 parent 73513f1 commit ca3c3b5
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ struct OutboundHTLCOutput {
payment_hash: PaymentHash,
state: OutboundHTLCState,
source: HTLCSource,
skimmed_fee_msat: Option<u64>,
}

/// See AwaitingRemoteRevoke ChannelState for more info
Expand All @@ -233,6 +234,8 @@ enum HTLCUpdateAwaitingACK {
payment_hash: PaymentHash,
source: HTLCSource,
onion_routing_packet: msgs::OnionPacket,
// The extra fee we're skimming off the top of this HTLC.
skimmed_fee_msat: Option<u64>,
},
ClaimHTLC {
payment_preimage: PaymentPreimage,
Expand Down Expand Up @@ -6003,6 +6006,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
cltv_expiry,
source,
onion_routing_packet,
skimmed_fee_msat: None,
});
return Ok(None);
}
Expand All @@ -6014,6 +6018,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
cltv_expiry,
state: OutboundHTLCState::LocalAnnounced(Box::new(onion_routing_packet.clone())),
source,
skimmed_fee_msat: None,
});

let res = msgs::UpdateAddHTLC {
Expand Down Expand Up @@ -6533,18 +6538,23 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
reason.write(writer)?;
}
}
htlc.skimmed_fee_msat.write(writer)?;
}

(self.holding_cell_htlc_updates.len() as u64).write(writer)?;
for update in self.holding_cell_htlc_updates.iter() {
match update {
&HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet } => {
&HTLCUpdateAwaitingACK::AddHTLC {
ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet,
ref skimmed_fee_msat,
} => {
0u8.write(writer)?;
amount_msat.write(writer)?;
cltv_expiry.write(writer)?;
payment_hash.write(writer)?;
source.write(writer)?;
onion_routing_packet.write(writer)?;
skimmed_fee_msat.write(writer)?;
},
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
1u8.write(writer)?;
Expand Down Expand Up @@ -6821,6 +6831,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
},
_ => return Err(DecodeError::InvalidValue),
},
skimmed_fee_msat: Readable::read(reader)?,
});
}

Expand All @@ -6834,6 +6845,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
payment_hash: Readable::read(reader)?,
source: Readable::read(reader)?,
onion_routing_packet: Readable::read(reader)?,
skimmed_fee_msat: Readable::read(reader)?,
},
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
payment_preimage: Readable::read(reader)?,
Expand Down Expand Up @@ -7393,7 +7405,8 @@ mod tests {
session_priv: SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
first_hop_htlc_msat: 548,
payment_id: PaymentId([42; 32]),
}
},
skimmed_fee_msat: None,
});

// Make sure when Node A calculates their local commitment transaction, none of the HTLCs pass
Expand Down Expand Up @@ -7927,6 +7940,7 @@ mod tests {
payment_hash: PaymentHash([0; 32]),
state: OutboundHTLCState::Committed,
source: HTLCSource::dummy(),
skimmed_fee_msat: None,
};
out.payment_hash.0 = Sha256::hash(&hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap()).into_inner();
out
Expand All @@ -7939,6 +7953,7 @@ mod tests {
payment_hash: PaymentHash([0; 32]),
state: OutboundHTLCState::Committed,
source: HTLCSource::dummy(),
skimmed_fee_msat: None,
};
out.payment_hash.0 = Sha256::hash(&hex::decode("0303030303030303030303030303030303030303030303030303030303030303").unwrap()).into_inner();
out
Expand Down Expand Up @@ -8340,6 +8355,7 @@ mod tests {
payment_hash: PaymentHash([0; 32]),
state: OutboundHTLCState::Committed,
source: HTLCSource::dummy(),
skimmed_fee_msat: None,
};
out.payment_hash.0 = Sha256::hash(&hex::decode("0505050505050505050505050505050505050505050505050505050505050505").unwrap()).into_inner();
out
Expand All @@ -8352,6 +8368,7 @@ mod tests {
payment_hash: PaymentHash([0; 32]),
state: OutboundHTLCState::Committed,
source: HTLCSource::dummy(),
skimmed_fee_msat: None,
};
out.payment_hash.0 = Sha256::hash(&hex::decode("0505050505050505050505050505050505050505050505050505050505050505").unwrap()).into_inner();
out
Expand Down

0 comments on commit ca3c3b5

Please sign in to comment.