@@ -130,9 +130,9 @@ pub enum ChannelMonitorUpdateErr {
130
130
}
131
131
132
132
/// 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 .
136
136
/// Contains a human-readable error message.
137
137
#[ derive( Debug ) ]
138
138
pub struct MonitorUpdateError ( pub & ' static str ) ;
@@ -149,7 +149,7 @@ impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
149
149
150
150
/// Simple trait indicating ability to track a set of ChannelMonitors and multiplex events between
151
151
/// them. Generally should be implemented by keeping a local SimpleManyChannelMonitor and passing
152
- /// events to it, while also taking any add_update_monitor events and passing them to some remote
152
+ /// events to it, while also taking any add/update_monitor events and passing them to some remote
153
153
/// server(s).
154
154
///
155
155
/// Note that any updates to a channel's monitor *must* be applied to each instance of the
@@ -163,7 +163,7 @@ impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
163
163
/// BlockNotifier and call the BlockNotifier's `block_(dis)connected` methods, which will notify
164
164
/// all registered listeners in one go.
165
165
pub trait ManyChannelMonitor < ChanSigner : ChannelKeys > : Send + Sync {
166
- /// Adds or updates a monitor for the given `funding_txo`.
166
+ /// Adds a monitor for the given `funding_txo`.
167
167
///
168
168
/// Implementer must also ensure that the funding_txo txid *and* outpoint are registered with
169
169
/// any relevant ChainWatchInterfaces such that the provided monitor receives block_connected
@@ -175,7 +175,7 @@ pub trait ManyChannelMonitor<ChanSigner: ChannelKeys>: Send + Sync {
175
175
///
176
176
/// Any spends of outputs which should have been registered which aren't passed to
177
177
/// ChannelMonitors via block_connected may result in funds loss.
178
- fn add_update_monitor ( & self , funding_txo : OutPoint , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , ChannelMonitorUpdateErr > ;
178
+ fn add_monitor ( & self , funding_txo : OutPoint , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , ChannelMonitorUpdateErr > ;
179
179
180
180
/// Updates a monitor for the given `funding_txo`.
181
181
///
@@ -274,14 +274,11 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys> Simpl
274
274
}
275
275
276
276
/// Adds or updates the monitor which monitors the channel referred to by the given key.
277
- pub fn add_update_monitor_by_key ( & self , key : Key , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , MonitorUpdateError > {
277
+ pub fn add_monitor_by_key ( & self , key : Key , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , MonitorUpdateError > {
278
278
let mut monitors = self . monitors . lock ( ) . unwrap ( ) ;
279
- match monitors. get_mut ( & key) {
280
- Some ( orig_monitor) => {
281
- log_trace ! ( self , "Updating Channel Monitor for channel {}" , log_funding_info!( monitor. key_storage) ) ;
282
- return orig_monitor. insert_combine ( monitor) ;
283
- } ,
284
- None => { }
279
+ let entry = match monitors. entry ( key) {
280
+ hash_map:: Entry :: Occupied ( _) => return Err ( MonitorUpdateError ( "Channel monitor for given key is already present" ) ) ,
281
+ hash_map:: Entry :: Vacant ( e) => e,
285
282
} ;
286
283
match monitor. key_storage {
287
284
Storage :: Local { ref funding_info, .. } => {
@@ -305,7 +302,7 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys> Simpl
305
302
self . chain_monitor . install_watch_outpoint ( ( * txid, idx as u32 ) , script) ;
306
303
}
307
304
}
308
- monitors . insert ( key , monitor) ;
305
+ entry . insert ( monitor) ;
309
306
Ok ( ( ) )
310
307
}
311
308
@@ -323,8 +320,8 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys> Simpl
323
320
}
324
321
325
322
impl < ChanSigner : ChannelKeys > ManyChannelMonitor < ChanSigner > for SimpleManyChannelMonitor < OutPoint , ChanSigner > {
326
- fn add_update_monitor ( & self , funding_txo : OutPoint , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , ChannelMonitorUpdateErr > {
327
- match self . add_update_monitor_by_key ( funding_txo, monitor) {
323
+ fn add_monitor ( & self , funding_txo : OutPoint , monitor : ChannelMonitor < ChanSigner > ) -> Result < ( ) , ChannelMonitorUpdateErr > {
324
+ match self . add_monitor_by_key ( funding_txo, monitor) {
328
325
Ok ( _) => Ok ( ( ) ) ,
329
326
Err ( _) => Err ( ChannelMonitorUpdateErr :: PermanentFailure ) ,
330
327
}
@@ -867,7 +864,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
867
864
868
865
// We simply modify last_block_hash in Channel's block_connected so that serialization is
869
866
// consistent but hopefully the users' copy handles block_connected in a consistent way.
870
- // (we do *not*, however, update them in insert_combine to ensure any local user copies keep
867
+ // (we do *not*, however, update them in update_monitor to ensure any local user copies keep
871
868
// their last_block_hash from its state and not based on updated copies that didn't run through
872
869
// the full block_connected).
873
870
pub ( crate ) last_block_hash : Sha256dHash ,
@@ -1497,68 +1494,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1497
1494
Ok ( ( ) )
1498
1495
}
1499
1496
1500
- /// Combines this ChannelMonitor with the information contained in the other ChannelMonitor.
1501
- /// After a successful call this ChannelMonitor is up-to-date and is safe to use to monitor the
1502
- /// chain for new blocks/transactions.
1503
- pub fn insert_combine ( & mut self , mut other : ChannelMonitor < ChanSigner > ) -> Result < ( ) , MonitorUpdateError > {
1504
- match self . key_storage {
1505
- Storage :: Local { ref funding_info, .. } => {
1506
- if funding_info. is_none ( ) { return Err ( MonitorUpdateError ( "Try to combine a Local monitor without funding_info" ) ) ; }
1507
- let our_funding_info = funding_info;
1508
- if let Storage :: Local { ref funding_info, .. } = other. key_storage {
1509
- if funding_info. is_none ( ) { return Err ( MonitorUpdateError ( "Try to combine a Local monitor without funding_info" ) ) ; }
1510
- // We should be able to compare the entire funding_txo, but in fuzztarget it's trivially
1511
- // easy to collide the funding_txo hash and have a different scriptPubKey.
1512
- if funding_info. as_ref ( ) . unwrap ( ) . 0 != our_funding_info. as_ref ( ) . unwrap ( ) . 0 {
1513
- return Err ( MonitorUpdateError ( "Funding transaction outputs are not identical!" ) ) ;
1514
- }
1515
- } else {
1516
- return Err ( MonitorUpdateError ( "Try to combine a Local monitor with a Watchtower one !" ) ) ;
1517
- }
1518
- } ,
1519
- Storage :: Watchtower { .. } => {
1520
- if let Storage :: Watchtower { .. } = other. key_storage {
1521
- unimplemented ! ( ) ;
1522
- } else {
1523
- return Err ( MonitorUpdateError ( "Try to combine a Watchtower monitor with a Local one !" ) ) ;
1524
- }
1525
- } ,
1526
- }
1527
- let other_min_secret = other. get_min_seen_secret ( ) ;
1528
- let our_min_secret = self . get_min_seen_secret ( ) ;
1529
- if our_min_secret > other_min_secret {
1530
- self . provide_secret ( other_min_secret, other. get_secret ( other_min_secret) . unwrap ( ) ) ?;
1531
- }
1532
- if let Some ( ref local_tx) = self . current_local_signed_commitment_tx {
1533
- if let Some ( ref other_local_tx) = other. current_local_signed_commitment_tx {
1534
- 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 ) ;
1535
- 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 ) ;
1536
- if our_commitment_number >= other_commitment_number {
1537
- self . key_storage = other. key_storage ;
1538
- }
1539
- }
1540
- }
1541
- // TODO: We should use current_remote_commitment_number and the commitment number out of
1542
- // local transactions to decide how to merge
1543
- if our_min_secret >= other_min_secret {
1544
- self . their_cur_revocation_points = other. their_cur_revocation_points ;
1545
- for ( txid, htlcs) in other. remote_claimable_outpoints . drain ( ) {
1546
- self . remote_claimable_outpoints . insert ( txid, htlcs) ;
1547
- }
1548
- if let Some ( local_tx) = other. prev_local_signed_commitment_tx {
1549
- self . prev_local_signed_commitment_tx = Some ( local_tx) ;
1550
- }
1551
- if let Some ( local_tx) = other. current_local_signed_commitment_tx {
1552
- self . current_local_signed_commitment_tx = Some ( local_tx) ;
1553
- }
1554
- self . payment_preimages = other. payment_preimages ;
1555
- self . to_remote_rescue = other. to_remote_rescue ;
1556
- }
1557
-
1558
- self . current_remote_commitment_number = cmp:: min ( self . current_remote_commitment_number , other. current_remote_commitment_number ) ;
1559
- Ok ( ( ) )
1560
- }
1561
-
1562
1497
/// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
1563
1498
/// ChannelMonitor.
1564
1499
pub fn get_latest_update_id ( & self ) -> u64 {
0 commit comments