Skip to content

Commit 4491986

Browse files
author
Antoine Riard
committed
Change variable nomenclature for to_self_delay
To avoid reviewers confusion, rename counterparty_to_self_delay to counteparty_selected_contest_delay, i.e the justice delay announced by a channel counterparty restraining our transactions, and to_self_delay to locally_selected_contest_delay, i.e the justice delay announced by us restraining counterparty's transactions We deviate from wider nomenclature by prefixing local data with a locally_ extension due to the leak of this value in transactions/scripts builder, where the confusion may happen. Rename further AcceptChannelData to the new nomenclature.
1 parent c7ef6df commit 4491986

File tree

4 files changed

+76
-76
lines changed

4 files changed

+76
-76
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,13 @@ pub trait ChannelKeys : Send+Clone {
319319
/// protocol.
320320
fn sign_channel_announcement<T: secp256k1::Signing>(&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
321321

322-
/// Set the remote channel basepoints and counterparty/local_to_self_delay.
322+
/// Set the counterparty channel basepoints and counterparty_selected/locally_selected_contest_delay.
323323
/// This is done immediately on incoming channels and as soon as the channel is accepted on outgoing channels.
324324
///
325-
/// We bind local_to_self_delay late here for API convenience.
325+
/// We bind locally_selected_contest_delay late here for API convenience.
326326
///
327327
/// Will be called before any signatures are applied.
328-
fn on_accept(&mut self, channel_points: &ChannelPublicKeys, counterparty_to_self_delay: u16, local_to_self_delay: u16);
328+
fn on_accept(&mut self, channel_points: &ChannelPublicKeys, counterparty_selected_contest_delay: u16, locally_selected_contest_delay: u16);
329329
}
330330

331331
/// A trait to describe an object which can get user secrets and key material.
@@ -354,17 +354,17 @@ pub trait KeysInterface: Send + Sync {
354354
/// when receiving an open_channel for an inbound channel or when
355355
/// receiving accept_channel for an outbound channel.
356356
struct AcceptedChannelData {
357-
/// Remote public keys and base points
358-
remote_channel_pubkeys: ChannelPublicKeys,
359-
/// The to_self_delay value specified by our counterparty and applied on locally-broadcastable
357+
/// Counterparty public keys and base points
358+
counterparty_channel_pubkeys: ChannelPublicKeys,
359+
/// The contest_delay value specified by our counterparty and applied on locally-broadcastable
360360
/// transactions, ie the amount of time that we have to wait to recover our funds if we
361361
/// broadcast a transaction. You'll likely want to pass this to the
362362
/// ln::chan_utils::build*_transaction functions when signing local transactions.
363-
counterparty_to_self_delay: u16,
364-
/// The to_self_delay value specified by us and applied on transactions broadcastable
363+
counterparty_selected_contest_delay: u16,
364+
/// The contest_delay value specified by us and applied on transactions broadcastable
365365
/// by our counterparty, ie the amount of time that they have to wait to recover their funds
366366
/// if they broadcast a transaction.
367-
local_to_self_delay: u16,
367+
locally_selected_contest_delay: u16,
368368
}
369369

370370
#[derive(Clone)]
@@ -384,7 +384,7 @@ pub struct InMemoryChannelKeys {
384384
pub commitment_seed: [u8; 32],
385385
/// Local public keys and basepoints
386386
pub(crate) local_channel_pubkeys: ChannelPublicKeys,
387-
/// Remote public keys and counterparty/local to_self_delay, populated on channel acceptance
387+
/// Counterparty public keys and counterparty/locally selected_contest_delay, populated on channel acceptance
388388
accepted_channel_data: Option<AcceptedChannelData>,
389389
/// The total value of this channel
390390
channel_value_satoshis: u64,
@@ -438,22 +438,22 @@ impl InMemoryChannelKeys {
438438
}
439439
}
440440

441-
/// Remote pubkeys.
441+
/// Counterparty pubkeys.
442442
/// Will panic if on_accept wasn't called.
443-
pub fn remote_pubkeys(&self) -> &ChannelPublicKeys { &self.accepted_channel_data.as_ref().unwrap().remote_channel_pubkeys }
443+
pub fn counterparty_pubkeys(&self) -> &ChannelPublicKeys { &self.accepted_channel_data.as_ref().unwrap().counterparty_channel_pubkeys }
444444

445-
/// The to_self_delay value specified by our counterparty and applied on locally-broadcastable
445+
/// The contest_delay value specified by our counterparty and applied on locally-broadcastable
446446
/// transactions, ie the amount of time that we have to wait to recover our funds if we
447447
/// broadcast a transaction. You'll likely want to pass this to the
448448
/// ln::chan_utils::build*_transaction functions when signing local transactions.
449449
/// Will panic if on_accept wasn't called.
450-
pub fn counterparty_to_self_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().counterparty_to_self_delay }
450+
pub fn counterparty_selected_contest_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().counterparty_selected_contest_delay }
451451

