Skip to content

Commit efe8314

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 1ed62b1 commit efe8314

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
@@ -10592,6 +10592,8 @@ where
1059210592
your_last_per_commitment_secret: remote_last_secret,
1059310593
my_current_per_commitment_point: dummy_pubkey,
1059410594
next_funding_txid: self.maybe_get_next_funding_txid(),
10595+
your_last_funding_locked_txid: None,
10596+
my_current_funding_locked_txid: None,
1059510597
}
1059610598
}
1059710599

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11049,6 +11049,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1104911049
your_last_per_commitment_secret: [1u8; 32],
1105011050
my_current_per_commitment_point: PublicKey::from_slice(&[2u8; 33]).unwrap(),
1105111051
next_funding_txid: None,
11052+
your_last_funding_locked_txid: None,
11053+
my_current_funding_locked_txid: None,
1105211054
},
1105311055
});
1105411056
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
@@ -927,6 +927,16 @@ pub struct ChannelReestablish {
927927
/// * `channel_reestablish`-sending node: https:///github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2466-L2470
928928
/// * `channel_reestablish`-receiving node: https:///github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2520-L2531
929929
pub next_funding_txid: Option<Txid>,
930+
/// The last funding txid received by the sending node, which may be:
931+
/// - the txid of the last `splice_locked` it received, otherwise
932+
/// - the txid of the funding transaction if it received `channel_ready`, or else
933+
/// - `None` if it has never received `channel_ready` or `splice_locked`
934+
pub your_last_funding_locked_txid: Option<Txid>,
935+
/// The last funding txid sent by the sending node, which may be:
936+
/// - the txid of the last `splice_locked` it sent, otherwise
937+
/// - the txid of the funding transaction if it sent `channel_ready`, or else
938+
/// - `None` if it has never sent `channel_ready` or `splice_locked`
939+
pub my_current_funding_locked_txid: Option<Txid>,
930940
}
931941

932942
/// An [`announcement_signatures`] message to be sent to or received from a peer.
@@ -2811,6 +2821,8 @@ impl_writeable_msg!(ChannelReestablish, {
28112821
my_current_per_commitment_point,
28122822
}, {
28132823
(0, next_funding_txid, option),
2824+
(1, your_last_funding_locked_txid, option),
2825+
(3, my_current_funding_locked_txid, option),
28142826
});
28152827

28162828
impl_writeable_msg!(ClosingSigned,
@@ -4283,6 +4295,8 @@ mod tests {
42834295
your_last_per_commitment_secret: [9; 32],
42844296
my_current_per_commitment_point: public_key,
42854297
next_funding_txid: None,
4298+
your_last_funding_locked_txid: None,
4299+
my_current_funding_locked_txid: None,
42864300
};
42874301

42884302
let encoded_value = cr.encode();
@@ -4334,6 +4348,8 @@ mod tests {
43344348
])
43354349
.unwrap(),
43364350
)),
4351+
your_last_funding_locked_txid: None,
4352+
my_current_funding_locked_txid: None,
43374353
};
43384354

43394355
let encoded_value = cr.encode();
@@ -4357,6 +4373,73 @@ mod tests {
43574373
);
43584374
}
43594375

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

0 commit comments

Comments
 (0)