Skip to content

Commit 4a38ff2

Browse files
committed
fixup! cleanup
1 parent 45246f5 commit 4a38ff2

File tree

7 files changed

+119
-113
lines changed

7 files changed

+119
-113
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
975975
let (holder_commitment_tx, current_holder_commitment_number) = {
976976
let commitment_tx = &initial_holder_commitment_tx.inner;
977977
let tx_keys = &commitment_tx.keys;
978-
let current_holder_commitment_number = commitment_tx.commitment_number;
979978
let holder_commitment_tx = HolderSignedTx {
980979
txid,
981980
revocation_key: tx_keys.revocation_key,
@@ -986,7 +985,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
986985
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());

lightning/src/chain/keysinterface.rs

Lines changed: 12 additions & 30 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,
@@ -486,8 +468,8 @@ impl ChannelKeys for InMemoryChannelKeys {
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.trust_built_transaction();
472+
let commitment_sig = built_tx.sign(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx);
491473

492474
let commitment_txid = commitment_tx.trust_txid();
493475

@@ -496,11 +478,11 @@ impl ChannelKeys for InMemoryChannelKeys {
496478
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.trust_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.trust_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_directed();
533515
commitment_tx.inner.get_htlc_sigs(&self.htlc_base_key, &channel_parameters, secp_ctx)
534516
}
535517

0 commit comments

Comments
 (0)