Skip to content

Commit f018fdc

Browse files
committed
Expose initial countrparty commitment txid and value on ChannelMonitor
The very first counterparty commitment tx is provided to the `ChannelMonitor` directly upon creation rather than through a `ChannelMonitorUpdate`, so in order to form a justice tx in the persistence pipeline for the very first commitment, we need to expose extra information. There is probably a better API for this, but this at the least shows the minimum information necessary required to make this work.
1 parent 37bfbc9 commit f018fdc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
751751

752752
on_holder_tx_csv: u16,
753753

754+
initial_to_counterparty_value: u64,
755+
754756
commitment_secrets: CounterpartyCommitmentSecrets,
755757
/// The set of outpoints in each counterparty commitment transaction. We always need at least
756758
/// the payment hash from `HTLCOutputInCommitment` to claim even a revoked commitment
@@ -927,6 +929,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signe
927929
self.counterparty_commitment_params.write(writer)?;
928930
self.funding_redeemscript.write(writer)?;
929931
self.channel_value_satoshis.write(writer)?;
932+
self.initial_to_counterparty_value.write(writer)?;
930933

931934
match self.their_cur_per_commitment_points {
932935
Some((idx, pubkey, second_option)) => {
@@ -1087,6 +1090,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
10871090

10881091
let channel_keys_id = keys.channel_keys_id();
10891092
let holder_revocation_basepoint = keys.pubkeys().revocation_basepoint;
1093+
let initial_to_counterparty_value = initial_holder_commitment_tx.to_countersignatory_value_sat();
10901094

10911095
// block for Rust 1.34 compat
10921096
let (holder_commitment_tx, current_holder_commitment_number) = {
@@ -1137,6 +1141,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
11371141

11381142
on_holder_tx_csv: counterparty_channel_parameters.selected_contest_delay,
11391143

1144+
initial_to_counterparty_value,
1145+
11401146
commitment_secrets: CounterpartyCommitmentSecrets::new(),
11411147
counterparty_claimable_outpoints: HashMap::new(),
11421148
counterparty_commitment_txn_on_chain: HashMap::new(),
@@ -1300,6 +1306,16 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
13001306
self.inner.lock().unwrap().sign_justice_revoked_output(justice_tx, input_idx, value, per_commitment_key)
13011307
}
13021308

1309+
/// TODO: docs
1310+
pub fn get_current_counterparty_commitment_txid(&self) -> Option<Txid> {
1311+
self.inner.lock().unwrap().get_current_counterparty_commitment_txid()
1312+
}
1313+
1314+
/// TODO: docs
1315+
pub fn initial_to_counterparty_value(&self) -> u64 {
1316+
self.inner.lock().unwrap().initial_to_counterparty_value()
1317+
}
1318+
13031319
pub(crate) fn get_min_seen_secret(&self) -> u64 {
13041320
self.inner.lock().unwrap().get_min_seen_secret()
13051321
}
@@ -2579,6 +2595,14 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
25792595
self.onchain_tx_handler.signer.sign_justice_revoked_output(&justice_tx, input_idx, value, &per_commitment_key, &self.onchain_tx_handler.secp_ctx)
25802596
}
25812597

2598+
pub(crate) fn get_current_counterparty_commitment_txid(&self) -> Option<Txid> {
2599+
self.current_counterparty_commitment_txid
2600+
}
2601+
2602+
pub(crate) fn initial_to_counterparty_value(&self) -> u64 {
2603+
self.initial_to_counterparty_value
2604+
}
2605+
25822606
/// Can only fail if idx is < get_min_seen_secret
25832607
fn get_secret(&self, idx: u64) -> Option<[u8; 32]> {
25842608
self.commitment_secrets.get_secret(idx)
@@ -3873,6 +3897,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
38733897
let counterparty_commitment_params = Readable::read(reader)?;
38743898
let funding_redeemscript = Readable::read(reader)?;
38753899
let channel_value_satoshis = Readable::read(reader)?;
3900+
let initial_to_counterparty_value = Readable::read(reader)?;
38763901

38773902
let their_cur_per_commitment_points = {
38783903
let first_idx = <U48 as Readable>::read(reader)?.0;
@@ -4073,6 +4098,8 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
40734098

40744099
on_holder_tx_csv,
40754100

4101+
initial_to_counterparty_value,
4102+
40764103
commitment_secrets,
40774104
counterparty_claimable_outpoints,
40784105
counterparty_commitment_txn_on_chain,

0 commit comments

Comments
 (0)