Skip to content

Commit 6cf638a

Browse files
committed
f s/local/sent/ & s/remote/received/ where appropriate
1 parent e51ad75 commit 6cf638a

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl NegotiationContext {
109109
.map(|(_, input_with_prevout)| input_with_prevout)
110110
}
111111

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> {
113113
// The interactive-txs spec calls for us to fail negotiation if the `prevtx` we receive is
114114
// invalid. However, we would not need to account for this explicit negotiation failure
115115
// mode here since `PeerManager` would already disconnect the peer if the `prevtx` is
@@ -187,7 +187,7 @@ impl NegotiationContext {
187187
Ok(())
188188
}
189189

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> {
191191
if !self.is_serial_id_valid_for_counterparty(&msg.serial_id) {
192192
return Err(AbortReason::IncorrectSerialIdParity);
193193
}
@@ -203,7 +203,7 @@ impl NegotiationContext {
203203
}
204204
}
205205

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> {
207207
// The receiving node:
208208
// - MUST fail the negotiation if:
209209
// - the serial_id has the wrong parity
@@ -260,7 +260,7 @@ impl NegotiationContext {
260260
Ok(())
261261
}
262262

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> {
264264
if !self.is_serial_id_valid_for_counterparty(&msg.serial_id) {
265265
return Err(AbortReason::IncorrectSerialIdParity);
266266
}
@@ -275,7 +275,7 @@ impl NegotiationContext {
275275
}
276276
}
277277

278-
fn local_tx_add_input(&mut self, msg: &msgs::TxAddInput) {
278+
fn sent_tx_add_input(&mut self, msg: &msgs::TxAddInput) {
279279
let tx = msg.prevtx.as_transaction();
280280
let input = TxIn {
281281
previous_output: OutPoint { txid: tx.txid(), vout: msg.prevtx_out },
@@ -291,16 +291,16 @@ impl NegotiationContext {
291291
);
292292
}
293293

294-
fn local_tx_add_output(&mut self, msg: &msgs::TxAddOutput) {
294+
fn sent_tx_add_output(&mut self, msg: &msgs::TxAddOutput) {
295295
self.outputs
296296
.insert(msg.serial_id, TxOut { value: msg.sats, script_pubkey: msg.script.clone() });
297297
}
298298

299-
fn local_tx_remove_input(&mut self, msg: &msgs::TxRemoveInput) {
299+
fn sent_tx_remove_input(&mut self, msg: &msgs::TxRemoveInput) {
300300
self.inputs.remove(&msg.serial_id);
301301
}
302302

303-
fn local_tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput) {
303+
fn sent_tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput) {
304304
self.outputs.remove(&msg.serial_id);
305305
}
306306

@@ -424,22 +424,22 @@ macro_rules! define_state {
424424

425425
define_state!(
426426
LOCAL_STATE,
427-
LocalChange,
427+
SentChange,
428428
"We have sent a message to the counterparty that has affected our negotiation state."
429429
);
430430
define_state!(
431431
LOCAL_STATE,
432-
LocalTxComplete,
432+
SentTxComplete,
433433
"We have sent a `tx_complete` message and are awaiting the counterparty's."
434434
);
435435
define_state!(
436436
REMOTE_STATE,
437-
RemoteChange,
437+
ReceivedChange,
438438
"We have received a message from the counterparty that has affected our negotiation state."
439439
);
440440
define_state!(
441441
REMOTE_STATE,
442-
RemoteTxComplete,
442+
ReceivedTxComplete,
443443
"We have received a `tx_complete` message and the counterparty is awaiting ours."
444444
);
445445
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> {
458458
macro_rules! define_state_transitions {
459459
(LOCAL_STATE, [$(DATA $data: ty, TRANSITION $transition: ident),+]) => {
460460
$(
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> {
463463
let mut context = self.into_negotiation_context();
464464
let _ = context.$transition(data)?;
465-
Ok(RemoteChange(context))
465+
Ok(ReceivedChange(context))
466466
}
467467
}
468468
)*
469469
};
470470
(REMOTE_STATE, [$(DATA $data: ty, TRANSITION $transition: ident),+]) => {
471471
$(
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> {
474474
let mut context = self.into_negotiation_context();
475475
let _ = context.$transition(data);
476-
Ok(LocalChange(context))
476+
Ok(SentChange(context))
477477
}
478478
}
479479
)*
@@ -497,29 +497,29 @@ macro_rules! define_state_transitions {
497497
}
498498

499499
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
504504
]);
505505
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
510510
]);
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);
515515

516516
#[derive(Debug)]
517517
enum StateMachine {
518518
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),
523523
NegotiationComplete(NegotiationComplete),
524524
NegotiationAborted(NegotiationAborted),
525525
}
@@ -546,12 +546,12 @@ macro_rules! define_state_machine_transitions {
546546
};
547547
(LOCAL_OR_REMOTE_CHANGE, $to_local_transition: ident, $to_remote_transition: ident, $msg: ty) => {
548548
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
551551
]);
552552
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
555555
]);
556556
};
557557
}
@@ -573,43 +573,43 @@ impl StateMachine {
573573
to_remote_value,
574574
};
575575
if is_initiator {
576-
Self::RemoteChange(RemoteChange(context))
576+
Self::ReceivedChange(ReceivedChange(context))
577577
} else {
578-
Self::LocalChange(LocalChange(context))
578+
Self::SentChange(SentChange(context))
579579
}
580580
}
581581

