@@ -217,32 +217,33 @@ pub fn derive_public_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_com
217217
218218/// Derives a per-commitment-transaction revocation key from its constituent parts.
219219///
220+ /// Only the cheating participant owns a valid witness to propagate a revoked
221+ /// commitment transaction, thus per_commitment_secret always come from cheater
222+ /// and revocation_base_secret always come from punisher, which is the broadcaster
223+ /// of the transaction spending with this key knowledge.
224+ ///
220225/// Note that this is infallible iff we trust that at least one of the two input keys are randomly
221226/// generated (ie our own).
222- pub fn derive_private_revocation_key < T : secp256k1:: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_secret : & SecretKey , revocation_base_secret : & SecretKey ) -> Result < SecretKey , SecpError > {
223- let revocation_base_point = PublicKey :: from_secret_key ( & secp_ctx, & revocation_base_secret ) ;
227+ pub fn derive_private_revocation_key < T : secp256k1:: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_secret : & SecretKey , countersignatory_revocation_base_secret : & SecretKey ) -> Result < SecretKey , SecpError > {
228+ let countersignatory_revocation_base_point = PublicKey :: from_secret_key ( & secp_ctx, & countersignatory_revocation_base_secret ) ;
224229 let per_commitment_point = PublicKey :: from_secret_key ( & secp_ctx, & per_commitment_secret) ;
225230
226231 let rev_append_commit_hash_key = {
227232 let mut sha = Sha256 :: engine ( ) ;
228- sha. input ( & revocation_base_point . serialize ( ) ) ;
233+ sha. input ( & countersignatory_revocation_base_point . serialize ( ) ) ;
229234 sha. input ( & per_commitment_point. serialize ( ) ) ;
230235
231236 Sha256 :: from_engine ( sha) . into_inner ( )
232237 } ;
233238 let commit_append_rev_hash_key = {
234239 let mut sha = Sha256 :: engine ( ) ;
235240 sha. input ( & per_commitment_point. serialize ( ) ) ;
236- sha. input ( & revocation_base_point . serialize ( ) ) ;
241+ sha. input ( & countersignatory_revocation_base_point . serialize ( ) ) ;
237242
238243 Sha256 :: from_engine ( sha) . into_inner ( )
239244 } ;
240245
241- // Only the transaction broadcaster owns a valid witness to propagate
242- // a revoked commitment transaction, thus per_commitment_secret always
243- // come from broadcaster and revocation_base_secret always come
244- // from countersignatory of the transaction.
245- let mut countersignatory_contrib = revocation_base_secret. clone ( ) ;
246+ let mut countersignatory_contrib = countersignatory_revocation_base_secret. clone ( ) ;
246247 countersignatory_contrib. mul_assign ( & rev_append_commit_hash_key) ?;
247248 let mut broadcaster_contrib = per_commitment_secret. clone ( ) ;
248249 broadcaster_contrib. mul_assign ( & commit_append_rev_hash_key) ?;
@@ -254,29 +255,30 @@ pub fn derive_private_revocation_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1
254255/// the public equivalend of derive_private_revocation_key - using only public keys to derive a
255256/// public key instead of private keys.
256257///
258+ /// Only the cheating participant owns a valid witness to propagate a revoked
259+ /// commitment transaction, thus per_commitment_point always come from cheater
260+ /// and revocation_base_point always come from punisher, which is the broadcaster
261+ /// of the transaction spending with this key knowledge.
262+ ///
257263/// Note that this is infallible iff we trust that at least one of the two input keys are randomly
258264/// generated (ie our own).
259- pub fn derive_public_revocation_key < T : secp256k1:: Verification > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , revocation_base_point : & PublicKey ) -> Result < PublicKey , SecpError > {
265+ pub fn derive_public_revocation_key < T : secp256k1:: Verification > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , countersignatory_revocation_base_point : & PublicKey ) -> Result < PublicKey , SecpError > {
260266 let rev_append_commit_hash_key = {
261267 let mut sha = Sha256 :: engine ( ) ;
262- sha. input ( & revocation_base_point . serialize ( ) ) ;
268+ sha. input ( & countersignatory_revocation_base_point . serialize ( ) ) ;
263269 sha. input ( & per_commitment_point. serialize ( ) ) ;
264270
265271 Sha256 :: from_engine ( sha) . into_inner ( )
266272 } ;
267273 let commit_append_rev_hash_key = {
268274 let mut sha = Sha256 :: engine ( ) ;
269275 sha. input ( & per_commitment_point. serialize ( ) ) ;
270- sha. input ( & revocation_base_point . serialize ( ) ) ;
276+ sha. input ( & countersignatory_revocation_base_point . serialize ( ) ) ;
271277
272278 Sha256 :: from_engine ( sha) . into_inner ( )
273279 } ;
274280
275- // Only the transaction broadcaster owns a valid witness to propagate
276- // a revoked commitment transaction, thus per_commitment_point always
277- // come from broadcaster and revocation_base_point always come
278- // from countersignatory of the transaction.
279- let mut countersignatory_contrib = revocation_base_point. clone ( ) ;
281+ let mut countersignatory_contrib = countersignatory_revocation_base_point. clone ( ) ;
280282 countersignatory_contrib. mul_assign ( & secp_ctx, & rev_append_commit_hash_key) ?;
281283 let mut broadcaster_contrib = per_commitment_point. clone ( ) ;
282284 broadcaster_contrib. mul_assign ( & secp_ctx, & commit_append_rev_hash_key) ?;
@@ -298,7 +300,7 @@ pub fn derive_public_revocation_key<T: secp256k1::Verification>(secp_ctx: &Secp2
298300pub struct TxCreationKeys {
299301 /// The broadcaster's per-commitment public key which was used to derive the other keys.
300302 pub per_commitment_point : PublicKey ,
301- /// The broadcaster's revocation key which is used to allow the broadcaster of the commitment
303+ /// The revocation key which is used to allow the broadcaster of the commitment
302304 /// transaction to provide their counterparty the ability to punish them if they broadcast
303305 /// an old state.
304306 pub revocation_key : PublicKey ,
@@ -307,10 +309,10 @@ pub struct TxCreationKeys {
307309 /// Countersignatory's HTLC Key
308310 pub countersignatory_htlc_key : PublicKey ,
309311 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
310- pub delayed_payment_key : PublicKey ,
312+ pub broadcaster_delayed_payment_key : PublicKey ,
311313}
312314impl_writeable ! ( TxCreationKeys , 33 * 6 ,
313- { per_commitment_point, revocation_key, broadcaster_htlc_key, countersignatory_htlc_key, delayed_payment_key } ) ;
315+ { per_commitment_point, revocation_key, broadcaster_htlc_key, countersignatory_htlc_key, broadcaster_delayed_payment_key } ) ;
314316
315317/// The per-commitment point and a set of pre-calculated public keys used for transaction creation
316318/// in the signer.
@@ -377,22 +379,22 @@ impl TxCreationKeys {
377379 revocation_key : derive_public_revocation_key ( & secp_ctx, & per_commitment_point, & countersignatory_revocation_base) ?,
378380 broadcaster_htlc_key : derive_public_key ( & secp_ctx, & per_commitment_point, & broadcaster_htlc_base) ?,
379381 countersignatory_htlc_key : derive_public_key ( & secp_ctx, & per_commitment_point, & countersignatory_htlc_base) ?,
380- delayed_payment_key : derive_public_key ( & secp_ctx, & per_commitment_point, & broadcaster_delayed_payment_base) ?,
382+ broadcaster_delayed_payment_key : derive_public_key ( & secp_ctx, & per_commitment_point, & broadcaster_delayed_payment_base) ?,
381383 } )
382384 }
383385}
384386
385387/// A script either spendable by the revocation
386- /// key or the delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
388+ /// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
387389/// Encumbering a `to_local` output on a commitment transaction or 2nd-stage HTLC transactions.
388- pub fn get_revokeable_redeemscript ( revocation_key : & PublicKey , contest_delay : u16 , delayed_payment_key : & PublicKey ) -> Script {
390+ pub fn get_revokeable_redeemscript ( revocation_key : & PublicKey , contest_delay : u16 , broadcaster_delayed_payment_key : & PublicKey ) -> Script {
389391 Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_IF )
390392 . push_slice ( & revocation_key. serialize ( ) )
391393 . push_opcode ( opcodes:: all:: OP_ELSE )
392394 . push_int ( contest_delay as i64 )
393395 . push_opcode ( opcodes:: all:: OP_CSV )
394396 . push_opcode ( opcodes:: all:: OP_DROP )
395- . push_slice ( & delayed_payment_key . serialize ( ) )
397+ . push_slice ( & broadcaster_delayed_payment_key . serialize ( ) )
396398 . push_opcode ( opcodes:: all:: OP_ENDIF )
397399 . push_opcode ( opcodes:: all:: OP_CHECKSIG )
398400 . into_script ( )
@@ -516,7 +518,7 @@ pub fn make_funding_redeemscript(broadcaster: &PublicKey, countersignatory: &Pub
516518}
517519
518520/// panics if htlc.transaction_output_index.is_none()!
519- pub fn build_htlc_transaction ( prev_hash : & Txid , feerate_per_kw : u32 , contest_delay : u16 , htlc : & HTLCOutputInCommitment , delayed_payment_key : & PublicKey , revocation_key : & PublicKey ) -> Transaction {
521+ pub fn build_htlc_transaction ( prev_hash : & Txid , feerate_per_kw : u32 , contest_delay : u16 , htlc : & HTLCOutputInCommitment , broadcaster_delayed_payment_key : & PublicKey , revocation_key : & PublicKey ) -> Transaction {
520522 let mut txins: Vec < TxIn > = Vec :: new ( ) ;
521523 txins. push ( TxIn {
522524 previous_output : OutPoint {
@@ -536,7 +538,7 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, contest_del
536538
537539 let mut txouts: Vec < TxOut > = Vec :: new ( ) ;
538540 txouts. push ( TxOut {
539- script_pubkey : get_revokeable_redeemscript ( revocation_key, contest_delay, delayed_payment_key ) . to_v0_p2wsh ( ) ,
541+ script_pubkey : get_revokeable_redeemscript ( revocation_key, contest_delay, broadcaster_delayed_payment_key ) . to_v0_p2wsh ( ) ,
540542 value : htlc. amount_msat / 1000 - total_fee //TODO: BOLT 3 does not specify if we should add amount_msat before dividing or if we should divide by 1000 before subtracting (as we do here)
541543 } ) ;
542544
@@ -605,7 +607,7 @@ impl LocalCommitmentTransaction {
605607 revocation_key : dummy_key. clone ( ) ,
606608 broadcaster_htlc_key : dummy_key. clone ( ) ,
607609 countersignatory_htlc_key : dummy_key. clone ( ) ,
608- delayed_payment_key : dummy_key. clone ( ) ,
610+ broadcaster_delayed_payment_key : dummy_key. clone ( ) ,
609611 } ,
610612 feerate_per_kw : 0 ,
611613 per_htlc : Vec :: new ( )
@@ -701,7 +703,7 @@ impl LocalCommitmentTransaction {
701703
702704 for this_htlc in self . per_htlc . iter ( ) {
703705 if this_htlc. 0 . transaction_output_index . is_some ( ) {
704- let htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . delayed_payment_key , & self . local_keys . revocation_key ) ;
706+ let htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . broadcaster_delayed_payment_key , & self . local_keys . revocation_key ) ;
705707
706708 let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys ( & this_htlc. 0 , & self . local_keys . broadcaster_htlc_key , & self . local_keys . countersignatory_htlc_key , & self . local_keys . revocation_key ) ;
707709
@@ -724,7 +726,7 @@ impl LocalCommitmentTransaction {
724726 // Further, we should never be provided the preimage for an HTLC-Timeout transaction.
725727 if this_htlc. 0 . offered && preimage. is_some ( ) { unreachable ! ( ) ; }
726728
727- let mut htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . delayed_payment_key , & self . local_keys . revocation_key ) ;
729+ let mut htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . broadcaster_delayed_payment_key , & self . local_keys . revocation_key ) ;
728730 // Channel should have checked that we have a remote signature for this HTLC at
729731 // creation, and we should have a sensible htlc transaction:
730732 assert ! ( this_htlc. 1 . is_some( ) ) ;
0 commit comments