Skip to content

Commit ffa2ae8

Browse files
author
Antoine Riard
committed
Overhaul ChannelMonitor/OnchainTxHandler to new nomenclature
1 parent 9535b5c commit ffa2ae8

File tree

9 files changed

+519
-519
lines changed

9 files changed

+519
-519
lines changed

fuzz/src/full_stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,6 @@ mod tests {
903903
assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030200000000000000000000000000000000000000000000000000000000000000 with 1 adds, 0 fulfills, 0 fails for channel 3900000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&3)); // 7
904904
assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030000000000000000000000000000000000000000000000000000000000000000 with 0 adds, 1 fulfills, 0 fails for channel 3d00000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&1)); // 8
905905
assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030000000000000000000000000000000000000000000000000000000000000000 with 0 adds, 0 fulfills, 1 fails for channel 3d00000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&2)); // 9
906-
assert_eq!(log_entries.get(&("lightning::ln::channelmonitor".to_string(), "Input spending remote commitment tx (00000000000000000000000000000000000000000000000000000000000000a1:0) in 0000000000000000000000000000000000000000000000000000000000000018 resolves outbound HTLC with payment hash ff00000000000000000000000000000000000000000000000000000000000000 with timeout".to_string())), Some(&1)); // 10
906+
assert_eq!(log_entries.get(&("lightning::ln::channelmonitor".to_string(), "Input spending counterparty commitment tx (00000000000000000000000000000000000000000000000000000000000000a1:0) in 0000000000000000000000000000000000000000000000000000000000000018 resolves outbound HTLC with payment hash ff00000000000000000000000000000000000000000000000000000000000000 with timeout".to_string())), Some(&1)); // 10
907907
}
908908
}

