Remove temporary anti-duplicata logic
[rust-lightning] / lightning / src / util / test_utils.rs
index 9af8d5cf2f3d92db21ab81a775ae4b1b03ad8860..13cbde4aa1fe35c24702d277a48b310c77d08490 100644 (file)
@@ -1,5 +1,5 @@
 use chain::chaininterface;
-use chain::chaininterface::ConfirmationTarget;
+use chain::chaininterface::{ConfirmationTarget, ChainError, ChainWatchInterface};
 use chain::transaction::OutPoint;
 use chain::keysinterface;
 use ln::channelmonitor;
@@ -13,7 +13,9 @@ use util::logger::{Logger, Level, Record};
 use util::ser::{Readable, ReadableArgs, Writer, Writeable};
 
 use bitcoin::blockdata::transaction::Transaction;
-use bitcoin::blockdata::script::Script;
+use bitcoin::blockdata::script::{Builder, Script};
+use bitcoin::blockdata::block::Block;
+use bitcoin::blockdata::opcodes;
 use bitcoin_hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::network::constants::Network;
 
@@ -22,7 +24,7 @@ use secp256k1::{SecretKey, PublicKey};
 use std::time::{SystemTime, UNIX_EPOCH};
 use std::sync::{Arc,Mutex};
 use std::{mem};
-use std::collections::{HashMap, HashSet};
+use std::collections::HashMap;
 
 pub struct TestVecWriter(pub Vec<u8>);
 impl Writer for TestVecWriter {
@@ -108,19 +110,9 @@ impl<'a> channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChanne
 
 pub struct TestBroadcaster {
        pub txn_broadcasted: Mutex<Vec<Transaction>>,
-       pub broadcasted_txn: Mutex<HashSet<Sha256dHash>> // Temporary field while refactoring out tx duplication
 }
 impl chaininterface::BroadcasterInterface for TestBroadcaster {
        fn broadcast_transaction(&self, tx: &Transaction) {
-               {
-                       if let Some(_) = self.broadcasted_txn.lock().unwrap().get(&tx.txid()) {
-                               // If commitment tx, HTLC-timeout or HTLC-Success, duplicate broadcast are still ok
-                               if tx.input[0].sequence == 0xfffffffd {
-                                       return;
-                               }
-                       }
-               }
-               self.broadcasted_txn.lock().unwrap().insert(tx.txid());
                self.txn_broadcasted.lock().unwrap().push(tx.clone());
        }
 }
@@ -186,7 +178,7 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler {
                Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
        }
        fn handle_htlc_fail_channel_update(&self, _update: &msgs::HTLCFailChannelUpdate) {}
-       fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, msgs::ChannelUpdate,msgs::ChannelUpdate)> {
+       fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, Option<msgs::ChannelUpdate>, Option<msgs::ChannelUpdate>)> {
                Vec::new()
        }
        fn get_next_node_announcements(&self, _starting_point: Option<&PublicKey>, _batch_amount: u8) -> Vec<msgs::NodeAnnouncement> {
@@ -273,3 +265,28 @@ impl TestKeysInterface {
                }
        }
 }
+
+pub struct TestChainWatcher {
+       pub utxo_ret: Mutex<Result<(Script, u64), ChainError>>,
+}
+
+impl TestChainWatcher {
+       pub fn new() -> Self {
+               let script = Builder::new().push_opcode(opcodes::OP_TRUE).into_script();
+               Self { utxo_ret: Mutex::new(Ok((script, u64::max_value()))) }
+       }
+}
+
+impl ChainWatchInterface for TestChainWatcher {
+       fn install_watch_tx(&self, _txid: &Sha256dHash, _script_pub_key: &Script) { }
+       fn install_watch_outpoint(&self, _outpoint: (Sha256dHash, u32), _out_script: &Script) { }
+       fn watch_all_txn(&self) { }
+       fn filter_block<'a>(&self, _block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>) {
+               (Vec::new(), Vec::new())
+       }
+       fn reentered(&self) -> usize { 0 }
+
+       fn get_chain_utxo(&self, _genesis_hash: Sha256dHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
+               self.utxo_ret.lock().unwrap().clone()
+       }
+}