@@ -927,6 +927,28 @@ pub struct ChannelReestablish {
927
927
/// * `channel_reestablish`-sending node: https:///github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2466-L2470
928
928
/// * `channel_reestablish`-receiving node: https:///github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2520-L2531
929
929
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 ,
930
952
}
931
953
932
954
/// An [`announcement_signatures`] message to be sent to or received from a peer.
@@ -2811,6 +2833,12 @@ impl_writeable_msg!(ChannelReestablish, {
2811
2833
my_current_per_commitment_point,
2812
2834
} , {
2813
2835
( 0 , next_funding_txid, option) ,
2836
+ ( 5 , my_current_funding_locked, option) ,
2837
+ } ) ;
2838
+
2839
+ impl_writeable ! ( FundingLocked , {
2840
+ txid,
2841
+ retransmit_flags
2814
2842
} ) ;
2815
2843
2816
2844
impl_writeable_msg ! ( ClosingSigned ,
@@ -4283,6 +4311,7 @@ mod tests {
4283
4311
your_last_per_commitment_secret : [ 9 ; 32 ] ,
4284
4312
my_current_per_commitment_point : public_key,
4285
4313
next_funding_txid : None ,
4314
+ my_current_funding_locked : None ,
4286
4315
} ;
4287
4316
4288
4317
let encoded_value = cr. encode ( ) ;
@@ -4334,6 +4363,7 @@ mod tests {
4334
4363
] )
4335
4364
. unwrap ( ) ,
4336
4365
) ) ,
4366
+ my_current_funding_locked : None ,
4337
4367
} ;
4338
4368
4339
4369
let encoded_value = cr. encode ( ) ;
@@ -4357,6 +4387,65 @@ mod tests {
4357
4387
) ;
4358
4388
}
4359
4389
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
+
4360
4449
macro_rules! get_keys_from {
4361
4450
( $slice: expr, $secp_ctx: expr) => { {
4362
4451
let privkey = SecretKey :: from_slice( & <Vec <u8 >>:: from_hex( $slice) . unwrap( ) [ ..] ) . unwrap( ) ;
0 commit comments