From 6033d096af537967b247ca4c798e9e4a709f776c Mon Sep 17 00:00:00 2001 From: Yuko Roodt Date: Tue, 13 Nov 2018 14:42:10 +0200 Subject: [PATCH 1/2] Added appropriate actions --- src/ln/channel.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ln/channel.rs b/src/ln/channel.rs index b9a81f6ebc0..3d9d1392267 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -2491,22 +2491,26 @@ impl Channel { pub fn closing_signed(&mut self, fee_estimator: &FeeEstimator, msg: &msgs::ClosingSigned) -> Result<(Option, Option), HandleError> { if self.channel_state & BOTH_SIDES_SHUTDOWN_MASK != BOTH_SIDES_SHUTDOWN_MASK { - return Err(HandleError{err: "Remote end sent us a closing_signed before both sides provided a shutdown", action: None}); + //return Err(HandleError{err: "Remote end sent us a closing_signed before both sides provided a shutdown", action: None}); + return Err(HandleError{err: "Remote end sent us a closing_signed before both sides provided a shutdown", action: Some(msgs::ErrorAction::DisconnectPeer{msg: Some(msgs::ErrorMessage{data: "Remote end sent us a closing_signed before both sides provided a shutdown".to_string(), channel_id: msg.channel_id})})}); } if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 { return Err(HandleError{err: "Peer sent closing_signed when we needed a channel_reestablish", action: Some(msgs::ErrorAction::SendErrorMessage{msg: msgs::ErrorMessage{data: "Peer sent closing_signed when we needed a channel_reestablish".to_string(), channel_id: msg.channel_id}})}); } if !self.pending_inbound_htlcs.is_empty() || !self.pending_outbound_htlcs.is_empty() { - return Err(HandleError{err: "Remote end sent us a closing_signed while there were still pending HTLCs", action: None}); + //return Err(HandleError{err: "Remote end sent us a closing_signed while there were still pending HTLCs", action: None}); + return Err(HandleError{err: "Remote end sent us a closing_signed while there were still pending HTLCs", action: Some(msgs::ErrorAction::SendErrorMessage{msg: msgs::ErrorMessage{data: "Remote end sent us a closing_signed while there were still pending HTLCs".to_string(), channel_id: msg.channel_id}})}); } if msg.fee_satoshis > 21000000 * 10000000 { //this is required to stop potential overflow in build_closing_transaction - return Err(HandleError{err: "Remote tried to send us a closing tx with > 21 million BTC fee", action: None}); + //return Err(HandleError{err: "Remote tried to send us a closing tx with > 21 million BTC fee", action: None}); + return Err(HandleError{err: "Remote tried to send us a closing tx with > 21 million BTC fee", action: Some(msgs::ErrorAction::DisconnectPeer{msg: Some(msgs::ErrorMessage{data: "Remote tried to send us a closing tx with > 21 million BTC fee".to_string(), channel_id: msg.channel_id})})}); } let funding_redeemscript = self.get_funding_redeemscript(); let (mut closing_tx, used_total_fee) = self.build_closing_transaction(msg.fee_satoshis, false); if used_total_fee != msg.fee_satoshis { - return Err(HandleError{err: "Remote sent us a closing_signed with a fee greater than the value they can claim", action: None}); + //return Err(HandleError{err: "Remote sent us a closing_signed with a fee greater than the value they can claim", action: None}); + return Err(HandleError{err: "Remote sent us a closing_signed with a fee greater than the value they can claim", action: Some(msgs::ErrorAction::DisconnectPeer{msg: Some(msgs::ErrorMessage{data: "Remote sent us a closing_signed with a fee greater than the value they can claim".to_string(), channel_id: msg.channel_id})})}); } let mut sighash = Message::from_slice(&bip143::SighashComponents::new(&closing_tx).sighash_all(&closing_tx.input[0], &funding_redeemscript, self.channel_value_satoshis)[..]).unwrap(); @@ -2551,7 +2555,8 @@ impl Channel { if proposed_sat_per_kw > our_max_feerate { if let Some((last_feerate, _)) = self.last_sent_closing_fee { if our_max_feerate <= last_feerate { - return Err(HandleError{err: "Unable to come to consensus about closing feerate, remote wanted something higher than our Normal feerate", action: None}); + //return Err(HandleError{err: "Unable to come to consensus about closing feerate, remote wanted something higher than our Normal feerate", action: None}); + return Err(HandleError{err: "Unable to come to consensus about closing feerate, remote wanted something higher than our Normal feerate", action: Some(msgs::ErrorAction::DisconnectPeer{msg: Some(msgs::ErrorMessage{data: "Unable to come to consensus about closing feerate, remote wanted something higher than our Normal feerate".to_string(), channel_id: msg.channel_id})})}); } } propose_new_feerate!(our_max_feerate); @@ -2561,7 +2566,8 @@ impl Channel { if proposed_sat_per_kw < our_min_feerate { if let Some((last_feerate, _)) = self.last_sent_closing_fee { if our_min_feerate >= last_feerate { - return Err(HandleError{err: "Unable to come to consensus about closing feerate, remote wanted something lower than our Background feerate", action: None}); + //return Err(HandleError{err: "Unable to come to consensus about closing feerate, remote wanted something lower than our Background feerate", action: None}); + return Err(HandleError{err: "Unable to come to consensus about closing feerate, remote wanted something lower than our Background feerate", action: Some(msgs::ErrorAction::DisconnectPeer{msg: Some(msgs::ErrorMessage{data: "Unable to come to consensus about closing feerate, remote wanted something lower than our Background feerate".to_string(), channel_id: msg.channel_id})})}); } } propose_new_feerate!(our_min_feerate); From 8f0682baa7c5228865fa7c855bfbbfd6041a1967 Mon Sep 17 00:00:00 2001 From: Yuko Roodt Date: Tue, 13 Nov 2018 14:48:05 +0200 Subject: [PATCH 2/2] Removed temporary code --- src/ln/channel.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 3d9d1392267..54a4d5b0ff8 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -2491,25 +2491,21 @@ impl Channel { pub fn closing_signed(&mut self, fee_estimator: &FeeEstimator, msg: &msgs::ClosingSigned) -> Result<(Option, Option), HandleError> { if self.channel_state & BOTH_SIDES_SHUTDOWN_MASK != BOTH_SIDES_SHUTDOWN_MASK { - //return Err(HandleError{err: "Remote end sent us a closing_signed before both sides provided a shutdown", action: None}); return Err(HandleError{err: "Remote end sent us a closing_signed before both sides provided a shutdown", action: Some(msgs::ErrorAction::DisconnectPeer{msg: Some(msgs::ErrorMessage{data: "Remote end sent us a closing_signed before both sides provided a shutdown".to_string(), channel_id: msg.channel_id})})}); } if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 { return Err(HandleError{err: "Peer sent closing_signed when we needed a channel_reestablish", action: Some(msgs::ErrorAction::SendErrorMessage{msg: msgs::ErrorMessage{data: "Peer sent closing_signed when we needed a channel_reestablish".to_string(), channel_id: msg.channel_id}})}); } if !self.pending_inbound_htlcs.is_empty() || !self.pending_outbound_htlcs.is_empty() { - //return Err(HandleError{err: "Remote end sent us a closing_signed while there were still pending HTLCs", action: None}); return Err(HandleError{err: "Remote end sent us a closing_signed while there were still pending HTLCs", action: Some(msgs::ErrorAction::SendErrorMessage{msg: msgs::ErrorMessage{data: "Remote end sent us a closing_signed while there were still pending HTLCs".to_string(), channel_id: msg.channel_id}})}); } if msg.fee_satoshis > 21000000 * 10000000 { //this is required to stop potential overflow in build_closing_transaction - //return Err(HandleError{err: "Remote tried to send us a closing tx with > 21 million BTC fee", action: None}); return Err(HandleError{err: "Remote tried to send us a closing tx with > 21 million BTC fee", action: Some(msgs::ErrorAction::DisconnectPeer{msg: Some(msgs::ErrorMessage{data: "Remote tried to send us a closing tx with > 21 million BTC fee".to_string(), channel_id: msg.channel_id})})}); } let funding_redeemscript = self.get_funding_redeemscript(); let (mut closing_tx, used_total_fee) = self.build_closing_transaction(msg.fee_satoshis, false); if used_total_fee != msg.fee_satoshis { - //return Err(HandleError{err: "Remote sent us a closing_signed with a fee greater than the value they can claim", action: None}); return Err(HandleError{err: "Remote sent us a closing_signed with a fee greater than the value they can claim", action: Some(msgs::ErrorAction::DisconnectPeer{msg: Some(msgs::ErrorMessage{data: "Remote sent us a closing_signed with a fee greater than the value they can claim".to_string(), channel_id: msg.channel_id})})}); } let mut sighash = Message::from_slice(&bip143::SighashComponents::new(&closing_tx).sighash_all(&closing_tx.input[0], &funding_redeemscript, self.channel_value_satoshis)[..]).unwrap(); @@ -2555,7 +2551,6 @@ impl Channel { if proposed_sat_per_kw > our_max_feerate { if let Some((last_feerate, _)) = self.last_sent_closing_fee { if our_max_feerate <= last_feerate { - //return Err(HandleError{err: "Unable to come to consensus about closing feerate, remote wanted something higher than our Normal feerate", action: None}); return Err(HandleError{err: "Unable to come to consensus about closing feerate, remote wanted something higher than our Normal feerate", action: Some(msgs::ErrorAction::DisconnectPeer{msg: Some(msgs::ErrorMessage{data: "Unable to come to consensus about closing feerate, remote wanted something higher than our Normal feerate".to_string(), channel_id: msg.channel_id})})}); } } @@ -2566,7 +2561,6 @@ impl Channel { if proposed_sat_per_kw < our_min_feerate { if let Some((last_feerate, _)) = self.last_sent_closing_fee { if our_min_feerate >= last_feerate { - //return Err(HandleError{err: "Unable to come to consensus about closing feerate, remote wanted something lower than our Background feerate", action: None}); return Err(HandleError{err: "Unable to come to consensus about closing feerate, remote wanted something lower than our Background feerate", action: Some(msgs::ErrorAction::DisconnectPeer{msg: Some(msgs::ErrorMessage{data: "Unable to come to consensus about closing feerate, remote wanted something lower than our Background feerate".to_string(), channel_id: msg.channel_id})})}); } }