Skip to content

Commit fb39cdd

Browse files
committed
fixup! cleanup
1 parent 16114a2 commit fb39cdd

File tree

7 files changed

+189
-177
lines changed

7 files changed

+189
-177
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -969,24 +969,23 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
969969

970970
let secp_ctx = Secp256k1::new();
971971

972-
let txid = initial_holder_commitment_tx.trust_txid();
972+
let txid = initial_holder_commitment_tx.untrusted_txid();
973973

974974
// block for Rust 1.34 compat
975975
let (holder_commitment_tx, current_holder_commitment_number) = {
976976
let commitment_tx = &initial_holder_commitment_tx.inner;
977-
let tx_keys = &commitment_tx.keys;
978-
let current_holder_commitment_number = commitment_tx.commitment_number;
977+
let tx_keys = commitment_tx.untrusted_key_derivation();
979978
let holder_commitment_tx = HolderSignedTx {
980979
txid,
981980
revocation_key: tx_keys.revocation_key,
982981
a_htlc_key: tx_keys.broadcaster_htlc_key,
983982
b_htlc_key: tx_keys.countersignatory_htlc_key,
984983
delayed_payment_key: tx_keys.broadcaster_delayed_payment_key,
985984
per_commitment_point: tx_keys.per_commitment_point,
986-
feerate_per_kw: commitment_tx.feerate_per_kw,
985+
feerate_per_kw: commitment_tx.feerate_per_kw(),
987986
htlc_outputs: Vec::new(), // There are never any HTLCs in the initial commitment transactions
988987
};
989-
(holder_commitment_tx, current_holder_commitment_number)
988+
(holder_commitment_tx, commitment_tx.commitment_number())
990989
};
991990
onchain_tx_handler.provide_latest_holder_tx(initial_holder_commitment_tx);
992991

@@ -1106,8 +1105,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11061105
}
11071106

