Skip to content

Commit bbbae59

Browse files
committed
temp: to remote spk
1 parent ccb8039 commit bbbae59

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ pub(crate) enum ChannelMonitorUpdateStep {
544544
to_broadcaster_value_sat: Option<u64>,
545545
to_countersignatory_value_sat: Option<u64>,
546546
tolocal_spk: ScriptBuf,
547+
toremote_spk: ScriptBuf,
547548
},
548549
PaymentPreimage {
549550
payment_preimage: PaymentPreimage,
@@ -596,6 +597,7 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
596597
(5, to_countersignatory_value_sat, option),
597598
(6, htlc_outputs, required_vec),
598599
(8, tolocal_spk, required),
600+
(10, toremote_spk, required),
599601
},
600602
(2, PaymentPreimage) => {
601603
(0, payment_preimage, required),
@@ -3446,7 +3448,7 @@ impl<Signer: ChannelSigner> ChannelMonitorImpl<Signer> {
34463448
ref htlc_outputs, commitment_number, their_per_commitment_point,
34473449
feerate_per_kw: Some(feerate_per_kw),
34483450
to_broadcaster_value_sat: Some(to_broadcaster_value),
3449-
to_countersignatory_value_sat: Some(to_countersignatory_value), ref tolocal_spk } => {
3451+
to_countersignatory_value_sat: Some(to_countersignatory_value), ref tolocal_spk, toremote_spk: _ } => {
34503452

34513453
let nondust_htlcs = htlc_outputs.iter().filter_map(|(htlc, _)| {
34523454
htlc.transaction_output_index.map(|_| (htlc.clone(), None))

lightning/src/ln/chan_utils.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,8 @@ pub struct CommitmentTransaction {
13741374
built: BuiltCommitmentTransaction,
13751375
// delayed spk
13761376
revokeable_spk: ScriptBuf,
1377+
// to_remote spk
1378+
to_remote_spk: ScriptBuf,
13771379
}
13781380

13791381
impl Eq for CommitmentTransaction {}
@@ -1386,7 +1388,8 @@ impl PartialEq for CommitmentTransaction {
13861388
self.htlcs == o.htlcs &&
13871389
self.channel_type_features == o.channel_type_features &&
13881390
self.keys == o.keys &&
1389-
self.revokeable_spk == o.revokeable_spk;
1391+
self.revokeable_spk == o.revokeable_spk &&
1392+
self.to_remote_spk == o.to_remote_spk;
13901393
if eq {
13911394
debug_assert_eq!(self.built.transaction, o.built.transaction);
13921395
debug_assert_eq!(self.built.txid, o.built.txid);
@@ -1410,6 +1413,7 @@ impl Writeable for CommitmentTransaction {
14101413
(14, legacy_deserialization_prevention_marker, option),
14111414
(15, self.channel_type_features, required),
14121415
(16, self.revokeable_spk, required),
1416+
(18, self.to_remote_spk, required),
14131417
});
14141418
Ok(())
14151419
}
@@ -1429,6 +1433,7 @@ impl Readable for CommitmentTransaction {
14291433
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
14301434
(15, channel_type_features, option),
14311435
(16, revokeable_spk, required),
1436+
(18, to_remote_spk, required),
14321437
});
14331438

14341439
let mut additional_features = ChannelTypeFeatures::empty();
@@ -1446,6 +1451,7 @@ impl Readable for CommitmentTransaction {
14461451
htlcs,
14471452
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key()),
14481453
revokeable_spk: revokeable_spk.0.unwrap(),
1454+
to_remote_spk: to_remote_spk.0.unwrap(),
14491455
})
14501456
}
14511457
}
@@ -1466,7 +1472,7 @@ impl CommitmentTransaction {
14661472
let to_countersignatory_value_sat = Amount::from_sat(to_countersignatory_value_sat);
14671473

14681474
// Sort outputs and populate output indices while keeping track of the auxiliary data
1469-
let (outputs, htlcs, revokeable_spk) = Self::internal_build_outputs(&keys.per_commitment_point, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, signer, secp_ctx, is_holder_tx, commitment_number).unwrap();
1475+
let (outputs, htlcs, revokeable_spk, to_remote_spk) = Self::internal_build_outputs(&keys.per_commitment_point, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, signer, secp_ctx, is_holder_tx, commitment_number).unwrap();
14701476

14711477
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters);
14721478
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
@@ -1485,6 +1491,7 @@ impl CommitmentTransaction {
14851491
txid
14861492
},
14871493
revokeable_spk,
1494+
to_remote_spk,
14881495
}
14891496
}
14901497

