@@ -109,7 +109,7 @@ impl NegotiationContext {
109
109
. map ( |( _, input_with_prevout) | input_with_prevout)
110
110
}
111
111
112
- fn remote_tx_add_input ( & mut self , msg : & msgs:: TxAddInput ) -> Result < ( ) , AbortReason > {
112
+ fn received_tx_add_input ( & mut self , msg : & msgs:: TxAddInput ) -> Result < ( ) , AbortReason > {
113
113
// The interactive-txs spec calls for us to fail negotiation if the `prevtx` we receive is
114
114
// invalid. However, we would not need to account for this explicit negotiation failure
115
115
// mode here since `PeerManager` would already disconnect the peer if the `prevtx` is
@@ -187,7 +187,7 @@ impl NegotiationContext {
187
187
Ok ( ( ) )
188
188
}
189
189
190
- fn remote_tx_remove_input ( & mut self , msg : & msgs:: TxRemoveInput ) -> Result < ( ) , AbortReason > {
190
+ fn received_tx_remove_input ( & mut self , msg : & msgs:: TxRemoveInput ) -> Result < ( ) , AbortReason > {
191
191
if !self . is_serial_id_valid_for_counterparty ( & msg. serial_id ) {
192
192
return Err ( AbortReason :: IncorrectSerialIdParity ) ;
193
193
}
@@ -203,7 +203,7 @@ impl NegotiationContext {
203
203
}
204
204
}
205
205
206
- fn remote_tx_add_output ( & mut self , msg : & msgs:: TxAddOutput ) -> Result < ( ) , AbortReason > {
206
+ fn received_tx_add_output ( & mut self , msg : & msgs:: TxAddOutput ) -> Result < ( ) , AbortReason > {
207
207
// The receiving node:
208
208
// - MUST fail the negotiation if:
209
209
// - the serial_id has the wrong parity
@@ -260,7 +260,7 @@ impl NegotiationContext {
260
260
Ok ( ( ) )
261
261
}
262
262
263
- fn remote_tx_remove_output ( & mut self , msg : & msgs:: TxRemoveOutput ) -> Result < ( ) , AbortReason > {
263
+ fn received_tx_remove_output ( & mut self , msg : & msgs:: TxRemoveOutput ) -> Result < ( ) , AbortReason > {
264
264
if !self . is_serial_id_valid_for_counterparty ( & msg. serial_id ) {
265
265
return Err ( AbortReason :: IncorrectSerialIdParity ) ;
266
266
}
@@ -275,7 +275,7 @@ impl NegotiationContext {
275
275
}
276
276
}
277
277
278
- fn local_tx_add_input ( & mut self , msg : & msgs:: TxAddInput ) {
278
+ fn sent_tx_add_input ( & mut self , msg : & msgs:: TxAddInput ) {
279
279
let tx = msg. prevtx . as_transaction ( ) ;
280
280
let input = TxIn {
281
281
previous_output : OutPoint { txid : tx. txid ( ) , vout : msg. prevtx_out } ,
@@ -291,16 +291,16 @@ impl NegotiationContext {
291
291
) ;
292
292
}
293
293
294
- fn local_tx_add_output ( & mut self , msg : & msgs:: TxAddOutput ) {
294
+ fn sent_tx_add_output ( & mut self , msg : & msgs:: TxAddOutput ) {
295
295
self . outputs
296
296
. insert ( msg. serial_id , TxOut { value : msg. sats , script_pubkey : msg. script . clone ( ) } ) ;
297
297
}
298
298
299
- fn local_tx_remove_input ( & mut self , msg : & msgs:: TxRemoveInput ) {
299
+ fn sent_tx_remove_input ( & mut self , msg : & msgs:: TxRemoveInput ) {
300
300
self . inputs . remove ( & msg. serial_id ) ;
301
301
}
302
302
303
- fn local_tx_remove_output ( & mut self , msg : & msgs:: TxRemoveOutput ) {
303
+ fn sent_tx_remove_output ( & mut self , msg : & msgs:: TxRemoveOutput ) {
304
304
self . outputs . remove ( & msg. serial_id ) ;
305
305
}
306
306
@@ -424,22 +424,22 @@ macro_rules! define_state {
424
424
425
425
define_state ! (
426
426
LOCAL_STATE ,
427
- LocalChange ,
427
+ SentChange ,
428
428
"We have sent a message to the counterparty that has affected our negotiation state."
429
429
) ;
430
430
define_state ! (
431
431
LOCAL_STATE ,
432
- LocalTxComplete ,
432
+ SentTxComplete ,
433
433
"We have sent a `tx_complete` message and are awaiting the counterparty's."
434
434
) ;
435
435
define_state ! (
436
436
REMOTE_STATE ,
437
- RemoteChange ,
437
+ ReceivedChange ,
438
438
"We have received a message from the counterparty that has affected our negotiation state."
439
439
) ;
440
440
define_state ! (
441
441
REMOTE_STATE ,
442
- RemoteTxComplete ,
442
+ ReceivedTxComplete ,
443
443
"We have received a `tx_complete` message and the counterparty is awaiting ours."
444
444
) ;
445
445
define_state ! ( NegotiationComplete , Transaction , "We have exchanged consecutive `tx_complete` messages with the counterparty and the transaction negotiation is complete." ) ;
@@ -458,22 +458,22 @@ trait StateTransition<NewState: State, TransitionData> {
458
458
macro_rules! define_state_transitions {
459
459
( LOCAL_STATE , [ $( DATA $data: ty, TRANSITION $transition: ident) ,+] ) => {
460
460
$(
461
- impl <S : LocalState > StateTransition <RemoteChange , $data> for S {
462
- fn transition( self , data: $data) -> StateTransitionResult <RemoteChange > {
461
+ impl <S : LocalState > StateTransition <ReceivedChange , $data> for S {
462
+ fn transition( self , data: $data) -> StateTransitionResult <ReceivedChange > {
463
463
let mut context = self . into_negotiation_context( ) ;
464
464
let _ = context. $transition( data) ?;
465
- Ok ( RemoteChange ( context) )
465
+ Ok ( ReceivedChange ( context) )
466
466
}
467
467
}
468
468
) *
469
469
} ;
470
470
( REMOTE_STATE , [ $( DATA $data: ty, TRANSITION $transition: ident) ,+] ) => {
471
471
$(
472
- impl <S : RemoteState > StateTransition <LocalChange , $data> for S {
473
- fn transition( self , data: $data) -> StateTransitionResult <LocalChange > {
472
+ impl <S : RemoteState > StateTransition <SentChange , $data> for S {
473
+ fn transition( self , data: $data) -> StateTransitionResult <SentChange > {
474
474
let mut context = self . into_negotiation_context( ) ;
475
475
let _ = context. $transition( data) ;
476
- Ok ( LocalChange ( context) )
476
+ Ok ( SentChange ( context) )
477
477
}
478
478
}
479
479
) *
@@ -497,29 +497,29 @@ macro_rules! define_state_transitions {
497
497
}
498
498
499
499
define_state_transitions ! ( LOCAL_STATE , [
500
- DATA & msgs:: TxAddInput , TRANSITION remote_tx_add_input ,
501
- DATA & msgs:: TxRemoveInput , TRANSITION remote_tx_remove_input ,
502
- DATA & msgs:: TxAddOutput , TRANSITION remote_tx_add_output ,
503
- DATA & msgs:: TxRemoveOutput , TRANSITION remote_tx_remove_output
500
+ DATA & msgs:: TxAddInput , TRANSITION received_tx_add_input ,
501
+ DATA & msgs:: TxRemoveInput , TRANSITION received_tx_remove_input ,
502
+ DATA & msgs:: TxAddOutput , TRANSITION received_tx_add_output ,
503
+ DATA & msgs:: TxRemoveOutput , TRANSITION received_tx_remove_output
504
504
] ) ;
505
505
define_state_transitions ! ( REMOTE_STATE , [
506
- DATA & msgs:: TxAddInput , TRANSITION local_tx_add_input ,
507
- DATA & msgs:: TxRemoveInput , TRANSITION local_tx_remove_input ,
508
- DATA & msgs:: TxAddOutput , TRANSITION local_tx_add_output ,
509
- DATA & msgs:: TxRemoveOutput , TRANSITION local_tx_remove_output
506
+ DATA & msgs:: TxAddInput , TRANSITION sent_tx_add_input ,
507
+ DATA & msgs:: TxRemoveInput , TRANSITION sent_tx_remove_input ,
508
+ DATA & msgs:: TxAddOutput , TRANSITION sent_tx_add_output ,
509
+ DATA & msgs:: TxRemoveOutput , TRANSITION sent_tx_remove_output
510
510
] ) ;
511
- define_state_transitions ! ( TX_COMPLETE_AS_ACK , LocalChange , RemoteTxComplete ) ;
512
- define_state_transitions ! ( TX_COMPLETE_AS_ACK , RemoteChange , LocalTxComplete ) ;
513
- define_state_transitions ! ( TX_COMPLETE , LocalTxComplete ) ;
514
- define_state_transitions ! ( TX_COMPLETE , RemoteTxComplete ) ;
511
+ define_state_transitions ! ( TX_COMPLETE_AS_ACK , SentChange , ReceivedTxComplete ) ;
512
+ define_state_transitions ! ( TX_COMPLETE_AS_ACK , ReceivedChange , SentTxComplete ) ;
513
+ define_state_transitions ! ( TX_COMPLETE , SentTxComplete ) ;
514
+ define_state_transitions ! ( TX_COMPLETE , ReceivedTxComplete ) ;
515
515
516
516
#[ derive( Debug ) ]
517
517
enum StateMachine {
518
518
Indeterminate ,
519
- LocalChange ( LocalChange ) ,
520
- RemoteChange ( RemoteChange ) ,
521
- LocalTxComplete ( LocalTxComplete ) ,
522
- RemoteTxComplete ( RemoteTxComplete ) ,
519
+ SentChange ( SentChange ) ,
520
+ ReceivedChange ( ReceivedChange ) ,
521
+ SentTxComplete ( SentTxComplete ) ,
522
+ ReceivedTxComplete ( ReceivedTxComplete ) ,
523
523
NegotiationComplete ( NegotiationComplete ) ,
524
524
NegotiationAborted ( NegotiationAborted ) ,
525
525
}
@@ -546,12 +546,12 @@ macro_rules! define_state_machine_transitions {
546
546
} ;
547
547
( LOCAL_OR_REMOTE_CHANGE , $to_local_transition: ident, $to_remote_transition: ident, $msg: ty) => {
548
548
define_state_machine_transitions!( $to_local_transition, $msg, [
549
- FROM RemoteChange , TO LocalChange ,
550
- FROM RemoteTxComplete , TO LocalChange
549
+ FROM ReceivedChange , TO SentChange ,
550
+ FROM ReceivedTxComplete , TO SentChange
551
551
] ) ;
552
552
define_state_machine_transitions!( $to_remote_transition, $msg, [
553
- FROM LocalChange , TO RemoteChange ,
554
- FROM LocalTxComplete , TO RemoteChange
553
+ FROM SentChange , TO ReceivedChange ,
554
+ FROM SentTxComplete , TO ReceivedChange
555
555
] ) ;
556
556
} ;
557
557
}
@@ -573,43 +573,43 @@ impl StateMachine {
573
573
to_remote_value,
574
574
} ;
575
575
if is_initiator {
576
- Self :: RemoteChange ( RemoteChange ( context) )
576
+ Self :: ReceivedChange ( ReceivedChange ( context) )
577
577
} else {
578
- Self :: LocalChange ( LocalChange ( context) )
578
+ Self :: SentChange ( SentChange ( context) )
579
579
}
580
580
}
581
581
582
582
define_state_machine_transitions ! (
583
583
LOCAL_OR_REMOTE_CHANGE ,
584
- local_tx_add_input ,
585
- remote_tx_add_input ,
584
+ sent_tx_add_input ,
585
+ received_tx_add_input ,
586
586
& msgs:: TxAddInput
587
587
) ;
588
588
define_state_machine_transitions ! (
589
589
LOCAL_OR_REMOTE_CHANGE ,
590
- local_tx_add_output ,
591
- remote_tx_add_output ,
590
+ sent_tx_add_output ,
591
+ received_tx_add_output ,
592
592
& msgs:: TxAddOutput
593
593
) ;
594
594
define_state_machine_transitions ! (
595
595
LOCAL_OR_REMOTE_CHANGE ,
596
- local_tx_remove_input ,
597
- remote_tx_remove_input ,
596
+ sent_tx_remove_input ,
597
+ received_tx_remove_input ,
598
598
& msgs:: TxRemoveInput
599
599
) ;
600
600
define_state_machine_transitions ! (
601
601
LOCAL_OR_REMOTE_CHANGE ,
602
- local_tx_remove_output ,
603
- remote_tx_remove_output ,
602
+ sent_tx_remove_output ,
603
+ received_tx_remove_output ,
604
604
& msgs:: TxRemoveOutput
605
605
) ;
606
- define_state_machine_transitions ! ( local_tx_complete , & msgs:: TxComplete , [
607
- FROM RemoteChange , TO LocalTxComplete ,
608
- FROM RemoteTxComplete , TO NegotiationComplete
606
+ define_state_machine_transitions ! ( sent_tx_complete , & msgs:: TxComplete , [
607
+ FROM ReceivedChange , TO SentTxComplete ,
608
+ FROM ReceivedTxComplete , TO NegotiationComplete
609
609
] ) ;
610
- define_state_machine_transitions ! ( remote_tx_complete , & msgs:: TxComplete , [
611
- FROM LocalChange , TO RemoteTxComplete ,
612
- FROM LocalTxComplete , TO NegotiationComplete
610
+ define_state_machine_transitions ! ( received_tx_complete , & msgs:: TxComplete , [
611
+ FROM SentChange , TO ReceivedTxComplete ,
612
+ FROM SentTxComplete , TO NegotiationComplete
613
613
] ) ;
614
614
}
615
615
@@ -711,7 +711,7 @@ impl InteractiveTxConstructor {
711
711
prevtx_out : input. previous_output . vout ,
712
712
sequence : input. sequence . to_consensus_u32 ( ) ,
713
713
} ;
714
- let _ = do_state_transition ! ( self , local_tx_add_input , & msg) ?;
714
+ let _ = do_state_transition ! ( self , sent_tx_add_input , & msg) ?;
715
715
Ok ( InteractiveTxMessageSend :: TxAddInput ( msg) )
716
716
} else if let Some ( ( serial_id, output) ) = self . outputs_to_contribute . pop ( ) {
717
717
let msg = msgs:: TxAddOutput {
@@ -720,53 +720,53 @@ impl InteractiveTxConstructor {
720
720
sats : output. value ,
721
721
script : output. script_pubkey ,
722
722
} ;
723
- let _ = do_state_transition ! ( self , local_tx_add_output , & msg) ?;
723
+ let _ = do_state_transition ! ( self , sent_tx_add_output , & msg) ?;
724
724
Ok ( InteractiveTxMessageSend :: TxAddOutput ( msg) )
725
725
} else {
726
726
let msg = msgs:: TxComplete { channel_id : self . channel_id } ;
727
- let _ = do_state_transition ! ( self , local_tx_complete , & msg) ?;
727
+ let _ = do_state_transition ! ( self , sent_tx_complete , & msg) ?;
728
728
Ok ( InteractiveTxMessageSend :: TxComplete ( msg) )
729
729
}
730
730
}
731
731
732
732
pub fn handle_tx_add_input (
733
733
& mut self , msg : & msgs:: TxAddInput ,
734
734
) -> Result < InteractiveTxMessageSend , AbortReason > {
735
- let _ = do_state_transition ! ( self , remote_tx_add_input , msg) ?;
735
+ let _ = do_state_transition ! ( self , received_tx_add_input , msg) ?;
736
736
self . do_local_state_transition ( )
737
737
}
738
738
739
739
pub fn handle_tx_remove_input (
740
740
& mut self , msg : & msgs:: TxRemoveInput ,
741
741
) -> Result < InteractiveTxMessageSend , AbortReason > {
742
- let _ = do_state_transition ! ( self , remote_tx_remove_input , msg) ?;
742
+ let _ = do_state_transition ! ( self , received_tx_remove_input , msg) ?;
743
743
self . do_local_state_transition ( )
744
744
}
745
745
746
746
pub fn handle_tx_add_output (
747
747
& mut self , msg : & msgs:: TxAddOutput ,
748
748
) -> Result < InteractiveTxMessageSend , AbortReason > {
749
- let _ = do_state_transition ! ( self , remote_tx_add_output , msg) ?;
749
+ let _ = do_state_transition ! ( self , received_tx_add_output , msg) ?;
750
750
self . do_local_state_transition ( )
751
751
}
752
752
753
753
pub fn handle_tx_remove_output (
754
754
& mut self , msg : & msgs:: TxRemoveOutput ,
755
755
) -> Result < InteractiveTxMessageSend , AbortReason > {
756
- let _ = do_state_transition ! ( self , remote_tx_remove_output , msg) ?;
756
+ let _ = do_state_transition ! ( self , received_tx_remove_output , msg) ?;
757
757
self . do_local_state_transition ( )
758
758
}
759
759
760
760
pub fn handle_tx_complete (
761
761
& mut self , msg : & msgs:: TxComplete ,
762
762
) -> Result < ( Option < InteractiveTxMessageSend > , Option < Transaction > ) , AbortReason > {
763
- let _ = do_state_transition ! ( self , remote_tx_complete , msg) ?;
763
+ let _ = do_state_transition ! ( self , received_tx_complete , msg) ?;
764
764
match & self . state_machine {
765
- StateMachine :: RemoteTxComplete ( _) => {
765
+ StateMachine :: ReceivedTxComplete ( _) => {
766
766
let msg_send = self . do_local_state_transition ( ) ?;
767
767
let negotiated_tx = match & self . state_machine {
768
768
StateMachine :: NegotiationComplete ( s) => Some ( s. 0 . clone ( ) ) ,
769
- StateMachine :: LocalChange ( _) => None , // We either had an input or output to contribute.
769
+ StateMachine :: SentChange ( _) => None , // We either had an input or output to contribute.
770
770
_ => {
771
771
debug_assert ! ( false , "We cannot transition to any other states after receiving `tx_complete` and responding" ) ;
772
772
return Err ( AbortReason :: InvalidStateTransition ) ;
0 commit comments