@@ -30,7 +30,7 @@ use crate::chain::package::WEIGHT_REVOKED_OUTPUT;
3030use crate :: sign:: EntropySource ;
3131use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
3232use crate :: ln:: msgs:: DecodeError ;
33- use crate :: util:: ser:: { Readable , RequiredWrapper , Writeable , Writer } ;
33+ use crate :: util:: ser:: { Readable , ReadableArgs , RequiredWrapper , Writeable , Writer } ;
3434use crate :: util:: transaction_utils;
3535
3636use bitcoin:: locktime:: absolute:: LockTime ;
@@ -882,7 +882,9 @@ pub struct ChannelTransactionParameters {
882882 pub funding_outpoint : Option < chain:: transaction:: OutPoint > ,
883883 /// This channel's type, as negotiated during channel open. For old objects where this field
884884 /// wasn't serialized, it will default to static_remote_key at deserialization.
885- pub channel_type_features : ChannelTypeFeatures
885+ pub channel_type_features : ChannelTypeFeatures ,
886+ /// The value locked in the channel, denominated in satoshis.
887+ pub channel_value_satoshis : u64 ,
886888}
887889
888890/// Late-bound per-channel counterparty data used to build transactions.
@@ -930,7 +932,7 @@ impl ChannelTransactionParameters {
930932 }
931933
932934 #[ cfg( test) ]
933- pub fn test_dummy ( ) -> Self {
935+ pub fn test_dummy ( channel_value_satoshis : u64 ) -> Self {
934936 let dummy_keys = ChannelPublicKeys {
935937 funding_pubkey : PublicKey :: from_slice ( & [ 2 ; 33 ] ) . unwrap ( ) ,
936938 revocation_basepoint : PublicKey :: from_slice ( & [ 2 ; 33 ] ) . unwrap ( ) . into ( ) ,
@@ -950,6 +952,7 @@ impl ChannelTransactionParameters {
950952 txid : Txid :: from_byte_array ( [ 42 ; 32 ] ) , index : 0
951953 } ) ,
952954 channel_type_features : ChannelTypeFeatures :: empty ( ) ,
955+ channel_value_satoshis,
953956 }
954957 }
955958}
@@ -970,20 +973,22 @@ impl Writeable for ChannelTransactionParameters {
970973 ( 8 , self . funding_outpoint, option) ,
971974 ( 10 , legacy_deserialization_prevention_marker, option) ,
972975 ( 11 , self . channel_type_features, required) ,
976+ ( 13 , self . channel_value_satoshis, required) ,
973977 } ) ;
974978 Ok ( ( ) )
975979 }
976980}
977981
978- impl Readable for ChannelTransactionParameters {
979- fn read < R : io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
982+ impl ReadableArgs < u64 > for ChannelTransactionParameters {
983+ fn read < R : io:: Read > ( reader : & mut R , read_args : u64 ) -> Result < Self , DecodeError > {
980984 let mut holder_pubkeys = RequiredWrapper ( None ) ;
981985 let mut holder_selected_contest_delay = RequiredWrapper ( None ) ;
982986 let mut is_outbound_from_holder = RequiredWrapper ( None ) ;
983987 let mut counterparty_parameters = None ;
984988 let mut funding_outpoint = None ;
985989 let mut _legacy_deserialization_prevention_marker: Option < ( ) > = None ;
986990 let mut channel_type_features = None ;
991+ let mut channel_value_satoshis = None ;
987992
988993 read_tlv_fields ! ( reader, {
989994 ( 0 , holder_pubkeys, required) ,
@@ -993,8 +998,14 @@ impl Readable for ChannelTransactionParameters {
993998 ( 8 , funding_outpoint, option) ,
994999 ( 10 , _legacy_deserialization_prevention_marker, option) ,
9951000 ( 11 , channel_type_features, option) ,
1001+ ( 13 , channel_value_satoshis, option) ,
9961002 } ) ;
9971003
1004+ let channel_value_satoshis = channel_value_satoshis. unwrap_or ( read_args) ;
1005+ if channel_value_satoshis != read_args {
1006+ return Err ( DecodeError :: InvalidValue ) ;
1007+ }
1008+
9981009 let mut additional_features = ChannelTypeFeatures :: empty ( ) ;
9991010 additional_features. set_anchors_nonzero_fee_htlc_tx_required ( ) ;
10001011 chain:: package:: verify_channel_type_features ( & channel_type_features, Some ( & additional_features) ) ?;
@@ -1005,7 +1016,8 @@ impl Readable for ChannelTransactionParameters {
10051016 is_outbound_from_holder : is_outbound_from_holder. 0 . unwrap ( ) ,
10061017 counterparty_parameters,
10071018 funding_outpoint,
1008- channel_type_features : channel_type_features. unwrap_or ( ChannelTypeFeatures :: only_static_remote_key ( ) )
1019+ channel_type_features : channel_type_features. unwrap_or ( ChannelTypeFeatures :: only_static_remote_key ( ) ) ,
1020+ channel_value_satoshis,
10091021 } )
10101022 }
10111023}
@@ -1105,7 +1117,7 @@ impl_writeable_tlv_based!(HolderCommitmentTransaction, {
11051117
11061118impl HolderCommitmentTransaction {
11071119 #[ cfg( test) ]
1108- pub fn dummy ( htlcs : & mut Vec < ( HTLCOutputInCommitment , ( ) ) > ) -> Self {
1120+ pub fn dummy ( channel_value_satoshis : u64 , htlcs : & mut Vec < ( HTLCOutputInCommitment , ( ) ) > ) -> Self {
11091121 let secp_ctx = Secp256k1 :: new ( ) ;
11101122 let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
11111123 let dummy_sig = sign ( & secp_ctx, & secp256k1:: Message :: from_digest ( [ 42 ; 32 ] ) , & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
@@ -1131,6 +1143,7 @@ impl HolderCommitmentTransaction {
11311143 counterparty_parameters : Some ( CounterpartyChannelTransactionParameters { pubkeys : channel_pubkeys. clone ( ) , selected_contest_delay : 0 } ) ,
11321144 funding_outpoint : Some ( chain:: transaction:: OutPoint { txid : Txid :: all_zeros ( ) , index : 0 } ) ,
11331145 channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
1146+ channel_value_satoshis,
11341147 } ;
11351148 let mut counterparty_htlc_sigs = Vec :: new ( ) ;
11361149 for _ in 0 ..htlcs. len ( ) {
@@ -1942,6 +1955,7 @@ mod tests {
19421955 counterparty_parameters : Some ( CounterpartyChannelTransactionParameters { pubkeys : counterparty_pubkeys. clone ( ) , selected_contest_delay : 0 } ) ,
19431956 funding_outpoint : Some ( chain:: transaction:: OutPoint { txid : Txid :: all_zeros ( ) , index : 0 } ) ,
19441957 channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
1958+ channel_value_satoshis : 3000 ,
19451959 } ;
19461960 let htlcs_with_aux = Vec :: new ( ) ;
19471961
0 commit comments