Skip to content

Commit 39ae79e

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 1ade599 commit 39ae79e

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10201,6 +10201,8 @@ where
1020110201
your_last_per_commitment_secret: remote_last_secret,
1020210202
my_current_per_commitment_point: dummy_pubkey,
1020310203
next_funding_txid: self.maybe_get_next_funding_txid(),
10204+
your_last_funding_locked_txid: None,
10205+
my_current_funding_locked_txid: None,
1020410206
}
1020510207
}
1020610208

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10091,6 +10091,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1009110091
your_last_per_commitment_secret: [1u8; 32],
1009210092
my_current_per_commitment_point: PublicKey::from_slice(&[2u8; 33]).unwrap(),
1009310093
next_funding_txid: None,
10094+
your_last_funding_locked_txid: None,
10095+
my_current_funding_locked_txid: None,
1009410096
},
1009510097
});
1009610098
return Err(MsgHandleErrInternal::send_err_msg_no_close(

lightning/src/ln/msgs.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,16 @@ pub struct ChannelReestablish {
928928
/// * `channel_reestablish`-sending node: https:///github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2466-L2470
929929
/// * `channel_reestablish`-receiving node: https:///github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2520-L2531
930930
pub next_funding_txid: Option<Txid>,
931+
/// The last funding txid received by the sending node, which may be:
932+
/// - the txid of the last `splice_locked` it received, otherwise
933+
/// - the txid of the funding transaction if it received `channel_ready`, or else
934+
/// - `None` if it has never received `channel_ready` or `splice_locked`
935+
pub your_last_funding_locked_txid: Option<Txid>,
936+
/// The last funding txid sent by the sending node, which may be:
937+
/// - the txid of the last `splice_locked` it sent, otherwise
938+
/// - the txid of the funding transaction if it sent `channel_ready`, or else
939+
/// - `None` if it has never sent `channel_ready` or `splice_locked`
940+
pub my_current_funding_locked_txid: Option<Txid>,
931941
}
932942

933943
/// An [`announcement_signatures`] message to be sent to or received from a peer.
@@ -2805,6 +2815,8 @@ impl_writeable_msg!(ChannelReestablish, {
28052815
my_current_per_commitment_point,
28062816
}, {
28072817
(0, next_funding_txid, option),
2818+
(1, your_last_funding_locked_txid, option),
2819+
(3, my_current_funding_locked_txid, option),
28082820
});
28092821

28102822
impl_writeable_msg!(ClosingSigned,
@@ -4275,6 +4287,8 @@ mod tests {
42754287
your_last_per_commitment_secret: [9; 32],
42764288
my_current_per_commitment_point: public_key,
42774289
next_funding_txid: None,
4290+
your_last_funding_locked_txid: None,
4291+
my_current_funding_locked_txid: None,
42784292
};
42794293

42804294
let encoded_value = cr.encode();
@@ -4326,6 +4340,8 @@ mod tests {
43264340
])
43274341
.unwrap(),
43284342
)),
4343+
your_last_funding_locked_txid: None,
4344+
my_current_funding_locked_txid: None,
43294345
};
43304346

43314347
let encoded_value = cr.encode();
@@ -4349,6 +4365,73 @@ mod tests {
43494365
);
43504366
}
43514367

4368+
#[test]
4369+
fn encoding_channel_reestablish_with_funding_locked_txid() {
4370+
let public_key = {
4371+
let secp_ctx = Secp256k1::new();
4372+
PublicKey::from_secret_key(
4373+
&secp_ctx,
4374+
&SecretKey::from_slice(
4375+
&<Vec<u8>>::from_hex(
4376+
"0101010101010101010101010101010101010101010101010101010101010101",
4377+
)
4378+
.unwrap()[..],
4379+
)
4380+
.unwrap(),
4381+
)
4382+
};
4383+
4384+
let cr = msgs::ChannelReestablish {
4385+
channel_id: ChannelId::from_bytes([
4386+
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,
4387+
0, 0, 0, 0,
4388+
]),
4389+
next_local_commitment_number: 3,
4390+
next_remote_commitment_number: 4,
4391+
your_last_per_commitment_secret: [9; 32],
4392+
my_current_per_commitment_point: public_key,
4393+
next_funding_txid: None,
4394+
your_last_funding_locked_txid: Some(Txid::from_raw_hash(
4395+
bitcoin::hashes::Hash::from_slice(&[
4396+
48, 167, 250, 69, 152, 48, 103, 172, 164, 99, 59, 19, 23, 11, 92, 84, 15, 80,
4397+
4, 12, 98, 82, 75, 31, 201, 11, 91, 23, 98, 23, 53, 124,
4398+
])
4399+
.unwrap(),
4400+
)),
4401+
my_current_funding_locked_txid: Some(Txid::from_raw_hash(
4402+
bitcoin::hashes::Hash::from_slice(&[
4403+
21, 167, 250, 69, 152, 48, 103, 172, 164, 99, 59, 19, 23, 11, 92, 84, 15, 80,
4404+
4, 12, 98, 82, 75, 31, 201, 11, 91, 23, 98, 23, 53, 124,
4405+
])
4406+
.unwrap(),
4407+
)),
4408+
};
4409+
4410+
let encoded_value = cr.encode();
4411+
assert_eq!(
4412+
encoded_value,
4413+
vec![
4414+
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,
4415+
0, 0, 0, 0, // channel_id
4416+
0, 0, 0, 0, 0, 0, 0, 3, // next_local_commitment_number
4417+
0, 0, 0, 0, 0, 0, 0, 4, // next_remote_commitment_number
4418+
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,
4419+
9, 9, 9, 9, // your_last_per_commitment_secret
4420+
3, 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30,
4421+
24, 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7,
4422+
143, // my_current_per_commitment_point
4423+
1, // Type (your_last_funding_locked_txid)
4424+
32, // Length
4425+
48, 167, 250, 69, 152, 48, 103, 172, 164, 99, 59, 19, 23, 11, 92, 84, 15, 80, 4,
4426+
12, 98, 82, 75, 31, 201, 11, 91, 23, 98, 23, 53, 124, // Value
4427+
3, // Type (my_current_funding_locked_txid)
4428+
32, // Length
4429+
21, 167, 250, 69, 152, 48, 103, 172, 164, 99, 59, 19, 23, 11, 92, 84, 15, 80, 4,
4430+
12, 98, 82, 75, 31, 201, 11, 91, 23, 98, 23, 53, 124, // Value
4431+
]
4432+
);
4433+
}
4434+
43524435
macro_rules! get_keys_from {
43534436
($slice: expr, $secp_ctx: expr) => {{
43544437
let privkey = SecretKey::from_slice(&<Vec<u8>>::from_hex($slice).unwrap()[..]).unwrap();

0 commit comments

Comments
 (0)