lightning/src/chain/keysinterface.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ pub enum SpendableOutputDescriptor {
7171
/// it is an output from an old state which we broadcast (which should never happen).
7272
///
7373
/// To derive the delayed_payment key which is used to sign for this input, you must pass the
74-
/// local delayed_payment_base_key (ie the private key which corresponds to the pubkey in
74+
/// holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in
7575
/// ChannelKeys::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to
7676
/// chan_utils::derive_private_key. The public key can be generated without the secret key
7777
/// using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in
7878
/// ChannelKeys::pubkeys().
7979
///
80-
/// To derive the remote_revocation_pubkey provided here (which is used in the witness
81-
/// script generation), you must pass the remote revocation_basepoint (which appears in the
80+
/// To derive the counterparty_revocation_pubkey provided here (which is used in the witness
81+
/// script generation), you must pass the counterparty revocation_basepoint (which appears in the
8282
/// call to ChannelKeys::on_accept) and the provided per_commitment point
8383
/// to chan_utils::derive_public_revocation_key.
8484
///
@@ -101,8 +101,8 @@ pub enum SpendableOutputDescriptor {
101101
/// The channel keys state used to proceed to derivation of signing key. Must
102102
/// be pass to KeysInterface::derive_channel_keys.
103103
key_derivation_params: (u64, u64),
104-
/// The remote_revocation_pubkey used to derive witnessScript
105-
remote_revocation_pubkey: PublicKey
104+
/// The counterparty_revocation_pubkey used to derive witnessScript
105+
counterparty_revocation_pubkey: PublicKey
106106
},
107107
/// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
108108
/// corresponds to the public key in ChannelKeys::pubkeys().payment_point).
@@ -111,7 +111,7 @@ pub enum SpendableOutputDescriptor {
111111
///
112112
/// These are generally the result of our counterparty having broadcast the current state,
113113
/// allowing us to claim the non-HTLC-encumbered outputs immediately.
114-
StaticOutputRemotePayment {
114+
StaticOutputCounterpartyPayment {
115115
/// The outpoint which is spendable
116116
outpoint: OutPoint,
117117
/// The output which is reference by the given outpoint
@@ -130,17 +130,17 @@ impl Writeable for SpendableOutputDescriptor {
130130
outpoint.write(writer)?;
131131
output.write(writer)?;
132132
},
133-
&SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref remote_revocation_pubkey } => {
133+
&SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref counterparty_revocation_pubkey } => {
134134
1u8.write(writer)?;
135135
outpoint.write(writer)?;
136136
per_commitment_point.write(writer)?;
137137
to_self_delay.write(writer)?;
138138
output.write(writer)?;
139139
key_derivation_params.0.write(writer)?;
140140
key_derivation_params.1.write(writer)?;
141-
remote_revocation_pubkey.write(writer)?;
141+
counterparty_revocation_pubkey.write(writer)?;
142142
},
143-
&SpendableOutputDescriptor::StaticOutputRemotePayment { ref outpoint, ref output, ref key_derivation_params } => {
143+
&SpendableOutputDescriptor::StaticOutputCounterpartyPayment { ref outpoint, ref output, ref key_derivation_params } => {
144144
2u8.write(writer)?;
145145
outpoint.write(writer)?;
146146
output.write(writer)?;
@@ -165,9 +165,9 @@ impl Readable for SpendableOutputDescriptor {
165165
to_self_delay: Readable::read(reader)?,
166166
output: Readable::read(reader)?,
167167
key_derivation_params: (Readable::read(reader)?, Readable::read(reader)?),
168-
remote_revocation_pubkey: Readable::read(reader)?,
168+
counterparty_revocation_pubkey: Readable::read(reader)?,
169169
}),
170-
2u8 => Ok(SpendableOutputDescriptor::StaticOutputRemotePayment {
170+
2u8 => Ok(SpendableOutputDescriptor::StaticOutputCounterpartyPayment {
171171
outpoint: Readable::read(reader)?,
172172
output: Readable::read(reader)?,
173173
key_derivation_params: (Readable::read(reader)?, Readable::read(reader)?),

lightning/src/ln/channel.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
15401540
self.get_commitment_transaction_number_obscure_factor(),
15411541
initial_commitment_tx.clone());
15421542

1543-
channel_monitor.provide_latest_remote_commitment_tx_info(&counterparty_initial_commitment_tx, Vec::new(), self.cur_counterparty_commitment_transaction_number, self.counterparty_cur_commitment_point.unwrap(), logger);
1543+
channel_monitor.provide_latest_counterparty_commitment_tx_info(&counterparty_initial_commitment_tx, Vec::new(), self.cur_counterparty_commitment_transaction_number, self.counterparty_cur_commitment_point.unwrap(), logger);
15441544
channel_monitor
15451545
} }
15461546
}
@@ -1604,7 +1604,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
16041604
self.get_commitment_transaction_number_obscure_factor(),
16051605
commitment_tx);
16061606

1607-
channel_monitor.provide_latest_remote_commitment_tx_info(&counterparty_initial_commitment_tx, Vec::new(), self.cur_counterparty_commitment_transaction_number, self.counterparty_cur_commitment_point.unwrap(), logger);
1607+
channel_monitor.provide_latest_counterparty_commitment_tx_info(&counterparty_initial_commitment_tx, Vec::new(), self.cur_counterparty_commitment_transaction_number, self.counterparty_cur_commitment_point.unwrap(), logger);
16081608

16091609
channel_monitor
16101610
} }
@@ -2045,7 +2045,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
20452045
self.latest_monitor_update_id += 1;
20462046
let mut monitor_update = ChannelMonitorUpdate {
20472047
update_id: self.latest_monitor_update_id,
2048-
updates: vec![ChannelMonitorUpdateStep::LatestLocalCommitmentTXInfo {
2048+
updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
20492049
commitment_tx: LocalCommitmentTransaction::new_missing_local_sig(commitment_tx.0, msg.signature.clone(), &self.holder_keys.pubkeys().funding_pubkey, &counterparty_funding_pubkey, keys, self.feerate_per_kw, htlcs_without_source),
20502050
htlc_outputs: htlcs_and_sigs
20512051
}]
@@ -3164,7 +3164,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
31643164
self.cur_counterparty_commitment_transaction_number + 1 - if self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32) != 0 { 1 } else { 0 }
31653165
}
31663166