452-
/// The to_self_delay value specified by us and applied on transactions broadcastable
452+
/// The contest_delay value specified by us and applied on transactions broadcastable
453453
/// by our counterparty, ie the amount of time that they have to wait to recover their funds
454454
/// if they broadcast a transaction.
455455
/// Will panic if on_accept wasn't called.
456-
pub fn local_to_self_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().local_to_self_delay }
456+
pub fn locally_selected_contest_delay(&self) -> u16 { self.accepted_channel_data.as_ref().unwrap().locally_selected_contest_delay }
457457
}
458458

459459
impl ChannelKeys for InMemoryChannelKeys {
@@ -475,7 +475,7 @@ impl ChannelKeys for InMemoryChannelKeys {
475475

476476
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
477477
let accepted_data = self.accepted_channel_data.as_ref().expect("must accept before signing");
478-
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &accepted_data.remote_channel_pubkeys.funding_pubkey);
478+
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &accepted_data.counterparty_channel_pubkeys.funding_pubkey);
479479

480480
let commitment_sighash = hash_to_message!(&bip143::SigHashCache::new(commitment_tx).signature_hash(0, &channel_funding_redeemscript, self.channel_value_satoshis, SigHashType::All)[..]);
481481
let commitment_sig = secp_ctx.sign(&commitment_sighash, &self.funding_key);
@@ -485,7 +485,7 @@ impl ChannelKeys for InMemoryChannelKeys {
485485
let mut htlc_sigs = Vec::with_capacity(htlcs.len());
486486
for ref htlc in htlcs {
487487
if let Some(_) = htlc.transaction_output_index {
488-
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, feerate_per_kw, accepted_data.local_to_self_delay, htlc, &keys.delayed_payment_key, &keys.revocation_key);
488+
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, feerate_per_kw, accepted_data.locally_selected_contest_delay, htlc, &keys.delayed_payment_key, &keys.revocation_key);
489489
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &keys);
490490
let htlc_sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, htlc.amount_msat / 1000, SigHashType::All)[..]);
491491
let our_htlc_key = match chan_utils::derive_private_key(&secp_ctx, &keys.per_commitment_point, &self.htlc_base_key) {
@@ -501,23 +501,23 @@ impl ChannelKeys for InMemoryChannelKeys {
501501

502502
fn sign_local_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
503503
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
504-
let remote_channel_data = self.accepted_channel_data.as_ref().expect("must accept before signing");
505-
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &remote_channel_data.remote_channel_pubkeys.funding_pubkey);
504+
let counterparty_channel_data = self.accepted_channel_data.as_ref().expect("must accept before signing");
505+
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &counterparty_channel_data.counterparty_channel_pubkeys.funding_pubkey);
506506

507507
Ok(local_commitment_tx.get_local_sig(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx))
508508
}
509509

