@@ -851,9 +851,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
851
851
let mut included_dust_htlcs: Vec < ( HTLCOutputInCommitment , Option < & HTLCSource > ) > = Vec :: new ( ) ;
852
852
853
853
let broadcaster_dust_limit_satoshis = if local { self . holder_dust_limit_satoshis } else { self . counterparty_dust_limit_satoshis } ;
854
- let mut remote_htlc_total_msat = 0 ;
855
- let mut local_htlc_total_msat = 0 ;
856
- let mut value_to_self_msat_offset = 0 ;
854
+ let mut counterparty_htlc_total_msat = 0 ;
855
+ let mut holder_htlc_total_msat = 0 ;
856
+ let mut holder_value_msat_offset = 0 ;
857
857
858
858
log_trace ! ( logger, "Building commitment transaction number {} (really {} xor {}) for {}, generated by {} with fee {}..." , commitment_number, ( INITIAL_COMMITMENT_NUMBER - commitment_number) , self . get_commitment_transaction_number_obscure_factor( ) , if local { "us" } else { "remote" } , if generated_by_local { "us" } else { "remote" } , feerate_per_kw) ;
859
859
@@ -910,14 +910,14 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
910
910
911
911
if include {
912
912
add_htlc_output ! ( htlc, false , None , state_name) ;
913
- remote_htlc_total_msat += htlc. amount_msat ;
913
+ counterparty_htlc_total_msat += htlc. amount_msat ;
914
914
} else {
915
915
log_trace ! ( logger, " ...not including inbound HTLC {} (hash {}) with value {} due to state ({})" , htlc. htlc_id, log_bytes!( htlc. payment_hash. 0 ) , htlc. amount_msat, state_name) ;
916
916
match & htlc. state {
917
917
& InboundHTLCState :: LocalRemoved ( ref reason) => {
918
918
if generated_by_local {
919
919
if let & InboundHTLCRemovalReason :: Fulfill ( _) = reason {
920
- value_to_self_msat_offset += htlc. amount_msat as i64 ;
920
+ holder_value_msat_offset += htlc. amount_msat as i64 ;
921
921
}
922
922
}
923
923
} ,
@@ -937,31 +937,31 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
937
937
938
938
if include {
939
939
add_htlc_output ! ( htlc, true , Some ( & htlc. source) , state_name) ;
940
- local_htlc_total_msat += htlc. amount_msat ;
940
+ holder_htlc_total_msat += htlc. amount_msat ;
941
941
} else {
942
942
log_trace ! ( logger, " ...not including outbound HTLC {} (hash {}) with value {} due to state ({})" , htlc. htlc_id, log_bytes!( htlc. payment_hash. 0 ) , htlc. amount_msat, state_name) ;
943
943
match htlc. state {
944
944
OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( None ) |OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( None ) => {
945
- value_to_self_msat_offset -= htlc. amount_msat as i64 ;
945
+ holder_value_msat_offset -= htlc. amount_msat as i64 ;
946
946
} ,
947
947
OutboundHTLCState :: RemoteRemoved ( None ) => {
948
948
if !generated_by_local {
949
- value_to_self_msat_offset -= htlc. amount_msat as i64 ;
949
+ holder_value_msat_offset -= htlc. amount_msat as i64 ;
950
950
}
951
951
} ,
952
952
_ => { } ,
953
953
}
954
954
}
955
955
}
956
956
957
- let value_to_self_msat : i64 = ( self . value_to_self_msat - local_htlc_total_msat ) as i64 + value_to_self_msat_offset ;
958
- assert ! ( value_to_self_msat >= 0 ) ;
957
+ let holder_value_msat : i64 = ( self . value_to_self_msat - holder_htlc_total_msat ) as i64 + holder_value_msat_offset ;
958
+ assert ! ( holder_value_msat >= 0 ) ;
959
959
// Note that in case they have several just-awaiting-last-RAA fulfills in-progress (ie
960
960
// AwaitingRemoteRevokeToRemove or AwaitingRemovedRemoteRevoke) we may have allowed them to
961
961
// "violate" their reserve value by couting those against it. Thus, we have to convert
962
962
// everything to i64 before subtracting as otherwise we can overflow.
963
- let value_to_remote_msat : i64 = ( self . channel_value_satoshis * 1000 ) as i64 - ( self . value_to_self_msat as i64 ) - ( remote_htlc_total_msat as i64 ) - value_to_self_msat_offset ;
964
- assert ! ( value_to_remote_msat >= 0 ) ;
963
+ let counterparty_value_msat : i64 = ( self . channel_value_satoshis * 1000 ) as i64 - ( self . value_to_self_msat as i64 ) - ( counterparty_htlc_total_msat as i64 ) - holder_value_msat_offset ;
964
+ assert ! ( counterparty_value_msat >= 0 ) ;
965
965
966
966
#[ cfg( debug_assertions) ]
967
967
{
@@ -972,21 +972,20 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
972
972
} else {
973
973
self . counterparty_max_commitment_tx_output . lock ( ) . unwrap ( )
974
974
} ;
975
- debug_assert ! ( broadcaster_max_commitment_tx_output. 0 <= value_to_self_msat as u64 || value_to_self_msat / 1000 >= self . counterparty_selected_channel_reserve_satoshis as i64 ) ;
976
- broadcaster_max_commitment_tx_output. 0 = cmp:: max ( broadcaster_max_commitment_tx_output. 0 , value_to_self_msat as u64 ) ;
977
- debug_assert ! ( broadcaster_max_commitment_tx_output. 1 <= value_to_remote_msat as u64 || value_to_remote_msat / 1000 >= Channel :: <ChanSigner >:: get_holder_selected_channel_reserve_satoshis( self . channel_value_satoshis) as i64 ) ;
978
- broadcaster_max_commitment_tx_output. 1 = cmp:: max ( broadcaster_max_commitment_tx_output. 1 , value_to_remote_msat as u64 ) ;
975
+ debug_assert ! ( broadcaster_max_commitment_tx_output. 0 <= holder_value_msat as u64 || holder_value_msat / 1000 >= self . counterparty_selected_channel_reserve_satoshis as i64 ) ;
976
+ broadcaster_max_commitment_tx_output. 0 = cmp:: max ( broadcaster_max_commitment_tx_output. 0 , holder_value_msat as u64 ) ;
977
+ debug_assert ! ( broadcaster_max_commitment_tx_output. 1 <= counterparty_value_msat as u64 || counterparty_value_msat / 1000 >= Channel :: <ChanSigner >:: get_holder_selected_channel_reserve_satoshis( self . channel_value_satoshis) as i64 ) ;
978
+ broadcaster_max_commitment_tx_output. 1 = cmp:: max ( broadcaster_max_commitment_tx_output. 1 , counterparty_value_msat as u64 ) ;
979
979
}
980
980
981
981
let total_fee = feerate_per_kw as u64 * ( COMMITMENT_TX_BASE_WEIGHT + ( txouts. len ( ) as u64 ) * COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ;
982
- let ( value_to_self , value_to_remote ) = if self . channel_outbound {
983
- ( value_to_self_msat / 1000 - total_fee as i64 , value_to_remote_msat / 1000 )
982
+ let ( holder_value , counterparty_value ) = if self . channel_outbound {
983
+ ( holder_value_msat / 1000 - total_fee as i64 , counterparty_value_msat / 1000 )
984
984
} else {
985
- ( value_to_self_msat / 1000 , value_to_remote_msat / 1000 - total_fee as i64 )
985
+ ( holder_value_msat / 1000 , counterparty_value_msat / 1000 - total_fee as i64 )
986
986
} ;
987
987
988
- let value_to_a = if local { value_to_self } else { value_to_remote } ;
989
- let value_to_b = if local { value_to_remote } else { value_to_self } ;
988
+ let ( value_to_a, value_to_b) = if local { ( holder_value, counterparty_value) } else { ( counterparty_value, holder_value) } ;
990
989
991
990
if value_to_a >= ( broadcaster_dust_limit_satoshis as i64 ) {
992
991
log_trace ! ( logger, " ...including {} output with value {}" , if local { "to_local" } else { "to_remote" } , value_to_a) ;
0 commit comments