Skip to content

Commit 4d56ff3

Browse files
committed
f s/local/sent/ & s/remote/received/ where appropriate
1 parent 23e6f4b commit 4d56ff3

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
@@ -255,7 +255,7 @@ impl NegotiationContext {
255255
Ok(())
256256
}
257257

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> {
259259
if !self.is_serial_id_valid_for_counterparty(&msg.serial_id) {
260260
return Err(AbortReason::IncorrectSerialIdParity);
261261
}
@@ -270,7 +270,7 @@ impl NegotiationContext {
270270
}
271271
}
272272

273-
fn local_tx_add_input(&mut self, msg: &msgs::TxAddInput) {
273+
fn sent_tx_add_input(&mut self, msg: &msgs::TxAddInput) {
274274
let tx = msg.prevtx.as_transaction();
275275
let input = TxIn {
276276
previous_output: OutPoint { txid: tx.txid(), vout: msg.prevtx_out },
@@ -286,16 +286,16 @@ impl NegotiationContext {
286286
);
287287
}
288288

289-
fn local_tx_add_output(&mut self, msg: &msgs::TxAddOutput) {
289+
fn sent_tx_add_output(&mut self, msg: &msgs::TxAddOutput) {
290290
self.outputs
291291
.insert(msg.serial_id, TxOut { value: msg.sats, script_pubkey: msg.script.clone() });
292292
}
293293

294-
fn local_tx_remove_input(&mut self, msg: &msgs::TxRemoveInput) {
294+
fn sent_tx_remove_input(&mut self, msg: &msgs::TxRemoveInput) {
295295
self.inputs.remove(&msg.serial_id);
296296
}
297297

298-
fn local_tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput) {
298+
fn sent_tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput) {
299299
self.outputs.remove(&msg.serial_id);
300300
}
301301

@@ -419,22 +419,22 @@ macro_rules! define_state {
419419

420420
define_state!(
421421
LOCAL_STATE,
422-
LocalChange,
422+
SentChange,
423423
"We have sent a message to the counterparty that has affected our negotiation state."
424424
);
425425
define_state!(
426426
LOCAL_STATE,
427-
LocalTxComplete,
427+
SentTxComplete,
428428
"We have sent a `tx_complete` message and are awaiting the counterparty's."
429429
);
430430
define_state!(
431431
REMOTE_STATE,
432-
RemoteChange,
432+
ReceivedChange,
433433
"We have received a message from the counterparty that has affected our negotiation state."
434434
);
435435
define_state!(
436436
REMOTE_STATE,
437-
RemoteTxComplete,
437+
ReceivedTxComplete,
438438
"We have received a `tx_complete` message and the counterparty is awaiting ours."
439439
);
440440
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> {
453453
macro_rules! define_state_transitions {
454454
(LOCAL_STATE, [$(DATA $data: ty, TRANSITION $transition: ident),+]) => {
455455
$(
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> {
458458
let mut context = self.into_negotiation_context();
459459
let _ = context.$transition(data)?;
460-
Ok(RemoteChange(context))
460+
Ok(ReceivedChange(context))
461461
}
462462
}
463463
)*
464464
};
465465
(REMOTE_STATE, [$(DATA $data: ty, TRANSITION $transition: ident),+]) => {
466466
$(
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> {
469469
let mut context = self.into_negotiation_context();
470470
let _ = context.$transition(data);
471-
Ok(LocalChange(context))
471+
Ok(SentChange(context))
472472
}
473473
}
474474
)*
@@ -492,29 +492,29 @@ macro_rules! define_state_transitions {
492492
}
493493

494494
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
499499
]);
500500
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
505505
]);
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);
510510

