Skip to content

Commit 857432b

Browse files
committed
Add funding_locked_txid TLVs to channel_reestablish
The splicing spec extends the channel_reestablish message with two more TLVs indicating which funding txid the sender has sent/received either explicitly via splice_locked or implicitly via channel_ready. This allows peers to detect if a splice_locked was lost during disconnection and must be retransmitted. This commit updates channel_reestablish with the TLVs. Subsequent commits will implement the spec requirements.
1 parent 3f4356a commit 857432b

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11013,6 +11013,7 @@ where
1101311013
your_last_per_commitment_secret: remote_last_secret,
1101411014
my_current_per_commitment_point: dummy_pubkey,
1101511015
next_funding_txid: self.maybe_get_next_funding_txid(),
11016+
my_current_funding_locked: None,
1101611017
}
1101711018
}
1101811019

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11088,6 +11088,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1108811088
your_last_per_commitment_secret: [1u8; 32],
1108911089
my_current_per_commitment_point: PublicKey::from_slice(&[2u8; 33]).unwrap(),
1109011090
next_funding_txid: None,
11091+
my_current_funding_locked: None,
1109111092
},
1109211093
});
1109311094
return Err(MsgHandleErrInternal::send_err_msg_no_close(

lightning/src/ln/msgs.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,28 @@ pub struct ChannelReestablish {
926926
/// * `channel_reestablish`-sending node: https:///github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2466-L2470
927927
/// * `channel_reestablish`-receiving node: https:///github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2520-L2531
928928
pub next_funding_txid: Option<Txid>,
929+
/// The last funding txid sent by the sending node, which may be:
930+
/// - the txid of the last `splice_locked` it sent, otherwise
931+
/// - the txid of the funding transaction if it sent `channel_ready`, or else
932+
/// - `None` if it has never sent `channel_ready` or `splice_locked`
933+
///
934+
/// Also contains a bitfield indicating which messages should be retransmitted.
935+
pub my_current_funding_locked: Option<FundingLocked>,
936+
}
937+
938+
/// Information exchanged during channel reestablishment about the last funding locked.
939+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
940+
pub struct FundingLocked {
941+
/// The last txid sent by the sending node, which may be either from the last `splice_locked` or
942+
/// for the initial funding transaction if it sent `channel_ready`.
943+
pub txid: Txid,
944+
945+
/// A bitfield indicating which messages should be retransmitted by the receiving node.
946+
///
947+
/// | Bit Position | Name |
948+
/// | ------------- | --------------------------|
949+
/// | 0 | `announcement_signatures` |
950+
pub retransmit_flags: u8,
929951
}
930952

931953
/// An [`announcement_signatures`] message to be sent to or received from a peer.
@@ -2852,6 +2874,12 @@ impl_writeable_msg!(ChannelReestablish, {
28522874
my_current_per_commitment_point,
28532875
}, {
28542876
(0, next_funding_txid, option),
2877+
(5, my_current_funding_locked, option),
2878+
});
2879+
2880+
impl_writeable!(FundingLocked, {
2881+
txid,
2882+
retransmit_flags
28552883
});
28562884

28572885
impl_writeable_msg!(ClosingSigned,
@@ -4321,6 +4349,7 @@ mod tests {
43214349
your_last_per_commitment_secret: [9; 32],
43224350
my_current_per_commitment_point: public_key,
43234351
next_funding_txid: None,
4352+
my_current_funding_locked: None,
43244353
};
43254354

43264355
let encoded_value = cr.encode();
@@ -4372,6 +4401,7 @@ mod tests {
43724401
])
43734402
.unwrap(),
43744403
)),
4404+
my_current_funding_locked: None,
43754405
};
43764406

43774407
let encoded_value = cr.encode();
@@ -4395,6 +4425,65 @@ mod tests {
43954425
);
43964426
}
43974427

4428+
#[test]
4429+
fn encoding_channel_reestablish_with_funding_locked_txid() {
4430+
let public_key = {
4431+
let secp_ctx = Secp256k1::new();
4432+
PublicKey::from_secret_key(
4433+
&secp_ctx,
4434+
&SecretKey::from_slice(
4435+
&<Vec<u8>>::from_hex(
4436+
"0101010101010101010101010101010101010101010101010101010101010101",
4437+
)
4438+
.unwrap()[..],
4439+
)
4440+
.unwrap(),
4441+
)
4442+
};
4443+
4444+
let cr = msgs::ChannelReestablish {
4445+
channel_id: ChannelId::from_bytes([
4446+
4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
4447+
0, 0, 0, 0,
4448+
]),
4449+
next_local_commitment_number: 3,
4450+
next_remote_commitment_number: 4,
4451+
your_last_per_commitment_secret: [9; 32],
4452+
my_current_per_commitment_point: public_key,
4453+
next_funding_txid: None,
4454+
my_current_funding_locked: Some(msgs::FundingLocked {
4455+
txid: Txid::from_raw_hash(
4456+
bitcoin::hashes::Hash::from_slice(&[
4457+
21, 167, 250, 69, 152, 48, 103, 172, 164, 99, 59, 19, 23, 11, 92, 84, 15,
4458+
80, 4, 12, 98, 82, 75, 31, 201, 11, 91, 23, 98, 23, 53, 124,
4459+
])
4460+
.unwrap(),
4461+
),
4462+
retransmit_flags: 1,
4463+
}),
4464+
};
4465+
4466+
let encoded_value = cr.encode();
4467+
assert_eq!(
4468+
encoded_value,
4469+
vec![
4470+
4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
4471+
0, 0, 0, 0, // channel_id
4472+
0, 0, 0, 0, 0, 0, 0, 3, // next_local_commitment_number
4473+
0, 0, 0, 0, 0, 0, 0, 4, // next_remote_commitment_number
4474+
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
4475+
9, 9, 9, 9, // your_last_per_commitment_secret
4476+
3, 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30,
4477+
24, 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7,
4478+
143, // my_current_per_commitment_point
4479+
5, // Type (my_current_funding_locked)
4480+
33, // Length
4481+
21, 167, 250, 69, 152, 48, 103, 172, 164, 99, 59, 19, 23, 11, 92, 84, 15, 80, 4,
4482+
12, 98, 82, 75, 31, 201, 11, 91, 23, 98, 23, 53, 124, 1, // Value
4483+
]
4484+
);
4485+
}
4486+
43984487
macro_rules! get_keys_from {
43994488
($slice: expr, $secp_ctx: expr) => {{
44004489
let privkey = SecretKey::from_slice(&<Vec<u8>>::from_hex($slice).unwrap()[..]).unwrap();

0 commit comments

Comments
 (0)