Skip to content

Commit 8f5d100

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 56812cd commit 8f5d100

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

Diff for: 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};
@@ -9239,7 +9240,16 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
92399240
self.context.channel_id.write(writer)?;
92409241
{
92419242
let mut channel_state = self.context.channel_state;
9242-
if matches!(channel_state, ChannelState::AwaitingChannelReady(_)|ChannelState::ChannelReady(_)) {
9243+
if matches!(channel_state, ChannelState::AwaitingChannelReady(_)|ChannelState::ChannelReady(_))
9244+
{
9245+
channel_state.set_peer_disconnected();
9246+
} else if self.interactive_tx_signing_session.is_some() {
9247+
if !matches!(channel_state, ChannelState::FundingNegotiated) {
9248+
debug_assert!(false, "V2 channels in pre-signing state should not be written");
9249+
}
9250+
// This is a V2 session which has an active signing session
9251+
// TODO(dual_funding): When we allow contributing funds to dual-funded channels,
9252+
// we will need to handle persisting appropriate signing session state.
92439253
channel_state.set_peer_disconnected();
92449254
} else {
92459255
debug_assert!(false, "Pre-funded/shutdown channels should not be written");
@@ -9893,6 +9903,28 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
98939903
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
98949904
let mut is_manual_broadcast = None;
98959905

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

Diff for: 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)