@@ -69,7 +69,10 @@ impl<Key : Send + cmp::Eq + hash::Hash> ChainListener for SimpleManyChannelMonit
69
69
fn block_connected ( & self , _header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , _indexes_of_txn_matched : & [ u32 ] ) {
70
70
let monitors = self . monitors . lock ( ) . unwrap ( ) ;
71
71
for monitor in monitors. values ( ) {
72
- monitor. block_connected ( txn_matched, height, & * self . broadcaster ) ;
72
+ let outputs = monitor. block_connected ( txn_matched, height, & * self . broadcaster ) ;
73
+ for output in outputs {
74
+ self . chain_monitor . install_watch_script ( & output. script_pubkey ) ;
75
+ }
73
76
}
74
77
}
75
78
@@ -464,8 +467,9 @@ impl ChannelMonitor {
464
467
/// optional, without it this monitor cannot be used in an SPV client, but you may wish to
465
468
/// avoid this (or call unset_funding_info) on a monitor you wish to send to a watchtower as it
466
469
/// provides slightly better privacy.
470
+ /// It is the responsability of the caller to register outpoint and script with passing the former
471
+ /// value as key to update current monitor
467
472
pub ( super ) fn set_funding_info ( & mut self , funding_info : ( OutPoint , Script ) ) {
468
- //TODO: Need to register the given script here with a chain_monitor
469
473
self . funding_txo = Some ( funding_info) ;
470
474
}
471
475
@@ -908,15 +912,16 @@ impl ChannelMonitor {
908
912
/// height > height + CLTV_SHARED_CLAIM_BUFFER. In any case, will install monitoring for
909
913
/// HTLC-Success/HTLC-Timeout transactions, and claim them using the revocation key (if
910
914
/// applicable) as well.
911
- fn check_spend_remote_transaction ( & self , tx : & Transaction , height : u32 ) -> Vec < Transaction > {
915
+ fn check_spend_remote_transaction ( & self , tx : & Transaction , height : u32 ) -> ( Vec < Transaction > , Vec < TxOut > ) {
912
916
// Most secp and related errors trying to create keys means we have no hope of constructing
913
917
// a spend transaction...so we return no transactions to broadcast
914
918
let mut txn_to_broadcast = Vec :: new ( ) ;
919
+ let mut outputs = Vec :: new ( ) ;
915
920
macro_rules! ignore_error {
916
921
( $thing : expr ) => {
917
922
match $thing {
918
923
Ok ( a) => a,
919
- Err ( _) => return txn_to_broadcast
924
+ Err ( _) => return ( txn_to_broadcast, outputs )
920
925
}
921
926
} ;
922
927
}
@@ -942,7 +947,7 @@ impl ChannelMonitor {
942
947
} ;
943
948
let delayed_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & PublicKey :: from_secret_key( & self . secp_ctx, & per_commitment_key) , & self . delayed_payment_base_key) ) ;
944
949
let a_htlc_key = match self . their_htlc_base_key {
945
- None => return txn_to_broadcast,
950
+ None => return ( txn_to_broadcast, outputs ) ,
946
951
Some ( their_htlc_base_key) => ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & PublicKey :: from_secret_key( & self . secp_ctx, & per_commitment_key) , & their_htlc_base_key) ) ,
947
952
} ;
948
953
@@ -1009,7 +1014,7 @@ impl ChannelMonitor {
1009
1014
if htlc. transaction_output_index as usize >= tx. output . len ( ) ||
1010
1015
tx. output [ htlc. transaction_output_index as usize ] . value != htlc. amount_msat / 1000 ||
1011
1016
tx. output [ htlc. transaction_output_index as usize ] . script_pubkey != expected_script. to_v0_p2wsh ( ) {
1012
- return txn_to_broadcast; // Corrupted per_commitment_data, fuck this user
1017
+ return ( txn_to_broadcast, outputs ) ; // Corrupted per_commitment_data, fuck this user
1013
1018
}
1014
1019
let input = TxIn {
1015
1020
previous_output : BitcoinOutPoint {
@@ -1044,10 +1049,10 @@ impl ChannelMonitor {
1044
1049
1045
1050
if !inputs. is_empty ( ) || !txn_to_broadcast. is_empty ( ) { // ie we're confident this is actually ours
1046
1051
// We're definitely a remote commitment transaction!
1047
- // TODO: Register all outputs in commitment_tx with the ChainWatchInterface!
1052
+ outputs. append ( & mut tx . output . clone ( ) ) ;
1048
1053
self . remote_commitment_txn_on_chain . lock ( ) . unwrap ( ) . insert ( commitment_txid, commitment_number) ;
1049
1054
}
1050
- if inputs. is_empty ( ) { return txn_to_broadcast; } // Nothing to be done...probably a false positive/local tx
1055
+ if inputs. is_empty ( ) { return ( txn_to_broadcast, outputs ) ; } // Nothing to be done...probably a false positive/local tx
1051
1056
1052
1057
let outputs = vec ! ( TxOut {
1053
1058
script_pubkey: self . destination_script. clone( ) ,
@@ -1077,7 +1082,7 @@ impl ChannelMonitor {
1077
1082
// already processed the block, resulting in the remote_commitment_txn_on_chain entry
1078
1083
// not being generated by the above conditional. Thus, to be safe, we go ahead and
1079
1084
// insert it here.
1080
- // TODO: Register all outputs in commitment_tx with the ChainWatchInterface!
1085
+ outputs. append ( & mut tx . output . clone ( ) ) ;
1081
1086
self . remote_commitment_txn_on_chain . lock ( ) . unwrap ( ) . insert ( commitment_txid, commitment_number) ;
1082
1087
1083
1088
if let Some ( revocation_points) = self . their_cur_revocation_points {
@@ -1098,7 +1103,7 @@ impl ChannelMonitor {
1098
1103
} ,
1099
1104
} ;
1100
1105
let a_htlc_key = match self . their_htlc_base_key {
1101
- None => return txn_to_broadcast,
1106
+ None => return ( txn_to_broadcast, outputs ) ,
1102
1107
Some ( their_htlc_base_key) => ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, revocation_point, & their_htlc_base_key) ) ,
1103
1108
} ;
1104
1109
@@ -1161,7 +1166,7 @@ impl ChannelMonitor {
1161
1166
}
1162
1167
}
1163
1168
1164
- if inputs. is_empty ( ) { return txn_to_broadcast; } // Nothing to be done...probably a false positive/local tx
1169
+ if inputs. is_empty ( ) { return ( txn_to_broadcast, outputs ) ; } // Nothing to be done...probably a false positive/local tx
1165
1170
1166
1171
let outputs = vec ! ( TxOut {
1167
1172
script_pubkey: self . destination_script. clone( ) ,
@@ -1189,7 +1194,7 @@ impl ChannelMonitor {
1189
1194
//TODO: For each input check if its in our remote_commitment_txn_on_chain map!
1190
1195
}
1191
1196
1192
- txn_to_broadcast
1197
+ ( txn_to_broadcast, outputs )
1193
1198
}
1194
1199
1195
1200
fn broadcast_by_local_state ( & self , local_tx : & LocalSignedTx ) -> Vec < Transaction > {
@@ -1250,11 +1255,13 @@ impl ChannelMonitor {
1250
1255
Vec :: new ( )
1251
1256
}
1252
1257
1253
- fn block_connected ( & self , txn_matched : & [ & Transaction ] , height : u32 , broadcaster : & BroadcasterInterface ) {
1258
+ fn block_connected ( & self , txn_matched : & [ & Transaction ] , height : u32 , broadcaster : & BroadcasterInterface ) -> Vec < TxOut > {
1259
+ let mut outputs = Vec :: new ( ) ;
1254
1260
for tx in txn_matched {
1255
1261
for txin in tx. input . iter ( ) {
1256
1262
if self . funding_txo . is_none ( ) || ( txin. previous_output . txid == self . funding_txo . as_ref ( ) . unwrap ( ) . 0 . txid && txin. previous_output . vout == self . funding_txo . as_ref ( ) . unwrap ( ) . 0 . index as u32 ) {
1257
- let mut txn = self . check_spend_remote_transaction ( tx, height) ;
1263
+ let ( mut txn, out) = self . check_spend_remote_transaction ( tx, height) ;
1264
+ outputs = out;
1258
1265
if txn. is_empty ( ) {
1259
1266
txn = self . check_spend_local_transaction ( tx, height) ;
1260
1267
}
@@ -1281,6 +1288,7 @@ impl ChannelMonitor {
1281
1288
}
1282
1289
}
1283
1290
}
1291
+ outputs
1284
1292
}
1285
1293
1286
1294
pub fn would_broadcast_at_height ( & self , height : u32 ) -> bool {
0 commit comments