Skip to content

Commit ddd38ed

Browse files
committed
Persist InteractiveTxSigningSession to resume signing across restarts
We fully persist `InteractiveTxSigningSession` as it provides the full context of the constructed transaction which is still needed for signing.
1 parent 6e44026 commit ddd38ed

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

lightning/src/ln/channel.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -10648,6 +10648,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1064810648
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
1064910649
(51, is_manual_broadcast, option), // Added in 0.0.124
1065010650
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
10651+
(54, self.interactive_tx_signing_session, option) // Added in 0.2, even as we don't want downgrades during a signing session
1065110652
});
1065210653

1065310654
Ok(())
@@ -10939,6 +10940,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1093910940
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
1094010941
let mut is_manual_broadcast = None;
1094110942

10943+
let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
10944+
1094210945
read_tlv_fields!(reader, {
1094310946
(0, announcement_sigs, option),
1094410947
(1, minimum_depth, option),
@@ -10974,6 +10977,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1097410977
(49, local_initiated_shutdown, option),
1097510978
(51, is_manual_broadcast, option),
1097610979
(53, funding_tx_broadcast_safe_event_emitted, option),
10980+
(54, interactive_tx_signing_session, option),
1097710981
});
1097810982

1097910983
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -11228,7 +11232,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1122811232

1122911233
is_holder_quiescence_initiator: None,
1123011234
},
11231-
interactive_tx_signing_session: None,
11235+
interactive_tx_signing_session,
1123211236
is_v2_established,
1123311237
holder_commitment_point,
1123411238
#[cfg(splicing)]

lightning/src/ln/interactivetxs.rs

+52
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ pub(crate) struct ConstructedTransaction {
168168
holder_sends_tx_signatures_first: bool,
169169
}
170170

