@@ -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
@@ -255,7 +255,7 @@ impl NegotiationContext {
255
255
Ok ( ( ) )
256
256
}
257
257
258
- fn remote_tx_remove_output ( & mut self , msg : & msgs:: TxRemoveOutput ) -> Result < ( ) , AbortReason > {
258
+ fn received_tx_remove_output ( & mut self , msg : & msgs:: TxRemoveOutput ) -> Result < ( ) , AbortReason > {
259
259
if !self . is_serial_id_valid_for_counterparty ( & msg. serial_id ) {
260
260
return Err ( AbortReason :: IncorrectSerialIdParity ) ;
261
261
}
@@ -270,7 +270,7 @@ impl NegotiationContext {
270
270
}
271
271
}
272
272
273
- fn local_tx_add_input ( & mut self , msg : & msgs:: TxAddInput ) {
273
+ fn sent_tx_add_input ( & mut self , msg : & msgs:: TxAddInput ) {
274
274
let tx = msg. prevtx . as_transaction ( ) ;
275
275
let input = TxIn {
276
276
previous_output : OutPoint { txid : tx. txid ( ) , vout : msg. prevtx_out } ,
@@ -286,16 +286,16 @@ impl NegotiationContext {
286
286
) ;
287
287
}
288
288
289
- fn local_tx_add_output ( & mut self , msg : & msgs:: TxAddOutput ) {
289
+ fn sent_tx_add_output ( & mut self , msg : & msgs:: TxAddOutput ) {
290
290
self . outputs
291
291
. insert ( msg. serial_id , TxOut { value : msg. sats , script_pubkey : msg. script . clone ( ) } ) ;
292
292
}
293
293
294
- fn local_tx_remove_input ( & mut self , msg : & msgs:: TxRemoveInput ) {
294
+ fn sent_tx_remove_input ( & mut self , msg : & msgs:: TxRemoveInput ) {
295
295
self . inputs . remove ( & msg. serial_id ) ;
296
296
}
297
297
298
- fn local_tx_remove_output ( & mut self , msg : & msgs:: TxRemoveOutput ) {
298
+ fn sent_tx_remove_output ( & mut self , msg : & msgs:: TxRemoveOutput ) {
299
299
self . outputs . remove ( & msg. serial_id ) ;
300
300
}
301
301
@@ -419,22 +419,22 @@ macro_rules! define_state {
419
419
420
420
define_state ! (
421
421
LOCAL_STATE ,
422
- LocalChange ,
422
+ SentChange ,
423
423
"We have sent a message to the counterparty that has affected our negotiation state."
424
424
) ;
425
425
define_state ! (
426
426
LOCAL_STATE ,
427
- LocalTxComplete ,
427
+ SentTxComplete ,
428
428
"We have sent a `tx_complete` message and are awaiting the counterparty's."
429
429
) ;
430
430
define_state ! (
431
431
REMOTE_STATE ,
432
- RemoteChange ,
432
+ ReceivedChange ,
433
433
"We have received a message from the counterparty that has affected our negotiation state."
434
434
) ;
435
435
define_state ! (
436
436
REMOTE_STATE ,
437
- RemoteTxComplete ,
437
+ ReceivedTxComplete ,
438
438
"We have received a `tx_complete` message and the counterparty is awaiting ours."
439
439
) ;
440
440
define_state ! ( NegotiationComplete , Transaction , "We have exchanged consecutive `tx_complete` messages with the counterparty and the transaction negotiation is complete." ) ;
@@ -453,22 +453,22 @@ trait StateTransition<NewState: State, TransitionData> {
453
453
macro_rules! define_state_transitions {
454
454
( LOCAL_STATE , [ $( DATA $data: ty, TRANSITION $transition: ident) ,+] ) => {
455
455
$(
456
- impl <S : LocalState > StateTransition <RemoteChange , $data> for S {
457
- fn transition( self , data: $data) -> StateTransitionResult <RemoteChange > {
456
+ impl <S : LocalState > StateTransition <ReceivedChange , $data> for S {
457
+ fn transition( self , data: $data) -> StateTransitionResult <ReceivedChange > {
458
458
let mut context = self . into_negotiation_context( ) ;
459
459
let _ = context. $transition( data) ?;
460
- Ok ( RemoteChange ( context) )
460
+ Ok ( ReceivedChange ( context) )
461
461
}
462
462
}
463
463
) *
464
464
} ;
465
465
( REMOTE_STATE , [ $( DATA $data: ty, TRANSITION $transition: ident) ,+] ) => {
466
466
$(
467
- impl <S : RemoteState > StateTransition <LocalChange , $data> for S {
468
- fn transition( self , data: $data) -> StateTransitionResult <LocalChange > {
467
+ impl <S : RemoteState > StateTransition <SentChange , $data> for S {
468
+ fn transition( self , data: $data) -> StateTransitionResult <SentChange > {
469
469
let mut context = self . into_negotiation_context( ) ;
470
470
let _ = context. $transition( data) ;
471
- Ok ( LocalChange ( context) )
471
+ Ok ( SentChange ( context) )
472
472
}
473
473
}
474
474
) *
@@ -492,29 +492,29 @@ macro_rules! define_state_transitions {
492
492
}
493
493
494
494
define_state_transitions ! ( LOCAL_STATE , [
495
- DATA & msgs:: TxAddInput , TRANSITION remote_tx_add_input ,
496
- DATA & msgs:: TxRemoveInput , TRANSITION remote_tx_remove_input ,
497
- DATA & msgs:: TxAddOutput , TRANSITION remote_tx_add_output ,
498
- DATA & msgs:: TxRemoveOutput , TRANSITION remote_tx_remove_output
495
+ DATA & msgs:: TxAddInput , TRANSITION received_tx_add_input ,
496
+ DATA & msgs:: TxRemoveInput , TRANSITION received_tx_remove_input ,
497
+ DATA & msgs:: TxAddOutput , TRANSITION received_tx_add_output ,
498
+ DATA & msgs:: TxRemoveOutput , TRANSITION received_tx_remove_output
499
499
] ) ;
500
500
define_state_transitions ! ( REMOTE_STATE , [
501
- DATA & msgs:: TxAddInput , TRANSITION local_tx_add_input ,
502
- DATA & msgs:: TxRemoveInput , TRANSITION local_tx_remove_input ,
503
- DATA & msgs:: TxAddOutput , TRANSITION local_tx_add_output ,
504
- DATA & msgs:: TxRemoveOutput , TRANSITION local_tx_remove_output
501
+ DATA & msgs:: TxAddInput , TRANSITION sent_tx_add_input ,
502
+ DATA & msgs:: TxRemoveInput , TRANSITION sent_tx_remove_input ,
503
+ DATA & msgs:: TxAddOutput , TRANSITION sent_tx_add_output ,
504
+ DATA & msgs:: TxRemoveOutput , TRANSITION sent_tx_remove_output
505
505
] ) ;
506
- define_state_transitions ! ( TX_COMPLETE_AS_ACK , LocalChange , RemoteTxComplete ) ;
507
- define_state_transitions ! ( TX_COMPLETE_AS_ACK , RemoteChange , LocalTxComplete ) ;
508
- define_state_transitions ! ( TX_COMPLETE , LocalTxComplete ) ;
509
- define_state_transitions ! ( TX_COMPLETE , RemoteTxComplete ) ;
506
+ define_state_transitions ! ( TX_COMPLETE_AS_ACK , SentChange , ReceivedTxComplete ) ;
507
+ define_state_transitions ! ( TX_COMPLETE_AS_ACK , ReceivedChange , SentTxComplete ) ;
508
+ define_state_transitions ! ( TX_COMPLETE , SentTxComplete ) ;
509
+ define_state_transitions ! ( TX_COMPLETE , ReceivedTxComplete ) ;
510
510
511
511
#[ derive( Debug ) ]
512
512
enum StateMachine {
513
513
Indeterminate ,
514
- LocalChange ( LocalChange ) ,
515
- RemoteChange ( RemoteChange ) ,
516
- LocalTxComplete ( LocalTxComplete ) ,
517
- RemoteTxComplete ( RemoteTxComplete ) ,
514
+ SentChange ( SentChange ) ,
515
+ ReceivedChange ( ReceivedChange ) ,
516
+ SentTxComplete ( SentTxComplete ) ,
517
+ ReceivedTxComplete ( ReceivedTxComplete ) ,
518
518
NegotiationComplete ( NegotiationComplete ) ,
519
519
NegotiationAborted ( NegotiationAborted ) ,
520
520
}
@@ -541,12 +541,12 @@ macro_rules! define_state_machine_transitions {
541
541
} ;
542
542
( LOCAL_OR_REMOTE_CHANGE , $to_local_transition: ident, $to_remote_transition: ident, $msg: ty) => {
543
543
define_state_machine_transitions!( $to_local_transition, $msg, [
544
- FROM RemoteChange , TO LocalChange ,
545
- FROM RemoteTxComplete , TO LocalChange
544
+ FROM ReceivedChange , TO SentChange ,
545
+ FROM ReceivedTxComplete , TO SentChange
546
546
] ) ;
547
547
define_state_machine_transitions!( $to_remote_transition, $msg, [
548
- FROM LocalChange , TO RemoteChange ,
549
- FROM LocalTxComplete , TO RemoteChange
548
+ FROM SentChange , TO ReceivedChange ,
549
+ FROM SentTxComplete , TO ReceivedChange
550
550
] ) ;
551
551
} ;
552
552
}
@@ -568,43 +568,43 @@ impl StateMachine {
568
568
to_remote_value,
569
569
} ;
570
570
if is_initiator {
571
- Self :: RemoteChange ( RemoteChange ( context) )
571
+ Self :: ReceivedChange ( ReceivedChange ( context) )
572
572
} else {
573
- Self :: LocalChange ( LocalChange ( context) )
573
+ Self :: SentChange ( SentChange ( context) )
574
574
}
575
575
}
576
576
577
577
define_state_machine_transitions ! (
578
578
LOCAL_OR_REMOTE_CHANGE ,
579
- local_tx_add_input ,
580
- remote_tx_add_input ,
579
+ sent_tx_add_input ,
580
+ received_tx_add_input ,
581
581
& msgs:: TxAddInput
582
582
) ;
583
583
define_state_machine_transitions ! (
584
584
LOCAL_OR_REMOTE_CHANGE ,
585
- local_tx_add_output ,
586
- remote_tx_add_output ,
585
+ sent_tx_add_output ,
586
+ received_tx_add_output ,
587
587
& msgs:: TxAddOutput
588
588
) ;
589
589
define_state_machine_transitions ! (
590
590
LOCAL_OR_REMOTE_CHANGE ,
591
- local_tx_remove_input ,
592
- remote_tx_remove_input ,
591
+ sent_tx_remove_input ,
592
+ received_tx_remove_input ,
593
593
& msgs:: TxRemoveInput
594
594
) ;
595
595
define_state_machine_transitions ! (
596
596
LOCAL_OR_REMOTE_CHANGE ,
597
- local_tx_remove_output ,
598
- remote_tx_remove_output ,
597
+ sent_tx_remove_output ,
598
+ received_tx_remove_output ,
599
599
& msgs:: TxRemoveOutput
600
600
) ;
601
- define_state_machine_transitions ! ( local_tx_complete , & msgs:: TxComplete , [
602
- FROM RemoteChange , TO LocalTxComplete ,
603
- FROM RemoteTxComplete , TO NegotiationComplete
601
+ define_state_machine_transitions ! ( sent_tx_complete , & msgs:: TxComplete , [
602
+ FROM ReceivedChange , TO SentTxComplete ,
603
+ FROM ReceivedTxComplete , TO NegotiationComplete
604
604
] ) ;
605
- define_state_machine_transitions ! ( remote_tx_complete , & msgs:: TxComplete , [
606
- FROM LocalChange , TO RemoteTxComplete ,
607
- FROM LocalTxComplete , TO NegotiationComplete
605
+ define_state_machine_transitions ! ( received_tx_complete , & msgs:: TxComplete , [
606
+ FROM SentChange , TO ReceivedTxComplete ,
607
+ FROM SentTxComplete , TO NegotiationComplete
608
608
] ) ;
609
609
}
610
610
@@ -706,7 +706,7 @@ impl InteractiveTxConstructor {
706
706
prevtx_out : input. previous_output . vout ,
707
707
sequence : input. sequence . to_consensus_u32 ( ) ,
708
708
} ;
709
- let _ = do_state_transition ! ( self , local_tx_add_input , & msg) ?;
709
+ let _ = do_state_transition ! ( self , sent_tx_add_input , & msg) ?;
710
710
Ok ( InteractiveTxMessageSend :: TxAddInput ( msg) )
711
711
} else if let Some ( ( serial_id, output) ) = self . outputs_to_contribute . pop ( ) {
712
712
let msg = msgs:: TxAddOutput {
@@ -715,53 +715,53 @@ impl InteractiveTxConstructor {
715
715
sats : output. value ,
716
716
script : output. script_pubkey ,
717
717
} ;
718
- let _ = do_state_transition ! ( self , local_tx_add_output , & msg) ?;
718
+ let _ = do_state_transition ! ( self , sent_tx_add_output , & msg) ?;
719
719
Ok ( InteractiveTxMessageSend :: TxAddOutput ( msg) )
720
720
} else {
721
721
let msg = msgs:: TxComplete { channel_id : self . channel_id } ;
722
- let _ = do_state_transition ! ( self , local_tx_complete , & msg) ?;
722
+ let _ = do_state_transition ! ( self , sent_tx_complete , & msg) ?;
723
723
Ok ( InteractiveTxMessageSend :: TxComplete ( msg) )
724
724
}
725
725
}
726
726
727
727
pub fn handle_tx_add_input (
728
728
& mut self , msg : & msgs:: TxAddInput ,
729
729
) -> Result < InteractiveTxMessageSend , AbortReason > {
730
- let _ = do_state_transition ! ( self , remote_tx_add_input , msg) ?;
730
+ let _ = do_state_transition ! ( self , received_tx_add_input , msg) ?;
731
731
self . do_local_state_transition ( )
732
732
}
733
733
734
734
pub fn handle_tx_remove_input (
735
735
& mut self , msg : & msgs:: TxRemoveInput ,
736
736
) -> Result < InteractiveTxMessageSend , AbortReason > {
737
- let _ = do_state_transition ! ( self , remote_tx_remove_input , msg) ?;
737
+ let _ = do_state_transition ! ( self , received_tx_remove_input , msg) ?;
738
738
self . do_local_state_transition ( )
739
739
}
740
740
741
741
pub fn handle_tx_add_output (
742
742
& mut self , msg : & msgs:: TxAddOutput ,
743
743
) -> Result < InteractiveTxMessageSend , AbortReason > {
744
- let _ = do_state_transition ! ( self , remote_tx_add_output , msg) ?;
744
+ let _ = do_state_transition ! ( self , received_tx_add_output , msg) ?;
745
745
self . do_local_state_transition ( )
746
746
}
747
747
748
748
pub fn handle_tx_remove_output (
749
749
& mut self , msg : & msgs:: TxRemoveOutput ,
750
750
) -> Result < InteractiveTxMessageSend , AbortReason > {
751
- let _ = do_state_transition ! ( self , remote_tx_remove_output , msg) ?;
751
+ let _ = do_state_transition ! ( self , received_tx_remove_output , msg) ?;
752
752
self . do_local_state_transition ( )
753
753
}
754
754
755
755
pub fn handle_tx_complete (
756
756
& mut self , msg : & msgs:: TxComplete ,
757
757
) -> Result < ( Option < InteractiveTxMessageSend > , Option < Transaction > ) , AbortReason > {
758
- let _ = do_state_transition ! ( self , remote_tx_complete , msg) ?;
758
+ let _ = do_state_transition ! ( self , received_tx_complete , msg) ?;
759
759
match & self . state_machine {
760
- StateMachine :: RemoteTxComplete ( _) => {
760
+ StateMachine :: ReceivedTxComplete ( _) => {
761
761
let msg_send = self . do_local_state_transition ( ) ?;
762
762
let negotiated_tx = match & self . state_machine {
763
763
StateMachine :: NegotiationComplete ( s) => Some ( s. 0 . clone ( ) ) ,
764
- StateMachine :: LocalChange ( _) => None , // We either had an input or output to contribute.
764
+ StateMachine :: SentChange ( _) => None , // We either had an input or output to contribute.
765
765
_ => {
766
766
debug_assert ! ( false , "We cannot transition to any other states after receiving `tx_complete` and responding" ) ;
767
767
return Err ( AbortReason :: InvalidStateTransition ) ;
0 commit comments