Skip to content

Commit 26fb59f

Browse files
committed
Populate Channel::interactive_tx_signing_session on read
We allow persisting `Channel`s in a `ChannelState::FundingNegotiated` only if `Channel::interactive_tx_signing_session` is Some. When reading a persisted `Channel` in `ChannelState::FundingNegotiate`, we populate `Channel::interactive_tx_signing_session` with appropriate values for accepting dual-funded channels without contributing. Currently we don't need persistence, but we will need to persist some information when we allow contributing funds to dual-funded channels.
1 parent e1fd19d commit 26fb59f

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

lightning/src/ln/channel.rs

+36-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ use crate::ln::types::ChannelId;
3131
use crate::types::payment::{PaymentPreimage, PaymentHash};
3232
use crate::types::features::{ChannelTypeFeatures, InitFeatures};
3333
use crate::ln::interactivetxs::{
34-
get_output_weight, HandleTxCompleteResult, InteractiveTxConstructor, InteractiveTxConstructorArgs,
35-
InteractiveTxSigningSession, InteractiveTxMessageSendResult, TX_COMMON_FIELDS_WEIGHT,
34+
ConstructedTransaction, get_output_weight, HandleTxCompleteResult, InteractiveTxConstructor,
35+
InteractiveTxConstructorArgs, InteractiveTxSigningSession, InteractiveTxMessageSendResult,
36+
TX_COMMON_FIELDS_WEIGHT,
3637
};
3738
use crate::ln::msgs;
3839
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError};
@@ -9244,7 +9245,16 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
92449245
self.context.channel_id.write(writer)?;
92459246
{
92469247
let mut channel_state = self.context.channel_state;
9247-
if matches!(channel_state, ChannelState::AwaitingChannelReady(_)|ChannelState::ChannelReady(_)) {
9248+
if matches!(channel_state, ChannelState::AwaitingChannelReady(_)|ChannelState::ChannelReady(_))
9249+
{
9250+
channel_state.set_peer_disconnected();
9251+
} else if self.interactive_tx_signing_session.is_some() {
9252+
if !matches!(channel_state, ChannelState::FundingNegotiated) {
9253+
debug_assert!(false, "V2 channels in pre-signing state should not be written");
9254+
}
9255+
// This is a V2 session which has an active signing session
9256+
// TODO(dual_funding): When we allow contributing funds to dual-funded channels,
9257+
// we will need to handle persisting appropriate signing session state.
92489258
channel_state.set_peer_disconnected();
92499259
} else {
92509260
debug_assert!(false, "Pre-funded/shutdown channels should not be written");
@@ -9898,6 +9908,28 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
98989908
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
98999909
let mut is_manual_broadcast = None;
99009910

9911+
let interactive_tx_signing_session = if matches!(channel_state, ChannelState::FundingNegotiated) {
9912+
if let Some(ref funding_tx) = funding_transaction {
9913+
// TODO(dual_funding): When we allow contributing funds to dual-funded channels,
9914+
// we will need to handle persisting appropriate signing session state.
9915+
Some(InteractiveTxSigningSession {
9916+
unsigned_tx: ConstructedTransaction::default(),
9917+
counterparty_sent_tx_signatures: false,
9918+
holder_sends_tx_signatures_first: true, // TODO(dual_funding): Fixed to true as we currently don't contribute inputs.
9919+
received_commitment_signed: true, // We only enter the FundingNegotiated state once we have persisted the initial channel monitor.
9920+
holder_tx_signatures: Some(msgs::TxSignatures {
9921+
channel_id,
9922+
tx_hash: funding_tx.compute_txid(),
9923+
witnesses: vec![], // TODO(dual_funding): Fixed to true as we currently don't contribute inputs.
9924+
shared_input_signature: None, // TODO(splicing): Only relevant to splicing
9925+
})
9926+
})
9927+
} else {
9928+
debug_assert!(false, "Tried to read V2 channel with signing session but there is no funding transaction");
9929+
None
9930+
}
9931+
} else { None };
9932+
99019933
read_tlv_fields!(reader, {
99029934
(0, announcement_sigs, option),
99039935
(1, minimum_depth, option),
@@ -10194,7 +10226,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1019410226
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1019510227
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
1019610228
},
10197-
interactive_tx_signing_session: None,
10229+
interactive_tx_signing_session,
1019810230
})
1019910231
}
1020010232
}

lightning/src/ln/interactivetxs.rs

+17
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ pub(crate) struct ConstructedTransaction {
169169
holder_sends_tx_signatures_first: bool,
170170
}
171171

172+
impl Default for ConstructedTransaction {
173+
fn default() -> Self {
174+
ConstructedTransaction {
175+
holder_is_initiator: false,
176+
inputs: vec![],
177+
outputs: vec![],
178+
local_inputs_value_satoshis: 0,
179+
local_outputs_value_satoshis: 0,
180+
remote_inputs_value_satoshis: 0,
181+
remote_outputs_value_satoshis: 0,
182+
lock_time: AbsoluteLockTime::from_height(0)
183+
.expect("0 is a valid block height for a locktime"),
184+
holder_sends_tx_signatures_first: true,
185+
}
186+
}
187+
}
188+
172189
impl ConstructedTransaction {
173190
fn new(context: NegotiationContext) -> Self {
174191
let local_inputs_value_satoshis = context

0 commit comments

Comments
 (0)