@@ -130,9 +130,9 @@ pub enum ChannelMonitorUpdateErr {
130130}
131131
132132/// General Err type for ChannelMonitor actions. Generally, this implies that the data provided is
133- /// inconsistent with the ChannelMonitor being called. eg for ChannelMonitor::insert_combine this
134- /// means you tried to merge two monitors for different channels or for a channel which was
135- /// restored from a backup and then generated new commitment updates .
133+ /// inconsistent with the ChannelMonitor being called. eg for ChannelMonitor::update_monitor this
134+ /// means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was
135+ /// corrupted .
136136/// Contains a human-readable error message.
137137#[ derive( Debug ) ]
138138pub struct MonitorUpdateError ( pub & ' static str ) ;
@@ -147,7 +147,7 @@ pub struct HTLCUpdate {
147147
148148/// Simple trait indicating ability to track a set of ChannelMonitors and multiplex events between
149149/// them. Generally should be implemented by keeping a local SimpleManyChannelMonitor and passing
150- /// events to it, while also taking any add_update_monitor events and passing them to some remote
150+ /// events to it, while also taking any add/update_monitor events and passing them to some remote
151151/// server(s).
152152///
153153/// Note that any updates to a channel's monitor *must* be applied to each instance of the
@@ -161,7 +161,7 @@ pub struct HTLCUpdate {
161161/// BlockNotifier and call the BlockNotifier's `block_(dis)connected` methods, which will notify
162162/// all registered listeners in one go.
163163pub trait ManyChannelMonitor < ChanSigner : ChannelKeys > : Send + Sync {
164- /// Adds or updates a monitor for the given `funding_txo`.
164+ /// Adds a monitor for the given `funding_txo`.
165165 ///
166166 /// Implementer must also ensure that the funding_txo txid *and* outpoint are registered with
167167 /// any relevant ChainWatchInterfaces such that the provided monitor receives block_connected
@@ -170,7 +170,7 @@ pub trait ManyChannelMonitor<ChanSigner: ChannelKeys>: Send + Sync {
170170 /// Further, the implementer must also ensure that each output returned in
171171 /// monitor.get_outputs_to_watch() is registered to ensure that the provided monitor learns about
172172 /// any spends of any of the outputs.
173- fn add_update_monitor ( & self , funding_txo : OutPoint , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , ChannelMonitorUpdateErr > ;
173+ fn add_monitor ( & self , funding_txo : OutPoint , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , ChannelMonitorUpdateErr > ;
174174
175175 /// Updates a monitor for the given `funding_txo`.
176176 ///
@@ -266,14 +266,11 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys> Simpl
266266 }
267267
268268 /// Adds or updates the monitor which monitors the channel referred to by the given key.
269- pub fn add_update_monitor_by_key ( & self , key : Key , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , MonitorUpdateError > {
269+ pub fn add_monitor_by_key ( & self , key : Key , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , MonitorUpdateError > {
270270 let mut monitors = self . monitors . lock ( ) . unwrap ( ) ;
271- match monitors. get_mut ( & key) {
272- Some ( orig_monitor) => {
273- log_trace ! ( self , "Updating Channel Monitor for channel {}" , log_funding_info!( monitor. key_storage) ) ;
274- return orig_monitor. insert_combine ( monitor) ;
275- } ,
276- None => { }
271+ let entry = match monitors. entry ( key) {
272+ hash_map:: Entry :: Occupied ( _) => return Err ( MonitorUpdateError ( "Channel monitor for given key is already present" ) ) ,
273+ hash_map:: Entry :: Vacant ( e) => e,
277274 } ;
278275 match monitor. key_storage {
279276 Storage :: Local { ref funding_info, .. } => {
@@ -297,7 +294,7 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys> Simpl
297294 self . chain_monitor . install_watch_outpoint ( ( * txid, idx as u32 ) , script) ;
298295 }
299296 }
300- monitors . insert ( key , monitor) ;
297+ entry . insert ( monitor) ;
301298 Ok ( ( ) )
302299 }
303300
@@ -315,8 +312,8 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys> Simpl
315312}
316313
317314impl < ChanSigner : ChannelKeys > ManyChannelMonitor < ChanSigner > for SimpleManyChannelMonitor < OutPoint , ChanSigner > {
318- fn add_update_monitor ( & self , funding_txo : OutPoint , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , ChannelMonitorUpdateErr > {
319- match self . add_update_monitor_by_key ( funding_txo, monitor) {
315+ fn add_monitor ( & self , funding_txo : OutPoint , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , ChannelMonitorUpdateErr > {
316+ match self . add_monitor_by_key ( funding_txo, monitor) {
320317 Ok ( _) => Ok ( ( ) ) ,
321318 Err ( _) => Err ( ChannelMonitorUpdateErr :: PermanentFailure ) ,
322319 }
@@ -859,7 +856,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
859856
860857 // We simply modify last_block_hash in Channel's block_connected so that serialization is
861858 // consistent but hopefully the users' copy handles block_connected in a consistent way.
862- // (we do *not*, however, update them in insert_combine to ensure any local user copies keep
859+ // (we do *not*, however, update them in update_monitor to ensure any local user copies keep
863860 // their last_block_hash from its state and not based on updated copies that didn't run through
864861 // the full block_connected).
865862 pub ( crate ) last_block_hash : Sha256dHash ,
@@ -1494,68 +1491,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14941491 Ok ( ( ) )
14951492 }
14961493
1497- /// Combines this ChannelMonitor with the information contained in the other ChannelMonitor.
1498- /// After a successful call this ChannelMonitor is up-to-date and is safe to use to monitor the
1499- /// chain for new blocks/transactions.
1500- pub fn insert_combine ( & mut self , mut other : ChannelMonitor < ChanSigner > ) -> Result < ( ) , MonitorUpdateError > {
1501- match self . key_storage {
1502- Storage :: Local { ref funding_info, .. } => {
1503- if funding_info. is_none ( ) { return Err ( MonitorUpdateError ( "Try to combine a Local monitor without funding_info" ) ) ; }
1504- let our_funding_info = funding_info;
1505- if let Storage :: Local { ref funding_info, .. } = other. key_storage {
1506- if funding_info. is_none ( ) { return Err ( MonitorUpdateError ( "Try to combine a Local monitor without funding_info" ) ) ; }
1507- // We should be able to compare the entire funding_txo, but in fuzztarget it's trivially
1508- // easy to collide the funding_txo hash and have a different scriptPubKey.
1509- if funding_info. as_ref ( ) . unwrap ( ) . 0 != our_funding_info. as_ref ( ) . unwrap ( ) . 0 {
1510- return Err ( MonitorUpdateError ( "Funding transaction outputs are not identical!" ) ) ;
1511- }
1512- } else {
1513- return Err ( MonitorUpdateError ( "Try to combine a Local monitor with a Watchtower one !" ) ) ;
1514- }
1515- } ,
1516- Storage :: Watchtower { .. } => {
1517- if let Storage :: Watchtower { .. } = other. key_storage {
1518- unimplemented ! ( ) ;
1519- } else {
1520- return Err ( MonitorUpdateError ( "Try to combine a Watchtower monitor with a Local one !" ) ) ;
1521- }
1522- } ,
1523- }
1524- let other_min_secret = other. get_min_seen_secret ( ) ;
1525- let our_min_secret = self . get_min_seen_secret ( ) ;
1526- if our_min_secret > other_min_secret {
1527- self . provide_secret ( other_min_secret, other. get_secret ( other_min_secret) . unwrap ( ) ) ?;
1528- }
1529- if let Some ( ref local_tx) = self . current_local_signed_commitment_tx {
1530- if let Some ( ref other_local_tx) = other. current_local_signed_commitment_tx {
1531- let our_commitment_number = 0xffffffffffff - ( ( ( ( local_tx. tx . without_valid_witness ( ) . input [ 0 ] . sequence as u64 & 0xffffff ) << 3 * 8 ) | ( local_tx. tx . without_valid_witness ( ) . lock_time as u64 & 0xffffff ) ) ^ self . commitment_transaction_number_obscure_factor ) ;
1532- let other_commitment_number = 0xffffffffffff - ( ( ( ( other_local_tx. tx . without_valid_witness ( ) . input [ 0 ] . sequence as u64 & 0xffffff ) << 3 * 8 ) | ( other_local_tx. tx . without_valid_witness ( ) . lock_time as u64 & 0xffffff ) ) ^ other. commitment_transaction_number_obscure_factor ) ;
1533- if our_commitment_number >= other_commitment_number {
1534- self . key_storage = other. key_storage ;
1535- }
1536- }
1537- }
1538- // TODO: We should use current_remote_commitment_number and the commitment number out of
1539- // local transactions to decide how to merge
1540- if our_min_secret >= other_min_secret {
1541- self . their_cur_revocation_points = other. their_cur_revocation_points ;
1542- for ( txid, htlcs) in other. remote_claimable_outpoints . drain ( ) {
1543- self . remote_claimable_outpoints . insert ( txid, htlcs) ;
1544- }
1545- if let Some ( local_tx) = other. prev_local_signed_commitment_tx {
1546- self . prev_local_signed_commitment_tx = Some ( local_tx) ;
1547- }
1548- if let Some ( local_tx) = other. current_local_signed_commitment_tx {
1549- self . current_local_signed_commitment_tx = Some ( local_tx) ;
1550- }
1551- self . payment_preimages = other. payment_preimages ;
1552- self . to_remote_rescue = other. to_remote_rescue ;
1553- }
1554-
1555- self . current_remote_commitment_number = cmp:: min ( self . current_remote_commitment_number , other. current_remote_commitment_number ) ;
1556- Ok ( ( ) )
1557- }
1558-
15591494 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
15601495 /// ChannelMonitor.
15611496 pub fn get_latest_update_id ( & self ) -> u64 {
0 commit comments