X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=lightning%2Fsrc%2Fln%2Fchannel.rs;h=9b73d30f23f1d95c47c7df4e6c3c075008003db1;hb=89f162c168bc934f64a663f31ea12793568c55b1;hp=8c8202e3efdfdfc8aa7f99cfdd9a19be1353abd7;hpb=091172380434bd3f279f79a1c81110055acec87d;p=rust-lightning diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 8c8202e3..9b73d30f 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -509,7 +509,7 @@ pub(super) struct Channel { inbound_handshake_limits_override: Option, - user_id: u64, + user_id: u128, channel_id: [u8; 32], channel_state: u32, @@ -902,7 +902,7 @@ impl Channel { // Constructors: pub fn new_outbound( fee_estimator: &LowerBoundedFeeEstimator, keys_provider: &K, counterparty_node_id: PublicKey, their_features: &InitFeatures, - channel_value_satoshis: u64, push_msat: u64, user_id: u64, config: &UserConfig, current_chain_height: u32, + channel_value_satoshis: u64, push_msat: u64, user_id: u128, config: &UserConfig, current_chain_height: u32, outbound_scid_alias: u64 ) -> Result, APIError> where K::Target: KeysInterface, @@ -1102,7 +1102,7 @@ impl Channel { /// Assumes chain_hash has already been checked and corresponds with what we expect! pub fn new_from_req( fee_estimator: &LowerBoundedFeeEstimator, keys_provider: &K, counterparty_node_id: PublicKey, their_features: &InitFeatures, - msg: &msgs::OpenChannel, user_id: u64, config: &UserConfig, current_chain_height: u32, logger: &L, + msg: &msgs::OpenChannel, user_id: u128, config: &UserConfig, current_chain_height: u32, logger: &L, outbound_scid_alias: u64 ) -> Result, ChannelError> where K::Target: KeysInterface, @@ -4205,7 +4205,7 @@ impl Channel { pub fn shutdown( &mut self, keys_provider: &K, their_features: &InitFeatures, msg: &msgs::Shutdown ) -> Result<(Option, Option, Vec<(HTLCSource, PaymentHash)>), ChannelError> - where K::Target: KeysInterface + where K::Target: KeysInterface { if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 { return Err(ChannelError::Close("Peer sent shutdown when we needed a channel_reestablish".to_owned())); @@ -4482,7 +4482,7 @@ impl Channel { /// Gets the "user_id" value passed into the construction of this channel. It has no special /// meaning and exists only to allow users to have a persistent identifier of a channel. - pub fn get_user_id(&self) -> u64 { + pub fn get_user_id(&self) -> u128 { self.user_id } @@ -4520,6 +4520,11 @@ impl Channel { self.channel_transaction_parameters.funding_outpoint } + /// Returns the block hash in which our funding transaction was confirmed. + pub fn get_funding_tx_confirmed_in(&self) -> Option { + self.funding_tx_confirmed_in + } + fn get_holder_selected_contest_delay(&self) -> u16 { self.channel_transaction_parameters.holder_selected_contest_delay } @@ -5173,7 +5178,7 @@ impl Channel { /// should be sent back to the counterparty node. /// /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel - pub fn accept_inbound_channel(&mut self, user_id: u64) -> msgs::AcceptChannel { + pub fn accept_inbound_channel(&mut self, user_id: u128) -> msgs::AcceptChannel { if self.is_outbound() { panic!("Tried to send accept_channel for an outbound channel?"); } @@ -5820,7 +5825,7 @@ impl Channel { /// holding cell HTLCs for payment failure. pub fn get_shutdown(&mut self, keys_provider: &K, their_features: &InitFeatures, target_feerate_sats_per_kw: Option) -> Result<(msgs::Shutdown, Option, Vec<(HTLCSource, PaymentHash)>), APIError> - where K::Target: KeysInterface { + where K::Target: KeysInterface { for htlc in self.pending_outbound_htlcs.iter() { if let OutboundHTLCState::LocalAnnounced(_) = htlc.state { return Err(APIError::APIMisuseError{err: "Cannot begin shutdown with pending HTLCs. Process pending events first".to_owned()}); @@ -5936,6 +5941,17 @@ impl Channel { self.update_time_counter += 1; (monitor_update, dropped_outbound_htlcs) } + + pub fn inflight_htlc_sources(&self) -> impl Iterator { + self.holding_cell_htlc_updates.iter() + .flat_map(|htlc_update| { + match htlc_update { + HTLCUpdateAwaitingACK::AddHTLC { source, .. } => { Some(source) } + _ => None + } + }) + .chain(self.pending_outbound_htlcs.iter().map(|htlc| &htlc.source)) + } } const SERIALIZATION_VERSION: u8 = 2; @@ -6002,7 +6018,11 @@ impl Writeable for Channel { write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION); - self.user_id.write(writer)?; + // `user_id` used to be a single u64 value. In order to remain backwards compatible with + // versions prior to 0.0.113, the u128 is serialized as two separate u64 values. We write + // the low bytes now and the optional high bytes later. + let user_id_low = self.user_id as u64; + user_id_low.write(writer)?; // Version 1 deserializers expected to read parts of the config object here. Version 2 // deserializers (0.0.99) now read config through TLVs, and as we now require them for @@ -6249,6 +6269,11 @@ impl Writeable for Channel { let channel_ready_event_emitted = Some(self.channel_ready_event_emitted); + // `user_id` used to be a single u64 value. In order to remain backwards compatible with + // versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore, + // we write the high bytes as an option here. + let user_id_high_opt = Some((self.user_id >> 64) as u64); + write_tlv_fields!(writer, { (0, self.announcement_sigs, option), // minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a @@ -6272,6 +6297,7 @@ impl Writeable for Channel { (19, self.latest_inbound_scid_alias, option), (21, self.outbound_scid_alias, required), (23, channel_ready_event_emitted, option), + (25, user_id_high_opt, option), }); Ok(()) @@ -6279,13 +6305,16 @@ impl Writeable for Channel { } const MAX_ALLOC_SIZE: usize = 64*1024; -impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel - where K::Target: KeysInterface { +impl<'a, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<::Signer> + where K::Target: KeysInterface { fn read(reader: &mut R, args: (&'a K, u32)) -> Result { let (keys_source, serialized_height) = args; let ver = read_ver_prefix!(reader, SERIALIZATION_VERSION); - let user_id = Readable::read(reader)?; + // `user_id` used to be a single u64 value. In order to remain backwards compatible with + // versions prior to 0.0.113, the u128 is serialized as two separate u64 values. We read + // the low bytes now and the high bytes later. + let user_id_low: u64 = Readable::read(reader)?; let mut config = Some(LegacyChannelConfig::default()); if ver == 1 { @@ -6531,6 +6560,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel let mut outbound_scid_alias = None; let mut channel_ready_event_emitted = None; + let mut user_id_high_opt: Option = None; + read_tlv_fields!(reader, { (0, announcement_sigs, option), (1, minimum_depth, option), @@ -6548,6 +6579,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel (19, latest_inbound_scid_alias, option), (21, outbound_scid_alias, option), (23, channel_ready_event_emitted, option), + (25, user_id_high_opt, option), }); if let Some(preimages) = preimages_opt { @@ -6584,6 +6616,11 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel let mut secp_ctx = Secp256k1::new(); secp_ctx.seeded_randomize(&keys_source.get_secure_random_bytes()); + // `user_id` used to be a single u64 value. In order to remain backwards + // compatible with versions prior to 0.0.113, the u128 is serialized as two + // separate u64 values. + let user_id = user_id_low as u128 + ((user_id_high_opt.unwrap_or(0) as u128) << 64); + Ok(Channel { user_id,