@@ -290,16 +290,9 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys, T: De
290
290
hash_map:: Entry :: Occupied ( _) => return Err ( MonitorUpdateError ( "Channel monitor for given key is already present" ) ) ,
291
291
hash_map:: Entry :: Vacant ( e) => e,
292
292
} ;
293
- match monitor. funding_info {
294
- None => {
295
- return Err ( MonitorUpdateError ( "Try to update a useless monitor without funding_txo !" ) ) ;
296
- } ,
297
- Some ( ( ref outpoint, ref script) ) => {
298
- log_trace ! ( self , "Got new Channel Monitor for channel {}" , log_bytes!( outpoint. to_channel_id( ) [ ..] ) ) ;
299
- self . chain_monitor . install_watch_tx ( & outpoint. txid , script) ;
300
- self . chain_monitor . install_watch_outpoint ( ( outpoint. txid , outpoint. index as u32 ) , script) ;
301
- } ,
302
- }
293
+ log_trace ! ( self , "Got new Channel Monitor for channel {}" , log_bytes!( monitor. funding_info. 0 . to_channel_id( ) [ ..] ) ) ;
294
+ self . chain_monitor . install_watch_tx ( & monitor. funding_info . 0 . txid , & monitor. funding_info . 1 ) ;
295
+ self . chain_monitor . install_watch_outpoint ( ( monitor. funding_info . 0 . txid , monitor. funding_info . 0 . index as u32 ) , & monitor. funding_info . 1 ) ;
303
296
for ( txid, outputs) in monitor. get_outputs_to_watch ( ) . iter ( ) {
304
297
for ( idx, script) in outputs. iter ( ) . enumerate ( ) {
305
298
self . chain_monitor . install_watch_outpoint ( ( * txid, idx as u32 ) , script) ;
@@ -721,19 +714,19 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
721
714
shutdown_script : Script ,
722
715
723
716
keys : ChanSigner ,
724
- funding_info : Option < ( OutPoint , Script ) > ,
717
+ funding_info : ( OutPoint , Script ) ,
725
718
current_remote_commitment_txid : Option < Sha256dHash > ,
726
719
prev_remote_commitment_txid : Option < Sha256dHash > ,
727
720
728
- their_htlc_base_key : Option < PublicKey > ,
729
- their_delayed_payment_base_key : Option < PublicKey > ,
730
- funding_redeemscript : Option < Script > ,
731
- channel_value_satoshis : Option < u64 > ,
721
+ their_htlc_base_key : PublicKey ,
722
+ their_delayed_payment_base_key : PublicKey ,
723
+ funding_redeemscript : Script ,
724
+ channel_value_satoshis : u64 ,
732
725
// first is the idx of the first of the two revocation points
733
726
their_cur_revocation_points : Option < ( u64 , PublicKey , Option < PublicKey > ) > ,
734
727
735
728
our_to_self_delay : u16 ,
736
- their_to_self_delay : Option < u16 > ,
729
+ their_to_self_delay : u16 ,
737
730
738
731
commitment_secrets : CounterpartyCommitmentSecrets ,
739
732
remote_claimable_outpoints : HashMap < Sha256dHash , Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > > ,
@@ -872,23 +865,16 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
872
865
self . shutdown_script . write ( writer) ?;
873
866
874
867
self . keys . write ( writer) ?;
875
- match self . funding_info {
876
- Some ( ( ref outpoint, ref script) ) => {
877
- writer. write_all ( & outpoint. txid [ ..] ) ?;
878
- writer. write_all ( & byte_utils:: be16_to_array ( outpoint. index ) ) ?;
879
- script. write ( writer) ?;
880
- } ,
881
- None => {
882
- debug_assert ! ( false , "Try to serialize a useless Local monitor !" ) ;
883
- } ,
884
- }
868
+ writer. write_all ( & self . funding_info . 0 . txid [ ..] ) ?;
869
+ writer. write_all ( & byte_utils:: be16_to_array ( self . funding_info . 0 . index ) ) ?;
870
+ self . funding_info . 1 . write ( writer) ?;
885
871
self . current_remote_commitment_txid . write ( writer) ?;
886
872
self . prev_remote_commitment_txid . write ( writer) ?;
887
873
888
- writer. write_all ( & self . their_htlc_base_key . as_ref ( ) . unwrap ( ) . serialize ( ) ) ?;
889
- writer. write_all ( & self . their_delayed_payment_base_key . as_ref ( ) . unwrap ( ) . serialize ( ) ) ?;
890
- self . funding_redeemscript . as_ref ( ) . unwrap ( ) . write ( writer) ?;
891
- self . channel_value_satoshis . unwrap ( ) . write ( writer) ?;
874
+ writer. write_all ( & self . their_htlc_base_key . serialize ( ) ) ?;
875
+ writer. write_all ( & self . their_delayed_payment_base_key . serialize ( ) ) ?;
876
+ self . funding_redeemscript . write ( writer) ?;
877
+ self . channel_value_satoshis . write ( writer) ?;
892
878
893
879
match self . their_cur_revocation_points {
894
880
Some ( ( idx, pubkey, second_option) ) => {
@@ -909,7 +895,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
909
895
}
910
896
911
897
writer. write_all ( & byte_utils:: be16_to_array ( self . our_to_self_delay ) ) ?;
912
- writer. write_all ( & byte_utils:: be16_to_array ( self . their_to_self_delay . unwrap ( ) ) ) ?;
898
+ writer. write_all ( & byte_utils:: be16_to_array ( self . their_to_self_delay ) ) ?;
913
899
914
900
self . commitment_secrets . write ( writer) ?;
915
901
@@ -1099,18 +1085,18 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1099
1085
shutdown_script,
1100
1086
1101
1087
keys : keys. clone ( ) ,
1102
- funding_info : Some ( funding_info ) ,
1088
+ funding_info,
1103
1089
current_remote_commitment_txid : None ,
1104
1090
prev_remote_commitment_txid : None ,
1105
1091
1106
- their_htlc_base_key : Some ( their_htlc_base_key. clone ( ) ) ,
1107
- their_delayed_payment_base_key : Some ( their_delayed_payment_base_key. clone ( ) ) ,
1108
- funding_redeemscript : Some ( funding_redeemscript. clone ( ) ) ,
1109
- channel_value_satoshis : Some ( channel_value_satoshis) ,
1092
+ their_htlc_base_key : their_htlc_base_key. clone ( ) ,
1093
+ their_delayed_payment_base_key : their_delayed_payment_base_key. clone ( ) ,
1094
+ funding_redeemscript : funding_redeemscript. clone ( ) ,
1095
+ channel_value_satoshis : channel_value_satoshis,
1110
1096
their_cur_revocation_points : None ,
1111
1097
1112
- our_to_self_delay : our_to_self_delay ,
1113
- their_to_self_delay : Some ( their_to_self_delay ) ,
1098
+ our_to_self_delay,
1099
+ their_to_self_delay,
1114
1100
1115
1101
commitment_secrets : CounterpartyCommitmentSecrets :: new ( ) ,
1116
1102
remote_claimable_outpoints : HashMap :: new ( ) ,
@@ -1248,9 +1234,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1248
1234
/// up-to-date as our local commitment transaction is updated.
1249
1235
/// Panics if set_their_to_self_delay has never been called.
1250
1236
pub ( super ) fn provide_latest_local_commitment_tx_info ( & mut self , mut commitment_tx : LocalCommitmentTransaction , local_keys : chan_utils:: TxCreationKeys , feerate_per_kw : u64 , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Signature > , Option < HTLCSource > ) > ) -> Result < ( ) , MonitorUpdateError > {
1251
- if self . their_to_self_delay . is_none ( ) {
1252
- return Err ( MonitorUpdateError ( "Got a local commitment tx info update before we'd set basic information about the channel" ) ) ;
1253
- }
1254
1237
let txid = commitment_tx. txid ( ) ;
1255
1238
let sequence = commitment_tx. without_valid_witness ( ) . input [ 0 ] . sequence as u64 ;
1256
1239
let locktime = commitment_tx. without_valid_witness ( ) . lock_time as u64 ;
@@ -1366,11 +1349,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1366
1349
}
1367
1350
1368
1351
/// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
1369
- pub fn get_funding_txo ( & self ) -> Option < OutPoint > {
1370
- if let Some ( ( outp, _) ) = self . funding_info {
1371
- return Some ( outp)
1372
- }
1373
- None
1352
+ pub fn get_funding_txo ( & self ) -> OutPoint {
1353
+ self . funding_info . 0
1374
1354
}
1375
1355
1376
1356
/// Gets a list of txids, with their output scripts (in the order they appear in the
@@ -1463,11 +1443,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1463
1443
let revocation_key = ignore_error ! ( chan_utils:: derive_private_revocation_key( & self . secp_ctx, & per_commitment_key, & self . keys. revocation_base_key( ) ) ) ;
1464
1444
let b_htlc_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & per_commitment_point, & self . keys. pubkeys( ) . htlc_basepoint) ) ;
1465
1445
let local_payment_key = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, & per_commitment_point, & self . keys. payment_base_key( ) ) ) ;
1466
- let delayed_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & PublicKey :: from_secret_key( & self . secp_ctx, & per_commitment_key) , & self . their_delayed_payment_base_key. unwrap( ) ) ) ;
1467
- let a_htlc_key = match self . their_htlc_base_key {
1468
- None => return ( claimable_outpoints, ( commitment_txid, watch_outputs) ) ,
1469
- 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) ) ,
1470
- } ;
1446
+ let delayed_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & PublicKey :: from_secret_key( & self . secp_ctx, & per_commitment_key) , & self . their_delayed_payment_base_key) ) ;
1447
+ let a_htlc_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & PublicKey :: from_secret_key( & self . secp_ctx, & per_commitment_key) , & self . their_htlc_base_key) ) ;
1471
1448
1472
1449
let revokeable_redeemscript = chan_utils:: get_revokeable_redeemscript ( & revocation_pubkey, self . our_to_self_delay , & delayed_key) ;
1473
1450
let revokeable_p2wsh = revokeable_redeemscript. to_v0_p2wsh ( ) ;
@@ -1618,10 +1595,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1618
1595
let revocation_pubkey = ignore_error ! ( chan_utils:: derive_public_revocation_key( & self . secp_ctx, revocation_point, & self . keys. pubkeys( ) . revocation_basepoint) ) ;
1619
1596
let b_htlc_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, revocation_point, & self . keys. pubkeys( ) . htlc_basepoint) ) ;
1620
1597
let htlc_privkey = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, revocation_point, & self . keys. htlc_base_key( ) ) ) ;
1621
- let a_htlc_key = match self . their_htlc_base_key {
1622
- None => return ( claimable_outpoints, ( commitment_txid, watch_outputs) ) ,
1623
- Some ( their_htlc_base_key) => ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, revocation_point, & their_htlc_base_key) ) ,
1624
- } ;
1598
+ let a_htlc_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, revocation_point, & self . their_htlc_base_key) ) ;
1625
1599
let local_payment_key = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, revocation_point, & self . keys. payment_base_key( ) ) ) ;
1626
1600
1627
1601
self . broadcasted_remote_payment_script = {
@@ -1675,10 +1649,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1675
1649
let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
1676
1650
let revocation_pubkey = ignore_error ! ( chan_utils:: derive_public_revocation_key( & self . secp_ctx, & per_commitment_point, & self . keys. pubkeys( ) . revocation_basepoint) ) ;
1677
1651
let revocation_key = ignore_error ! ( chan_utils:: derive_private_revocation_key( & self . secp_ctx, & per_commitment_key, & self . keys. revocation_base_key( ) ) ) ;
1678
- let delayed_key = match self . their_delayed_payment_base_key {
1679
- None => return ( Vec :: new ( ) , None ) ,
1680
- Some ( their_delayed_payment_base_key) => ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & per_commitment_point, & their_delayed_payment_base_key) ) ,
1681
- } ;
1652
+ let delayed_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & per_commitment_point, & self . their_delayed_payment_base_key) ) ;
1682
1653
let redeemscript = chan_utils:: get_revokeable_redeemscript ( & revocation_pubkey, self . our_to_self_delay , & delayed_key) ;
1683
1654
1684
1655
log_trace ! ( self , "Remote HTLC broadcast {}:{}" , htlc_txid, 0 ) ;
@@ -1691,7 +1662,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1691
1662
let mut claim_requests = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1692
1663
let mut watch_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1693
1664
1694
- let redeemscript = chan_utils:: get_revokeable_redeemscript ( & local_tx. revocation_key , self . their_to_self_delay . unwrap ( ) , & local_tx. delayed_payment_key ) ;
1665
+ let redeemscript = chan_utils:: get_revokeable_redeemscript ( & local_tx. revocation_key , self . their_to_self_delay , & local_tx. delayed_payment_key ) ;
1695
1666
let broadcasted_local_revokable_script = if let Ok ( local_delayedkey) = chan_utils:: derive_private_key ( & self . secp_ctx , & local_tx. per_commitment_point , self . keys . delayed_payment_base_key ( ) ) {
1696
1667
Some ( ( redeemscript. to_v0_p2wsh ( ) , local_delayedkey, redeemscript) )
1697
1668
} else { None } ;
@@ -1873,8 +1844,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1873
1844
// which is an easy way to filter out any potential non-matching txn for lazy
1874
1845
// filters.
1875
1846
let prevout = & tx. input [ 0 ] . previous_output ;
1876
- let funding_txo = self . funding_info . clone ( ) ;
1877
- if funding_txo. is_none ( ) || ( prevout. txid == funding_txo. as_ref ( ) . unwrap ( ) . 0 . txid && prevout. vout == funding_txo. as_ref ( ) . unwrap ( ) . 0 . index as u32 ) {
1847
+ if prevout. txid == self . funding_info . 0 . txid && prevout. vout == self . funding_info . 0 . index as u32 {
1878
1848
if ( tx. input [ 0 ] . sequence >> 8 * 3 ) as u8 == 0x80 && ( tx. lock_time >> 8 * 3 ) as u8 == 0x20 {
1879
1849
let ( mut new_outpoints, new_outputs) = self . check_spend_remote_transaction ( & tx, height) ;
1880
1850
if !new_outputs. 1 . is_empty ( ) {
@@ -1910,7 +1880,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1910
1880
self . would_broadcast_at_height ( height)
1911
1881
} else { false } ;
1912
1882
if should_broadcast {
1913
- claimable_outpoints. push ( ClaimRequest { absolute_timelock : height, aggregable : false , outpoint : BitcoinOutPoint { txid : self . funding_info . as_ref ( ) . unwrap ( ) . 0 . txid . clone ( ) , vout : self . funding_info . as_ref ( ) . unwrap ( ) . 0 . index as u32 } , witness_data : InputMaterial :: Funding { channel_value : self . channel_value_satoshis . unwrap ( ) } } ) ;
1883
+ claimable_outpoints. push ( ClaimRequest { absolute_timelock : height, aggregable : false , outpoint : BitcoinOutPoint { txid : self . funding_info . 0 . txid . clone ( ) , vout : self . funding_info . 0 . index as u32 } , witness_data : InputMaterial :: Funding { channel_value : self . channel_value_satoshis } } ) ;
1914
1884
}
1915
1885
if let Some ( ref cur_local_tx) = self . current_local_signed_commitment_tx {
1916
1886
if should_broadcast {
@@ -2188,7 +2158,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
2188
2158
outpoint : BitcoinOutPoint { txid : tx. txid ( ) , vout : i as u32 } ,
2189
2159
key : broadcasted_local_revokable_script. 1 ,
2190
2160
witness_script : broadcasted_local_revokable_script. 2 . clone ( ) ,
2191
- to_self_delay : self . their_to_self_delay . unwrap ( ) ,
2161
+ to_self_delay : self . their_to_self_delay ,
2192
2162
output : outp. clone ( ) ,
2193
2163
} ) ;
2194
2164
break ;
@@ -2275,14 +2245,14 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2275
2245
txid : Readable :: read ( reader) ?,
2276
2246
index : Readable :: read ( reader) ?,
2277
2247
} ;
2278
- let funding_info = Some ( ( outpoint, Readable :: read ( reader) ?) ) ;
2248
+ let funding_info = ( outpoint, Readable :: read ( reader) ?) ;
2279
2249
let current_remote_commitment_txid = Readable :: read ( reader) ?;
2280
2250
let prev_remote_commitment_txid = Readable :: read ( reader) ?;
2281
2251
2282
- let their_htlc_base_key = Some ( Readable :: read ( reader) ?) ;
2283
- let their_delayed_payment_base_key = Some ( Readable :: read ( reader) ?) ;
2284
- let funding_redeemscript = Some ( Readable :: read ( reader) ?) ;
2285
- let channel_value_satoshis = Some ( Readable :: read ( reader) ?) ;
2252
+ let their_htlc_base_key = Readable :: read ( reader) ?;
2253
+ let their_delayed_payment_base_key = Readable :: read ( reader) ?;
2254
+ let funding_redeemscript = Readable :: read ( reader) ?;
2255
+ let channel_value_satoshis = Readable :: read ( reader) ?;
2286
2256
2287
2257
let their_cur_revocation_points = {
2288
2258
let first_idx = <U48 as Readable >:: read ( reader) ?. 0 ;
@@ -2300,7 +2270,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2300
2270
} ;
2301
2271
2302
2272
let our_to_self_delay: u16 = Readable :: read ( reader) ?;
2303
- let their_to_self_delay: Option < u16 > = Some ( Readable :: read ( reader) ?) ;
2273
+ let their_to_self_delay: u16 = Readable :: read ( reader) ?;
2304
2274
2305
2275
let commitment_secrets = Readable :: read ( reader) ?;
2306
2276
@@ -2643,9 +2613,7 @@ mod tests {
2643
2613
( OutPoint { txid : Sha256dHash :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } , Script :: new ( ) ) ,
2644
2614
& PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 44 ; 32 ] ) . unwrap ( ) ) ,
2645
2615
& PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 45 ; 32 ] ) . unwrap ( ) ) ,
2646
- 0 , Script :: new ( ) , 46 , 0 , logger. clone ( ) ) ;
2647
-
2648
- monitor. their_to_self_delay = Some ( 10 ) ;
2616
+ 10 , Script :: new ( ) , 46 , 0 , logger. clone ( ) ) ;
2649
2617
2650
2618
monitor. provide_latest_local_commitment_tx_info ( LocalCommitmentTransaction :: dummy ( ) , dummy_keys ! ( ) , 0 , preimages_to_local_htlcs ! ( preimages[ 0 ..10 ] ) ) . unwrap ( ) ;
2651
2619
monitor. provide_latest_remote_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 5 ..15 ] ) , 281474976710655 , dummy_key) ;
0 commit comments