Adopting new bitcoin hash types and crate version
authorDr. Maxim Orlovsky <orlovsky@pandoracore.com>
Mon, 27 Apr 2020 15:53:13 +0000 (17:53 +0200)
committerDr. Maxim Orlovsky <orlovsky@pandoracore.com>
Wed, 29 Apr 2020 10:37:46 +0000 (12:37 +0200)
22 files changed:
fuzz/Cargo.toml
fuzz/src/chanmon_consistency.rs
fuzz/src/chanmon_deser.rs
fuzz/src/full_stack.rs
fuzz/src/lib.rs
fuzz/src/router.rs
lightning-net-tokio/Cargo.toml
lightning/Cargo.toml
lightning/src/chain/chaininterface.rs
lightning/src/chain/transaction.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/channelmonitor.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/msgs.rs
lightning/src/ln/onchaintx.rs
lightning/src/ln/router.rs
lightning/src/util/macro_logger.rs
lightning/src/util/ser.rs
lightning/src/util/test_utils.rs

index 5e3197f8f8f1929c1c35270dd872f6f964130bca..115f3e8a4dc0db632cf417b0ae840051da4c783d 100644 (file)
@@ -19,11 +19,9 @@ stdin_fuzz = []
 [dependencies]
 afl = { version = "0.4", optional = true }
 lightning = { path = "../lightning", features = ["fuzztarget"] }
-bitcoin = { version = "0.21", features = ["fuzztarget"] }
-bitcoin_hashes = { version = "0.7", features = ["fuzztarget"] }
+bitcoin = { version = "0.23", features = ["fuzztarget"] }
 hex = "0.3"
 honggfuzz = { version = "0.5", optional = true }
-secp256k1 = { version = "0.15", features=["fuzztarget"] }
 libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git", optional = true }
 
 [build-dependencies]
index d458c6b96646a9a634f26946f286aaac157215af..8a57c4fc2693d75c88278e0d39369f44fad80ffd 100644 (file)
@@ -19,7 +19,7 @@ use bitcoin::network::constants::Network;
 use bitcoin::hashes::Hash as TraitImport;
 use bitcoin::hashes::hash160::Hash as Hash160;
 use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hashes::sha256d::Hash as Sha256d;
+use bitcoin::hash_types::BlockHash;
 
 use lightning::chain::chaininterface;
 use lightning::chain::transaction::OutPoint;
@@ -114,7 +114,7 @@ impl channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChannelMon
                        hash_map::Entry::Occupied(entry) => entry,
                        hash_map::Entry::Vacant(_) => panic!("Didn't have monitor on update call"),
                };
-               let mut deserialized_monitor = <(Sha256d, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::
+               let mut deserialized_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::
                        read(&mut Cursor::new(&map_entry.get().1), Arc::clone(&self.logger)).unwrap().1;
                deserialized_monitor.update_monitor(update.clone(), &&TestBroadcaster {}).unwrap();
                let mut ser = VecWriter(Vec::new());
@@ -215,7 +215,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                        let mut monitors = HashMap::new();
                        let mut old_monitors = $old_monitors.latest_monitors.lock().unwrap();
                        for (outpoint, (update_id, monitor_ser)) in old_monitors.drain() {
-                               monitors.insert(outpoint, <(Sha256d, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&monitor_ser), Arc::clone(&logger)).expect("Failed to read monitor").1);
+                               monitors.insert(outpoint, <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&monitor_ser), Arc::clone(&logger)).expect("Failed to read monitor").1);
                                monitor.latest_monitors.lock().unwrap().insert(outpoint, (update_id, monitor_ser));
                        }
                        let mut monitor_refs = HashMap::new();
@@ -233,7 +233,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                channel_monitors: &mut monitor_refs,
                        };
 
-                       (<(Sha256d, ChannelManager<EnforcingChannelKeys, Arc<TestChannelMonitor>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, monitor)
+                       (<(BlockHash, ChannelManager<EnforcingChannelKeys, Arc<TestChannelMonitor>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, monitor)
                } }
        }
 
index 45da43c0bee63b4fd64baa87b54a3d07bed00d18..52caf36e1b96c092cd8f029e37b86816a46a8679 100644 (file)
@@ -1,7 +1,7 @@
 // This file is auto-generated by gen_target.sh based on msg_target_template.txt
 // To modify it, modify msg_target_template.txt and run gen_target.sh instead.
 
-use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::BlockHash;
 
 use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
 use lightning::ln::channelmonitor;
@@ -26,10 +26,10 @@ impl Writer for VecWriter {
 #[inline]
 pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
        let logger = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
-       if let Ok((latest_block_hash, monitor)) = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(data), logger.clone()) {
+       if let Ok((latest_block_hash, monitor)) = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(data), logger.clone()) {
                let mut w = VecWriter(Vec::new());
                monitor.write_for_disk(&mut w).unwrap();
-               let deserialized_copy = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&w.0), logger.clone()).unwrap();
+               let deserialized_copy = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&w.0), logger.clone()).unwrap();
                assert!(latest_block_hash == deserialized_copy.0);
                assert!(monitor == deserialized_copy.1);
        }
index 83318abe83e05edfab88252a90302218e2eb40e6..377c9b0d7577294ed5180e7b2eef2c8cb435be62 100644 (file)
@@ -14,9 +14,9 @@ use bitcoin::util::hash::BitcoinHash;
 
 use bitcoin::hashes::Hash as TraitImport;
 use bitcoin::hashes::HashEngine as TraitImportEngine;
-use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::hash160::Hash as Hash160;
-use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hash_types::{Txid, BlockHash};
 
 use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil};
 use lightning::chain::transaction::OutPoint;
@@ -38,7 +38,6 @@ use bitcoin::secp256k1::Secp256k1;
 use std::cell::RefCell;
 use std::collections::{HashMap, hash_map};
 use std::cmp;
-use std::hash::Hash;
 use std::sync::Arc;
 use std::sync::atomic::{AtomicU64,AtomicUsize,Ordering};
 
@@ -129,7 +128,7 @@ impl<'a> PartialEq for Peer<'a> {
        }
 }
 impl<'a> Eq for Peer<'a> {}
