Test htlc outputs shared tx claim case
[rust-lightning] / src / ln / channel.rs
index c8bf624c95092d547e3e5aa145c595053b6502a1..83698f1172632ffc8903e4ee7cdb1091867e429f 100644 (file)
@@ -14,7 +14,7 @@ use crypto::digest::Digest;
 use crypto::hkdf::{hkdf_extract,hkdf_expand};
 
 use ln::msgs;
-use ln::msgs::{ErrorAction, HandleError, MsgEncodable};
+use ln::msgs::{ErrorAction, HandleError};
 use ln::channelmonitor::ChannelMonitor;
 use ln::channelmanager::{PendingHTLCStatus, HTLCSource, PendingForwardHTLCInfo, HTLCFailReason, HTLCFailureMsg};
 use ln::chan_utils::{TxCreationKeys,HTLCOutputInCommitment,HTLC_SUCCESS_TX_WEIGHT,HTLC_TIMEOUT_TX_WEIGHT};
@@ -22,6 +22,7 @@ use ln::chan_utils;
 use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
 use chain::transaction::OutPoint;
 use util::{transaction_utils,rng};
+use util::ser::Writeable;
 use util::sha2::Sha256;
 use util::logger::Logger;
 use util::errors::APIError;
@@ -262,7 +263,7 @@ const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1;
 // has been completed, and then turn into a Channel to get compiler-time enforcement of things like
 // calling channel_id() before we're set up or things like get_outbound_funding_signed on an
 // inbound channel.
-pub struct Channel {
+pub(super) struct Channel {
        user_id: u64,
 
        channel_id: [u8; 32],
@@ -2011,7 +2012,12 @@ impl Channel {
                if self.channel_outbound && msg.scriptpubkey.len() > 34 {
                        return Err(HandleError{err: "Got shutdown_scriptpubkey of absurd length from remote peer", action: None});
                }
-               //TODO: Check shutdown_scriptpubkey form as BOLT says we must? WHYYY
+
+               //Check shutdown_scriptpubkey form as BOLT says we must
+               if !(msg.scriptpubkey.is_p2pkh()) && !(msg.scriptpubkey.is_p2sh())
+                       && !(msg.scriptpubkey.is_v0_p2wpkh()) && !(msg.scriptpubkey.is_v0_p2wsh()){
+                       return Err(HandleError{err: "Got an invalid scriptpubkey from remote peer", action: Some(msgs::ErrorAction::DisconnectPeer{ msg: None })});
+               }
 
                if self.their_shutdown_scriptpubkey.is_some() {
                        if Some(&msg.scriptpubkey) != self.their_shutdown_scriptpubkey.as_ref() {
@@ -2097,7 +2103,7 @@ impl Channel {
                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});
                }
-               if msg.fee_satoshis > 21000000 * 10000000 {
+               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});
                }