11081107
log_trace!(logger, "Tracking new counterparty commitment transaction with txid {} at commitment number {} with {} HTLC outputs", txid, commitment_number, htlc_outputs.len());
1109-
// TODO do we really want to log the transaction hex?
1110-
// log_trace!(logger, "New potential counterparty commitment transaction: {}", encode::serialize_hex(unsigned_commitment_tx));
11111108
self.prev_counterparty_commitment_txid = self.current_counterparty_commitment_txid.take();
11121109
self.current_counterparty_commitment_txid = Some(txid);
11131110
self.counterparty_claimable_outpoints.insert(txid, htlc_outputs.clone());
@@ -1146,21 +1143,21 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11461143
/// up-to-date as our holder commitment transaction is updated.
11471144
/// Panics if set_on_holder_tx_csv has never been called.
11481145
fn provide_latest_holder_commitment_tx(&mut self, holder_commitment_tx: HolderCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
1149-
let txid = holder_commitment_tx.trust_txid();
1146+
let txid = holder_commitment_tx.untrusted_txid();
11501147

11511148
// block for Rust 1.34 compat
11521149
let mut new_holder_commitment_tx = {
11531150
let commitment_tx = &holder_commitment_tx.inner;
1154-
let tx_keys = &commitment_tx.keys;
1155-
self.current_holder_commitment_number = commitment_tx.commitment_number;
1151+
let tx_keys = &commitment_tx.untrusted_key_derivation();
1152+
self.current_holder_commitment_number = commitment_tx.commitment_number();
11561153
HolderSignedTx {
11571154
txid,
11581155
revocation_key: tx_keys.revocation_key,
11591156
a_htlc_key: tx_keys.broadcaster_htlc_key,
11601157
b_htlc_key: tx_keys.countersignatory_htlc_key,
11611158
delayed_payment_key: tx_keys.broadcaster_delayed_payment_key,
11621159
per_commitment_point: tx_keys.per_commitment_point,
1163-
feerate_per_kw: commitment_tx.feerate_per_kw,
1160+
feerate_per_kw: commitment_tx.feerate_per_kw(),
11641161
htlc_outputs,
11651162
}
11661163
};

lightning/src/chain/keysinterface.rs

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -350,29 +350,11 @@ pub trait KeysInterface: Send + Sync {
350350
fn get_secure_random_bytes(&self) -> [u8; 32];
351351
}
352352

353-
#[derive(Clone)]
354-
/// Holds late-bound static channel data.
355-
/// This data is available after the channel is readied, either
356-
/// when receiving an funding_created for an inbound channel or when
357-
/// creating a funding transaction for an outbound channel.
358-
struct StaticChannelData {
359-
/// Counterparty public keys and base points
360-
counterparty_channel_pubkeys: ChannelPublicKeys,
361-
/// The contest_delay value specified by our counterparty and applied on holder-broadcastable
362-
/// transactions, ie the amount of time that we have to wait to recover our funds if we
363-
/// broadcast a transaction. You'll likely want to pass this to the
364-
/// ln::chan_utils::build*_transaction functions when signing holder's transactions.
365-
counterparty_selected_contest_delay: u16,
366-
/// The contest_delay value specified by us and applied on transactions broadcastable
367-
/// by our counterparty, ie the amount of time that they have to wait to recover their funds
368-
/// if they broadcast a transaction.
369-
holder_selected_contest_delay: u16,
370-
/// Whether the holder is the initiator of this channel
371-
is_outbound: bool,
372-
}
373-
374353
#[derive(Clone)]
375354
/// A simple implementation of ChannelKeys that just keeps the private keys in memory.
355+
///
356+
/// This implementation performs no policy checks and is insufficient by itself as
357+
/// a secure external signer.
376358
pub struct InMemoryChannelKeys {
377359
/// Private key of anchor tx
378360
pub funding_key: SecretKey,
@@ -481,26 +463,26 @@ impl ChannelKeys for InMemoryChannelKeys {
481463
fn key_derivation_params(&self) -> (u64, u64) { self.key_derivation_params }
482464

483465
fn sign_counterparty_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &CommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()> {
484-
let keys = commitment_tx.trust_key_derivation();
466+
let keys = commitment_tx.untrusted_key_derivation();
485467

486468
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
487469
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &self.counterparty_pubkeys().funding_pubkey);
488470

489-
let built_tx = &commitment_tx.built;
490-
let commitment_sig = built_tx.get_signature(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx);
471+
let built_tx = commitment_tx.untrusted_built_transaction();
472+
let commitment_sig = built_tx.sign(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx);
491473

492-
let commitment_txid = commitment_tx.trust_txid();
474+
let commitment_txid = commitment_tx.untrusted_txid();
493475

494-
let mut htlc_sigs = Vec::with_capacity(commitment_tx.htlcs.len());
495-
for htlc in &commitment_tx.htlcs {
496-
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_tx.feerate_per_kw, self.holder_selected_contest_delay(), htlc, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
476+
let mut htlc_sigs = Vec::with_capacity(commitment_tx.htlcs().len());
477+
for htlc in commitment_tx.htlcs() {
478+
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_tx.feerate_per_kw(), self.holder_selected_contest_delay(), htlc, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
497479
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &keys);
498480
let htlc_sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, htlc.amount_msat / 1000, SigHashType::All)[..]);
499-
let our_htlc_key = match chan_utils::derive_private_key(&secp_ctx, &keys.per_commitment_point, &self.htlc_base_key) {
481+
let holder_htlc_key = match chan_utils::derive_private_key(&secp_ctx, &keys.per_commitment_point, &self.htlc_base_key) {
500482
Ok(s) => s,
501483
Err(_) => return Err(()),
502484
};
503-
htlc_sigs.push(secp_ctx.sign(&htlc_sighash, &our_htlc_key));
485+
htlc_sigs.push(secp_ctx.sign(&htlc_sighash, &holder_htlc_key));
504486
}
505487

506488
Ok((commitment_sig, htlc_sigs))
@@ -510,8 +492,8 @@ impl ChannelKeys for InMemoryChannelKeys {
510492
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
511493
let funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &self.counterparty_pubkeys().funding_pubkey);
512494

513-
let built_tx = &commitment_tx.inner.built;
514-
let sig = built_tx.get_signature(&self.funding_key, &funding_redeemscript, self.channel_value_satoshis, secp_ctx);
495+
let built_tx = commitment_tx.inner.untrusted_built_transaction();
496+
let sig = built_tx.sign(&self.funding_key, &funding_redeemscript, self.channel_value_satoshis, secp_ctx);
515497
let htlc_sigs_o = self.sign_holder_commitment_htlc_transactions(&commitment_tx, secp_ctx)?;
516498
let htlc_sigs = htlc_sigs_o.iter().map(|o| o.unwrap()).collect();
517499

@@ -523,13 +505,13 @@ impl ChannelKeys for InMemoryChannelKeys {
523505
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
524506
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &self.counterparty_pubkeys().funding_pubkey);
525507

526-
let built_tx = &holder_commitment_tx.inner.built;
527-
Ok(built_tx.get_signature(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx))
508+
let built_tx = holder_commitment_tx.inner.untrusted_built_transaction();
509+
Ok(built_tx.sign(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx))
528510
}
529511

530512
fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
531513
let channel_parameters = self.make_channel_parameters();
532-
let channel_parameters = channel_parameters.to_directed(true);
514+
let channel_parameters = channel_parameters.as_holder_broadcastable();
533515
commitment_tx.inner.get_htlc_sigs(&self.htlc_base_key, &channel_parameters, secp_ctx)
534516
}
535517

0 commit comments

Comments
 (0)