-impl<'a> Hash for Peer<'a> {
+impl<'a> std::hash::Hash for Peer<'a> {
        fn hash<H : std::hash::Hasher>(&self, h: &mut H) {
                self.id.hash(h)
        }
@@ -142,8 +141,8 @@ struct MoneyLossDetector<'a> {
 
        peers: &'a RefCell<[bool; 256]>,
        funding_txn: Vec<Transaction>,
-       txids_confirmed: HashMap<Sha256dHash, usize>,
-       header_hashes: Vec<Sha256dHash>,
+       txids_confirmed: HashMap<Txid, usize>,
+       header_hashes: Vec<BlockHash>,
        height: usize,
        max_height: usize,
        blocks_connected: u32,
index f87c7511c13c26469b3502c3746d97e4e57d9716..dbda28acf44d9dee7cb92336a27b7283a5c853ea 100644 (file)
@@ -1,7 +1,5 @@
 extern crate bitcoin;
-extern crate bitcoin_hashes;
 extern crate lightning;
-extern crate secp256k1;
 extern crate hex;
 
 pub mod utils;
index ae164ae2f449a10563dbd2d7c8ff5f395b83d79c..2ff160e4ec844406ef1ff523be18ab6aff7b1532 100644 (file)
@@ -1,7 +1,7 @@
-use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::blockdata::script::{Script, Builder};
 use bitcoin::blockdata::block::Block;
 use bitcoin::blockdata::transaction::Transaction;
+use bitcoin::hash_types::{Txid, BlockHash};
 
 use lightning::chain::chaininterface::{ChainError,ChainWatchInterface};
 use lightning::ln::channelmanager::ChannelDetails;
@@ -72,15 +72,15 @@ struct DummyChainWatcher {
 }
 
 impl ChainWatchInterface for DummyChainWatcher {
-       fn install_watch_tx(&self, _txid: &Sha256dHash, _script_pub_key: &Script) { }
-       fn install_watch_outpoint(&self, _outpoint: (Sha256dHash, u32), _out_script: &Script) { }
+       fn install_watch_tx(&self, _txid: &Txid, _script_pub_key: &Script) { }
+       fn install_watch_outpoint(&self, _outpoint: (Txid, 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> {
+       fn get_chain_utxo(&self, _genesis_hash: BlockHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
                match self.input.get_slice(2) {
                        Some(&[0, _]) => Err(ChainError::NotSupported),
                        Some(&[1, _]) => Err(ChainError::NotWatched),
index 70bc36a18309f195819fe63b3de90833e233190f..bdcb911395d939e31229a24b9b9851feb939d82d 100644 (file)
@@ -10,7 +10,7 @@ For Rust-Lightning clients which wish to make direct connections to Lightning P2
 """
 
 [dependencies]
-bitcoin = "0.21"
+bitcoin = "0.23"
 lightning = { version = "0.0.11", path = "../lightning" }
 tokio = { version = ">=0.2.12", features = [ "io-util", "macros", "rt-core", "sync", "tcp", "time" ] }
 
index 3b78a905baa319474e5a4456bcd99a7c99f437f8..50859aab27df683c82b0cab57f44aaaeaf014c5f 100644 (file)
@@ -22,10 +22,10 @@ max_level_info = []
 max_level_debug = []
 
 [dependencies]
-bitcoin = "0.21"
+bitcoin = "0.23"
 
 [dev-dependencies.bitcoin]
-version = "0.21"
+version = "0.23"
 features = ["bitcoinconsensus"]
 
 [dev-dependencies]
index f497236552844c65d2039a6847d52a4bc6571364..814193af0033a21987757b2d1258bd30b988feda 100644 (file)
@@ -9,8 +9,8 @@ use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::blockdata::script::Script;
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::util::hash::BitcoinHash;
-use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::network::constants::Network;
+use bitcoin::hash_types::{Txid, BlockHash};
 
 use util::logger::Logger;
 
@@ -40,11 +40,11 @@ pub enum ChainError {
 /// events).
 pub trait ChainWatchInterface: Sync + Send {
        /// Provides a txid/random-scriptPubKey-in-the-tx which much be watched for.
-       fn install_watch_tx(&self, txid: &Sha256dHash, script_pub_key: &Script);
+       fn install_watch_tx(&self, txid: &Txid, script_pub_key: &Script);
 
        /// Provides an outpoint which must be watched for, providing any transactions which spend the
        /// given outpoint.
-       fn install_watch_outpoint(&self, outpoint: (Sha256dHash, u32), out_script: &Script);
+       fn install_watch_outpoint(&self, outpoint: (Txid, u32), out_script: &Script);
 
        /// Indicates that a listener needs to see all transactions.
        fn watch_all_txn(&self);
@@ -53,7 +53,7 @@ pub trait ChainWatchInterface: Sync + Send {
        /// short_channel_id (aka unspent_tx_output_identier). For BTC/tBTC channels the top three
        /// bytes are the block height, the next 3 the transaction index within the block, and the
        /// final two the output within the transaction.
-       fn get_chain_utxo(&self, genesis_hash: Sha256dHash, unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError>;
+       fn get_chain_utxo(&self, genesis_hash: BlockHash, unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError>;
 
        /// Gets the list of transactions and transaction indices that the ChainWatchInterface is
        /// watching for.
@@ -135,11 +135,11 @@ pub struct ChainWatchedUtil {
        // We are more conservative in matching during testing to ensure everything matches *exactly*,
        // even though during normal runtime we take more optimized match approaches...
        #[cfg(test)]
-       watched_txn: HashSet<(Sha256dHash, Script)>,
+       watched_txn: HashSet<(Txid, Script)>,
        #[cfg(not(test))]
        watched_txn: HashSet<Script>,
 
-       watched_outpoints: HashSet<(Sha256dHash, u32)>,
+       watched_outpoints: HashSet<(Txid, u32)>,
 }
 
 impl ChainWatchedUtil {
@@ -154,7 +154,7 @@ impl ChainWatchedUtil {
 
        /// Registers a tx for monitoring, returning true if it was a new tx and false if we'd already
        /// been watching for it.
-       pub fn register_tx(&mut self, txid: &Sha256dHash, script_pub_key: &Script) -> bool {
+       pub fn register_tx(&mut self, txid: &Txid, script_pub_key: &Script) -> bool {
                if self.watch_all { return false; }
                #[cfg(test)]
                {
@@ -169,7 +169,7 @@ impl ChainWatchedUtil {
 
        /// Registers an outpoint for monitoring, returning true if it was a new outpoint and false if
        /// we'd already been watching for it
-       pub fn register_outpoint(&mut self, outpoint: (Sha256dHash, u32), _script_pub_key: &Script) -> bool {
+       pub fn register_outpoint(&mut self, outpoint: (Txid, u32), _script_pub_key: &Script) -> bool {
                if self.watch_all { return false; }
                self.watched_outpoints.insert(outpoint)
        }
@@ -332,14 +332,14 @@ impl PartialEq for ChainWatchInterfaceUtil {
 
 /// Register listener
 impl ChainWatchInterface for ChainWatchInterfaceUtil {
-       fn install_watch_tx(&self, txid: &Sha256dHash, script_pub_key: &Script) {
+       fn install_watch_tx(&self, txid: &Txid, script_pub_key: &Script) {
                let mut watched = self.watched.lock().unwrap();
                if watched.register_tx(txid, script_pub_key) {
                        self.reentered.fetch_add(1, Ordering::Relaxed);
                }
        }
 
-       fn install_watch_outpoint(&self, outpoint: (Sha256dHash, u32), out_script: &Script) {
+       fn install_watch_outpoint(&self, outpoint: (Txid, u32), out_script: &Script) {
                let mut watched = self.watched.lock().unwrap();
                if watched.register_outpoint(outpoint, out_script) {
                        self.reentered.fetch_add(1, Ordering::Relaxed);
@@ -353,7 +353,7 @@ impl ChainWatchInterface for ChainWatchInterfaceUtil {
                }
        }
 
-       fn get_chain_utxo(&self, genesis_hash: Sha256dHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
+       fn get_chain_utxo(&self, genesis_hash: BlockHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
                if genesis_hash != genesis_block(self.network).header.bitcoin_hash() {
                        return Err(ChainError::NotWatched);
                }
index df45d786bd73d1f3321816e89f0bc24799233fc3..33b9c7244a37d1ad13adedda973c70a23c40f10a 100644 (file)
@@ -1,6 +1,6 @@
 //! Contains simple structs describing parts of transactions on the chain.
 
-use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::Txid;
 use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
 
 /// A reference to a transaction output.
@@ -10,14 +10,14 @@ use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
 pub struct OutPoint {
        /// The referenced transaction's txid.
-       pub txid: Sha256dHash,
+       pub txid: Txid,
        /// The index of the referenced output in its transaction's vout.
        pub index: u16,
 }
 
 impl OutPoint {
        /// Creates a new `OutPoint` from the txid and the index.
-       pub fn new(txid: Sha256dHash, index: u16) -> OutPoint {
+       pub fn new(txid: Txid, index: u16) -> OutPoint {
                OutPoint { txid, index }
        }
 
index 3ab440d95f254d18da9ed677e6435ed864d26aa2..d833eca91c5fcf185f347bf88f788cb6b1dff20e 100644 (file)
@@ -12,7 +12,7 @@ use bitcoin::hashes::{Hash, HashEngine};
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::ripemd160::Hash as Ripemd160;
 use bitcoin::hashes::hash160::Hash as Hash160;
-use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::Txid;
 
 use ln::channelmanager::{PaymentHash, PaymentPreimage};
 use ln::msgs::DecodeError;
@@ -447,7 +447,7 @@ pub fn make_funding_redeemscript(a: &PublicKey, b: &PublicKey) -> Script {
 }
 
 /// panics if htlc.transaction_output_index.is_none()!
-pub fn build_htlc_transaction(prev_hash: &Sha256dHash, feerate_per_kw: u64, to_self_delay: u16, htlc: &HTLCOutputInCommitment, a_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction {
+pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u64, to_self_delay: u16, htlc: &HTLCOutputInCommitment, a_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction {
        let mut txins: Vec<TxIn> = Vec::new();
        txins.push(TxIn {
                previous_output: OutPoint {
@@ -563,7 +563,7 @@ impl LocalCommitmentTransaction {
 
        /// Get the txid of the local commitment transaction contained in this
        /// LocalCommitmentTransaction
-       pub fn txid(&self) -> Sha256dHash {
+       pub fn txid(&self) -> Txid {
                self.unsigned_tx.txid()
        }
 
index e08a7e93fb8c676d37d91e1525ddd16d788059cc..cfb5e8096e32d93680d4912c9c9e0f841f192f2a 100644 (file)
@@ -9,7 +9,7 @@ use bitcoin::consensus::encode;
 use bitcoin::hashes::{Hash, HashEngine};
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::hash160::Hash as Hash160;
-use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::{Txid, BlockHash};
 
 use bitcoin::secp256k1::key::{PublicKey,SecretKey};
 use bitcoin::secp256k1::{Secp256k1,Signature};
@@ -313,11 +313,11 @@ pub(super) struct Channel<ChanSigner: ChannelKeys> {
        /// to detect unconfirmation after a serialize-unserialize roundtrip where we may not see a full
        /// series of block_connected/block_disconnected calls. Obviously this is not a guarantee as we
        /// could miss the funding_tx_confirmed_in block as well, but it serves as a useful fallback.
-       funding_tx_confirmed_in: Option<Sha256dHash>,
+       funding_tx_confirmed_in: Option<BlockHash>,
        short_channel_id: Option<u64>,
        /// Used to deduplicate block_connected callbacks, also used to verify consistency during
        /// ChannelManager deserialization (hence pub(super))
-       pub(super) last_block_connected: Sha256dHash,
+       pub(super) last_block_connected: BlockHash,
        funding_tx_confirmations: u64,
 
        their_dust_limit_satoshis: u64,
@@ -1133,7 +1133,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
        /// Builds the htlc-success or htlc-timeout transaction which spends a given HTLC output
        /// @local is used only to convert relevant internal structures which refer to remote vs local
        /// to decide value of outputs and direction of HTLCs.
-       fn build_htlc_transaction(&self, prev_hash: &Sha256dHash, htlc: &HTLCOutputInCommitment, local: bool, keys: &TxCreationKeys, feerate_per_kw: u64) -> Transaction {
+       fn build_htlc_transaction(&self, prev_hash: &Txid, htlc: &HTLCOutputInCommitment, local: bool, keys: &TxCreationKeys, feerate_per_kw: u64) -> Transaction {
                chan_utils::build_htlc_transaction(prev_hash, feerate_per_kw, if local { self.their_to_self_delay } else { self.our_to_self_delay }, htlc, &keys.a_delayed_payment_key, &keys.revocation_key)
        }
 
@@ -3299,7 +3299,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
        // Methods to get unprompted messages to send to the remote end (or where we already returned
        // something in the handler for the message that prompted this message):
 
-       pub fn get_open_channel<F: Deref>(&self, chain_hash: Sha256dHash, fee_estimator: &F) -> msgs::OpenChannel
+       pub fn get_open_channel<F: Deref>(&self, chain_hash: BlockHash, fee_estimator: &F) -> msgs::OpenChannel
                where F::Target: FeeEstimator
        {
                if !self.channel_outbound {
@@ -3431,7 +3431,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
        /// closing).
        /// Note that the "channel must be funded" requirement is stricter than BOLT 7 requires - see
        /// https://github.com/lightningnetwork/lightning-rfc/issues/468
-       pub fn get_channel_announcement(&self, our_node_id: PublicKey, chain_hash: Sha256dHash) -> Result<(msgs::UnsignedChannelAnnouncement, Signature), ChannelError> {
+       pub fn get_channel_announcement(&self, our_node_id: PublicKey, chain_hash: BlockHash) -> Result<(msgs::UnsignedChannelAnnouncement, Signature), ChannelError> {
                if !self.config.announced_channel {
                        return Err(ChannelError::Ignore("Channel is not available for public announcements"));
                }
@@ -4310,9 +4310,9 @@ mod tests {
        use bitcoin::secp256k1::{Secp256k1, Message, Signature, All};
        use bitcoin::secp256k1::key::{SecretKey,PublicKey};
        use bitcoin::hashes::sha256::Hash as Sha256;
-       use bitcoin::hashes::sha256d::Hash as Sha256dHash;
        use bitcoin::hashes::hash160::Hash as Hash160;
        use bitcoin::hashes::Hash;
+       use bitcoin::hash_types::Txid;
        use std::sync::Arc;
        use rand::{thread_rng,Rng};
 
@@ -4457,7 +4457,7 @@ mod tests {
                chan.their_to_self_delay = 144;
                chan.our_dust_limit_satoshis = 546;
 
-               let funding_info = OutPoint::new(Sha256dHash::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), 0);
+               let funding_info = OutPoint::new(Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), 0);
                chan.funding_txo = Some(funding_info);
 
                let their_pubkeys = ChannelPublicKeys {
index 78cf5987afd80d03334847dc07705a5cca3bbdb7..8d22b8893e7bdf57270624c907bc5ede980ac340 100644 (file)
@@ -19,6 +19,7 @@ use bitcoin::hashes::hmac::{Hmac, HmacEngine};
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hashes::cmp::fixed_time_eq;
+use bitcoin::hash_types::BlockHash;
 
 use bitcoin::secp256k1::key::{SecretKey,PublicKey};
 use bitcoin::secp256k1::Secp256k1;
@@ -375,7 +376,7 @@ pub struct ChannelManager<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref,
         F::Target: FeeEstimator,
 {
        default_configuration: UserConfig,
-       genesis_hash: Sha256dHash,
+       genesis_hash: BlockHash,
        fee_estimator: F,
        monitor: M,
        tx_broadcaster: T,
@@ -384,7 +385,7 @@ pub struct ChannelManager<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref,
        pub(super) latest_block_height: AtomicUsize,
        #[cfg(not(test))]
        latest_block_height: AtomicUsize,
-       last_block_hash: Mutex<Sha256dHash>,
+       last_block_hash: Mutex<BlockHash>,
        secp_ctx: Secp256k1<secp256k1::All>,
 
        #[cfg(test)]
@@ -3686,20 +3687,20 @@ pub struct ChannelManagerReadArgs<'a, ChanSigner: 'a + ChannelKeys, M: Deref, T:
 // Implement ReadableArgs for an Arc'd ChannelManager to make it a bit easier to work with the
 // SipmleArcChannelManager type:
 impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: Deref>
-       ReadableArgs<ChannelManagerReadArgs<'a, ChanSigner, M, T, K, F>> for (Sha256dHash, Arc<ChannelManager<ChanSigner, M, T, K, F>>)
+       ReadableArgs<ChannelManagerReadArgs<'a, ChanSigner, M, T, K, F>> for (BlockHash, Arc<ChannelManager<ChanSigner, M, T, K, F>>)
        where M::Target: ManyChannelMonitor<ChanSigner>,
         T::Target: BroadcasterInterface,
         K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
         F::Target: FeeEstimator,
 {
        fn read<R: ::std::io::Read>(reader: &mut R, args: ChannelManagerReadArgs<'a, ChanSigner, M, T, K, F>) -> Result<Self, DecodeError> {
-               let (blockhash, chan_manager) = <(Sha256dHash, ChannelManager<ChanSigner, M, T, K, F>)>::read(reader, args)?;
+               let (blockhash, chan_manager) = <(BlockHash, ChannelManager<ChanSigner, M, T, K, F>)>::read(reader, args)?;
                Ok((blockhash, Arc::new(chan_manager)))
        }
 }
 
 impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: Deref>
-       ReadableArgs<ChannelManagerReadArgs<'a, ChanSigner, M, T, K, F>> for (Sha256dHash, ChannelManager<ChanSigner, M, T, K, F>)
+       ReadableArgs<ChannelManagerReadArgs<'a, ChanSigner, M, T, K, F>> for (BlockHash, ChannelManager<ChanSigner, M, T, K, F>)
        where M::Target: ManyChannelMonitor<ChanSigner>,
         T::Target: BroadcasterInterface,
         K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
@@ -3712,9 +3713,9 @@ impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: De
                        return Err(DecodeError::UnknownVersion);
                }
 
-               let genesis_hash: Sha256dHash = Readable::read(reader)?;
+               let genesis_hash: BlockHash = Readable::read(reader)?;
                let latest_block_height: u32 = Readable::read(reader)?;
-               let last_block_hash: Sha256dHash = Readable::read(reader)?;
+               let last_block_hash: BlockHash = Readable::read(reader)?;
 
                let mut failed_htlcs = Vec::new();
 
index 6bddd302ffc64163e2fb76944bc60df7b76f7764..edf87da6c59eba8dfde6c76d6181f55aab21e73c 100644 (file)
@@ -22,7 +22,7 @@ use bitcoin::util::hash::BitcoinHash;
 use bitcoin::hashes::Hash;
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::hash160::Hash as Hash160;
-use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::{Txid, BlockHash};
 
 use bitcoin::secp256k1::{Secp256k1,Signature};
 use bitcoin::secp256k1::key::{SecretKey,PublicKey};
@@ -409,7 +409,7 @@ pub(crate) const HTLC_FAIL_BACK_BUFFER: u32 = CLTV_CLAIM_BUFFER + LATENCY_GRACE_
 #[derive(Clone, PartialEq)]
 struct LocalSignedTx {
        /// txid of the transaction in tx, just used to make comparison faster
-       txid: Sha256dHash,
+       txid: Txid,
        revocation_key: PublicKey,
        a_htlc_key: PublicKey,
        b_htlc_key: PublicKey,
@@ -727,8 +727,8 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
 
        keys: ChanSigner,
        funding_info: (OutPoint, Script),
-       current_remote_commitment_txid: Option<Sha256dHash>,
-       prev_remote_commitment_txid: Option<Sha256dHash>,
+       current_remote_commitment_txid: Option<Txid>,
+       prev_remote_commitment_txid: Option<Txid>,
 
        their_htlc_base_key: PublicKey,
        their_delayed_payment_base_key: PublicKey,
@@ -741,13 +741,13 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
        their_to_self_delay: u16,
 
        commitment_secrets: CounterpartyCommitmentSecrets,
-       remote_claimable_outpoints: HashMap<Sha256dHash, Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)>>,
+       remote_claimable_outpoints: HashMap<Txid, Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)>>,
        /// We cannot identify HTLC-Success or HTLC-Timeout transactions by themselves on the chain.
        /// Nor can we figure out their commitment numbers without the commitment transaction they are
        /// spending. Thus, in order to claim them via revocation key, we track all the remote
        /// commitment transactions which we find on-chain, mapping them to the commitment number which
        /// can be used to derive the revocation key and claim the transactions.
-       remote_commitment_txn_on_chain: HashMap<Sha256dHash, (u64, Vec<Script>)>,
+       remote_commitment_txn_on_chain: HashMap<Txid, (u64, Vec<Script>)>,
        /// Cache used to make pruning of payment_preimages faster.
        /// Maps payment_hash values to commitment numbers for remote transactions for non-revoked
        /// remote transactions (ie should remain pretty small).
@@ -782,7 +782,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
        // interface knows about the TXOs that we want to be notified of spends of. We could probably
        // be smart and derive them from the above storage fields, but its much simpler and more
        // Obviously Correct (tm) if we just keep track of them explicitly.
-       outputs_to_watch: HashMap<Sha256dHash, Vec<Script>>,
+       outputs_to_watch: HashMap<Txid, Vec<Script>>,
 
        #[cfg(test)]
        pub onchain_tx_handler: OnchainTxHandler<ChanSigner>,
@@ -804,7 +804,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
        // (we do *not*, however, update them in update_monitor to ensure any local user copies keep
        // their last_block_hash from its state and not based on updated copies that didn't run through
        // the full block_connected).
-       pub(crate) last_block_hash: Sha256dHash,
+       pub(crate) last_block_hash: BlockHash,
        secp_ctx: Secp256k1<secp256k1::All>, //TODO: dedup this a bit...
        logger: Arc<Logger>,
 }
@@ -1363,7 +1363,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
 
        /// Gets a list of txids, with their output scripts (in the order they appear in the
        /// transaction), which we must learn about spends of via block_connected().
-       pub fn get_outputs_to_watch(&self) -> &HashMap<Sha256dHash, Vec<Script>> {
+       pub fn get_outputs_to_watch(&self) -> &HashMap<Txid, Vec<Script>> {
                &self.outputs_to_watch
        }
 
@@ -1371,7 +1371,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        /// Generally useful when deserializing as during normal operation the return values of
        /// block_connected are sufficient to ensure all relevant outpoints are being monitored (note
        /// that the get_funding_txo outpoint and transaction must also be monitored for!).
-       pub fn get_monitored_outpoints(&self) -> Vec<(Sha256dHash, u32, &Script)> {
+       pub fn get_monitored_outpoints(&self) -> Vec<(Txid, u32, &Script)> {
                let mut res = Vec::with_capacity(self.remote_commitment_txn_on_chain.len() * 2);
                for (ref txid, &(_, ref outputs)) in self.remote_commitment_txn_on_chain.iter() {
                        for (idx, output) in outputs.iter().enumerate() {
@@ -1424,7 +1424,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        /// HTLC-Success/HTLC-Timeout transactions.
        /// Return updates for HTLC pending in the channel and failed automatically by the broadcast of
        /// revoked remote commitment tx
-       fn check_spend_remote_transaction(&mut self, tx: &Transaction, height: u32) -> (Vec<ClaimRequest>, (Sha256dHash, Vec<TxOut>)) {
+       fn check_spend_remote_transaction(&mut self, tx: &Transaction, height: u32) -> (Vec<ClaimRequest>, (Txid, Vec<TxOut>)) {
                // Most secp and related errors trying to create keys means we have no hope of constructing
                // a spend transaction...so we return no transactions to broadcast
                let mut claimable_outpoints = Vec::new();
@@ -1637,7 +1637,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        }
 
        /// Attempts to claim a remote HTLC-Success/HTLC-Timeout's outputs using the revocation key
-       fn check_spend_remote_htlc(&mut self, tx: &Transaction, commitment_number: u64, height: u32) -> (Vec<ClaimRequest>, Option<(Sha256dHash, Vec<TxOut>)>) {
+       fn check_spend_remote_htlc(&mut self, tx: &Transaction, commitment_number: u64, height: u32) -> (Vec<ClaimRequest>, Option<(Txid, Vec<TxOut>)>) {
                let htlc_txid = tx.txid();
                if tx.input.len() != 1 || tx.output.len() != 1 || tx.input[0].witness.len() != 5 {
                        return (Vec::new(), None)
@@ -1699,7 +1699,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        /// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
        /// revoked using data in local_claimable_outpoints.
        /// Should not be used if check_spend_revoked_transaction succeeds.
-       fn check_spend_local_transaction(&mut self, tx: &Transaction, height: u32) -> (Vec<ClaimRequest>, (Sha256dHash, Vec<TxOut>)) {
+       fn check_spend_local_transaction(&mut self, tx: &Transaction, height: u32) -> (Vec<ClaimRequest>, (Txid, Vec<TxOut>)) {
                let commitment_txid = tx.txid();
                let mut claim_requests = Vec::new();
                let mut watch_outputs = Vec::new();
@@ -1843,7 +1843,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        /// Eventually this should be pub and, roughly, implement ChainListener, however this requires
        /// &mut self, as well as returns new spendable outputs and outpoints to watch for spending of
        /// on-chain.
-       fn block_connected<B: Deref, F: Deref>(&mut self, txn_matched: &[&Transaction], height: u32, block_hash: &Sha256dHash, broadcaster: B, fee_estimator: F)-> Vec<(Sha256dHash, Vec<TxOut>)>
+       fn block_connected<B: Deref, F: Deref>(&mut self, txn_matched: &[&Transaction], height: u32, block_hash: &BlockHash, broadcaster: B, fee_estimator: F)-> Vec<(Txid, Vec<TxOut>)>
                where B::Target: BroadcasterInterface,
                      F::Target: FeeEstimator
        {
@@ -1941,7 +1941,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                watch_outputs
        }
 
-       fn block_disconnected<B: Deref, F: Deref>(&mut self, height: u32, block_hash: &Sha256dHash, broadcaster: B, fee_estimator: F)
+       fn block_disconnected<B: Deref, F: Deref>(&mut self, height: u32, block_hash: &BlockHash, broadcaster: B, fee_estimator: F)
                where B::Target: BroadcasterInterface,
                      F::Target: FeeEstimator
        {
@@ -2210,7 +2210,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
 
 const MAX_ALLOC_SIZE: usize = 64*1024;
 
-impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dHash, ChannelMonitor<ChanSigner>) {
+impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (BlockHash, ChannelMonitor<ChanSigner>) {
        fn read<R: ::std::io::Read>(reader: &mut R, logger: Arc<Logger>) -> Result<Self, DecodeError> {
                macro_rules! unwrap_obj {
                        ($key: expr) => {
@@ -2307,7 +2307,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
                let remote_claimable_outpoints_len: u64 = Readable::read(reader)?;
                let mut remote_claimable_outpoints = HashMap::with_capacity(cmp::min(remote_claimable_outpoints_len as usize, MAX_ALLOC_SIZE / 64));
                for _ in 0..remote_claimable_outpoints_len {
-                       let txid: Sha256dHash = Readable::read(reader)?;
+                       let txid: Txid = Readable::read(reader)?;
                        let htlcs_count: u64 = Readable::read(reader)?;
                        let mut htlcs = Vec::with_capacity(cmp::min(htlcs_count as usize, MAX_ALLOC_SIZE / 32));
                        for _ in 0..htlcs_count {
@@ -2321,7 +2321,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
                let remote_commitment_txn_on_chain_len: u64 = Readable::read(reader)?;
                let mut remote_commitment_txn_on_chain = HashMap::with_capacity(cmp::min(remote_commitment_txn_on_chain_len as usize, MAX_ALLOC_SIZE / 32));
                for _ in 0..remote_commitment_txn_on_chain_len {
-                       let txid: Sha256dHash = Readable::read(reader)?;
+                       let txid: Txid = Readable::read(reader)?;
                        let commitment_number = <U48 as Readable>::read(reader)?.0;
                        let outputs_count = <u64 as Readable>::read(reader)?;
                        let mut outputs = Vec::with_capacity(cmp::min(outputs_count as usize, MAX_ALLOC_SIZE / 8));
@@ -2411,7 +2411,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
                        }
                }
 
-               let last_block_hash: Sha256dHash = Readable::read(reader)?;
+               let last_block_hash: BlockHash = Readable::read(reader)?;
 
                let waiting_threshold_conf_len: u64 = Readable::read(reader)?;
                let mut onchain_events_waiting_threshold_conf = HashMap::with_capacity(cmp::min(waiting_threshold_conf_len as usize, MAX_ALLOC_SIZE / 128));
@@ -2442,7 +2442,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
                }
 
                let outputs_to_watch_len: u64 = Readable::read(reader)?;
-               let mut outputs_to_watch = HashMap::with_capacity(cmp::min(outputs_to_watch_len as usize, MAX_ALLOC_SIZE / (mem::size_of::<Sha256dHash>() + mem::size_of::<Vec<Script>>())));
+               let mut outputs_to_watch = HashMap::with_capacity(cmp::min(outputs_to_watch_len as usize, MAX_ALLOC_SIZE / (mem::size_of::<Txid>() + mem::size_of::<Vec<Script>>())));
                for _ in 0..outputs_to_watch_len {
                        let txid = Readable::read(reader)?;
                        let outputs_len: u64 = Readable::read(reader)?;
@@ -2520,8 +2520,8 @@ mod tests {
        use bitcoin::util::bip143;
        use bitcoin::hashes::Hash;
        use bitcoin::hashes::sha256::Hash as Sha256;
-       use bitcoin::hashes::sha256d::Hash as Sha256dHash;
        use bitcoin::hashes::hex::FromHex;
+       use bitcoin::hash_types::Txid;
        use hex;
        use chain::transaction::OutPoint;
        use ln::channelmanager::{PaymentPreimage, PaymentHash};
@@ -2605,7 +2605,7 @@ mod tests {
                // old state.
                let mut monitor = ChannelMonitor::new(keys,
                        &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap()), 0, &Script::new(),
-                       (OutPoint { txid: Sha256dHash::from_slice(&[43; 32]).unwrap(), index: 0 }, Script::new()),
+                       (OutPoint { txid: Txid::from_slice(&[43; 32]).unwrap(), index: 0 }, Script::new()),
                        &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
                        &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()),
                        10, Script::new(), 46, 0, LocalCommitmentTransaction::dummy(), logger.clone());
@@ -2693,7 +2693,7 @@ mod tests {
                }
 
                let script_pubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script();
-               let txid = Sha256dHash::from_hex("56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d").unwrap();
+               let txid = Txid::from_hex("56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d").unwrap();
 
                // Justice tx with 1 to_local, 2 revoked offered HTLCs, 1 revoked received HTLCs
                let mut claim_tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: Vec::new() };
index 2906fc51d9a8b0643c706221e04cdeab1f6cea28..4a56ea412c6c321099dc58b4e58e03c6686fd0fe 100644 (file)
@@ -25,8 +25,8 @@ use bitcoin::blockdata::transaction::{Transaction, TxOut};
 use bitcoin::network::constants::Network;
 
 use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hashes::sha256d::Hash as Sha256d;
 use bitcoin::hashes::Hash;
+use bitcoin::hash_types::BlockHash;
 
 use bitcoin::secp256k1::Secp256k1;
 use bitcoin::secp256k1::key::PublicKey;
@@ -50,7 +50,7 @@ pub fn confirm_transaction<'a, 'b: 'a>(notifier: &'a chaininterface::BlockNotifi
        }
 }
 
-pub fn connect_blocks<'a, 'b>(notifier: &'a chaininterface::BlockNotifierRef<'b>, depth: u32, height: u32, parent: bool, prev_blockhash: Sha256d) -> Sha256d {
+pub fn connect_blocks<'a, 'b>(notifier: &'a chaininterface::BlockNotifierRef<'b>, depth: u32, height: u32, parent: bool, prev_blockhash: BlockHash) -> BlockHash {
        let mut header = BlockHeader { version: 0x2000000, prev_blockhash: if parent { prev_blockhash } else { Default::default() }, merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
        notifier.block_connected_checked(&header, height + 1, &Vec::new(), &Vec::new());
        for i in 2..depth + 1 {
@@ -137,7 +137,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
                                for (_, old_monitor) in old_monitors.iter() {
                                        let mut w = test_utils::TestVecWriter(Vec::new());
                                        old_monitor.write_for_disk(&mut w).unwrap();
-                                       let (_, deserialized_monitor) = <(Sha256d, ChannelMonitor<EnforcingChannelKeys>)>::read(
+                                       let (_, deserialized_monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(
                                                &mut ::std::io::Cursor::new(&w.0), Arc::clone(&self.logger) as Arc<Logger>).unwrap();
                                        deserialized_monitors.push(deserialized_monitor);
                                }
@@ -153,7 +153,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
 
                                let mut w = test_utils::TestVecWriter(Vec::new());
                                self.node.write(&mut w).unwrap();
-                               <(Sha256d, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut ::std::io::Cursor::new(w.0), ChannelManagerReadArgs {
+                               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut ::std::io::Cursor::new(w.0), ChannelManagerReadArgs {
                                        default_config: UserConfig::default(),
                                        keys_manager: self.keys_manager,
                                        fee_estimator: &test_utils::TestFeeEstimator { sat_per_kw: 253 },
index 49d0c0a9fe5ad26d97a1aba43d116f415c4131e2..3a440fb323c82e0ba55c1b09b2745ab1d9480a0d 100644 (file)
@@ -26,6 +26,7 @@ use util::logger::Logger;
 
 use bitcoin::util::hash::BitcoinHash;
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::{Txid, BlockHash};
 use bitcoin::util::bip143;
 use bitcoin::util::address::Address;
 use bitcoin::util::bip32::{ChildNumber, ExtendedPubKey, ExtendedPrivKey};
@@ -3078,7 +3079,7 @@ fn test_force_close_fail_back() {
        // Now check that if we add the preimage to ChannelMonitor it broadcasts our HTLC-Success..
        {
                let mut monitors = nodes[2].chan_monitor.simple_monitor.monitors.lock().unwrap();
-               monitors.get_mut(&OutPoint::new(Sha256dHash::from_slice(&payment_event.commitment_msg.channel_id[..]).unwrap(), 0)).unwrap()
+               monitors.get_mut(&OutPoint::new(Txid::from_slice(&payment_event.commitment_msg.channel_id[..]).unwrap(), 0)).unwrap()
                        .provide_payment_preimage(&our_payment_hash, &our_payment_preimage);
        }
        nodes[2].block_notifier.block_connected_checked(&header, 1, &[&tx], &[1]);
@@ -3827,7 +3828,7 @@ fn test_invalid_channel_announcement() {
        assert!(nodes[0].router.handle_channel_announcement(&chan_announcement).is_err());
 
        let mut unsigned_msg = dummy_unsigned_msg!();
-       unsigned_msg.chain_hash = Sha256dHash::hash(&[1,2,3,4,5,6,7,8,9]);
+       unsigned_msg.chain_hash = BlockHash::hash(&[1,2,3,4,5,6,7,8,9]);
        sign_msg!(unsigned_msg);
        assert!(nodes[0].router.handle_channel_announcement(&chan_announcement).is_err());
 }
@@ -3855,7 +3856,7 @@ fn test_no_txn_manager_serialize_deserialize() {
        new_chan_monitor = test_utils::TestChannelMonitor::new(nodes[0].chain_monitor.clone(), nodes[0].tx_broadcaster.clone(), Arc::new(test_utils::TestLogger::new()), &fee_estimator);
        nodes[0].chan_monitor = &new_chan_monitor;
        let mut chan_0_monitor_read = &chan_0_monitor_serialized.0[..];
-       let (_, mut chan_0_monitor) = <(Sha256dHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut chan_0_monitor_read, Arc::new(test_utils::TestLogger::new())).unwrap();
+       let (_, mut chan_0_monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut chan_0_monitor_read, Arc::new(test_utils::TestLogger::new())).unwrap();
        assert!(chan_0_monitor_read.is_empty());
 
        let mut nodes_0_read = &nodes_0_serialized[..];
@@ -3864,7 +3865,7 @@ fn test_no_txn_manager_serialize_deserialize() {
        let (_, nodes_0_deserialized_tmp) = {
                let mut channel_monitors = HashMap::new();
                channel_monitors.insert(chan_0_monitor.get_funding_txo(), &mut chan_0_monitor);
-               <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
                        default_config: config,
                        keys_manager: &keys_manager,
                        fee_estimator: &fee_estimator,
@@ -3929,7 +3930,7 @@ fn test_simple_manager_serialize_deserialize() {
        new_chan_monitor = test_utils::TestChannelMonitor::new(nodes[0].chain_monitor.clone(), nodes[0].tx_broadcaster.clone(), Arc::new(test_utils::TestLogger::new()), &fee_estimator);
        nodes[0].chan_monitor = &new_chan_monitor;
        let mut chan_0_monitor_read = &chan_0_monitor_serialized.0[..];
-       let (_, mut chan_0_monitor) = <(Sha256dHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut chan_0_monitor_read, Arc::new(test_utils::TestLogger::new())).unwrap();
+       let (_, mut chan_0_monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut chan_0_monitor_read, Arc::new(test_utils::TestLogger::new())).unwrap();
        assert!(chan_0_monitor_read.is_empty());
 
        let mut nodes_0_read = &nodes_0_serialized[..];
@@ -3937,7 +3938,7 @@ fn test_simple_manager_serialize_deserialize() {
        let (_, nodes_0_deserialized_tmp) = {
                let mut channel_monitors = HashMap::new();
                channel_monitors.insert(chan_0_monitor.get_funding_txo(), &mut chan_0_monitor);
-               <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
                        default_config: UserConfig::default(),
                        keys_manager: &keys_manager,
                        fee_estimator: &fee_estimator,
@@ -4008,7 +4009,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
        let mut node_0_stale_monitors = Vec::new();
        for serialized in node_0_stale_monitors_serialized.iter() {
                let mut read = &serialized[..];
-               let (_, monitor) = <(Sha256dHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut read, Arc::new(test_utils::TestLogger::new())).unwrap();
+               let (_, monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut read, Arc::new(test_utils::TestLogger::new())).unwrap();
                assert!(read.is_empty());
                node_0_stale_monitors.push(monitor);
        }
@@ -4016,7 +4017,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
        let mut node_0_monitors = Vec::new();
        for serialized in node_0_monitors_serialized.iter() {
                let mut read = &serialized[..];
-               let (_, monitor) = <(Sha256dHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut read, Arc::new(test_utils::TestLogger::new())).unwrap();
+               let (_, monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut read, Arc::new(test_utils::TestLogger::new())).unwrap();
                assert!(read.is_empty());
                node_0_monitors.push(monitor);
        }
@@ -4025,7 +4026,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
 
        let mut nodes_0_read = &nodes_0_serialized[..];
        if let Err(msgs::DecodeError::InvalidValue) =
-               <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
                default_config: UserConfig::default(),
                keys_manager: &keys_manager,
                fee_estimator: &fee_estimator,
@@ -4039,7 +4040,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
 
        let mut nodes_0_read = &nodes_0_serialized[..];
        let (_, nodes_0_deserialized_tmp) =
-               <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
                default_config: UserConfig::default(),
                keys_manager: &keys_manager,
                fee_estimator: &fee_estimator,
@@ -5445,7 +5446,7 @@ impl msgs::ChannelUpdate {
                msgs::ChannelUpdate {
                        signature: Signature::from(FFISignature::new()),
                        contents: msgs::UnsignedChannelUpdate {
-                               chain_hash: Sha256dHash::hash(&vec![0u8][..]),
+                               chain_hash: BlockHash::hash(&vec![0u8][..]),
                                short_channel_id: 0,
                                timestamp: 0,
                                flags: 0,
@@ -6833,7 +6834,7 @@ fn test_data_loss_protect() {
 
        // Restore node A from previous state
        let logger: Arc<Logger> = Arc::new(test_utils::TestLogger::with_id(format!("node {}", 0)));
-       let mut chan_monitor = <(Sha256dHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut ::std::io::Cursor::new(previous_chan_monitor_state.0), Arc::clone(&logger)).unwrap().1;
+       let mut chan_monitor = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut ::std::io::Cursor::new(previous_chan_monitor_state.0), Arc::clone(&logger)).unwrap().1;
        let chain_monitor = Arc::new(ChainWatchInterfaceUtil::new(Network::Testnet, Arc::clone(&logger)));
        tx_broadcaster = test_utils::TestBroadcaster{txn_broadcasted: Mutex::new(Vec::new())};
        fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: 253 };
@@ -6842,7 +6843,7 @@ fn test_data_loss_protect() {
        node_state_0 = {
                let mut channel_monitors = HashMap::new();
                channel_monitors.insert(OutPoint { txid: chan.3.txid(), index: 0 }, &mut chan_monitor);
-               <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut ::std::io::Cursor::new(previous_node_state), ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut ::std::io::Cursor::new(previous_node_state), ChannelManagerReadArgs {
                        keys_manager: &keys_manager,
                        fee_estimator: &fee_estimator,
                        monitor: &monitor,
@@ -7657,7 +7658,7 @@ fn test_update_err_monitor_lockdown() {
                let monitor = monitors.get(&outpoint).unwrap();
                let mut w = test_utils::TestVecWriter(Vec::new());
                monitor.write_for_disk(&mut w).unwrap();
-               let new_monitor = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
+               let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
                                &mut ::std::io::Cursor::new(&w.0), Arc::new(test_utils::TestLogger::new())).unwrap().1;
                assert!(new_monitor == *monitor);
                let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet, logger.clone() as Arc<Logger>));
index 6c1d3cd928700a13550327c87d47b6fe1d634577..fb506c4759528a768a0ef98158c2e4d2b20c67dc 100644 (file)
@@ -18,8 +18,8 @@
 use bitcoin::secp256k1::key::PublicKey;
 use bitcoin::secp256k1::Signature;
 use bitcoin::secp256k1;
-use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::blockdata::script::Script;
+use bitcoin::hash_types::{Txid, BlockHash};
 
 use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
 
@@ -84,7 +84,7 @@ pub struct Pong {
 /// An open_channel message to be sent or received from a peer
 #[derive(Clone)]
 pub struct OpenChannel {
-       pub(crate) chain_hash: Sha256dHash,
+       pub(crate) chain_hash: BlockHash,
        pub(crate) temporary_channel_id: [u8; 32],
        pub(crate) funding_satoshis: u64,
        pub(crate) push_msat: u64,
@@ -129,7 +129,7 @@ pub struct AcceptChannel {
 #[derive(Clone)]
 pub struct FundingCreated {
        pub(crate) temporary_channel_id: [u8; 32],
-       pub(crate) funding_txid: Sha256dHash,
+       pub(crate) funding_txid: Txid,
        pub(crate) funding_output_index: u16,
        pub(crate) signature: Signature,
 }
@@ -403,7 +403,7 @@ pub struct NodeAnnouncement {
 #[derive(PartialEq, Clone, Debug)]
 pub struct UnsignedChannelAnnouncement {
        pub(crate) features: ChannelFeatures,
-       pub(crate) chain_hash: Sha256dHash,
+       pub(crate) chain_hash: BlockHash,
        pub(crate) short_channel_id: u64,
        /// One of the two node_ids which are endpoints of this channel
        pub        node_id_1: PublicKey,
@@ -425,7 +425,7 @@ pub struct ChannelAnnouncement {
 
 #[derive(PartialEq, Clone, Debug)]
 pub(crate) struct UnsignedChannelUpdate {
-       pub(crate) chain_hash: Sha256dHash,
+       pub(crate) chain_hash: BlockHash,
        pub(crate) short_channel_id: u64,
        pub(crate) timestamp: u32,
        pub(crate) flags: u16,
@@ -1360,12 +1360,12 @@ mod tests {
        use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret};
        use util::ser::{Writeable, Readable};
 
-       use bitcoin::hashes::sha256d::Hash as Sha256dHash;
        use bitcoin::hashes::hex::FromHex;
        use bitcoin::util::address::Address;
        use bitcoin::network::constants::Network;
        use bitcoin::blockdata::script::Builder;
        use bitcoin::blockdata::opcodes;
+       use bitcoin::hash_types::{Txid, BlockHash};
 
        use bitcoin::secp256k1::key::{PublicKey,SecretKey};
        use bitcoin::secp256k1::{Secp256k1, Message};
@@ -1461,7 +1461,7 @@ mod tests {
                }
                let unsigned_channel_announcement = msgs::UnsignedChannelAnnouncement {
                        features,
-                       chain_hash: if !non_bitcoin_chain_hash { Sha256dHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { Sha256dHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
+                       chain_hash: if !non_bitcoin_chain_hash { BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { BlockHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
                        short_channel_id: 2316138423780173,
                        node_id_1: pubkey_1,
                        node_id_2: pubkey_2,
@@ -1611,7 +1611,7 @@ mod tests {
                let (privkey_1, _) = get_keys_from!("0101010101010101010101010101010101010101010101010101010101010101", secp_ctx);
                let sig_1 = get_sig_on!(privkey_1, secp_ctx, String::from("01010101010101010101010101010101"));
                let unsigned_channel_update = msgs::UnsignedChannelUpdate {
-                       chain_hash: if !non_bitcoin_chain_hash { Sha256dHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { Sha256dHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
+                       chain_hash: if !non_bitcoin_chain_hash { BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { BlockHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
                        short_channel_id: 2316138423780173,
                        timestamp: 20190119,
                        flags: if direction { 1 } else { 0 } | if disable { 1 << 1 } else { 0 } | if htlc_maximum_msat { 1 << 8 } else { 0 },
@@ -1673,7 +1673,7 @@ mod tests {
                let (_, pubkey_5) = get_keys_from!("0505050505050505050505050505050505050505050505050505050505050505", secp_ctx);
                let (_, pubkey_6) = get_keys_from!("0606060606060606060606060606060606060606060606060606060606060606", secp_ctx);
                let open_channel = msgs::OpenChannel {
-                       chain_hash: if !non_bitcoin_chain_hash { Sha256dHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { Sha256dHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
+                       chain_hash: if !non_bitcoin_chain_hash { BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() } else { BlockHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() },
                        temporary_channel_id: [2; 32],
                        funding_satoshis: 1311768467284833366,
                        push_msat: 2536655962884945560,
@@ -1767,7 +1767,7 @@ mod tests {
                let sig_1 = get_sig_on!(privkey_1, secp_ctx, String::from("01010101010101010101010101010101"));
                let funding_created = msgs::FundingCreated {
                        temporary_channel_id: [2; 32],
-                       funding_txid: Sha256dHash::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap(),
+                       funding_txid: Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap(),
                        funding_output_index: 255,
                        signature: sig_1,
                };
index dd393d82f8bc8fb044f18378948d8c67999c3460..19c901fc9d009eb7dc564d8e9b4b857c7859c398 100644 (file)
@@ -8,7 +8,7 @@ use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
 use bitcoin::blockdata::script::Script;
 use bitcoin::util::bip143;
 
-use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::Txid;
 
 use bitcoin::secp256k1::{Secp256k1, Signature};
 use bitcoin::secp256k1;
@@ -37,7 +37,7 @@ enum OnchainEvent {
        /// Outpoint under claim process by our own tx, once this one get enough confirmations, we remove it from
        /// bump-txn candidate buffer.
        Claim {
-               claim_request: Sha256dHash,
+               claim_request: Txid,
        },
        /// Claim tx aggregate multiple claimable outpoints. One of the outpoint may be claimed by a remote party tx.
        /// In this case, we need to drop the outpoint and regenerate a new claim tx. By safety, we keep tracking
@@ -210,9 +210,9 @@ pub struct OnchainTxHandler<ChanSigner: ChannelKeys> {
        // us and is immutable until all outpoint of the claimable set are post-anti-reorg-delay solved.
        // Entry is cache of elements need to generate a bumped claiming transaction (see ClaimTxBumpMaterial)
        #[cfg(test)] // Used in functional_test to verify sanitization
-       pub pending_claim_requests: HashMap<Sha256dHash, ClaimTxBumpMaterial>,
+       pub pending_claim_requests: HashMap<Txid, ClaimTxBumpMaterial>,
        #[cfg(not(test))]
-       pending_claim_requests: HashMap<Sha256dHash, ClaimTxBumpMaterial>,
+       pending_claim_requests: HashMap<Txid, ClaimTxBumpMaterial>,
 
        // Used to link outpoints claimed in a connected block to a pending claim request.
        // Key is outpoint than monitor parsing has detected we have keys/scripts to claim
@@ -221,9 +221,9 @@ pub struct OnchainTxHandler<ChanSigner: ChannelKeys> {
        // post-anti-reorg-delay solved, confirmaiton_block is used to erase entry if
        // block with output gets disconnected.
        #[cfg(test)] // Used in functional_test to verify sanitization
-       pub claimable_outpoints: HashMap<BitcoinOutPoint, (Sha256dHash, u32)>,
+       pub claimable_outpoints: HashMap<BitcoinOutPoint, (Txid, u32)>,
        #[cfg(not(test))]
-       claimable_outpoints: HashMap<BitcoinOutPoint, (Sha256dHash, u32)>,
+       claimable_outpoints: HashMap<BitcoinOutPoint, (Txid, u32)>,
 
        onchain_events_waiting_threshold_conf: HashMap<u32, Vec<OnchainEvent>>,
 
index a1a6e42d8f51ec3c00f7524e38458152a89f328f..b98569d3d1bfba18ba971b8ac942940b244ac5da 100644 (file)
@@ -9,6 +9,7 @@ use bitcoin::secp256k1;
 
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hashes::Hash;
+use bitcoin::hash_types::BlockHash;
 use bitcoin::blockdata::script::Builder;
 use bitcoin::blockdata::opcodes;
 
@@ -329,19 +330,19 @@ impl std::fmt::Display for NetworkMap {
 impl NetworkMap {
        #[cfg(feature = "non_bitcoin_chain_hash_routing")]
        #[inline]
-       fn get_key(short_channel_id: u64, chain_hash: Sha256dHash) -> (u64, Sha256dHash) {
+       fn get_key(short_channel_id: u64, chain_hash: BlockHash) -> (u64, BlockHash) {
                (short_channel_id, chain_hash)
        }
 
        #[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
        #[inline]
-       fn get_key(short_channel_id: u64, _: Sha256dHash) -> u64 {
+       fn get_key(short_channel_id: u64, _: BlockHash) -> u64 {
                short_channel_id
        }
 
        #[cfg(feature = "non_bitcoin_chain_hash_routing")]
        #[inline]
-       fn get_short_id(id: &(u64, Sha256dHash)) -> &u64 {
+       fn get_short_id(id: &(u64, BlockHash)) -> &u64 {
                &id.0
        }
 
@@ -1087,6 +1088,7 @@ mod tests {
 
        use bitcoin::hashes::sha256d::Hash as Sha256dHash;
        use bitcoin::hashes::Hash;
+       use bitcoin::hash_types::BlockHash;
        use bitcoin::network::constants::Network;
        use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::blockdata::script::Builder;
@@ -1181,7 +1183,7 @@ mod tests {
                let node7 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0808080808080808080808080808080808080808080808080808080808080808").unwrap()[..]).unwrap());
                let node8 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0909090909090909090909090909090909090909090909090909090909090909").unwrap()[..]).unwrap());
 
-               let zero_hash = Sha256dHash::hash(&[0; 32]);
+               let zero_hash = BlockHash::hash(&[0; 32]);
 
                macro_rules! id_to_feature_flags {
                        // Set the feature flags to the id'th odd (ie non-required) feature bit so that we can
index b6f89fe9b191cc98dc3e9acfcb59ca4be77568da..b94540446339d421fec525597d653878a647f621 100644 (file)
@@ -1,7 +1,7 @@
 use chain::transaction::OutPoint;
 use chain::keysinterface::SpendableOutputDescriptor;
 
-use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::Txid;
 use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::secp256k1::key::PublicKey;
 
@@ -40,7 +40,7 @@ macro_rules! log_bytes {
        }
 }
 
-pub(crate) struct DebugFundingChannelId<'a>(pub &'a Sha256dHash, pub u16);
+pub(crate) struct DebugFundingChannelId<'a>(pub &'a Txid, pub u16);
 impl<'a> std::fmt::Display for DebugFundingChannelId<'a> {
        fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
                for i in OutPoint::new(self.0.clone(), self.1).to_channel_id().iter() {
index fd0e9f7a383b2bb9e0530e183e5ee9203218e065..a087467f7a438304ee3db7f52c956ce1a9ef90c3 100644 (file)
@@ -15,6 +15,7 @@ use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxOut};
 use bitcoin::consensus;
 use bitcoin::consensus::Encodable;
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
+use bitcoin::hash_types::{Txid, BlockHash};
 use std::marker::Sized;
 use ln::msgs::DecodeError;
 use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret};
@@ -632,6 +633,36 @@ impl<T: Readable> Readable for Option<T>
        }
 }
 
+impl Writeable for Txid {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+               w.write_all(&self[..])
+       }
+}
+
+impl Readable for Txid {
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               use bitcoin::hashes::Hash;
+
+               let buf: [u8; 32] = Readable::read(r)?;
+               Ok(Txid::from_slice(&buf[..]).unwrap())
+       }
+}
+
+impl Writeable for BlockHash {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+               w.write_all(&self[..])
+       }
+}
+
+impl Readable for BlockHash {
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               use bitcoin::hashes::Hash;
+
+               let buf: [u8; 32] = Readable::read(r)?;
+               Ok(BlockHash::from_slice(&buf[..]).unwrap())
+       }
+}
+
 impl Writeable for OutPoint {
        fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
                self.txid.write(w)?;
index 12b48944677bf1f97332c68aac8ade044efa295e..b436d0c13d9e93caadce620bf5d04bf25f576f2b 100644 (file)
@@ -16,8 +16,8 @@ use bitcoin::blockdata::transaction::Transaction;
 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;
+use bitcoin::hash_types::{Txid, BlockHash};
 
 use bitcoin::secp256k1::{SecretKey, PublicKey};
 
@@ -72,7 +72,7 @@ impl<'a> channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChanne
                // to a watchtower and disk...
                let mut w = TestVecWriter(Vec::new());
                monitor.write_for_disk(&mut w).unwrap();
-               let new_monitor = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
+               let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
                                &mut ::std::io::Cursor::new(&w.0), Arc::new(TestLogger::new())).unwrap().1;
                assert!(new_monitor == monitor);
                self.latest_monitor_update_id.lock().unwrap().insert(funding_txo.to_channel_id(), (funding_txo, monitor.get_latest_update_id()));
@@ -101,7 +101,7 @@ impl<'a> channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChanne
                let monitor = monitors.get(&funding_txo).unwrap();
                w.0.clear();
                monitor.write_for_disk(&mut w).unwrap();
-               let new_monitor = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
+               let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
                                &mut ::std::io::Cursor::new(&w.0), Arc::new(TestLogger::new())).unwrap().1;
                assert!(new_monitor == *monitor);
                self.added_monitors.lock().unwrap().push((funding_txo, new_monitor));
@@ -288,15 +288,15 @@ impl TestChainWatcher {
 }
 
 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 install_watch_tx(&self, _txid: &Txid, _script_pub_key: &Script) { }
+       fn install_watch_outpoint(&self, _outpoint: (Txid, 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> {
+       fn get_chain_utxo(&self, _genesis_hash: BlockHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
                self.utxo_ret.lock().unwrap().clone()
        }
 }