}
let secp_ctx = Secp256k1::new();
- let mut channel_monitor = ChannelMonitor::new(chan_keys.revocation_base_key(), chan_keys.delayed_payment_base_key(),
- chan_keys.htlc_base_key(), chan_keys.payment_base_key(), &keys_provider.get_shutdown_pubkey(), config.own_channel_config.our_to_self_delay,
- keys_provider.get_destination_script(), logger.clone());
- channel_monitor.set_their_base_keys(&msg.htlc_basepoint, &msg.delayed_payment_basepoint);
- channel_monitor.set_their_to_self_delay(msg.to_self_delay);
+ let channel_monitor = ChannelMonitor::new(chan_keys.revocation_base_key(), chan_keys.delayed_payment_base_key(),
+ chan_keys.htlc_base_key(), chan_keys.payment_base_key(), &keys_provider.get_shutdown_pubkey(), config.own_channel_config.our_to_self_delay,
+ keys_provider.get_destination_script(), logger.clone());
let their_shutdown_scriptpubkey = if their_local_features.supports_upfront_shutdown_script() {
match &msg.shutdown_scriptpubkey {
};
let obscure_factor = chan.get_commitment_transaction_number_obscure_factor();
- chan.channel_monitor.set_commitment_obscure_factor(obscure_factor);
+ let funding_redeemscript = chan.get_funding_redeemscript();
+ chan.channel_monitor.set_basic_channel_info(&msg.htlc_basepoint, &msg.delayed_payment_basepoint, msg.to_self_delay, funding_redeemscript, msg.funding_satoshis, obscure_factor);
Ok(chan)
}
}
} else { None };
- self.channel_monitor.set_their_base_keys(&msg.htlc_basepoint, &msg.delayed_payment_basepoint);
-
self.their_dust_limit_satoshis = msg.dust_limit_satoshis;
self.their_max_htlc_value_in_flight_msat = cmp::min(msg.max_htlc_value_in_flight_msat, self.channel_value_satoshis * 1000);
self.their_channel_reserve_satoshis = msg.channel_reserve_satoshis;
self.their_shutdown_scriptpubkey = their_shutdown_scriptpubkey;
let obscure_factor = self.get_commitment_transaction_number_obscure_factor();
- self.channel_monitor.set_commitment_obscure_factor(obscure_factor);
- self.channel_monitor.set_their_to_self_delay(msg.to_self_delay);
+ let funding_redeemscript = self.get_funding_redeemscript();
+ self.channel_monitor.set_basic_channel_info(&msg.htlc_basepoint, &msg.delayed_payment_basepoint, msg.to_self_delay, funding_redeemscript, self.channel_value_satoshis, obscure_factor);
self.channel_state = ChannelState::OurInitSent as u32 | ChannelState::TheirInitSent as u32;
key_storage: Storage,
their_htlc_base_key: Option<PublicKey>,
their_delayed_payment_base_key: Option<PublicKey>,
+ funding_redeemscript: Option<Script>,
+ channel_value_satoshis: Option<u64>,
// first is the idx of the first of the two revocation points
their_cur_revocation_points: Option<(u64, PublicKey, Option<PublicKey>)>,
self.key_storage != other.key_storage ||
self.their_htlc_base_key != other.their_htlc_base_key ||
self.their_delayed_payment_base_key != other.their_delayed_payment_base_key ||
+ self.funding_redeemscript != other.funding_redeemscript ||
+ self.channel_value_satoshis != other.channel_value_satoshis ||
self.their_cur_revocation_points != other.their_cur_revocation_points ||
self.our_to_self_delay != other.our_to_self_delay ||
self.their_to_self_delay != other.their_to_self_delay ||
},
their_htlc_base_key: None,
their_delayed_payment_base_key: None,
+ funding_redeemscript: None,
+ channel_value_satoshis: None,
their_cur_revocation_points: None,
our_to_self_delay: our_to_self_delay,
Ok(())
}
- /// Panics if commitment_transaction_number_obscure_factor doesn't fit in 48 bits
- pub(super) fn set_commitment_obscure_factor(&mut self, commitment_transaction_number_obscure_factor: u64) {
- assert!(commitment_transaction_number_obscure_factor < (1 << 48));
- self.commitment_transaction_number_obscure_factor = commitment_transaction_number_obscure_factor;
- }
-
/// Allows this monitor to scan only for transactions which are applicable. Note that this is
/// optional, without it this monitor cannot be used in an SPV client, but you may wish to
/// avoid this (or call unset_funding_info) on a monitor you wish to send to a watchtower as it
}
/// We log these base keys at channel opening to being able to rebuild redeemscript in case of leaked revoked commit tx
- pub(super) fn set_their_base_keys(&mut self, their_htlc_base_key: &PublicKey, their_delayed_payment_base_key: &PublicKey) {
+ /// Panics if commitment_transaction_number_obscure_factor doesn't fit in 48 bits
+ pub(super) fn set_basic_channel_info(&mut self, their_htlc_base_key: &PublicKey, their_delayed_payment_base_key: &PublicKey, their_to_self_delay: u16, funding_redeemscript: Script, channel_value_satoshis: u64, commitment_transaction_number_obscure_factor: u64) {
self.their_htlc_base_key = Some(their_htlc_base_key.clone());
self.their_delayed_payment_base_key = Some(their_delayed_payment_base_key.clone());
- }
-
- pub(super) fn set_their_to_self_delay(&mut self, their_to_self_delay: u16) {
self.their_to_self_delay = Some(their_to_self_delay);
+ self.funding_redeemscript = Some(funding_redeemscript);
+ self.channel_value_satoshis = Some(channel_value_satoshis);
+ assert!(commitment_transaction_number_obscure_factor < (1 << 48));
+ self.commitment_transaction_number_obscure_factor = commitment_transaction_number_obscure_factor;
}
pub(super) fn unset_funding_info(&mut self) {
writer.write_all(&self.their_htlc_base_key.as_ref().unwrap().serialize())?;
writer.write_all(&self.their_delayed_payment_base_key.as_ref().unwrap().serialize())?;
+ self.funding_redeemscript.as_ref().unwrap().write(writer)?;
+ self.channel_value_satoshis.unwrap().write(writer)?;
match self.their_cur_revocation_points {
Some((idx, pubkey, second_option)) => {
let their_htlc_base_key = Some(Readable::read(reader)?);
let their_delayed_payment_base_key = Some(Readable::read(reader)?);
+ let funding_redeemscript = Some(Readable::read(reader)?);
+ let channel_value_satoshis = Some(Readable::read(reader)?);
let their_cur_revocation_points = {
let first_idx = <U48 as Readable<R>>::read(reader)?.0;
key_storage,
their_htlc_base_key,
their_delayed_payment_base_key,
+ funding_redeemscript,
+ channel_value_satoshis,
their_cur_revocation_points,
our_to_self_delay,
// Prune with one old state and a local commitment tx holding a few overlaps with the
// old state.
let mut monitor = ChannelMonitor::new(&SecretKey::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[43; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()), 0, Script::new(), logger.clone());
- monitor.set_their_to_self_delay(10);
+ monitor.their_to_self_delay = Some(10);
monitor.provide_latest_local_commitment_tx_info(dummy_tx.clone(), dummy_keys!(), 0, preimages_to_local_htlcs!(preimages[0..10]));
monitor.provide_latest_remote_commitment_tx_info(&dummy_tx, preimages_slice_to_htlc_outputs!(preimages[5..15]), 281474976710655, dummy_key);