@@ -1500,7 +1507,7 @@ impl CommitmentTransaction {
15001507
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(self.commitment_number, channel_parameters);
15011508

15021509
let mut htlcs_with_aux = self.htlcs.iter().map(|h| (h.clone(), ())).collect();
1503-
let (outputs, _, _) = Self::internal_build_outputs(per_commitment_point, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, signer, secp_ctx, is_holder_tx, self.commitment_number)?;
1510+
let (outputs, _, _, _) = Self::internal_build_outputs(per_commitment_point, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, signer, secp_ctx, is_holder_tx, self.commitment_number)?;
15041511

15051512
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
15061513
let txid = transaction.compute_txid();
@@ -1524,13 +1531,14 @@ impl CommitmentTransaction {
15241531
// - initial sorting of outputs / HTLCs in the constructor, in which case T is auxiliary data the
15251532
// caller needs to have sorted together with the HTLCs so it can keep track of the output index
15261533
// - building of a bitcoin transaction during a verify() call, in which case T is just ()
1527-
fn internal_build_outputs<T, Signer: ChannelSigner>(per_commitment_point: &PublicKey, to_broadcaster_value_sat: Amount, to_countersignatory_value_sat: Amount, htlcs_with_aux: &mut Vec<(HTLCOutputInCommitment, T)>, signer: &Signer, secp_ctx: &Secp256k1<secp256k1::All>, is_holder_tx: bool, commitment_number: u64) -> Result<(Vec<TxOut>, Vec<HTLCOutputInCommitment>, ScriptBuf), ()> {
1534+
fn internal_build_outputs<T, Signer: ChannelSigner>(per_commitment_point: &PublicKey, to_broadcaster_value_sat: Amount, to_countersignatory_value_sat: Amount, htlcs_with_aux: &mut Vec<(HTLCOutputInCommitment, T)>, signer: &Signer, secp_ctx: &Secp256k1<secp256k1::All>, is_holder_tx: bool, commitment_number: u64) -> Result<(Vec<TxOut>, Vec<HTLCOutputInCommitment>, ScriptBuf, ScriptBuf), ()> {
15281535
let mut txouts: Vec<(TxOut, Option<&mut HTLCOutputInCommitment>)> = Vec::new();
15291536

1537+
let to_remote_spk = signer.get_counterparty_payment_script(is_holder_tx);
15301538
if to_countersignatory_value_sat > Amount::ZERO {
15311539
txouts.push((
15321540
TxOut {
1533-
script_pubkey: signer.get_counterparty_payment_script(is_holder_tx),
1541+
script_pubkey: to_remote_spk.clone(),
15341542
value: to_countersignatory_value_sat,
15351543
},
15361544
None,
@@ -1593,7 +1601,7 @@ impl CommitmentTransaction {
15931601
}
15941602
outputs.push(out.0);
15951603
}
1596-
Ok((outputs, htlcs, revokeable_spk))
1604+
Ok((outputs, htlcs, revokeable_spk, to_remote_spk))
15971605
}
15981606

15991607
fn internal_build_inputs(commitment_number: u64, channel_parameters: &DirectedChannelTransactionParameters) -> (u64, Vec<TxIn>) {
@@ -1762,6 +1770,11 @@ impl<'a> TrustedCommitmentTransaction<'a> {
17621770
self.inner.revokeable_spk.clone()
17631771
}
17641772

1773+
/// To remote spk
1774+
pub fn to_remote_spk(&self) -> ScriptBuf {
1775+
self.inner.to_remote_spk.clone()
1776+
}
1777+
17651778
/// Helper method to build an unsigned justice transaction spending the revokeable
17661779
/// `to_local` output to a destination script. Fee estimation accounts for the expected
17671780
/// revocation witness data that will be added when signed.

lightning/src/ln/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8150,6 +8150,7 @@ impl<SP: Deref> FundedChannel<SP> where
81508150
to_broadcaster_value_sat: Some(counterparty_commitment_tx.to_broadcaster_value_sat()),
81518151
to_countersignatory_value_sat: Some(counterparty_commitment_tx.to_countersignatory_value_sat()),
81528152
tolocal_spk: counterparty_commitment_tx.trust().revokeable_spk(),
8153+
toremote_spk: counterparty_commitment_tx.trust().to_remote_spk(),
81538154
}],
81548155
channel_id: Some(self.context.channel_id()),
81558156
};

0 commit comments

Comments
 (0)