X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannelmanager.rs;h=daf66ffe218d3621eb8475a9f5b73f1abb5349b7;hb=refs%2Fheads%2F2020-02-one-conf-lock;hp=a59b85b6e5a6364fa1fe558facbbe664eeefc19f;hpb=af4738b778d08b728c69a8b3f27d721f7444938e;p=rust-lightning diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index a59b85b6..daf66ffe 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -196,7 +196,7 @@ impl MsgHandleErrInternal { } } #[inline] - fn from_chan_no_close(err: ChannelError, channel_id: [u8; 32]) -> Self { + fn from_chan_no_close(err: ChannelError, channel_id: [u8; 32]) -> Self { Self { err: match err { ChannelError::Ignore(msg) => LightningError { @@ -337,7 +337,7 @@ pub type SimpleRefChannelManager<'a, M> = ChannelManager where M::Target: ManyChannelMonitor { +pub struct ChannelManager where M::Target: ManyChannelMonitor { default_configuration: UserConfig, genesis_hash: Sha256dHash, fee_estimator: Arc, @@ -479,7 +479,7 @@ macro_rules! break_chan_entry { match $res { Ok(res) => res, Err(ChannelError::Ignore(msg)) => { - break Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $entry.key().clone())) + break Err(MsgHandleErrInternal::from_chan_no_close::(ChannelError::Ignore(msg), $entry.key().clone())) }, Err(ChannelError::Close(msg)) => { log_trace!($self, "Closing channel {} due to Close-required error: {}", log_bytes!($entry.key()[..]), msg); @@ -499,7 +499,7 @@ macro_rules! try_chan_entry { match $res { Ok(res) => res, Err(ChannelError::Ignore(msg)) => { - return Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), $entry.key().clone())) + return Err(MsgHandleErrInternal::from_chan_no_close::(ChannelError::Ignore(msg), $entry.key().clone())) }, Err(ChannelError::Close(msg)) => { log_trace!($self, "Closing channel {} due to Close-required error: {}", log_bytes!($entry.key()[..]), msg); @@ -516,7 +516,7 @@ macro_rules! try_chan_entry { $channel_state.short_to_id.remove(&short_id); } if let Some(update) = update { - if let Err(e) = $self.monitor.add_update_monitor(update.get_funding_txo().unwrap(), update) { + if let Err(e) = $self.monitor.add_update_monitor(update.get_funding_txo().unwrap(), update.clone()) { match e { // Upstream channel is dead, but we want at least to fail backward HTLCs to save // downstream channels. In case of PermanentFailure, we are not going to be able @@ -582,7 +582,7 @@ macro_rules! handle_monitor_err { debug_assert!($action_type == RAACommitmentOrder::CommitmentFirst || !$resend_commitment); } $entry.get_mut().monitor_update_failed($resend_raa, $resend_commitment, $failed_forwards, $failed_fails); - Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore("Failed to update ChannelMonitor"), *$entry.key())) + Err(MsgHandleErrInternal::from_chan_no_close::(ChannelError::Ignore("Failed to update ChannelMonitor"), *$entry.key())) }, } } @@ -609,7 +609,7 @@ macro_rules! maybe_break_monitor_err { } } -impl ChannelManager where M::Target: ManyChannelMonitor { +impl ChannelManager where M::Target: ManyChannelMonitor { /// Constructs a new ChannelManager to hold several channels and route between them. /// /// This is the main "logic hub" for all channel-related actions, and implements @@ -1268,7 +1268,10 @@ impl ChannelManager where M::T } fn get_announcement_sigs(&self, chan: &Channel) -> Option { - if !chan.should_announce() { return None } + if !chan.should_announce() { + log_trace!(self, "Can't send announcement_signatures for private channel {}", log_bytes!(chan.channel_id())); + return None + } let (announcement, our_bitcoin_sig) = match chan.get_channel_announcement(self.get_our_node_id(), self.genesis_hash.clone()) { Ok(res) => res, @@ -1984,6 +1987,7 @@ impl ChannelManager where M::T } try_chan_entry!(self, chan.get_mut().funding_locked(&msg), channel_state, chan); if let Some(announcement_sigs) = self.get_announcement_sigs(chan.get()) { + log_trace!(self, "Sending announcement_signatures for {} in response to funding_locked", log_bytes!(chan.get().channel_id())); // If we see locking block before receiving remote funding_locked, we broadcast our // announcement_sigs at remote funding_locked reception. If we receive remote // funding_locked before seeing locking block, we broadcast our announcement_sigs at locking @@ -2196,7 +2200,8 @@ impl ChannelManager where M::T return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id)); } if (msg.failure_code & 0x8000) == 0 { - try_chan_entry!(self, Err(ChannelError::Close("Got update_fail_malformed_htlc with BADONION not set")), channel_state, chan); + let chan_err: ChannelError = ChannelError::Close("Got update_fail_malformed_htlc with BADONION not set"); + try_chan_entry!(self, Err(chan_err), channel_state, chan); } try_chan_entry!(self, chan.get_mut().update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() }), channel_state, chan); Ok(()) @@ -2361,7 +2366,8 @@ impl ChannelManager where M::T let msghash = hash_to_message!(&Sha256dHash::hash(&announcement.encode()[..])[..]); if self.secp_ctx.verify(&msghash, &msg.node_signature, if were_node_one { &announcement.node_id_2 } else { &announcement.node_id_1 }).is_err() || self.secp_ctx.verify(&msghash, &msg.bitcoin_signature, if were_node_one { &announcement.bitcoin_key_2 } else { &announcement.bitcoin_key_1 }).is_err() { - try_chan_entry!(self, Err(ChannelError::Close("Bad announcement_signatures node_signature")), channel_state, chan); + let chan_err: ChannelError = ChannelError::Close("Bad announcement_signatures node_signature"); + try_chan_entry!(self, Err(chan_err), channel_state, chan); } let our_node_sig = self.secp_ctx.sign(&msghash, &self.our_network_key); @@ -2507,7 +2513,7 @@ impl ChannelManager where M::T } } -impl events::MessageSendEventsProvider for ChannelManager where M::Target: ManyChannelMonitor { +impl events::MessageSendEventsProvider for ChannelManager where M::Target: ManyChannelMonitor { fn get_and_clear_pending_msg_events(&self) -> Vec { // TODO: Event release to users and serialization is currently race-y: it's very easy for a // user to serialize a ChannelManager with pending events in it and lose those events on @@ -2532,7 +2538,7 @@ impl events::MessageSendEventsProvider for Ch } } -impl events::EventsProvider for ChannelManager where M::Target: ManyChannelMonitor { +impl events::EventsProvider for ChannelManager where M::Target: ManyChannelMonitor { fn get_and_clear_pending_events(&self) -> Vec { // TODO: Event release to users and serialization is currently race-y: it's very easy for a // user to serialize a ChannelManager with pending events in it and lose those events on @@ -2557,7 +2563,7 @@ impl events::EventsProvider for ChannelManage } } -impl ChainListener for ChannelManager where M::Target: ManyChannelMonitor { +impl ChainListener for ChannelManager where M::Target: ManyChannelMonitor { fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]) { let header_hash = header.bitcoin_hash(); log_trace!(self, "Block {} at height {} connected with {} txn matched", header_hash, height, txn_matched.len()); @@ -2576,10 +2582,13 @@ impl ChainListener for ChannelM msg: funding_locked, }); if let Some(announcement_sigs) = self.get_announcement_sigs(channel) { + log_trace!(self, "Sending funding_locked and announcement_signatures for {}", log_bytes!(channel.channel_id())); pending_msg_events.push(events::MessageSendEvent::SendAnnouncementSignatures { node_id: channel.get_their_node_id(), msg: announcement_sigs, }); + } else { + log_trace!(self, "Sending funding_locked WITHOUT announcement_signatures for {}", log_bytes!(channel.channel_id())); } short_to_id.insert(channel.get_short_channel_id().unwrap(), channel.channel_id()); } else if let Err(e) = chan_res { @@ -2671,7 +2680,7 @@ impl ChainListener for ChannelM } } -impl ChannelMessageHandler for ChannelManager where M::Target: ManyChannelMonitor { +impl ChannelMessageHandler for ChannelManager where M::Target: ManyChannelMonitor { fn handle_open_channel(&self, their_node_id: &PublicKey, their_features: InitFeatures, msg: &msgs::OpenChannel) { let _ = self.total_consistency_lock.read().unwrap(); let res = self.internal_open_channel(their_node_id, their_features, msg); @@ -3141,7 +3150,7 @@ impl Readable for HTLCForwardInfo { } } -impl Writeable for ChannelManager where M::Target: ManyChannelMonitor { +impl Writeable for ChannelManager where M::Target: ManyChannelMonitor { fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { let _ = self.total_consistency_lock.write().unwrap(); @@ -3212,7 +3221,7 @@ impl Writeable for ChannelManager /// 5) Move the ChannelMonitors into your local ManyChannelMonitor. /// 6) Disconnect/connect blocks on the ChannelManager. /// 7) Register the new ChannelManager with your ChainWatchInterface. -pub struct ChannelManagerReadArgs<'a, ChanSigner: ChannelKeys, M: Deref> where M::Target: ManyChannelMonitor { +pub struct ChannelManagerReadArgs<'a, ChanSigner: 'a + ChannelKeys, M: Deref> where M::Target: ManyChannelMonitor { /// The keys provider which will give us relevant keys. Some keys will be loaded during /// deserialization. pub keys_manager: Arc>, @@ -3249,10 +3258,10 @@ pub struct ChannelManagerReadArgs<'a, ChanSigner: ChannelKeys, M: Deref> where M /// /// In such cases the latest local transactions will be sent to the tx_broadcaster included in /// this struct. - pub channel_monitors: &'a mut HashMap, + pub channel_monitors: &'a mut HashMap>, } -impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable, M: Deref> ReadableArgs> for (Sha256dHash, ChannelManager) where M::Target: ManyChannelMonitor { +impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable, M: Deref> ReadableArgs> for (Sha256dHash, ChannelManager) where M::Target: ManyChannelMonitor { fn read(reader: &mut R, args: ChannelManagerReadArgs<'a, ChanSigner, M>) -> Result { let _ver: u8 = Readable::read(reader)?; let min_ver: u8 = Readable::read(reader)?;