@@ -84,6 +84,7 @@ struct NegotiationContext {
84
84
outputs : HashMap < SerialId , TxOut > ,
85
85
tx_locktime : AbsoluteLockTime ,
86
86
feerate_sat_per_kw : u32 ,
87
+ to_remote_value : u64 ,
87
88
}
88
89
89
90
impl NegotiationContext {
@@ -314,7 +315,11 @@ impl NegotiationContext {
314
315
for output in self . counterparty_outputs_contributed ( ) {
315
316
counterparty_outputs_value = counterparty_outputs_value. saturating_add ( output. value ) ;
316
317
}
317
- if counterparty_inputs_value < counterparty_outputs_value {
318
+ // ...actually the counterparty might be splicing out, so that their balance also contributes
319
+ // to the total input value.
320
+ if counterparty_inputs_value. saturating_add ( self . to_remote_value )
321
+ < counterparty_outputs_value
322
+ {
318
323
return Err ( AbortReason :: OutputsValueExceedsInputsValue ) ;
319
324
}
320
325
@@ -549,7 +554,10 @@ macro_rules! define_state_machine_transitions {
549
554
}
550
555
551
556
impl StateMachine {
552
- fn new ( feerate_sat_per_kw : u32 , is_initiator : bool , tx_locktime : AbsoluteLockTime ) -> Self {
557
+ fn new (
558
+ feerate_sat_per_kw : u32 , is_initiator : bool , tx_locktime : AbsoluteLockTime ,
559
+ to_remote_value : u64 ,
560
+ ) -> Self {
553
561
let context = NegotiationContext {
554
562
tx_locktime,
555
563
holder_is_initiator : is_initiator,
@@ -559,6 +567,7 @@ impl StateMachine {
559
567
prevtx_outpoints : new_hash_set ( ) ,
560
568
outputs : new_hash_map ( ) ,
561
569
feerate_sat_per_kw,
570
+ to_remote_value,
562
571
} ;
563
572
if is_initiator {
564
573
Self :: RemoteChange ( RemoteChange ( context) )
@@ -643,12 +652,13 @@ impl InteractiveTxConstructor {
643
652
pub fn new < ES : Deref > (
644
653
entropy_source : & ES , channel_id : ChannelId , feerate_sat_per_kw : u32 , is_initiator : bool ,
645
654
tx_locktime : AbsoluteLockTime , inputs_to_contribute : Vec < ( TxIn , TransactionU16LenLimited ) > ,
646
- outputs_to_contribute : Vec < TxOut > ,
655
+ outputs_to_contribute : Vec < TxOut > , to_remote_value : u64 ,
647
656
) -> ( Self , Option < InteractiveTxMessageSend > )
648
657
where
649
658
ES :: Target : EntropySource ,
650
659
{
651
- let state_machine = StateMachine :: new ( feerate_sat_per_kw, is_initiator, tx_locktime) ;
660
+ let state_machine =
661
+ StateMachine :: new ( feerate_sat_per_kw, is_initiator, tx_locktime, to_remote_value) ;
652
662
let inputs_to_contribute = inputs_to_contribute
653
663
. into_iter ( )
654
664
. map ( |( input, tx) | {
@@ -813,6 +823,7 @@ mod tests {
813
823
tx_locktime,
814
824
session. inputs_a ,
815
825
session. outputs_a ,
826
+ 0 ,
816
827
) ;
817
828
let ( mut constructor_b, first_message_b) = InteractiveTxConstructor :: new (
818
829
& & entropy_source,
@@ -822,6 +833,7 @@ mod tests {
822
833
tx_locktime,
823
834
session. inputs_b ,
824
835
session. outputs_b ,
836
+ 0 ,
825
837
) ;
826
838
827
839
let handle_message_send =
0 commit comments