510510
#[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
511511
fn unsafe_sign_local_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
512512
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
513-
let remote_channel_pubkeys = &self.accepted_channel_data.as_ref().expect("must accept before signing").remote_channel_pubkeys;
514-
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &remote_channel_pubkeys.funding_pubkey);
513+
let counterparty_channel_pubkeys = &self.accepted_channel_data.as_ref().expect("must accept before signing").counterparty_channel_pubkeys;
514+
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &counterparty_channel_pubkeys.funding_pubkey);
515515

516516
Ok(local_commitment_tx.get_local_sig(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx))
517517
}
518518

519519
fn sign_local_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
520-
let local_csv = self.accepted_channel_data.as_ref().unwrap().counterparty_to_self_delay;
520+
let local_csv = self.accepted_channel_data.as_ref().unwrap().counterparty_selected_contest_delay;
521521
local_commitment_tx.get_htlc_sigs(&self.htlc_base_key, local_csv, secp_ctx)
522522
}
523523

@@ -532,7 +532,7 @@ impl ChannelKeys for InMemoryChannelKeys {
532532
Err(_) => return Err(())
533533
};
534534
let witness_script = if let &Some(ref htlc) = htlc {
535-
let counterparty_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) {
535+
let counterparty_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().htlc_basepoint) {
536536
Ok(counterparty_htlcpubkey) => counterparty_htlcpubkey,
537537
Err(_) => return Err(())
538538
};
@@ -542,11 +542,11 @@ impl ChannelKeys for InMemoryChannelKeys {
542542
};
543543
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &counterparty_htlcpubkey, &local_htlcpubkey, &revocation_pubkey)
544544
} else {
545-
let counterparty_delayedpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().delayed_payment_basepoint) {
545+
let counterparty_delayedpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().delayed_payment_basepoint) {
546546
Ok(counterparty_delayedpubkey) => counterparty_delayedpubkey,
547547
Err(_) => return Err(())
548548
};
549-
chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.local_to_self_delay(), &counterparty_delayedpubkey)
549+
chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.locally_selected_contest_delay(), &counterparty_delayedpubkey)
550550
};
551551
let mut sighash_parts = bip143::SigHashCache::new(justice_tx);
552552
let sighash = hash_to_message!(&sighash_parts.signature_hash(input, &witness_script, amount, SigHashType::All)[..]);
@@ -556,7 +556,7 @@ impl ChannelKeys for InMemoryChannelKeys {
556556
fn sign_remote_htlc_transaction<T: secp256k1::Signing + secp256k1::Verification>(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
557557
if let Ok(htlc_key) = chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &self.htlc_base_key) {
558558
let witness_script = if let Ok(revocation_pubkey) = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint) {
559-
if let Ok(counterparty_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.remote_pubkeys().htlc_basepoint) {
559+
if let Ok(counterparty_htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().htlc_basepoint) {
560560
if let Ok(htlcpubkey) = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) {
561561
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &counterparty_htlcpubkey, &htlcpubkey, &revocation_pubkey)
562562
} else { return Err(()) }
@@ -575,8 +575,8 @@ impl ChannelKeys for InMemoryChannelKeys {
575575
if closing_tx.output.len() > 2 { return Err(()); }
576576

577577
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
578-
let remote_channel_data = self.accepted_channel_data.as_ref().expect("must accept before signing");
579-
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &remote_channel_data.remote_channel_pubkeys.funding_pubkey);
578+
let counterparty_channel_data = self.accepted_channel_data.as_ref().expect("must accept before signing");
579+
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &counterparty_channel_data.counterparty_channel_pubkeys.funding_pubkey);
580580

581581
let sighash = hash_to_message!(&bip143::SigHashCache::new(closing_tx)
582582
.signature_hash(0, &channel_funding_redeemscript, self.channel_value_satoshis, SigHashType::All)[..]);
@@ -588,18 +588,18 @@ impl ChannelKeys for InMemoryChannelKeys {
588588
Ok(secp_ctx.sign(&msghash, &self.funding_key))
589589
}
590590

591-
fn on_accept(&mut self, channel_pubkeys: &ChannelPublicKeys, counterparty_to_self_delay: u16, local_to_self_delay: u16) {
591+
fn on_accept(&mut self, channel_pubkeys: &ChannelPublicKeys, counterparty_selected_contest_delay: u16, locally_selected_contest_delay: u16) {
592592
assert!(self.accepted_channel_data.is_none(), "Already accepted");
593593
self.accepted_channel_data = Some(AcceptedChannelData {
594-
remote_channel_pubkeys: channel_pubkeys.clone(),
595-
counterparty_to_self_delay,
596-
local_to_self_delay,
594+
counterparty_channel_pubkeys: channel_pubkeys.clone(),
595+
counterparty_selected_contest_delay,
596+
locally_selected_contest_delay,
597597
});
598598
}
599599
}
600600

601601
impl_writeable!(AcceptedChannelData, 0,
602-
{ remote_channel_pubkeys, counterparty_to_self_delay, local_to_self_delay });
602+
{ counterparty_channel_pubkeys, counterparty_selected_contest_delay, locally_selected_contest_delay });
603603

