X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fchain%2Fchaininterface.rs;h=5ff720c32e5fed57d8c0ad23e20c3180c675674e;hb=8322c756cb3574d74cf1b88893dad14ec5be57ad;hp=3a0b2d735d9a877eb98f95dd23739a472ad6a54d;hpb=90b545ffe3e6855e09156361ecb1d5384add1e46;p=rust-lightning diff --git a/src/chain/chaininterface.rs b/src/chain/chaininterface.rs index 3a0b2d73..5ff720c3 100644 --- a/src/chain/chaininterface.rs +++ b/src/chain/chaininterface.rs @@ -5,9 +5,12 @@ use bitcoin::blockdata::constants::genesis_block; use bitcoin::util::hash::Sha256dHash; use bitcoin::network::constants::Network; use bitcoin::network::serialize::BitcoinHash; + use util::logger::Logger; + use std::sync::{Mutex,Weak,MutexGuard,Arc}; use std::sync::atomic::{AtomicUsize, Ordering}; +use std::collections::HashSet; /// Used to give chain error details upstream pub enum ChainError { @@ -57,6 +60,8 @@ pub trait ChainListener: Sync + Send { /// Note that if a new transaction/outpoint is watched during a block_connected call, the block /// *must* be re-scanned with the new transaction/outpoints and block_connected should be /// called again with the same header and (at least) the new transactions. + /// Note that if non-new transaction/outpoints may be registered during a call, a second call + /// *must not* happen. /// This also means those counting confirmations using block_connected callbacks should watch /// for duplicate headers and not count them towards confirmations! fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]); @@ -85,11 +90,98 @@ pub trait FeeEstimator: Sync + Send { fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u64; } +/// Utility for tracking registered txn/outpoints and checking for matches +pub struct ChainWatchedUtil { + watch_all: bool, + + // 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)>, + #[cfg(not(test))] + watched_txn: HashSet