@@ -362,7 +362,7 @@ pub struct ChannelMonitor {
362
362
their_to_self_delay : Option < u16 > ,
363
363
364
364
old_secrets : [ ( [ u8 ; 32 ] , u64 ) ; 49 ] ,
365
- remote_claimable_outpoints : HashMap < Sha256dHash , Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > > ,
365
+ remote_claimable_outpoints : HashMap < Sha256dHash , Vec < ( HTLCOutputInCommitment , Option < HTLCSource > ) > > ,
366
366
/// We cannot identify HTLC-Success or HTLC-Timeout transactions by themselves on the chain.
367
367
/// Nor can we figure out their commitment numbers without the commitment transaction they are
368
368
/// spending. Thus, in order to claim them via revocation key, we track all the remote
@@ -564,7 +564,7 @@ impl ChannelMonitor {
564
564
/// The monitor watches for it to be broadcasted and then uses the HTLC information (and
565
565
/// possibly future revocation/preimage information) to claim outputs where possible.
566
566
/// We cache also the mapping hash:commitment number to lighten pruning of old preimages by watchtowers.
567
- pub ( super ) fn provide_latest_remote_commitment_tx_info ( & mut self , unsigned_commitment_tx : & Transaction , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > , commitment_number : u64 , their_revocation_point : PublicKey ) {
567
+ pub ( super ) fn provide_latest_remote_commitment_tx_info ( & mut self , unsigned_commitment_tx : & Transaction , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < HTLCSource > ) > , commitment_number : u64 , their_revocation_point : PublicKey ) {
568
568
// TODO: Encrypt the htlc_outputs data with the single-hash of the commitment transaction
569
569
// so that a remote monitor doesn't learn anything unless there is a malicious close.
570
570
// (only maybe, sadly we cant do the same for local info, as we need to be aware of
@@ -781,18 +781,6 @@ impl ChannelMonitor {
781
781
// Set in initial Channel-object creation, so should always be set by now:
782
782
U48 ( self . commitment_transaction_number_obscure_factor ) . write ( writer) ?;
783
783
784
- macro_rules! write_option {
785
- ( $thing: expr) => {
786
- match $thing {
787
- & Some ( ref t) => {
788
- 1u8 . write( writer) ?;
789
- t. write( writer) ?;
790
- } ,
791
- & None => 0u8 . write( writer) ?,
792
- }
793
- }
794
- }
795
-
796
784
match self . key_storage {
797
785
Storage :: Local { ref revocation_base_key, ref htlc_base_key, ref delayed_payment_base_key, ref payment_base_key, ref shutdown_pubkey, ref prev_latest_per_commitment_point, ref latest_per_commitment_point, ref funding_info, ref current_remote_commitment_txid, ref prev_remote_commitment_txid } => {
798
786
writer. write_all ( & [ 0 ; 1 ] ) ?;
@@ -801,18 +789,8 @@ impl ChannelMonitor {
801
789
writer. write_all ( & delayed_payment_base_key[ ..] ) ?;
802
790
writer. write_all ( & payment_base_key[ ..] ) ?;
803
791
writer. write_all ( & shutdown_pubkey. serialize ( ) ) ?;
804
- if let Some ( ref prev_latest_per_commitment_point) = * prev_latest_per_commitment_point {
805
- writer. write_all ( & [ 1 ; 1 ] ) ?;
806
- writer. write_all ( & prev_latest_per_commitment_point. serialize ( ) ) ?;
807
- } else {
808
- writer. write_all ( & [ 0 ; 1 ] ) ?;
809
- }
810
- if let Some ( ref latest_per_commitment_point) = * latest_per_commitment_point {
811
- writer. write_all ( & [ 1 ; 1 ] ) ?;
812
- writer. write_all ( & latest_per_commitment_point. serialize ( ) ) ?;
813
- } else {
814
- writer. write_all ( & [ 0 ; 1 ] ) ?;
815
- }
792
+ prev_latest_per_commitment_point. write ( writer) ?;
793
+ latest_per_commitment_point. write ( writer) ?;
816
794
match funding_info {
817
795
& Some ( ( ref outpoint, ref script) ) => {
818
796
writer. write_all ( & outpoint. txid [ ..] ) ?;
@@ -823,8 +801,8 @@ impl ChannelMonitor {
823
801
debug_assert ! ( false , "Try to serialize a useless Local monitor !" ) ;
824
802
} ,
825
803
}
826
- write_option ! ( current_remote_commitment_txid) ;
827
- write_option ! ( prev_remote_commitment_txid) ;
804
+ current_remote_commitment_txid. write ( writer ) ? ;
805
+ prev_remote_commitment_txid. write ( writer ) ? ;
828
806
} ,
829
807
Storage :: Watchtower { .. } => unimplemented ! ( ) ,
830
808
}
@@ -864,7 +842,7 @@ impl ChannelMonitor {
864
842
writer. write_all( & byte_utils:: be64_to_array( $htlc_output. amount_msat) ) ?;
865
843
writer. write_all( & byte_utils:: be32_to_array( $htlc_output. cltv_expiry) ) ?;
866
844
writer. write_all( & $htlc_output. payment_hash. 0 [ ..] ) ?;
867
- write_option! ( & $htlc_output. transaction_output_index) ;
845
+ $htlc_output. transaction_output_index. write ( writer ) ? ;
868
846
}
869
847
}
870
848
@@ -874,7 +852,7 @@ impl ChannelMonitor {
874
852
writer. write_all ( & byte_utils:: be64_to_array ( htlc_infos. len ( ) as u64 ) ) ?;
875
853
for & ( ref htlc_output, ref htlc_source) in htlc_infos. iter ( ) {
876
854
serialize_htlc_in_commitment ! ( htlc_output) ;
877
- write_option ! ( htlc_source) ;
855
+ htlc_source. write ( writer ) ? ;
878
856
}
879
857
}
880
858
@@ -923,7 +901,8 @@ impl ChannelMonitor {
923
901
} else {
924
902
0u8 . write( writer) ?;
925
903
}
926
- write_option!( htlc_source) ;
904
+ htlc_source. write( writer) ?;
905
+ //write_option!(htlc_source);
927
906
}
928
907
}
929
908
}
@@ -1188,7 +1167,7 @@ impl ChannelMonitor {
1188
1167
for & ( ref htlc, ref source_option) in outpoints. iter( ) {
1189
1168
if let & Some ( ref source) = source_option {
1190
1169
log_trace!( self , "Failing HTLC with payment_hash {} from {} remote commitment tx due to broadcast of revoked remote commitment transaction" , log_bytes!( htlc. payment_hash. 0 ) , $commitment_tx) ;
1191
- htlc_updated. push( ( ( * * source) . clone( ) , None , htlc. payment_hash. clone( ) ) ) ;
1170
+ htlc_updated. push( ( ( * source) . clone( ) , None , htlc. payment_hash. clone( ) ) ) ;
1192
1171
}
1193
1172
}
1194
1173
}
@@ -1266,7 +1245,7 @@ impl ChannelMonitor {
1266
1245
}
1267
1246
}
1268
1247
log_trace!( self , "Failing HTLC with payment_hash {} from {} remote commitment tx due to broadcast of remote commitment transaction" , log_bytes!( htlc. payment_hash. 0 ) , $commitment_tx) ;
1269
- htlc_updated. push( ( ( * * source) . clone( ) , None , htlc. payment_hash. clone( ) ) ) ;
1248
+ htlc_updated. push( ( ( * source) . clone( ) , None , htlc. payment_hash. clone( ) ) ) ;
1270
1249
}
1271
1250
}
1272
1251
}
@@ -1903,7 +1882,7 @@ impl ChannelMonitor {
1903
1882
if pending_htlc. payment_hash == $htlc_output. payment_hash && pending_htlc. amount_msat == $htlc_output. amount_msat {
1904
1883
if let & Some ( ref source) = pending_source {
1905
1884
log_claim!( "revoked remote commitment tx" , false , pending_htlc, true ) ;
1906
- payment_data = Some ( ( ( * * source) . clone( ) , $htlc_output. payment_hash) ) ;
1885
+ payment_data = Some ( ( ( * source) . clone( ) , $htlc_output. payment_hash) ) ;
1907
1886
break ;
1908
1887
}
1909
1888
}
@@ -1956,7 +1935,7 @@ impl ChannelMonitor {
1956
1935
}
1957
1936
}
1958
1937
if let Some ( ref htlc_outputs) = self . remote_claimable_outpoints . get ( & input. previous_output . txid ) {
1959
- scan_commitment ! ( htlc_outputs. iter( ) . map( |& ( ref a, ref b) | ( a, ( b. as_ref( ) . clone( ) ) . map ( |boxed| & * * boxed ) ) ) ,
1938
+ scan_commitment ! ( htlc_outputs. iter( ) . map( |& ( ref a, ref b) | ( a, ( b. as_ref( ) . clone( ) ) ) ) ,
1960
1939
"remote commitment tx" , false ) ;
1961
1940
}
1962
1941
@@ -2085,7 +2064,7 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
2085
2064
let htlcs_count: u64 = Readable :: read ( reader) ?;
2086
2065
let mut htlcs = Vec :: with_capacity ( cmp:: min ( htlcs_count as usize , MAX_ALLOC_SIZE / 32 ) ) ;
2087
2066
for _ in 0 ..htlcs_count {
2088
- htlcs. push ( ( read_htlc_in_commitment ! ( ) , <Option < HTLCSource > as Readable < R > >:: read ( reader) ?. map ( | o : HTLCSource | Box :: new ( o ) ) ) ) ;
2067
+ htlcs. push ( ( read_htlc_in_commitment ! ( ) , <Option < HTLCSource > as Readable < R > >:: read ( reader) ?) ) ;
2089
2068
}
2090
2069
if let Some ( _) = remote_claimable_outpoints. insert ( txid, htlcs) {
2091
2070
return Err ( DecodeError :: InvalidValue ) ;
0 commit comments