604604
impl Writeable for InMemoryChannelKeys {
605605
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
@@ -626,7 +626,7 @@ impl Readable for InMemoryChannelKeys {
626626
let delayed_payment_base_key = Readable::read(reader)?;
627627
let htlc_base_key = Readable::read(reader)?;
628628
let commitment_seed = Readable::read(reader)?;
629-
let remote_channel_data = Readable::read(reader)?;
629+
let counterparty_channel_data = Readable::read(reader)?;
630630
let channel_value_satoshis = Readable::read(reader)?;
631631
let secp_ctx = Secp256k1::signing_only();
632632
let local_channel_pubkeys =
@@ -645,7 +645,7 @@ impl Readable for InMemoryChannelKeys {
645645
commitment_seed,
646646
channel_value_satoshis,
647647
local_channel_pubkeys,
648-
accepted_channel_data: remote_channel_data,
648+
accepted_channel_data: counterparty_channel_data,
649649
key_derivation_params: (params_1, params_2),
650650
})
651651
}

lightning/src/ln/chan_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,11 @@ impl TxCreationKeys {
385385
/// A script either spendable by the revocation
386386
/// key or the delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
387387
/// Encumbering a `to_local` output on a commitment transaction or 2nd-stage HTLC transactions.
388-
pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, to_self_delay: u16, delayed_payment_key: &PublicKey) -> Script {
388+
pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, contest_delay: u16, delayed_payment_key: &PublicKey) -> Script {
389389
Builder::new().push_opcode(opcodes::all::OP_IF)
390390
.push_slice(&revocation_key.serialize())
391391
.push_opcode(opcodes::all::OP_ELSE)
392-
.push_int(to_self_delay as i64)
392+
.push_int(contest_delay as i64)
393393
.push_opcode(opcodes::all::OP_CSV)
394394
.push_opcode(opcodes::all::OP_DROP)
395395
.push_slice(&delayed_payment_key.serialize())
@@ -516,7 +516,7 @@ pub fn make_funding_redeemscript(broadcaster: &PublicKey, countersignatory: &Pub
516516
}
517517

518518
/// panics if htlc.transaction_output_index.is_none()!
519-
pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, to_self_delay: u16, htlc: &HTLCOutputInCommitment, delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction {
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 {
520520
let mut txins: Vec<TxIn> = Vec::new();
521521
txins.push(TxIn {
522522
previous_output: OutPoint {
@@ -536,7 +536,7 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, to_self_del
536536

537537
let mut txouts: Vec<TxOut> = Vec::new();
538538
txouts.push(TxOut {
539-
script_pubkey: get_revokeable_redeemscript(revocation_key, to_self_delay, delayed_payment_key).to_v0_p2wsh(),
539+
script_pubkey: get_revokeable_redeemscript(revocation_key, contest_delay, delayed_payment_key).to_v0_p2wsh(),
540540
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)
541541
});
542542

0 commit comments

Comments
 (0)