511511
#[derive(Debug)]
512512
enum StateMachine {
513513
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),
518518
NegotiationComplete(NegotiationComplete),
519519
NegotiationAborted(NegotiationAborted),
520520
}
@@ -541,12 +541,12 @@ macro_rules! define_state_machine_transitions {
541541
};
542542
(LOCAL_OR_REMOTE_CHANGE, $to_local_transition: ident, $to_remote_transition: ident, $msg: ty) => {
543543
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
546546
]);
547547
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
550550
]);
551551
};
552552
}
@@ -568,43 +568,43 @@ impl StateMachine {
568568
to_remote_value,
569569
};
570570
if is_initiator {
571-
Self::RemoteChange(RemoteChange(context))
571+
Self::ReceivedChange(ReceivedChange(context))
572572
} else {
573-
Self::LocalChange(LocalChange(context))
573+
Self::SentChange(SentChange(context))
574574
}
575575
}
576576

577577
define_state_machine_transitions!(
578578
LOCAL_OR_REMOTE_CHANGE,
579-
local_tx_add_input,
580-
remote_tx_add_input,
579+
sent_tx_add_input,
580+
received_tx_add_input,
581581
&msgs::TxAddInput
582582
);
583583
define_state_machine_transitions!(
584584
LOCAL_OR_REMOTE_CHANGE,
585-
local_tx_add_output,
586-
remote_tx_add_output,
585+
sent_tx_add_output,
586+
received_tx_add_output,
587587
&msgs::TxAddOutput
588588
);
589589
define_state_machine_transitions!(
590590
LOCAL_OR_REMOTE_CHANGE,
591-
local_tx_remove_input,
592-
remote_tx_remove_input,
591+
sent_tx_remove_input,
592+
received_tx_remove_input,
593593
&msgs::TxRemoveInput
594594
);
595595
define_state_machine_transitions!(
596596
LOCAL_OR_REMOTE_CHANGE,
597-
local_tx_remove_output,
598-
remote_tx_remove_output,
597+
sent_tx_remove_output,
598+
received_tx_remove_output,
599599
&msgs::TxRemoveOutput
600600
);
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
604604
]);
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
608608
]);
609609
}
610610

@@ -706,7 +706,7 @@ impl InteractiveTxConstructor {
706706
prevtx_out: input.previous_output.vout,
707707
sequence: input.sequence.to_consensus_u32(),
708708
};
709-
let _ = do_state_transition!(self, local_tx_add_input, &msg)?;
709+
let _ = do_state_transition!(self, sent_tx_add_input, &msg)?;
710710
Ok(InteractiveTxMessageSend::TxAddInput(msg))
711711
} else if let Some((serial_id, output)) = self.outputs_to_contribute.pop() {
712712
let msg = msgs::TxAddOutput {
@@ -715,53 +715,53 @@ impl InteractiveTxConstructor {
715715
sats: output.value,
716716
script: output.script_pubkey,
717717
};
718-
let _ = do_state_transition!(self, local_tx_add_output, &msg)?;
718+
let _ = do_state_transition!(self, sent_tx_add_output, &msg)?;
719719
Ok(InteractiveTxMessageSend::TxAddOutput(msg))
720720
} else {
721721
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)?;
723723
Ok(InteractiveTxMessageSend::TxComplete(msg))
724724
}
725725
}
726726

727727
pub fn handle_tx_add_input(
728728
&mut self, msg: &msgs::TxAddInput,
729729
) -> 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)?;
731731
self.do_local_state_transition()
732732
}
733733

734734
pub fn handle_tx_remove_input(
735735
&mut self, msg: &msgs::TxRemoveInput,
736736
) -> 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)?;
738738
self.do_local_state_transition()
739739
}
740740

741741
pub fn handle_tx_add_output(
742742
&mut self, msg: &msgs::TxAddOutput,
743743
) -> 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)?;
745745
self.do_local_state_transition()
746746
}
747747

748748
pub fn handle_tx_remove_output(
749749
&mut self, msg: &msgs::TxRemoveOutput,
750750
) -> 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)?;
752752
self.do_local_state_transition()
753753
}
754754

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

0 commit comments

Comments
 (0)