3167-
pub fn get_revoked_remote_commitment_transaction_number(&self) -> u64 {
3167+
pub fn get_revoked_counterparty_commitment_transaction_number(&self) -> u64 {
31683168
self.cur_counterparty_commitment_transaction_number + 2
31693169
}
31703170

@@ -3838,7 +3838,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
38383838
self.latest_monitor_update_id += 1;
38393839
let monitor_update = ChannelMonitorUpdate {
38403840
update_id: self.latest_monitor_update_id,
3841-
updates: vec![ChannelMonitorUpdateStep::LatestRemoteCommitmentTXInfo {
3841+
updates: vec![ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo {
38423842
unsigned_commitment_tx: counterparty_commitment_tx.clone(),
38433843
htlc_outputs: htlcs.clone(),
38443844
commitment_number: self.cur_counterparty_commitment_transaction_number,

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,20 +3848,20 @@ impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: De
38483848
let funding_txo = channel.get_funding_txo().ok_or(DecodeError::InvalidValue)?;
38493849
funding_txo_set.insert(funding_txo.clone());
38503850
if let Some(ref mut monitor) = args.channel_monitors.get_mut(&funding_txo) {
3851-
if channel.get_cur_holder_commitment_transaction_number() < monitor.get_cur_local_commitment_number() ||
3852-
channel.get_revoked_remote_commitment_transaction_number() < monitor.get_min_seen_secret() ||
3853-
channel.get_cur_counterparty_commitment_transaction_number() < monitor.get_cur_remote_commitment_number() ||
3851+
if channel.get_cur_holder_commitment_transaction_number() < monitor.get_cur_holder_commitment_number() ||
3852+
channel.get_revoked_counterparty_commitment_transaction_number() < monitor.get_min_seen_secret() ||
3853+
channel.get_cur_counterparty_commitment_transaction_number() < monitor.get_cur_counterparty_commitment_number() ||
38543854
channel.get_latest_monitor_update_id() > monitor.get_latest_update_id() {
38553855
// If the channel is ahead of the monitor, return InvalidValue:
38563856
return Err(DecodeError::InvalidValue);
3857-
} else if channel.get_cur_holder_commitment_transaction_number() > monitor.get_cur_local_commitment_number() ||
3858-
channel.get_revoked_remote_commitment_transaction_number() > monitor.get_min_seen_secret() ||
3859-
channel.get_cur_counterparty_commitment_transaction_number() > monitor.get_cur_remote_commitment_number() ||
3857+
} else if channel.get_cur_holder_commitment_transaction_number() > monitor.get_cur_holder_commitment_number() ||
3858+
channel.get_revoked_counterparty_commitment_transaction_number() > monitor.get_min_seen_secret() ||
3859+
channel.get_cur_counterparty_commitment_transaction_number() > monitor.get_cur_counterparty_commitment_number() ||
38603860
channel.get_latest_monitor_update_id() < monitor.get_latest_update_id() {
38613861
// But if the channel is behind of the monitor, close the channel:
38623862
let (_, _, mut new_failed_htlcs) = channel.force_shutdown(true);
38633863
failed_htlcs.append(&mut new_failed_htlcs);
3864-
monitor.broadcast_latest_local_commitment_txn(&args.tx_broadcaster, &args.logger);
3864+
monitor.broadcast_latest_holder_commitment_txn(&args.tx_broadcaster, &args.logger);
38653865
} else {
38663866
if let Some(short_channel_id) = channel.get_short_channel_id() {
38673867
short_to_id.insert(short_channel_id, channel.channel_id());
@@ -3875,7 +3875,7 @@ impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: De
38753875

38763876
for (ref funding_txo, ref mut monitor) in args.channel_monitors.iter_mut() {
38773877
if !funding_txo_set.contains(funding_txo) {
3878-
monitor.broadcast_latest_local_commitment_txn(&args.tx_broadcaster, &args.logger);
3878+
monitor.broadcast_latest_holder_commitment_txn(&args.tx_broadcaster, &args.logger);
38793879
}
38803880
}
38813881

0 commit comments

Comments
 (0)