@@ -33,7 +33,7 @@ use util::ser::{Writeable, Writer, Readable};
33
33
34
34
use chain:: transaction:: OutPoint ;
35
35
use ln:: chan_utils;
36
- use ln:: chan_utils:: { HTLCOutputInCommitment , make_funding_redeemscript, ChannelPublicKeys , HolderCommitmentTransaction , ChannelTransactionParameters , CommitmentTransaction } ;
36
+ use ln:: chan_utils:: { HTLCOutputInCommitment , make_funding_redeemscript, ChannelPublicKeys , HolderCommitmentTransaction , ChannelTransactionParameters , CommitmentTransaction , CounterpartyChannelTransactionParameters } ;
37
37
use ln:: msgs:: UnsignedChannelAnnouncement ;
38
38
39
39
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
@@ -327,7 +327,7 @@ pub trait ChannelKeys : Send+Clone {
327
327
/// We bind holder_selected_contest_delay late here for API convenience.
328
328
///
329
329
/// Will be called before any signatures are applied.
330
- fn ready_channel ( & mut self , channel_points : & ChannelPublicKeys , counterparty_selected_contest_delay : u16 , holder_selected_contest_delay : u16 , is_outbound : bool , funding_outpoint : & OutPoint ) ;
330
+ fn ready_channel ( & mut self , channel_parameters : & ChannelTransactionParameters ) ;
331
331
}
332
332
333
333
/// A trait to describe an object which can get user secrets and key material.
@@ -389,9 +389,7 @@ pub struct InMemoryChannelKeys {
389
389
/// Holder public keys and basepoints
390
390
pub ( crate ) holder_channel_pubkeys : ChannelPublicKeys ,
391
391
/// Counterparty public keys and counterparty/holder selected_contest_delay, populated on channel acceptance
392
- accepted_channel_data : Option < StaticChannelData > ,
393
- /// Funding outpoint, populated on channel funding creation
394
- funding_outpoint : Option < OutPoint > ,
392
+ channel_parameters : Option < ChannelTransactionParameters > ,
395
393
/// The total value of this channel
396
394
channel_value_satoshis : u64 ,
397
395
/// Key derivation parameters
@@ -423,8 +421,7 @@ impl InMemoryChannelKeys {
423
421
commitment_seed,
424
422
channel_value_satoshis,
425
423
holder_channel_pubkeys,
426
- accepted_channel_data : None ,
427
- funding_outpoint : None ,
424
+ channel_parameters : None ,
428
425
key_derivation_params,
429
426
}
430
427
}
@@ -447,27 +444,27 @@ impl InMemoryChannelKeys {
447
444
448
445
/// Counterparty pubkeys.
449
446
/// Will panic if ready_channel wasn't called.
450
- pub fn counterparty_pubkeys ( & self ) -> & ChannelPublicKeys { & self . accepted_channel_data . as_ref ( ) . unwrap ( ) . counterparty_channel_pubkeys }
447
+ pub fn counterparty_pubkeys ( & self ) -> & ChannelPublicKeys { & self . channel_parameters . as_ref ( ) . unwrap ( ) . counterparty_parameters . as_ref ( ) . unwrap ( ) . pubkeys }
451
448
452
449
/// The contest_delay value specified by our counterparty and applied on holder-broadcastable
453
450
/// transactions, ie the amount of time that we have to wait to recover our funds if we
454
451
/// broadcast a transaction. You'll likely want to pass this to the
455
452
/// ln::chan_utils::build*_transaction functions when signing holder's transactions.
456
453
/// Will panic if ready_channel wasn't called.
457
- pub fn counterparty_selected_contest_delay ( & self ) -> u16 { self . accepted_channel_data . as_ref ( ) . unwrap ( ) . counterparty_selected_contest_delay }
454
+ pub fn counterparty_selected_contest_delay ( & self ) -> u16 { self . channel_parameters . as_ref ( ) . unwrap ( ) . counterparty_parameters . as_ref ( ) . unwrap ( ) . selected_contest_delay }
458
455
459
456
/// The contest_delay value specified by us and applied on transactions broadcastable
460
457
/// by our counterparty, ie the amount of time that they have to wait to recover their funds
461
458
/// if they broadcast a transaction.
462
459
/// Will panic if ready_channel wasn't called.
463
- pub fn holder_selected_contest_delay ( & self ) -> u16 { self . accepted_channel_data . as_ref ( ) . unwrap ( ) . holder_selected_contest_delay }
460
+ pub fn holder_selected_contest_delay ( & self ) -> u16 { self . channel_parameters . as_ref ( ) . unwrap ( ) . holder_selected_contest_delay }
464
461
465
462
/// Whether the holder is the initiator
466
- pub fn is_outbound ( & self ) -> bool { self . accepted_channel_data . as_ref ( ) . unwrap ( ) . is_outbound }
463
+ pub fn is_outbound ( & self ) -> bool { self . channel_parameters . as_ref ( ) . unwrap ( ) . is_outbound_from_holder }
467
464
468
465
/// Funding outpoint
469
466
/// Will panic if ready_channel wasn't called.
470
- pub fn funding_outpoint ( & self ) -> & OutPoint { self . funding_outpoint . as_ref ( ) . unwrap ( ) }
467
+ pub fn funding_outpoint ( & self ) -> & OutPoint { self . channel_parameters . as_ref ( ) . unwrap ( ) . funding_outpoint . as_ref ( ) . unwrap ( ) }
471
468
}
472
469
473
470
impl ChannelKeys for InMemoryChannelKeys {
@@ -487,8 +484,7 @@ impl ChannelKeys for InMemoryChannelKeys {
487
484
let keys = commitment_tx. trust_key_derivation ( ) ;
488
485
489
486
let funding_pubkey = PublicKey :: from_secret_key ( secp_ctx, & self . funding_key ) ;
490
- let accepted_data = self . accepted_channel_data . as_ref ( ) . expect ( "must accept before signing" ) ;
491
- let channel_funding_redeemscript = make_funding_redeemscript ( & funding_pubkey, & accepted_data. counterparty_channel_pubkeys . funding_pubkey ) ;
487
+ let channel_funding_redeemscript = make_funding_redeemscript ( & funding_pubkey, & self . counterparty_pubkeys ( ) . funding_pubkey ) ;
492
488
493
489
let channel_parameters = self . make_channel_parameters ( ) ;
494
490
let directed_channel_parameters = channel_parameters. to_directed ( false ) ;
@@ -498,7 +494,7 @@ impl ChannelKeys for InMemoryChannelKeys {
498
494
499
495
let mut htlc_sigs = Vec :: with_capacity ( commitment_tx. htlcs . len ( ) ) ;
500
496
for htlc in & commitment_tx. htlcs {
501
- let htlc_tx = chan_utils:: build_htlc_transaction ( & commitment_txid, commitment_tx. feerate_per_kw , accepted_data . holder_selected_contest_delay , htlc, & keys. broadcaster_delayed_payment_key , & keys. revocation_key ) ;
497
+ let htlc_tx = chan_utils:: build_htlc_transaction ( & commitment_txid, commitment_tx. feerate_per_kw , self . holder_selected_contest_delay ( ) , htlc, & keys. broadcaster_delayed_payment_key , & keys. revocation_key ) ;
502
498
let htlc_redeemscript = chan_utils:: get_htlc_redeemscript ( & htlc, & keys) ;
503
499
let htlc_sighash = hash_to_message ! ( & bip143:: SigHashCache :: new( & htlc_tx) . signature_hash( 0 , & htlc_redeemscript, htlc. amount_msat / 1000 , SigHashType :: All ) [ ..] ) ;
504
500
let our_htlc_key = match chan_utils:: derive_private_key ( & secp_ctx, & keys. per_commitment_point , & self . htlc_base_key ) {
@@ -527,8 +523,7 @@ impl ChannelKeys for InMemoryChannelKeys {
527
523
#[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
528
524
fn unsafe_sign_holder_commitment < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , holder_commitment_tx : & HolderCommitmentTransaction , secp_ctx : & Secp256k1 < T > ) -> Result < Signature , ( ) > {
529
525
let funding_pubkey = PublicKey :: from_secret_key ( secp_ctx, & self . funding_key ) ;
530
- let counterparty_channel_pubkeys = & self . accepted_channel_data . as_ref ( ) . expect ( "must accept before signing" ) . counterparty_channel_pubkeys ;
531
- let channel_funding_redeemscript = make_funding_redeemscript ( & funding_pubkey, & counterparty_channel_pubkeys. funding_pubkey ) ;
526
+ let channel_funding_redeemscript = make_funding_redeemscript ( & funding_pubkey, & self . counterparty_pubkeys ( ) . funding_pubkey ) ;
532
527
let channel_parameters = self . make_channel_parameters ( ) ;
533
528
let channel_parameters = channel_parameters. to_directed ( true ) ;
534
529
@@ -595,8 +590,7 @@ impl ChannelKeys for InMemoryChannelKeys {
595
590
if closing_tx. output . len ( ) > 2 { return Err ( ( ) ) ; }
596
591
597
592
let funding_pubkey = PublicKey :: from_secret_key ( secp_ctx, & self . funding_key ) ;
598
- let counterparty_channel_data = self . accepted_channel_data . as_ref ( ) . expect ( "must accept before signing" ) ;
599
- let channel_funding_redeemscript = make_funding_redeemscript ( & funding_pubkey, & counterparty_channel_data. counterparty_channel_pubkeys . funding_pubkey ) ;
593
+ let channel_funding_redeemscript = make_funding_redeemscript ( & funding_pubkey, & self . counterparty_pubkeys ( ) . funding_pubkey ) ;
600
594
601
595
let sighash = hash_to_message ! ( & bip143:: SigHashCache :: new( closing_tx)
602
596
. signature_hash( 0 , & channel_funding_redeemscript, self . channel_value_satoshis, SigHashType :: All ) [ ..] ) ;
@@ -608,23 +602,13 @@ impl ChannelKeys for InMemoryChannelKeys {
608
602
Ok ( secp_ctx. sign ( & msghash, & self . funding_key ) )
609
603
}
610
604
611
- fn ready_channel ( & mut self , channel_pubkeys : & ChannelPublicKeys , counterparty_selected_contest_delay : u16 , holder_selected_contest_delay : u16 , is_outbound : bool , funding_outpoint : & OutPoint ) {
612
- assert ! ( self . accepted_channel_data. is_none( ) , "Acceptance already noted" ) ;
613
- self . accepted_channel_data = Some ( StaticChannelData {
614
- counterparty_channel_pubkeys : channel_pubkeys. clone ( ) ,
615
- counterparty_selected_contest_delay,
616
- holder_selected_contest_delay,
617
- is_outbound,
618
- } ) ;
619
- assert ! ( self . funding_outpoint. is_none( ) , "Funding creation already noted" ) ;
620
- self . funding_outpoint = Some ( funding_outpoint. clone ( ) ) ;
605
+ fn ready_channel ( & mut self , channel_parameters : & ChannelTransactionParameters ) {
606
+ assert ! ( self . channel_parameters. is_none( ) , "Acceptance already noted" ) ;
607
+ assert ! ( channel_parameters. is_populated( ) , "Channel parameters must be fully populated" ) ;
608
+ self . channel_parameters = Some ( channel_parameters. clone ( ) ) ;
621
609
}
622
610
}
623
611
624
-
625
- impl_writeable ! ( StaticChannelData , 0 ,
626
- { counterparty_channel_pubkeys, counterparty_selected_contest_delay, holder_selected_contest_delay, is_outbound } ) ;
627
-
628
612
impl Writeable for InMemoryChannelKeys {
629
613
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , Error > {
630
614
self . funding_key . write ( writer) ?;
@@ -633,8 +617,7 @@ impl Writeable for InMemoryChannelKeys {
633
617
self . delayed_payment_base_key . write ( writer) ?;
634
618
self . htlc_base_key . write ( writer) ?;
635
619
self . commitment_seed . write ( writer) ?;
636
- self . accepted_channel_data . write ( writer) ?;
637
- self . funding_outpoint . write ( writer) ?;
620
+ self . channel_parameters . write ( writer) ?;
638
621
self . channel_value_satoshis . write ( writer) ?;
639
622
self . key_derivation_params . 0 . write ( writer) ?;
640
623
self . key_derivation_params . 1 . write ( writer) ?;
@@ -652,7 +635,6 @@ impl Readable for InMemoryChannelKeys {
652
635
let htlc_base_key = Readable :: read ( reader) ?;
653
636
let commitment_seed = Readable :: read ( reader) ?;
654
637
let counterparty_channel_data = Readable :: read ( reader) ?;
655
- let funding_outpoint = Readable :: read ( reader) ?;
656
638
let channel_value_satoshis = Readable :: read ( reader) ?;
657
639
let secp_ctx = Secp256k1 :: signing_only ( ) ;
658
640
let holder_channel_pubkeys =
@@ -671,8 +653,7 @@ impl Readable for InMemoryChannelKeys {
671
653
commitment_seed,
672
654
channel_value_satoshis,
673
655
holder_channel_pubkeys,
674
- accepted_channel_data : counterparty_channel_data,
675
- funding_outpoint,
656
+ channel_parameters : counterparty_channel_data,
676
657
key_derivation_params : ( params_1, params_2) ,
677
658
} )
678
659
}
@@ -858,11 +839,13 @@ impl InMemoryChannelKeys {
858
839
pub ( crate ) fn make_channel_parameters ( & self ) -> ChannelTransactionParameters {
859
840
ChannelTransactionParameters {
860
841
holder_pubkeys : self . pubkeys ( ) . clone ( ) ,
861
- counterparty_pubkeys : self . counterparty_pubkeys ( ) . clone ( ) ,
862
842
holder_selected_contest_delay : self . holder_selected_contest_delay ( ) ,
863
- counterparty_selected_contest_delay : self . counterparty_selected_contest_delay ( ) ,
864
- funding_outpoint : self . funding_outpoint ( ) . into_bitcoin_outpoint ( ) ,
865
- is_outbound_from_holder : self . is_outbound ( )
843
+ is_outbound_from_holder : self . is_outbound ( ) ,
844
+ counterparty_parameters : Some ( CounterpartyChannelTransactionParameters {
845
+ pubkeys : self . counterparty_pubkeys ( ) . clone ( ) ,
846
+ selected_contest_delay : self . counterparty_selected_contest_delay ( ) ,
847
+ } ) ,
848
+ funding_outpoint : Some ( self . funding_outpoint ( ) . clone ( ) ) ,
866
849
}
867
850
}
868
851
}
0 commit comments