@@ -227,12 +227,12 @@ pub fn derive_private_revocation_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1
227
227
Sha256 :: from_engine ( sha) . into_inner ( )
228
228
} ;
229
229
230
- let mut part_a = revocation_base_secret. clone ( ) ;
231
- part_a . mul_assign ( & rev_append_commit_hash_key) ?;
232
- let mut part_b = per_commitment_secret. clone ( ) ;
233
- part_b . mul_assign ( & commit_append_rev_hash_key) ?;
234
- part_a . add_assign ( & part_b [ ..] ) ?;
235
- Ok ( part_a )
230
+ let mut counterparty_contrib = revocation_base_secret. clone ( ) ;
231
+ counterparty_contrib . mul_assign ( & rev_append_commit_hash_key) ?;
232
+ let mut our_contrib = per_commitment_secret. clone ( ) ;
233
+ our_contrib . mul_assign ( & commit_append_rev_hash_key) ?;
234
+ counterparty_contrib . add_assign ( & our_contrib [ ..] ) ?;
235
+ Ok ( counterparty_contrib )
236
236
}
237
237
238
238
/// Derives a per-commitment-transaction revocation public key from its constituent parts. This is
@@ -257,11 +257,11 @@ pub fn derive_public_revocation_key<T: secp256k1::Verification>(secp_ctx: &Secp2
257
257
Sha256 :: from_engine ( sha) . into_inner ( )
258
258
} ;
259
259
260
- let mut part_a = revocation_base_point. clone ( ) ;
261
- part_a . mul_assign ( & secp_ctx, & rev_append_commit_hash_key) ?;
262
- let mut part_b = per_commitment_point. clone ( ) ;
263
- part_b . mul_assign ( & secp_ctx, & commit_append_rev_hash_key) ?;
264
- part_a . combine ( & part_b )
260
+ let mut counterparty_contrib = revocation_base_point. clone ( ) ;
261
+ counterparty_contrib . mul_assign ( & secp_ctx, & rev_append_commit_hash_key) ?;
262
+ let mut our_contrib = per_commitment_point. clone ( ) ;
263
+ our_contrib . mul_assign ( & secp_ctx, & commit_append_rev_hash_key) ?;
264
+ counterparty_contrib . combine ( & our_contrib )
265
265
}
266
266
267
267
/// The set of public keys which are used in the creation of one commitment transaction.
@@ -273,15 +273,15 @@ pub struct TxCreationKeys {
273
273
/// The revocation key which is used to allow the owner of the commitment transaction to
274
274
/// provide their counterparty the ability to punish them if they broadcast an old state.
275
275
pub ( crate ) revocation_key : PublicKey ,
276
- /// A 's HTLC Key
277
- pub ( crate ) a_htlc_key : PublicKey ,
278
- /// B 's HTLC Key
279
- pub ( crate ) b_htlc_key : PublicKey ,
280
- /// A 's Payment Key (which isn't allowed to be spent from for some delay)
281
- pub ( crate ) a_delayed_payment_key : PublicKey ,
276
+ /// Local 's HTLC Key
277
+ pub ( crate ) local_htlc_key : PublicKey ,
278
+ /// Remote 's HTLC Key
279
+ pub ( crate ) remote_htlc_key : PublicKey ,
280
+ /// Local 's Payment Key (which isn't allowed to be spent from for some delay)
281
+ pub ( crate ) local_delayed_payment_key : PublicKey ,
282
282
}
283
283
impl_writeable ! ( TxCreationKeys , 33 * 6 ,
284
- { per_commitment_point, revocation_key, a_htlc_key , b_htlc_key , a_delayed_payment_key } ) ;
284
+ { per_commitment_point, revocation_key, local_htlc_key , remote_htlc_key , local_delayed_payment_key } ) ;
285
285
286
286
/// One counterparty's public keys which do not change over the life of a channel.
287
287
#[ derive( Clone , PartialEq ) ]
@@ -317,13 +317,13 @@ impl_writeable!(ChannelPublicKeys, 33*5, {
317
317
318
318
319
319
impl TxCreationKeys {
320
- pub ( crate ) fn new < T : secp256k1:: Signing + secp256k1:: Verification > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , a_delayed_payment_base : & PublicKey , a_htlc_base : & PublicKey , b_revocation_base : & PublicKey , b_htlc_base : & PublicKey ) -> Result < TxCreationKeys , secp256k1:: Error > {
320
+ pub ( crate ) fn new < T : secp256k1:: Signing + secp256k1:: Verification > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , local_delayed_payment_base : & PublicKey , local_htlc_base : & PublicKey , remote_revocation_base : & PublicKey , remote_htlc_base : & PublicKey ) -> Result < TxCreationKeys , secp256k1:: Error > {
321
321
Ok ( TxCreationKeys {
322
322
per_commitment_point : per_commitment_point. clone ( ) ,
323
- revocation_key : derive_public_revocation_key ( & secp_ctx, & per_commitment_point, & b_revocation_base ) ?,
324
- a_htlc_key : derive_public_key ( & secp_ctx, & per_commitment_point, & a_htlc_base ) ?,
325
- b_htlc_key : derive_public_key ( & secp_ctx, & per_commitment_point, & b_htlc_base ) ?,
326
- a_delayed_payment_key : derive_public_key ( & secp_ctx, & per_commitment_point, & a_delayed_payment_base ) ?,
323
+ revocation_key : derive_public_revocation_key ( & secp_ctx, & per_commitment_point, & remote_revocation_base ) ?,
324
+ local_htlc_key : derive_public_key ( & secp_ctx, & per_commitment_point, & local_htlc_base ) ?,
325
+ remote_htlc_key : derive_public_key ( & secp_ctx, & per_commitment_point, & remote_htlc_base ) ?,
326
+ local_delayed_payment_key : derive_public_key ( & secp_ctx, & per_commitment_point, & local_delayed_payment_base ) ?,
327
327
} )
328
328
}
329
329
}
@@ -374,7 +374,7 @@ impl_writeable!(HTLCOutputInCommitment, 1 + 8 + 4 + 32 + 5, {
374
374
} ) ;
375
375
376
376
#[ inline]
377
- pub ( crate ) fn get_htlc_redeemscript_with_explicit_keys ( htlc : & HTLCOutputInCommitment , a_htlc_key : & PublicKey , b_htlc_key : & PublicKey , revocation_key : & PublicKey ) -> Script {
377
+ pub ( crate ) fn get_htlc_redeemscript_with_explicit_keys ( htlc : & HTLCOutputInCommitment , local_htlc_key : & PublicKey , remote_htlc_key : & PublicKey , revocation_key : & PublicKey ) -> Script {
378
378
let payment_hash160 = Ripemd160 :: hash ( & htlc. payment_hash . 0 [ ..] ) . into_inner ( ) ;
379
379
if htlc. offered {
380
380
Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_DUP )
@@ -384,7 +384,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
384
384
. push_opcode ( opcodes:: all:: OP_IF )
385
385
. push_opcode ( opcodes:: all:: OP_CHECKSIG )
386
386
. push_opcode ( opcodes:: all:: OP_ELSE )
387
- . push_slice ( & b_htlc_key . serialize ( ) [ ..] )
387
+ . push_slice ( & remote_htlc_key . serialize ( ) [ ..] )
388
388
. push_opcode ( opcodes:: all:: OP_SWAP )
389
389
. push_opcode ( opcodes:: all:: OP_SIZE )
390
390
. push_int ( 32 )
@@ -393,7 +393,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
393
393
. push_opcode ( opcodes:: all:: OP_DROP )
394
394
. push_int ( 2 )
395
395
. push_opcode ( opcodes:: all:: OP_SWAP )
396
- . push_slice ( & a_htlc_key . serialize ( ) [ ..] )
396
+ . push_slice ( & local_htlc_key . serialize ( ) [ ..] )
397
397
. push_int ( 2 )
398
398
. push_opcode ( opcodes:: all:: OP_CHECKMULTISIG )
399
399
. push_opcode ( opcodes:: all:: OP_ELSE )
@@ -412,7 +412,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
412
412
. push_opcode ( opcodes:: all:: OP_IF )
413
413
. push_opcode ( opcodes:: all:: OP_CHECKSIG )
414
414
. push_opcode ( opcodes:: all:: OP_ELSE )
415
- . push_slice ( & b_htlc_key . serialize ( ) [ ..] )
415
+ . push_slice ( & remote_htlc_key . serialize ( ) [ ..] )
416
416
. push_opcode ( opcodes:: all:: OP_SWAP )
417
417
. push_opcode ( opcodes:: all:: OP_SIZE )
418
418
. push_int ( 32 )
@@ -423,7 +423,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
423
423
. push_opcode ( opcodes:: all:: OP_EQUALVERIFY )
424
424
. push_int ( 2 )
425
425
. push_opcode ( opcodes:: all:: OP_SWAP )
426
- . push_slice ( & a_htlc_key . serialize ( ) [ ..] )
426
+ . push_slice ( & local_htlc_key . serialize ( ) [ ..] )
427
427
. push_int ( 2 )
428
428
. push_opcode ( opcodes:: all:: OP_CHECKMULTISIG )
429
429
. push_opcode ( opcodes:: all:: OP_ELSE )
@@ -438,31 +438,31 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
438
438
}
439
439
}
440
440
441
- /// note here that 'a_revocation_key ' is generated using b_revocation_basepoint and a 's
441
+ /// note here that 'revocation_key ' is generated using remote_revocation_basepoint and local 's
442
442
/// commitment secret. 'htlc' does *not* need to have its previous_output_index filled.
443
443
#[ inline]
444
444
pub fn get_htlc_redeemscript ( htlc : & HTLCOutputInCommitment , keys : & TxCreationKeys ) -> Script {
445
- get_htlc_redeemscript_with_explicit_keys ( htlc, & keys. a_htlc_key , & keys. b_htlc_key , & keys. revocation_key )
445
+ get_htlc_redeemscript_with_explicit_keys ( htlc, & keys. local_htlc_key , & keys. remote_htlc_key , & keys. revocation_key )
446
446
}
447
447
448
448
/// Gets the redeemscript for a funding output from the two funding public keys.
449
449
/// Note that the order of funding public keys does not matter.
450
- pub fn make_funding_redeemscript ( a : & PublicKey , b : & PublicKey ) -> Script {
451
- let our_funding_key = a . serialize ( ) ;
452
- let their_funding_key = b . serialize ( ) ;
450
+ pub fn make_funding_redeemscript ( local : & PublicKey , remote : & PublicKey ) -> Script {
451
+ let local_funding_key = local . serialize ( ) ;
452
+ let remote_funding_key = remote . serialize ( ) ;
453
453
454
454
let builder = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHNUM_2 ) ;
455
- if our_funding_key [ ..] < their_funding_key [ ..] {
456
- builder. push_slice ( & our_funding_key )
457
- . push_slice ( & their_funding_key )
455
+ if local_funding_key [ ..] < remote_funding_key [ ..] {
456
+ builder. push_slice ( & local_funding_key )
457
+ . push_slice ( & remote_funding_key )
458
458
} else {
459
- builder. push_slice ( & their_funding_key )
460
- . push_slice ( & our_funding_key )
459
+ builder. push_slice ( & remote_funding_key )
460
+ . push_slice ( & local_funding_key )
461
461
} . push_opcode ( opcodes:: all:: OP_PUSHNUM_2 ) . push_opcode ( opcodes:: all:: OP_CHECKMULTISIG ) . into_script ( )
462
462
}
463
463
464
464
/// panics if htlc.transaction_output_index.is_none()!
465
- pub fn build_htlc_transaction ( prev_hash : & Txid , feerate_per_kw : u64 , to_self_delay : u16 , htlc : & HTLCOutputInCommitment , a_delayed_payment_key : & PublicKey , revocation_key : & PublicKey ) -> Transaction {
465
+ pub fn build_htlc_transaction ( prev_hash : & Txid , feerate_per_kw : u64 , to_self_delay : u16 , htlc : & HTLCOutputInCommitment , local_delayed_payment_key : & PublicKey , revocation_key : & PublicKey ) -> Transaction {
466
466
let mut txins: Vec < TxIn > = Vec :: new ( ) ;
467
467
txins. push ( TxIn {
468
468
previous_output : OutPoint {
@@ -482,7 +482,7 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u64, to_self_del
482
482
483
483
let mut txouts: Vec < TxOut > = Vec :: new ( ) ;
484
484
txouts. push ( TxOut {
485
- script_pubkey : get_revokeable_redeemscript ( revocation_key, to_self_delay, a_delayed_payment_key ) . to_v0_p2wsh ( ) ,
485
+ script_pubkey : get_revokeable_redeemscript ( revocation_key, to_self_delay, local_delayed_payment_key ) . to_v0_p2wsh ( ) ,
486
486
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)
487
487
} ) ;
488
488
@@ -550,9 +550,9 @@ impl LocalCommitmentTransaction {
550
550
local_keys : TxCreationKeys {
551
551
per_commitment_point : dummy_key. clone ( ) ,
552
552
revocation_key : dummy_key. clone ( ) ,
553
- a_htlc_key : dummy_key. clone ( ) ,
554
- b_htlc_key : dummy_key. clone ( ) ,
555
- a_delayed_payment_key : dummy_key. clone ( ) ,
553
+ local_htlc_key : dummy_key. clone ( ) ,
554
+ remote_htlc_key : dummy_key. clone ( ) ,
555
+ local_delayed_payment_key : dummy_key. clone ( ) ,
556
556
} ,
557
557
feerate_per_kw : 0 ,
558
558
per_htlc : Vec :: new ( )
@@ -627,9 +627,9 @@ impl LocalCommitmentTransaction {
627
627
628
628
for this_htlc in self . per_htlc . iter ( ) {
629
629
if this_htlc. 0 . transaction_output_index . is_some ( ) {
630
- let htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . a_delayed_payment_key , & self . local_keys . revocation_key ) ;
630
+ let htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . local_delayed_payment_key , & self . local_keys . revocation_key ) ;
631
631
632
- let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys ( & this_htlc. 0 , & self . local_keys . a_htlc_key , & self . local_keys . b_htlc_key , & self . local_keys . revocation_key ) ;
632
+ let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys ( & this_htlc. 0 , & self . local_keys . local_htlc_key , & self . local_keys . remote_htlc_key , & self . local_keys . revocation_key ) ;
633
633
634
634
let sighash = hash_to_message ! ( & bip143:: SighashComponents :: new( & htlc_tx) . sighash_all( & htlc_tx. input[ 0 ] , & htlc_redeemscript, this_htlc. 0 . amount_msat / 1000 ) [ ..] ) ;
635
635
ret. push ( Some ( secp_ctx. sign ( & sighash, & our_htlc_key) ) ) ;
@@ -650,12 +650,12 @@ impl LocalCommitmentTransaction {
650
650
// Further, we should never be provided the preimage for an HTLC-Timeout transaction.
651
651
if this_htlc. 0 . offered && preimage. is_some ( ) { unreachable ! ( ) ; }
652
652
653
- let mut htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . a_delayed_payment_key , & self . local_keys . revocation_key ) ;
653
+ let mut htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . local_delayed_payment_key , & self . local_keys . revocation_key ) ;
654
654
// Channel should have checked that we have a remote signature for this HTLC at
655
655
// creation, and we should have a sensible htlc transaction:
656
656
assert ! ( this_htlc. 1 . is_some( ) ) ;
657
657
658
- let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys ( & this_htlc. 0 , & self . local_keys . a_htlc_key , & self . local_keys . b_htlc_key , & self . local_keys . revocation_key ) ;
658
+ let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys ( & this_htlc. 0 , & self . local_keys . local_htlc_key , & self . local_keys . remote_htlc_key , & self . local_keys . revocation_key ) ;
659
659
660
660
// First push the multisig dummy, note that due to BIP147 (NULLDUMMY) it must be a zero-length element.
661
661
htlc_tx. input [ 0 ] . witness . push ( Vec :: new ( ) ) ;
0 commit comments