@@ -780,13 +780,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
780
780
Ok ( chan)
781
781
}
782
782
783
- // Utilities to derive keys:
784
-
785
- fn build_local_commitment_secret ( & self , idx : u64 ) -> SecretKey {
786
- let res = self . local_keys . commitment_secret ( idx) ;
787
- SecretKey :: from_slice ( & res) . unwrap ( )
788
- }
789
-
790
783
// Utilities to build transactions:
791
784
792
785
fn get_commitment_transaction_number_obscure_factor ( & self ) -> u64 {
@@ -1118,7 +1111,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1118
1111
/// The result is a transaction which we can revoke ownership of (ie a "local" transaction)
1119
1112
/// TODO Some magic rust shit to compile-time check this?
1120
1113
fn build_local_transaction_keys ( & self , commitment_number : u64 ) -> Result < TxCreationKeys , ChannelError > {
1121
- let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & self . build_local_commitment_secret ( commitment_number ) ) ;
1114
+ let per_commitment_point = self . local_keys . get_per_commitment_point ( commitment_number , & self . secp_ctx ) ;
1122
1115
let delayed_payment_base = & self . local_keys . pubkeys ( ) . delayed_payment_basepoint ;
1123
1116
let htlc_basepoint = & self . local_keys . pubkeys ( ) . htlc_basepoint ;
1124
1117
let their_pubkeys = self . their_pubkeys . as_ref ( ) . unwrap ( ) ;
@@ -2020,8 +2013,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2020
2013
}
2021
2014
}
2022
2015
2023
- let next_per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number - 1 ) ) ;
2024
- let per_commitment_secret = self . local_keys . commitment_secret ( self . cur_local_commitment_transaction_number + 1 ) ;
2016
+ let next_per_commitment_point = self . local_keys . get_per_commitment_point ( self . cur_local_commitment_transaction_number - 1 , & self . secp_ctx ) ;
2017
+ let per_commitment_secret = self . local_keys . revoke_commitment ( self . cur_local_commitment_transaction_number + 1 ) ;
2025
2018
2026
2019
// Update state now that we've passed all the can-fail calls...
2027
2020
let mut need_our_commitment = false ;
@@ -2606,8 +2599,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2606
2599
let funding_locked = if self . monitor_pending_funding_locked {
2607
2600
assert ! ( !self . channel_outbound, "Funding transaction broadcast without FundingBroadcastSafe!" ) ;
2608
2601
self . monitor_pending_funding_locked = false ;
2609
- let next_per_commitment_secret = self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ;
2610
- let next_per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & next_per_commitment_secret) ;
2602
+ let next_per_commitment_point = self . local_keys . get_per_commitment_point ( self . cur_local_commitment_transaction_number , & self . secp_ctx ) ;
2611
2603
Some ( msgs:: FundingLocked {
2612
2604
channel_id : self . channel_id ( ) ,
2613
2605
next_per_commitment_point : next_per_commitment_point,
@@ -2659,8 +2651,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2659
2651
}
2660
2652
2661
2653
fn get_last_revoke_and_ack ( & self ) -> msgs:: RevokeAndACK {
2662
- let next_per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ) ;
2663
- let per_commitment_secret = self . local_keys . commitment_secret ( self . cur_local_commitment_transaction_number + 2 ) ;
2654
+ let next_per_commitment_point = self . local_keys . get_per_commitment_point ( self . cur_local_commitment_transaction_number , & self . secp_ctx ) ;
2655
+ let per_commitment_secret = self . local_keys . revoke_commitment ( self . cur_local_commitment_transaction_number + 2 ) ;
2664
2656
msgs:: RevokeAndACK {
2665
2657
channel_id : self . channel_id ,
2666
2658
per_commitment_secret,
@@ -2743,7 +2735,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2743
2735
if msg. next_remote_commitment_number > 0 {
2744
2736
match msg. data_loss_protect {
2745
2737
OptionalField :: Present ( ref data_loss) => {
2746
- if self . local_keys . commitment_secret ( INITIAL_COMMITMENT_NUMBER - msg. next_remote_commitment_number + 1 ) != data_loss. your_last_per_commitment_secret {
2738
+ // FIXME
2739
+ if self . local_keys . revoke_commitment ( INITIAL_COMMITMENT_NUMBER - msg. next_remote_commitment_number + 1 ) != data_loss. your_last_per_commitment_secret {
2747
2740
return Err ( ChannelError :: Close ( "Peer sent a garbage channel_reestablish with secret key not matching the commitment height provided" ) ) ;
2748
2741
}
2749
2742
if msg. next_remote_commitment_number > INITIAL_COMMITMENT_NUMBER - self . cur_local_commitment_transaction_number {
@@ -2779,8 +2772,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2779
2772
}
2780
2773
2781
2774
// We have OurFundingLocked set!
2782
- let next_per_commitment_secret = self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ;
2783
- let next_per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & next_per_commitment_secret) ;
2775
+ let next_per_commitment_point = self . local_keys . get_per_commitment_point ( self . cur_local_commitment_transaction_number , & self . secp_ctx ) ;
2784
2776
return Ok ( ( Some ( msgs:: FundingLocked {
2785
2777
channel_id : self . channel_id ( ) ,
2786
2778
next_per_commitment_point : next_per_commitment_point,
@@ -2810,8 +2802,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2810
2802
2811
2803
let resend_funding_locked = if msg. next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self . cur_local_commitment_transaction_number == 1 {
2812
2804
// We should never have to worry about MonitorUpdateFailed resending FundingLocked
2813
- let next_per_commitment_secret = self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ;
2814
- let next_per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & next_per_commitment_secret) ;
2805
+ let next_per_commitment_point = self . local_keys . get_per_commitment_point ( self . cur_local_commitment_transaction_number , & self . secp_ctx ) ;
2815
2806
Some ( msgs:: FundingLocked {
2816
2807
channel_id : self . channel_id ( ) ,
2817
2808
next_per_commitment_point : next_per_commitment_point,
@@ -3397,8 +3388,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3397
3388
//a protocol oversight, but I assume I'm just missing something.
3398
3389
if need_commitment_update {
3399
3390
if self . channel_state & ( ChannelState :: MonitorUpdateFailed as u32 ) == 0 {
3400
- let next_per_commitment_secret = self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ;
3401
- let next_per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & next_per_commitment_secret) ;
3391
+ let next_per_commitment_point = self . local_keys . get_per_commitment_point ( self . cur_local_commitment_transaction_number , & self . secp_ctx ) ;
3402
3392
return Ok ( ( Some ( msgs:: FundingLocked {
3403
3393
channel_id : self . channel_id ,
3404
3394
next_per_commitment_point : next_per_commitment_point,
@@ -3449,7 +3439,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3449
3439
panic ! ( "Tried to send an open_channel for a channel that has already advanced" ) ;
3450
3440
}
3451
3441
3452
- let local_commitment_secret = self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ;
3442
+ let first_per_commitment_point = self . local_keys . get_per_commitment_point ( self . cur_local_commitment_transaction_number , & self . secp_ctx ) ;
3453
3443
let local_keys = self . local_keys . pubkeys ( ) ;
3454
3444
3455
3445
msgs:: OpenChannel {
@@ -3469,7 +3459,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3469
3459
payment_point : local_keys. payment_point ,
3470
3460
delayed_payment_basepoint : local_keys. delayed_payment_basepoint ,
3471
3461
htlc_basepoint : local_keys. htlc_basepoint ,
3472
- first_per_commitment_point : PublicKey :: from_secret_key ( & self . secp_ctx , & local_commitment_secret ) ,
3462
+ first_per_commitment_point,
3473
3463
channel_flags : if self . config . announced_channel { 1 } else { 0 } ,
3474
3464
shutdown_scriptpubkey : OptionalField :: Present ( if self . config . commit_upfront_shutdown_pubkey { self . get_closing_scriptpubkey ( ) } else { Builder :: new ( ) . into_script ( ) } )
3475
3465
}
@@ -3486,7 +3476,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3486
3476
panic ! ( "Tried to send an accept_channel for a channel that has already advanced" ) ;
3487
3477
}
3488
3478
3489
- let local_commitment_secret = self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ;
3479
+ let first_per_commitment_point = self . local_keys . get_per_commitment_point ( self . cur_local_commitment_transaction_number , & self . secp_ctx ) ;
3490
3480
let local_keys = self . local_keys . pubkeys ( ) ;
3491
3481
3492
3482
msgs:: AcceptChannel {
@@ -3503,7 +3493,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3503
3493
payment_point : local_keys. payment_point ,
3504
3494
delayed_payment_basepoint : local_keys. delayed_payment_basepoint ,
3505
3495
htlc_basepoint : local_keys. htlc_basepoint ,
3506
- first_per_commitment_point : PublicKey :: from_secret_key ( & self . secp_ctx , & local_commitment_secret ) ,
3496
+ first_per_commitment_point,
3507
3497
shutdown_scriptpubkey : OptionalField :: Present ( if self . config . commit_upfront_shutdown_pubkey { self . get_closing_scriptpubkey ( ) } else { Builder :: new ( ) . into_script ( ) } )
3508
3498
}
3509
3499
}
0 commit comments