Use new ChannelError type in accept_channel
authorMatt Corallo <git@bluematt.me>
Sun, 30 Sep 2018 23:08:24 +0000 (19:08 -0400)
committerMatt Corallo <git@bluematt.me>
Mon, 1 Oct 2018 00:05:39 +0000 (20:05 -0400)
src/ln/channel.rs
src/ln/channelmanager.rs

index f2c0f82ee0c9a590b66b06bbd5bacfc25c6a16fd..92f5ad0d50ef18ecd2c0be0f26a1bf1ae0fab75b 100644 (file)
@@ -1222,48 +1222,43 @@ impl Channel {
 
        // Message handlers:
 
-       pub fn accept_channel(&mut self, msg: &msgs::AcceptChannel) -> Result<(), HandleError> {
-               macro_rules! return_error_message {
-                       ( $msg: expr ) => {
-                               return Err(HandleError{err: $msg, action: Some(msgs::ErrorAction::SendErrorMessage{ msg: msgs::ErrorMessage { channel_id: msg.temporary_channel_id, data: $msg.to_string() }})});
-                       }
-               }
+       pub fn accept_channel(&mut self, msg: &msgs::AcceptChannel) -> Result<(), ChannelError> {
                // Check sanity of message fields:
                if !self.channel_outbound {
-                       return_error_message!("Got an accept_channel message from an inbound peer");
+                       return Err(ChannelError::Close("Got an accept_channel message from an inbound peer"));
                }
                if self.channel_state != ChannelState::OurInitSent as u32 {
-                       return_error_message!("Got an accept_channel message at a strange time");
+                       return Err(ChannelError::Close("Got an accept_channel message at a strange time"));
                }
                if msg.dust_limit_satoshis > 21000000 * 100000000 {
-                       return_error_message!("Peer never wants payout outputs?");
+                       return Err(ChannelError::Close("Peer never wants payout outputs?"));
                }
                if msg.channel_reserve_satoshis > self.channel_value_satoshis {
-                       return_error_message!("Bogus channel_reserve_satoshis");
+                       return Err(ChannelError::Close("Bogus channel_reserve_satoshis"));
                }
                if msg.dust_limit_satoshis > msg.channel_reserve_satoshis {
-                       return_error_message!("Bogus channel_reserve and dust_limit");
+                       return Err(ChannelError::Close("Bogus channel_reserve and dust_limit"));
                }
                if msg.channel_reserve_satoshis < self.our_dust_limit_satoshis {
-                       return_error_message!("Peer never wants payout outputs?");
+                       return Err(ChannelError::Close("Peer never wants payout outputs?"));
                }
                if msg.dust_limit_satoshis > Channel::get_our_channel_reserve_satoshis(self.channel_value_satoshis) {
-                       return_error_message!("Dust limit is bigger than our channel reverse");
+                       return Err(ChannelError::Close("Dust limit is bigger than our channel reverse"));
                }
                if msg.htlc_minimum_msat >= (self.channel_value_satoshis - msg.channel_reserve_satoshis) * 1000 {
-                       return_error_message!("Minimum htlc value is full channel value");
+                       return Err(ChannelError::Close("Minimum htlc value is full channel value"));
                }
                if msg.minimum_depth > Channel::derive_maximum_minimum_depth(self.channel_value_satoshis*1000,  self.value_to_self_msat) {
-                       return_error_message!("minimum_depth too large");
+                       return Err(ChannelError::Close("minimum_depth too large"));
                }
                if msg.to_self_delay > MAX_LOCAL_BREAKDOWN_TIMEOUT {
-                       return_error_message!("They wanted our payments to be delayed by a needlessly long period");
+                       return Err(ChannelError::Close("They wanted our payments to be delayed by a needlessly long period"));
                }
                if msg.max_accepted_htlcs < 1 {
-                       return_error_message!("0 max_accpted_htlcs makes for a useless channel");
+                       return Err(ChannelError::Close("0 max_accpted_htlcs makes for a useless channel"));
                }
                if msg.max_accepted_htlcs > 483 {
-                       return_error_message!("max_accpted_htlcs > 483");
+                       return Err(ChannelError::Close("max_accpted_htlcs > 483"));
                }
 
                // TODO: Optional additional constraints mentioned in the spec
index bebb4e776853f630224ad053e9beac1a1928a537..08d597795f32990b172a0aafd2a8169a1b158cd1 100644 (file)
@@ -1525,7 +1525,8 @@ impl ChannelManager {
                                                //TODO: see issue #153, need a consistent behavior on obnoxious behavior from random node
                                                return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.temporary_channel_id));
                                        }
-                                       chan.accept_channel(&msg).map_err(|e| MsgHandleErrInternal::from_maybe_close(e))?;
+                                       chan.accept_channel(&msg)
+                                               .map_err(|e| MsgHandleErrInternal::from_chan_maybe_close(e, msg.temporary_channel_id))?;
                                        (chan.get_value_satoshis(), chan.get_funding_redeemscript().to_v0_p2wsh(), chan.get_user_id())
                                },
                                //TODO: same as above