582582
define_state_machine_transitions!(
583583
LOCAL_OR_REMOTE_CHANGE,
584-
local_tx_add_input,
585-
remote_tx_add_input,
584+
sent_tx_add_input,
585+
received_tx_add_input,
586586
&msgs::TxAddInput
587587
);
588588
define_state_machine_transitions!(
589589
LOCAL_OR_REMOTE_CHANGE,
590-
local_tx_add_output,
591-
remote_tx_add_output,
590+
sent_tx_add_output,
591+
received_tx_add_output,
592592
&msgs::TxAddOutput
593593
);
594594
define_state_machine_transitions!(
595595
LOCAL_OR_REMOTE_CHANGE,
596-
local_tx_remove_input,
597-
remote_tx_remove_input,
596+
sent_tx_remove_input,
597+
received_tx_remove_input,
598598
&msgs::TxRemoveInput
599599
);
600600
define_state_machine_transitions!(
601601
LOCAL_OR_REMOTE_CHANGE,
602-
local_tx_remove_output,
603-
remote_tx_remove_output,
602+
sent_tx_remove_output,
603+
received_tx_remove_output,
604604
&msgs::TxRemoveOutput
605605
);
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
609609
]);
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
613613
]);
614614
}
615615

@@ -711,7 +711,7 @@ impl InteractiveTxConstructor {
711711
prevtx_out: input.previous_output.vout,
712712
sequence: input.sequence.to_consensus_u32(),
713713
};
714-
let _ = do_state_transition!(self, local_tx_add_input, &msg)?;
714+
let _ = do_state_transition!(self, sent_tx_add_input, &msg)?;
715715
Ok(InteractiveTxMessageSend::TxAddInput(msg))
716716
} else if let Some((serial_id, output)) = self.outputs_to_contribute.pop() {
717717
let msg = msgs::TxAddOutput {
@@ -720,53 +720,53 @@ impl InteractiveTxConstructor {
720720
sats: output.value,
721721
script: output.script_pubkey,
722722
};
723-
let _ = do_state_transition!(self, local_tx_add_output, &msg)?;
723+
let _ = do_state_transition!(self, sent_tx_add_output, &msg)?;
724724
Ok(InteractiveTxMessageSend::TxAddOutput(msg))
725725
} else {
726726
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)?;
728728
Ok(InteractiveTxMessageSend::TxComplete(msg))
729729
}
730730
}
731731

732732
pub fn handle_tx_add_input(
733733
&mut self, msg: &msgs::TxAddInput,
734734
) -> 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)?;
736736
self.do_local_state_transition()
737737
}
738738

739739
pub fn handle_tx_remove_input(
740740
&mut self, msg: &msgs::TxRemoveInput,
741741
) -> 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)?;
743743
self.do_local_state_transition()
744744
}
745745

746746
pub fn handle_tx_add_output(
747747
&mut self, msg: &msgs::TxAddOutput,
748748
) -> 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)?;
750750
self.do_local_state_transition()
751751
}
752752

753753
pub fn handle_tx_remove_output(
754754
&mut self, msg: &msgs::TxRemoveOutput,
755755
) -> 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)?;
757757
self.do_local_state_transition()
758758
}
759759

760760
pub fn handle_tx_complete(
761761
&mut self, msg: &msgs::TxComplete,
762762
) -> 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)?;
764764
match &self.state_machine {
765-
StateMachine::RemoteTxComplete(_) => {
765+
StateMachine::ReceivedTxComplete(_) => {
766766
let msg_send = self.do_local_state_transition()?;
767767
let negotiated_tx = match &self.state_machine {
768768
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.
770770
_ => {
771771
debug_assert!(false, "We cannot transition to any other states after receiving `tx_complete` and responding");
772772
return Err(AbortReason::InvalidStateTransition);

0 commit comments

Comments
 (0)