X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Ftest_utils.rs;h=a72af12d4db4dacf4eb26fe82fa62e724e1e6c8f;hb=3e9727b808814e6a6656a071a247695d9d95c572;hp=9ca517964994e5adf01d0fe3784d34ea738847cc;hpb=3a1982c74111f749853c307a192a7fb276612076;p=rust-lightning diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 9ca51796..a72af12d 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -24,6 +24,7 @@ use crate::ln::script::ShutdownScript; use crate::routing::gossip::NetworkGraph; use crate::routing::router::{find_route, InFlightHtlcs, Route, RouteHop, RouteParameters, Router, ScorerAccountingForInFlightHtlcs}; use crate::routing::scoring::FixedPenaltyScorer; +use crate::util::config::UserConfig; use crate::util::enforcing_trait_impls::{EnforcingSigner, EnforcementState}; use crate::util::events; use crate::util::logger::{Logger, Level, Record}; @@ -140,9 +141,6 @@ impl SignerProvider for OnlyReadsKeysInterface { fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { unreachable!(); } } -impl keysinterface::KeysInterface for OnlyReadsKeysInterface { -} - pub struct TestChainMonitor<'a> { pub added_monitors: Mutex)>>, pub monitor_updates: Mutex>>, @@ -178,7 +176,7 @@ impl<'a> chain::Watch for TestChainMonitor<'a> { let mut w = TestVecWriter(Vec::new()); monitor.write(&mut w).unwrap(); let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor)>::read( - &mut io::Cursor::new(&w.0), self.keys_manager).unwrap().1; + &mut io::Cursor::new(&w.0), (self.keys_manager, self.keys_manager)).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(), MonitorUpdateId::from_new_monitor(&monitor))); @@ -212,7 +210,7 @@ impl<'a> chain::Watch for TestChainMonitor<'a> { w.0.clear(); monitor.write(&mut w).unwrap(); let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor)>::read( - &mut io::Cursor::new(&w.0), self.keys_manager).unwrap().1; + &mut io::Cursor::new(&w.0), (self.keys_manager, self.keys_manager)).unwrap().1; assert!(new_monitor == *monitor); self.added_monitors.lock().unwrap().push((funding_txo, new_monitor)); update_res @@ -224,10 +222,9 @@ impl<'a> chain::Watch for TestChainMonitor<'a> { } pub struct TestPersister { - pub update_ret: Mutex, - /// If this is set to Some(), after the next return, we'll always return this until update_ret - /// is changed: - pub next_update_ret: Mutex>, + /// The queue of update statuses we'll return. If none are queued, ::Completed will always be + /// returned. + pub update_rets: Mutex>, /// When we get an update_persisted_channel call with no ChannelMonitorUpdate, we insert the /// MonitorUpdateId here. pub chain_sync_monitor_persistences: Mutex>>, @@ -238,34 +235,29 @@ pub struct TestPersister { impl TestPersister { pub fn new() -> Self { Self { - update_ret: Mutex::new(chain::ChannelMonitorUpdateStatus::Completed), - next_update_ret: Mutex::new(None), + update_rets: Mutex::new(VecDeque::new()), chain_sync_monitor_persistences: Mutex::new(HashMap::new()), offchain_monitor_updates: Mutex::new(HashMap::new()), } } - pub fn set_update_ret(&self, ret: chain::ChannelMonitorUpdateStatus) { - *self.update_ret.lock().unwrap() = ret; - } - - pub fn set_next_update_ret(&self, next_ret: Option) { - *self.next_update_ret.lock().unwrap() = next_ret; + /// Queue an update status to return. + pub fn set_update_ret(&self, next_ret: chain::ChannelMonitorUpdateStatus) { + self.update_rets.lock().unwrap().push_back(next_ret); } } impl chainmonitor::Persist for TestPersister { fn persist_new_channel(&self, _funding_txo: OutPoint, _data: &channelmonitor::ChannelMonitor, _id: MonitorUpdateId) -> chain::ChannelMonitorUpdateStatus { - let ret = self.update_ret.lock().unwrap().clone(); - if let Some(next_ret) = self.next_update_ret.lock().unwrap().take() { - *self.update_ret.lock().unwrap() = next_ret; + if let Some(update_ret) = self.update_rets.lock().unwrap().pop_front() { + return update_ret } - ret + chain::ChannelMonitorUpdateStatus::Completed } fn update_persisted_channel(&self, funding_txo: OutPoint, update: &Option, _data: &channelmonitor::ChannelMonitor, update_id: MonitorUpdateId) -> chain::ChannelMonitorUpdateStatus { - let ret = self.update_ret.lock().unwrap().clone(); - if let Some(next_ret) = self.next_update_ret.lock().unwrap().take() { - *self.update_ret.lock().unwrap() = next_ret; + let mut ret = chain::ChannelMonitorUpdateStatus::Completed; + if let Some(update_ret) = self.update_rets.lock().unwrap().pop_front() { + ret = update_ret; } if update.is_none() { self.chain_sync_monitor_persistences.lock().unwrap().entry(funding_txo).or_insert(HashSet::new()).insert(update_id); @@ -406,10 +398,10 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler { self.received_msg(wire::Message::Error(msg.clone())); } fn provided_node_features(&self) -> NodeFeatures { - channelmanager::provided_node_features() + channelmanager::provided_node_features(&UserConfig::default()) } fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures { - channelmanager::provided_init_features() + channelmanager::provided_init_features(&UserConfig::default()) } } @@ -719,8 +711,6 @@ impl SignerProvider for TestKeysInterface { } } -impl keysinterface::KeysInterface for TestKeysInterface {} - impl TestKeysInterface { pub fn new(seed: &[u8; 32], network: Network) -> Self { let now = Duration::from_secs(genesis_block(network).header.time as u64);