171+
impl_writeable_tlv_based!(ConstructedTransaction, {
172+
(1, holder_is_initiator, required),
173+
(3, inputs, required),
174+
(5, outputs, required),
175+
(7, local_inputs_value_satoshis, required),
176+
(9, local_outputs_value_satoshis, required),
177+
(11, remote_inputs_value_satoshis, required),
178+
(13, remote_outputs_value_satoshis, required),
179+
(15, lock_time, required),
180+
(17, holder_sends_tx_signatures_first, required),
181+
});
182+
171183
impl ConstructedTransaction {
172184
fn new(context: NegotiationContext) -> Self {
173185
let local_inputs_value_satoshis = context
@@ -418,6 +430,13 @@ impl InteractiveTxSigningSession {
418430
}
419431
}
420432

433+
impl_writeable_tlv_based!(InteractiveTxSigningSession, {
434+
(1, unsigned_tx, required),
435+
(3, holder_sends_tx_signatures_first, required),
436+
(5, has_received_commitment_signed, required),
437+
(7, holder_tx_signatures, required),
438+
});
439+
421440
#[derive(Debug)]
422441
struct NegotiationContext {
423442
holder_node_id: PublicKey,
@@ -1141,6 +1160,11 @@ enum AddingRole {
11411160
Remote,
11421161
}
11431162

1163+
impl_writeable_tlv_based_enum!(AddingRole,
1164+
(1, Local) => {},
1165+
(3, Remote) => {},
1166+
);
1167+
11441168
/// Represents an input -- local or remote (both have the same fields)
11451169
#[derive(Clone, Debug, Eq, PartialEq)]
11461170
pub struct LocalOrRemoteInput {
@@ -1149,19 +1173,35 @@ pub struct LocalOrRemoteInput {
11491173
prev_output: TxOut,
11501174
}
11511175

1176+
impl_writeable_tlv_based!(LocalOrRemoteInput, {
1177+
(1, serial_id, required),
1178+
(3, input, required),
1179+
(5, prev_output, required),
1180+
});
1181+
11521182
#[derive(Clone, Debug, Eq, PartialEq)]
11531183
pub(crate) enum InteractiveTxInput {
11541184
Local(LocalOrRemoteInput),
11551185
Remote(LocalOrRemoteInput),
11561186
// TODO(splicing) SharedInput should be added
11571187
}
11581188

1189+
impl_writeable_tlv_based_enum!(InteractiveTxInput,
1190+
{1, Local} => (),
1191+
{3, Remote} => (),
1192+
);
1193+
11591194
#[derive(Clone, Debug, Eq, PartialEq)]
11601195
pub struct SharedOwnedOutput {
11611196
tx_out: TxOut,
11621197
local_owned: u64,
11631198
}
11641199

1200+
impl_writeable_tlv_based!(SharedOwnedOutput, {
1201+
(1, tx_out, required),
1202+
(3, local_owned, required),
1203+
});
1204+
11651205
impl SharedOwnedOutput {
11661206
fn new(tx_out: TxOut, local_owned: u64) -> SharedOwnedOutput {
11671207
debug_assert!(
@@ -1191,6 +1231,12 @@ pub enum OutputOwned {
11911231
Shared(SharedOwnedOutput),
11921232
}
11931233

1234+
impl_writeable_tlv_based_enum!(OutputOwned,
1235+
{1, Single} => (),
1236+
{3, SharedControlFullyOwned} => (),
1237+
{5, Shared} => (),
1238+
);
1239+
11941240
impl OutputOwned {
11951241
fn tx_out(&self) -> &TxOut {
11961242
match self {
@@ -1250,6 +1296,12 @@ pub(crate) struct InteractiveTxOutput {
12501296
output: OutputOwned,
12511297
}
12521298

1299+
impl_writeable_tlv_based!(InteractiveTxOutput, {
1300+
(1, serial_id, required),
1301+
(3, added_by, required),
1302+
(5, output, required),
1303+
});
1304+
12531305
impl InteractiveTxOutput {
12541306
pub fn tx_out(&self) -> &TxOut {
12551307
self.output.tx_out()

lightning/src/util/ser.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
1616
use crate::io::{self, BufRead, Read, Write};
1717
use crate::io_extras::{copy, sink};
18+
use crate::ln::interactivetxs::{InteractiveTxInput, InteractiveTxOutput};
1819
use crate::prelude::*;
1920
use crate::sync::{Mutex, RwLock};
2021
use core::cmp;
@@ -23,6 +24,7 @@ use core::ops::Deref;
2324

2425
use alloc::collections::BTreeMap;
2526

27+
use bitcoin::absolute::LockTime as AbsoluteLockTime;
2628
use bitcoin::amount::Amount;
2729
use bitcoin::consensus::Encodable;
2830
use bitcoin::constants::ChainHash;
@@ -38,14 +40,14 @@ use bitcoin::secp256k1::ecdsa;
3840
use bitcoin::secp256k1::schnorr;
3941
use bitcoin::secp256k1::{PublicKey, SecretKey};
4042
use bitcoin::transaction::{OutPoint, Transaction, TxOut};
41-
use bitcoin::{consensus, Witness};
43+
use bitcoin::{consensus, TxIn, Witness};
4244

4345
use dnssec_prover::rr::Name;
4446

4547
use crate::chain::ClaimId;
46-
use crate::ln::msgs::DecodeError;
4748
#[cfg(taproot)]
4849
use crate::ln::msgs::PartialSignatureWithNonce;
50+
use crate::ln::msgs::{DecodeError, SerialId};
4951
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
5052
use core::time::Duration;
5153

@@ -1074,6 +1076,9 @@ impl_for_vec!(crate::ln::channelmanager::MonitorUpdateCompletionAction);
10741076
impl_for_vec!(crate::ln::channelmanager::PaymentClaimDetails);
10751077
impl_for_vec!(crate::ln::msgs::SocketAddress);
10761078
impl_for_vec!((A, B), A, B);
1079+
impl_for_vec!(SerialId);
1080+
impl_for_vec!(InteractiveTxInput);
1081+
impl_for_vec!(InteractiveTxOutput);
10771082
impl_writeable_for_vec!(&crate::routing::router::BlindedTail);
10781083
impl_readable_for_vec!(crate::routing::router::BlindedTail);
10791084
impl_for_vec!(crate::routing::router::TrampolineHop);
@@ -1345,6 +1350,19 @@ impl<T: LengthReadable> Readable for Option<T> {
13451350
}
13461351
}
13471352

1353+
impl Writeable for AbsoluteLockTime {
1354+
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
1355+
self.to_consensus_u32().write(w)
1356+
}
1357+
}
1358+
1359+
impl Readable for AbsoluteLockTime {
1360+
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
1361+
let lock_time: u32 = Readable::read(r)?;
1362+
Ok(AbsoluteLockTime::from_consensus(lock_time))
1363+
}
1364+
}
1365+
13481366
impl Writeable for Amount {
13491367
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
13501368
self.to_sat().write(w)
@@ -1446,6 +1464,7 @@ macro_rules! impl_consensus_ser {
14461464
};
14471465
}
14481466
impl_consensus_ser!(Transaction);
1467+
impl_consensus_ser!(TxIn);
14491468
impl_consensus_ser!(TxOut);
14501469
impl_consensus_ser!(Witness);
14511470

0 commit comments

Comments
 (0)