@@ -554,6 +554,20 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, contest_del
554
554
}
555
555
}
556
556
557
+ /// Static channel fields used to build transactions given per-commitment fields (CommitmentTransactionInfo)
558
+ pub struct ChannelStaticInfo {
559
+ /// Broadcaster public keys
560
+ pub broadcaster_pubkeys : ChannelPublicKeys ,
561
+ /// Counter-signatory public keys
562
+ pub countersignatory_pubkeys : ChannelPublicKeys ,
563
+ /// The funding outpoint
564
+ pub funding_outpoint : OutPoint ,
565
+ /// The contest delay selected by the countersignatory
566
+ pub contest_delay : u16 ,
567
+ /// Whether the channel is outbound from the point of view of the broadcaster
568
+ pub is_outbound : bool ,
569
+ }
570
+
557
571
/// This class tracks the information needed to build a holder's commitment transaction and to actually
558
572
/// build and sign. It is used for holder transactions that we sign only when needed.
559
573
pub struct HolderCommitmentTransactionInfo {
@@ -566,8 +580,8 @@ pub struct HolderCommitmentTransactionInfo {
566
580
}
567
581
568
582
impl HolderCommitmentTransactionInfo {
569
- pub ( crate ) fn to_holder_commitment_tx < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , holder_pubkeys : & ChannelPublicKeys , counterparty_pubkeys : & ChannelPublicKeys , funding_outpoint : & OutPoint , contest_delay : u16 , is_outbound : bool , secp_ctx : & Secp256k1 < T > ) -> HolderCommitmentTransaction {
570
- self . info . to_holder_commitment_tx ( self . counterparty_sig , self . htlcs_with_sig . clone ( ) , holder_pubkeys , counterparty_pubkeys , funding_outpoint , contest_delay , is_outbound , secp_ctx)
583
+ pub ( crate ) fn to_holder_commitment_tx < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_static_info : & ChannelStaticInfo , secp_ctx : & Secp256k1 < T > ) -> HolderCommitmentTransaction {
584
+ self . info . to_holder_commitment_tx ( self . counterparty_sig , self . htlcs_with_sig . clone ( ) , channel_static_info , secp_ctx)
571
585
}
572
586
}
573
587
@@ -638,16 +652,12 @@ impl CommitmentTransactionInfo {
638
652
/// is_outbound is true if the channel is outbound from the point of view of the broadcaster
639
653
pub fn build < T : secp256k1:: Signing + secp256k1:: Verification > (
640
654
& self ,
641
- broadcaster_pubkeys : & ChannelPublicKeys ,
642
- countersignatory_pubkeys : & ChannelPublicKeys ,
643
- funding_outpoint : & OutPoint ,
644
- contest_delay : u16 ,
645
- is_outbound : bool ,
655
+ channel_static_info : & ChannelStaticInfo ,
646
656
secp_ctx : & Secp256k1 < T > ,
647
657
) -> Result < ( bitcoin:: Transaction , Vec < HTLCOutputInCommitment > , Vec < Script > ) , ( ) > {
648
- let ( obscured_commitment_transaction_number, txins) = self . build_inputs ( broadcaster_pubkeys , countersignatory_pubkeys , funding_outpoint , is_outbound ) ;
658
+ let ( obscured_commitment_transaction_number, txins) = self . build_inputs ( channel_static_info ) ;
649
659
650
- let mut txouts = self . build_outputs ( broadcaster_pubkeys , countersignatory_pubkeys , contest_delay , secp_ctx) ?;
660
+ let mut txouts = self . build_outputs ( channel_static_info , secp_ctx) ?;
651
661
652
662
let mut outputs = Vec :: with_capacity ( txouts. len ( ) ) ;
653
663
let mut scripts = Vec :: with_capacity ( txouts. len ( ) ) ;
@@ -673,9 +683,9 @@ impl CommitmentTransactionInfo {
673
683
) )
674
684
}
675
685
676
- fn build_outputs < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , broadcaster_pubkeys : & ChannelPublicKeys , countersignatory_pubkeys : & ChannelPublicKeys , contest_delay : u16 , secp_ctx : & Secp256k1 < T > ) -> Result < Vec < ( TxOut , ( Script , Option < HTLCOutputInCommitment > ) ) > , ( ) > {
686
+ fn build_outputs < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_static_info : & ChannelStaticInfo , secp_ctx : & Secp256k1 < T > ) -> Result < Vec < ( TxOut , ( Script , Option < HTLCOutputInCommitment > ) ) > , ( ) > {
677
687
let htlcs = self . htlcs . iter ( ) . map ( |h| ( h. clone ( ) , ( ) ) ) . collect ( ) ;
678
- let mut txouts = Self :: do_build_outputs ( & self . keys , self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & htlcs, broadcaster_pubkeys, countersignatory_pubkeys, contest_delay, secp_ctx) ?;
688
+ let mut txouts = Self :: do_build_outputs ( & self . keys , self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & htlcs, & channel_static_info . broadcaster_pubkeys , & channel_static_info . countersignatory_pubkeys , channel_static_info . contest_delay , secp_ctx) ?;
679
689
let outs = txouts. drain ( ..) . map ( |( out, ( s, extra) ) | ( out, ( s, extra. map ( |( p, _) | p) ) ) ) . collect ( ) ;
680
690
Ok ( outs)
681
691
}
@@ -750,11 +760,11 @@ impl CommitmentTransactionInfo {
750
760
Ok ( txouts)
751
761
}
752
762
753
- fn build_inputs ( & self , broadcaster_pubkeys : & ChannelPublicKeys , countersignatory_pubkeys : & ChannelPublicKeys , funding_outpoint : & OutPoint , is_outbound : bool ) -> ( u64 , Vec < TxIn > ) {
763
+ fn build_inputs ( & self , channel_statc_info : & ChannelStaticInfo ) -> ( u64 , Vec < TxIn > ) {
754
764
let commitment_transaction_number_obscure_factor = get_commitment_transaction_number_obscure_factor (
755
- & broadcaster_pubkeys. payment_point ,
756
- & countersignatory_pubkeys. payment_point ,
757
- is_outbound,
765
+ & channel_statc_info . broadcaster_pubkeys . payment_point ,
766
+ & channel_statc_info . countersignatory_pubkeys . payment_point ,
767
+ channel_statc_info . is_outbound ,
758
768
) ;
759
769
760
770
let obscured_commitment_transaction_number =
@@ -763,7 +773,7 @@ impl CommitmentTransactionInfo {
763
773
let txins = {
764
774
let mut ins: Vec < TxIn > = Vec :: new ( ) ;
765
775
ins. push ( TxIn {
766
- previous_output : funding_outpoint. clone ( ) ,
776
+ previous_output : channel_statc_info . funding_outpoint . clone ( ) ,
767
777
script_sig : Script :: new ( ) ,
768
778
sequence : ( ( 0x80 as u32 ) << 8 * 3 )
769
779
| ( ( obscured_commitment_transaction_number >> 3 * 8 ) as u32 ) ,
@@ -778,24 +788,24 @@ impl CommitmentTransactionInfo {
778
788
/// because we are about to broadcast a holder transaction.
779
789
///
780
790
/// is_outbound is true if the channel is outbound from the point of view of the broadcaster
781
- pub fn get_signature < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , broadcaster_pubkeys : & ChannelPublicKeys , countersignatory_pubkeys : & ChannelPublicKeys , funding_outpoint : & OutPoint , contest_delay : u16 , is_outbound : bool , funding_key : & SecretKey , funding_redeemscript : & Script , channel_value_satoshis : u64 , secp_ctx : & Secp256k1 < T > ) -> Signature {
782
- let sighash = self . get_sighash ( broadcaster_pubkeys , countersignatory_pubkeys , funding_outpoint , contest_delay , is_outbound , funding_redeemscript, channel_value_satoshis, secp_ctx) . 0 ;
791
+ pub fn get_signature < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_static_info : & ChannelStaticInfo , funding_key : & SecretKey , funding_redeemscript : & Script , channel_value_satoshis : u64 , secp_ctx : & Secp256k1 < T > ) -> Signature {
792
+ let sighash = self . get_sighash ( channel_static_info , funding_redeemscript, channel_value_satoshis, secp_ctx) . 0 ;
783
793
secp_ctx. sign ( & sighash, funding_key)
784
794
}
785
795
786
796
/// Get the sighash and the transaction.
787
797
///
788
798
/// Builds the transaction and computes the sighash. This can be used to verify a signature.
789
- pub fn get_sighash < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , broadcaster_pubkeys : & ChannelPublicKeys , countersignatory_pubkeys : & ChannelPublicKeys , funding_outpoint : & OutPoint , contest_delay : u16 , is_outbound : bool , funding_redeemscript : & Script , channel_value_satoshis : u64 , secp_ctx : & Secp256k1 < T > ) -> ( Message , Transaction ) {
790
- let ( unsigned_tx, _, _) = self . build ( broadcaster_pubkeys , countersignatory_pubkeys , funding_outpoint , contest_delay , is_outbound , secp_ctx) . unwrap ( ) ;
799
+ pub fn get_sighash < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_static_info : & ChannelStaticInfo , funding_redeemscript : & Script , channel_value_satoshis : u64 , secp_ctx : & Secp256k1 < T > ) -> ( Message , Transaction ) {
800
+ let ( unsigned_tx, _, _) = self . build ( channel_static_info , secp_ctx) . unwrap ( ) ;
791
801
let sighash = hash_to_message ! ( & bip143:: SigHashCache :: new( & unsigned_tx)
792
802
. signature_hash( 0 , funding_redeemscript, channel_value_satoshis, SigHashType :: All ) [ ..] ) ;
793
803
( sighash, unsigned_tx)
794
804
}
795
805
796
- pub ( crate ) fn to_holder_commitment_tx < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , counterparty_sig : Signature , htlcs_with_sig : Vec < ( HTLCOutputInCommitment , Option < Signature > ) > , holder_pubkeys : & ChannelPublicKeys , counterparty_pubkeys : & ChannelPublicKeys , funding_outpoint : & OutPoint , contest_delay : u16 , is_outbound : bool , secp_ctx : & Secp256k1 < T > ) -> HolderCommitmentTransaction {
797
- let ( tx, _, _) = self . build ( holder_pubkeys , counterparty_pubkeys , funding_outpoint , contest_delay , is_outbound , secp_ctx) . unwrap ( ) ;
798
- HolderCommitmentTransaction :: new_missing_holder_sig ( tx, counterparty_sig, & holder_pubkeys . funding_pubkey , & counterparty_pubkeys . funding_pubkey , self . keys . clone ( ) , self . feerate_per_kw , htlcs_with_sig)
806
+ pub ( crate ) fn to_holder_commitment_tx < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , counterparty_sig : Signature , htlcs_with_sig : Vec < ( HTLCOutputInCommitment , Option < Signature > ) > , channel_static_info : & ChannelStaticInfo , secp_ctx : & Secp256k1 < T > ) -> HolderCommitmentTransaction {
807
+ let ( tx, _, _) = self . build ( channel_static_info , secp_ctx) . unwrap ( ) ;
808
+ HolderCommitmentTransaction :: new_missing_holder_sig ( tx, counterparty_sig, & channel_static_info . broadcaster_pubkeys . funding_pubkey , & channel_static_info . countersignatory_pubkeys . funding_pubkey , self . keys . clone ( ) , self . feerate_per_kw , htlcs_with_sig)
799
809
}
800
810
}
801
811
0 commit comments