Skip to content

Commit 25b1be4

Browse files
committed
f make signing session fields private
1 parent 1c0d3fb commit 25b1be4

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
19881988

19891989
let mut output_index = None;
19901990
let expected_spk = self.context.get_funding_redeemscript().to_p2wsh();
1991-
for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
1991+
for (idx, outp) in signing_session.unsigned_tx().outputs().enumerate() {
19921992
if outp.script_pubkey() == &expected_spk && outp.value() == self.context.get_value_satoshis() {
19931993
if output_index.is_some() {
19941994
return Err(ChannelError::Close(
@@ -2001,7 +2001,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
20012001
}
20022002
}
20032003
let outpoint = if let Some(output_index) = output_index {
2004-
OutPoint { txid: signing_session.unsigned_tx.compute_txid(), index: output_index }
2004+
OutPoint { txid: signing_session.unsigned_tx().compute_txid(), index: output_index }
20052005
} else {
20062006
return Err(ChannelError::Close(
20072007
(
@@ -2016,7 +2016,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
20162016
let commitment_signed = self.context.get_initial_commitment_signed(logger);
20172017
let commitment_signed = match commitment_signed {
20182018
Ok(commitment_signed) => {
2019-
self.context.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2019+
self.context.funding_transaction = Some(signing_session.unsigned_tx().build_unsigned_tx());
20202020
commitment_signed
20212021
},
20222022
Err(err) => {
@@ -5910,7 +5910,7 @@ impl<SP: Deref> FundedChannel<SP> where
59105910
}
59115911

59125912
if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
5913-
if msg.tx_hash != signing_session.unsigned_tx.compute_txid() {
5913+
if msg.tx_hash != signing_session.unsigned_tx().compute_txid() {
59145914
return Err(ChannelError::Close(
59155915
(
59165916
"The txid for the transaction does not match".to_string(),
@@ -6666,9 +6666,9 @@ impl<SP: Deref> FundedChannel<SP> where
66666666
let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
66676667
if let Some(session) = &self.interactive_tx_signing_session {
66686668
// if next_funding_txid matches the latest interactive funding transaction:
6669-
if session.unsigned_tx.compute_txid() == next_funding_txid {
6669+
if session.unsigned_tx().compute_txid() == next_funding_txid {
66706670
// if it has not received tx_signatures for that funding transaction:
6671-
if !session.counterparty_sent_tx_signatures {
6671+
if !session.counterparty_sent_tx_signatures() {
66726672
// if next_commitment_number is zero:
66736673
let commitment_update = if msg.next_local_commitment_number == 0 {
66746674
// MUST retransmit its commitment_signed for that funding transaction.
@@ -6683,16 +6683,16 @@ impl<SP: Deref> FundedChannel<SP> where
66836683
})
66846684
} else { None };
66856685
// if it has already received commitment_signed and it should sign first, as specified in the tx_signatures requirements:
6686-
if session.received_commitment_signed && session.holder_sends_tx_signatures_first {
6686+
if session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first() {
66876687
// MUST send its tx_signatures for that funding transaction.
6688-
(commitment_update, session.holder_tx_signatures.clone(), None)
6688+
(commitment_update, session.holder_tx_signatures().clone(), None)
66896689
} else {
66906690
(commitment_update, None, None)
66916691
}
66926692
} else {
66936693
// if it has already received tx_signatures for that funding transaction:
66946694
// MUST send its tx_signatures for that funding transaction.
6695-
(None, session.holder_tx_signatures.clone(), None)
6695+
(None, session.holder_tx_signatures().clone(), None)
66966696
}
66976697
} else {
66986698
// MUST send tx_abort to let the sending node know that they can forget this funding transaction.
@@ -8038,7 +8038,7 @@ impl<SP: Deref> FundedChannel<SP> where
80388038
// to the txid of that interactive transaction, else we MUST NOT set it.
80398039
if let Some(signing_session) = &self.interactive_tx_signing_session {
80408040
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8041-
if !signing_session.counterparty_sent_tx_signatures {
8041+
if !signing_session.counterparty_sent_tx_signatures() {
80428042
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
80438043
Some(self.funding_outpoint().txid)
80448044
} else {

lightning/src/ln/interactivetxs.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,36 @@ impl ConstructedTransaction {
289289
/// https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#sharing-funding-signatures-tx_signatures
290290
#[derive(Debug, Clone, PartialEq)]
291291
pub(crate) struct InteractiveTxSigningSession {
292-
pub unsigned_tx: ConstructedTransaction,
293-
pub counterparty_sent_tx_signatures: bool,
294-
pub holder_sends_tx_signatures_first: bool,
295-
pub received_commitment_signed: bool,
296-
pub holder_tx_signatures: Option<TxSignatures>,
292+
unsigned_tx: ConstructedTransaction,
293+
counterparty_sent_tx_signatures: bool,
294+
holder_sends_tx_signatures_first: bool,
295+
has_received_commitment_signed: bool,
296+
holder_tx_signatures: Option<TxSignatures>,
297297
}
298298

299299
impl InteractiveTxSigningSession {
300+
pub fn unsigned_tx(&self) -> &ConstructedTransaction {
301+
&self.unsigned_tx
302+
}
303+
304+
pub fn counterparty_sent_tx_signatures(&self) -> bool {
305+
self.counterparty_sent_tx_signatures
306+
}
307+
308+
pub fn holder_sends_tx_signatures_first(&self) -> bool {
309+
self.holder_sends_tx_signatures_first
310+
}
311+
312+
pub fn has_received_commitment_signed(&self) -> bool {
313+
self.has_received_commitment_signed
314+
}
315+
316+
pub fn holder_tx_signatures(&self) -> &Option<TxSignatures> {
317+
&self.holder_tx_signatures
318+
}
319+
300320
pub fn received_commitment_signed(&mut self) -> Option<TxSignatures> {
301-
self.received_commitment_signed = true;
321+
self.has_received_commitment_signed = true;
302322
if self.holder_sends_tx_signatures_first {
303323
self.holder_tx_signatures.clone()
304324
} else {
@@ -307,7 +327,7 @@ impl InteractiveTxSigningSession {
307327
}
308328

309329
pub fn get_tx_signatures(&self) -> Option<TxSignatures> {
310-
if self.received_commitment_signed {
330+
if self.has_received_commitment_signed {
311331
self.holder_tx_signatures.clone()
312332
} else {
313333
None
@@ -988,7 +1008,7 @@ macro_rules! define_state_transitions {
9881008
let signing_session = InteractiveTxSigningSession {
9891009
holder_sends_tx_signatures_first: tx.holder_sends_tx_signatures_first,
9901010
unsigned_tx: tx,
991-
received_commitment_signed: false,
1011+
has_received_commitment_signed: false,
9921012
holder_tx_signatures: None,
9931013
counterparty_sent_tx_signatures: false,
9941014
};

0 commit comments

Comments
 (0)