Skip to content

Commit 55ab7e5

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 00b4ade commit 55ab7e5

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
@@ -10557,6 +10557,7 @@ where
1055710557
your_last_per_commitment_secret: remote_last_secret,
1055810558
my_current_per_commitment_point: dummy_pubkey,
1055910559
next_funding_txid: self.maybe_get_next_funding_txid(),
10560+
my_current_funding_locked: None,
1056010561
}
1056110562
}
1056210563

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11085,6 +11085,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1108511085
your_last_per_commitment_secret: [1u8; 32],
1108611086
my_current_per_commitment_point: PublicKey::from_slice(&[2u8; 33]).unwrap(),
1108711087
next_funding_txid: None,
11088+
my_current_funding_locked: None,
1108811089
},
1108911090
});
1109011091
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
@@ -927,6 +927,28 @@ 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 sent by the sending node, which may be:
931+
/// - the txid of the last `splice_locked` it sent, otherwise
932+
/// - the txid of the funding transaction if it sent `channel_ready`, or else
933+
/// - `None` if it has never sent `channel_ready` or `splice_locked`
934+
///
935+
/// Also contains a bitfield indicating which messages should be retransmitted.
936+
pub my_current_funding_locked: Option<FundingLocked>,
937+
}
938+
939+
/// Information exchanged during channel reestablishment about the last funding locked.
940+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
941+
pub struct FundingLocked {
942+
/// The last txid sent by the sending node, which may be either from the last `splice_locked` or
943+
/// for the initial funding transaction if it sent `channel_ready`.
944+
pub txid: Txid,
945+
946+
/// A bitfield indicating which messages should be retransmitted by the receiving node.
947+
///
948+
/// | Bit Position | Name |
949+
/// | ------------- | --------------------------|
950+
/// | 0 | `announcement_signatures` |
951+
pub retransmit_flags: u8,
930952
}
931953

932954
/// An [`announcement_signatures`] message to be sent to or received from a peer.
@@ -2811,6 +2833,12 @@ impl_writeable_msg!(ChannelReestablish, {
28112833
my_current_per_commitment_point,
28122834
}, {
28132835
(0, next_funding_txid, option),
2836+
(5, my_current_funding_locked, option),
2837+
});
2838+
2839+
impl_writeable!(FundingLocked, {
2840+
txid,
2841+
retransmit_flags
28142842
});
28152843

28162844
impl_writeable_msg!(ClosingSigned,
@@ -4283,6 +4311,7 @@ mod tests {
42834311
your_last_per_commitment_secret: [9; 32],
42844312
my_current_per_commitment_point: public_key,
42854313
next_funding_txid: None,
4314+
my_current_funding_locked: None,
42864315
};
42874316

42884317
let encoded_value = cr.encode();
@@ -4334,6 +4363,7 @@ mod tests {
43344363
])
43354364
.unwrap(),
43364365
)),
4366+
my_current_funding_locked: None,
43374367
};
43384368

43394369
let encoded_value = cr.encode();
@@ -4357,6 +4387,65 @@ mod tests {
43574387
);
43584388
}
43594389

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

0 commit comments

Comments
 (0)