Update to rust-bitcoin v0.15
[rust-lightning] / src / ln / channelmanager.rs
index 8d31c3347f2d285f3b4eaa6ac50d2ae7b3025c3b..1f765eb197f5f218582af1dfdf39ee43a3e1926e 100644 (file)
@@ -12,8 +12,7 @@ use bitcoin::blockdata::block::BlockHeader;
 use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::network::constants::Network;
-use bitcoin::network::serialize::BitcoinHash;
-use bitcoin::util::hash::Sha256dHash;
+use bitcoin::util::hash::{BitcoinHash, Sha256dHash};
 
 use secp256k1::key::{SecretKey,PublicKey};
 use secp256k1::{Secp256k1,Message};
@@ -2194,8 +2193,8 @@ impl ChannelManager {
                                        //TODO: here and below MsgHandleErrInternal, #153 case
                                        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 {
-                                       return Err(MsgHandleErrInternal::send_err_msg_close_chan("Got update_fail_malformed_htlc with BADONION set", msg.channel_id));
+                               if (msg.failure_code & 0x8000) == 0 {
+                                       return Err(MsgHandleErrInternal::send_err_msg_close_chan("Got update_fail_malformed_htlc with BADONION not set", msg.channel_id));
                                }
                                chan.update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() })
                                        .map_err(|e| MsgHandleErrInternal::from_chan_maybe_close(e, msg.channel_id))?;
@@ -3224,13 +3223,11 @@ mod tests {
        use util::ser::{Writeable, Writer, ReadableArgs};
        use util::config::UserConfig;
 
-       use bitcoin::util::hash::Sha256dHash;
+       use bitcoin::util::hash::{BitcoinHash, Sha256dHash};
        use bitcoin::blockdata::block::{Block, BlockHeader};
        use bitcoin::blockdata::transaction::{Transaction, TxOut};
        use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::network::constants::Network;
-       use bitcoin::network::serialize::serialize;
-       use bitcoin::network::serialize::BitcoinHash;
 
        use hex;
 
@@ -3520,7 +3517,7 @@ mod tests {
                                tx = Transaction { version: chan_id as u32, lock_time: 0, input: Vec::new(), output: vec![TxOut {
                                        value: *channel_value_satoshis, script_pubkey: output_script.clone(),
                                }]};
-                               funding_output = OutPoint::new(Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), 0);
+                               funding_output = OutPoint::new(tx.txid(), 0);
 
                                node_a.node.funding_transaction_generated(&temporary_channel_id, funding_output);
                                let mut added_monitors = node_a.chan_monitor.added_monitors.lock().unwrap();
@@ -5708,7 +5705,13 @@ mod tests {
                get_announce_close_broadcast_events(&nodes, 3, 4);
                assert_eq!(nodes[3].node.list_channels().len(), 0);
                assert_eq!(nodes[4].node.list_channels().len(), 0);
+       }
+
+       #[test]
+       fn test_justice_tx() {
+               // Test justice txn built on revoked HTLC-Success tx, against both sides
 
+               let nodes = create_network(2);
                // Create some new channels:
                let chan_5 = create_announced_chan_between_nodes(&nodes, 0, 1);
 
@@ -5748,6 +5751,9 @@ mod tests {
                }
                get_announce_close_broadcast_events(&nodes, 0, 1);
 
+               assert_eq!(nodes[0].node.list_channels().len(), 0);
+               assert_eq!(nodes[1].node.list_channels().len(), 0);
+
                // We test justice_tx build by A on B's revoked HTLC-Success tx
                // Create some new channels:
                let chan_6 = create_announced_chan_between_nodes(&nodes, 0, 1);