Skip to content

Commit ebde818

Browse files
committed
f make signing session fields private
1 parent 72ea6c3 commit ebde818

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
@@ -1980,7 +1980,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
19801980

19811981
let mut output_index = None;
19821982
let expected_spk = self.context.get_funding_redeemscript().to_p2wsh();
1983-
for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
1983+
for (idx, outp) in signing_session.unsigned_tx().outputs().enumerate() {
19841984
if outp.script_pubkey() == &expected_spk && outp.value() == self.context.get_value_satoshis() {
19851985
if output_index.is_some() {
19861986
return Err(ChannelError::Close(
@@ -1993,7 +1993,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
19931993
}
19941994
}
19951995
let outpoint = if let Some(output_index) = output_index {
1996-
OutPoint { txid: signing_session.unsigned_tx.compute_txid(), index: output_index }
1996+
OutPoint { txid: signing_session.unsigned_tx().compute_txid(), index: output_index }
19971997
} else {
19981998
return Err(ChannelError::Close(
19991999
(
@@ -2008,7 +2008,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
20082008
let commitment_signed = self.context.get_initial_commitment_signed(logger);
20092009
let commitment_signed = match commitment_signed {
20102010
Ok(commitment_signed) => {
2011-
self.context.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2011+
self.context.funding_transaction = Some(signing_session.unsigned_tx().build_unsigned_tx());
20122012
commitment_signed
20132013
},
20142014
Err(err) => {
@@ -5902,7 +5902,7 @@ impl<SP: Deref> FundedChannel<SP> where
59025902
}
59035903

59045904
if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
5905-
if msg.tx_hash != signing_session.unsigned_tx.compute_txid() {
5905+
if msg.tx_hash != signing_session.unsigned_tx().compute_txid() {
59065906
return Err(ChannelError::Close(
59075907
(
59085908
"The txid for the transaction does not match".to_string(),
@@ -6658,9 +6658,9 @@ impl<SP: Deref> FundedChannel<SP> where
66586658
let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
66596659
if let Some(session) = &self.interactive_tx_signing_session {
66606660
// if next_funding_txid matches the latest interactive funding transaction:
6661-
if session.unsigned_tx.compute_txid() == next_funding_txid {
6661+
if session.unsigned_tx().compute_txid() == next_funding_txid {
66626662
// if it has not received tx_signatures for that funding transaction:
6663-
if !session.counterparty_sent_tx_signatures {
6663+
if !session.counterparty_sent_tx_signatures() {
66646664
// if next_commitment_number is zero:
66656665
let commitment_update = if msg.next_local_commitment_number == 0 {
66666666
// MUST retransmit its commitment_signed for that funding transaction.
@@ -6675,16 +6675,16 @@ impl<SP: Deref> FundedChannel<SP> where
66756675
})
66766676
} else { None };
66776677
// if it has already received commitment_signed and it should sign first, as specified in the tx_signatures requirements:
6678-
if session.received_commitment_signed && session.holder_sends_tx_signatures_first {
6678+
if session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first() {
66796679
// MUST send its tx_signatures for that funding transaction.
6680-
(commitment_update, session.holder_tx_signatures.clone(), None)
6680+
(commitment_update, session.holder_tx_signatures().clone(), None)
66816681
} else {
66826682
(commitment_update, None, None)
66836683
}
66846684
} else {
66856685
// if it has already received tx_signatures for that funding transaction:
66866686
// MUST send its tx_signatures for that funding transaction.
6687-
(None, session.holder_tx_signatures.clone(), None)
6687+
(None, session.holder_tx_signatures().clone(), None)
66886688
}
66896689
} else {
66906690
// MUST send tx_abort to let the sending node know that they can forget this funding transaction.
@@ -8030,7 +8030,7 @@ impl<SP: Deref> FundedChannel<SP> where
80308030
// to the txid of that interactive transaction, else we MUST NOT set it.
80318031
if let Some(signing_session) = &self.interactive_tx_signing_session {
80328032
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8033-
if !signing_session.counterparty_sent_tx_signatures {
8033+
if !signing_session.counterparty_sent_tx_signatures() {
80348034
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
80358035
Some(self.funding_outpoint().txid)
80368036
} 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)