Skip to content

Commit 2d49336

Browse files
committed
Add counterparty_node_id to ChannelMonitor
1 parent f3d5b94 commit 2d49336

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,9 @@ pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
722722
// the full block_connected).
723723
best_block: BestBlock,
724724

725+
/// The node_id of our counterparty
726+
counterparty_node_id: Option<PublicKey>,
727+
725728
secp_ctx: Secp256k1<secp256k1::All>, //TODO: dedup this a bit...
726729
}
727730

@@ -954,6 +957,7 @@ impl<Signer: Sign> Writeable for ChannelMonitorImpl<Signer> {
954957
(3, self.htlcs_resolved_on_chain, vec_type),
955958
(5, self.pending_monitor_events, vec_type),
956959
(7, self.funding_spend_seen, required),
960+
(9, self.counterparty_node_id, option),
957961
});
958962

959963
Ok(())
@@ -967,7 +971,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
967971
funding_redeemscript: Script, channel_value_satoshis: u64,
968972
commitment_transaction_number_obscure_factor: u64,
969973
initial_holder_commitment_tx: HolderCommitmentTransaction,
970-
best_block: BestBlock) -> ChannelMonitor<Signer> {
974+
best_block: BestBlock, counterparty_node_id: PublicKey) -> ChannelMonitor<Signer> {
971975

972976
assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
973977
let payment_key_hash = WPubkeyHash::hash(&keys.pubkeys().payment_point.serialize());
@@ -1057,6 +1061,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
10571061
htlcs_resolved_on_chain: Vec::new(),
10581062

10591063
best_block,
1064+
counterparty_node_id: Some(counterparty_node_id),
10601065

10611066
secp_ctx,
10621067
}),
@@ -3336,11 +3341,13 @@ impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
33363341
let mut funding_spend_confirmed = None;
33373342
let mut htlcs_resolved_on_chain = Some(Vec::new());
33383343
let mut funding_spend_seen = Some(false);
3344+
let mut counterparty_node_id = None;
33393345
read_tlv_fields!(reader, {
33403346
(1, funding_spend_confirmed, option),
33413347
(3, htlcs_resolved_on_chain, vec_type),
33423348
(5, pending_monitor_events, vec_type),
33433349
(7, funding_spend_seen, option),
3350+
(9, counterparty_node_id, option),
33443351
});
33453352

33463353
let mut secp_ctx = Secp256k1::new();
@@ -3395,6 +3402,7 @@ impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
33953402
htlcs_resolved_on_chain: htlcs_resolved_on_chain.unwrap(),
33963403

33973404
best_block,
3405+
counterparty_node_id,
33983406

33993407
secp_ctx,
34003408
}),
@@ -3631,7 +3639,7 @@ mod tests {
36313639
(OutPoint { txid: Txid::from_slice(&[43; 32]).unwrap(), index: 0 }, Script::new()),
36323640
&channel_parameters,
36333641
Script::new(), 46, 0,
3634-
HolderCommitmentTransaction::dummy(), best_block);
3642+
HolderCommitmentTransaction::dummy(), best_block, dummy_key);
36353643

36363644
monitor.provide_latest_holder_commitment_tx(HolderCommitmentTransaction::dummy(), preimages_to_holder_htlcs!(preimages[0..10])).unwrap();
36373645
let dummy_txid = dummy_tx.txid();

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,7 +2209,7 @@ impl<Signer: Sign> Channel<Signer> {
22092209
&self.channel_transaction_parameters,
22102210
funding_redeemscript.clone(), self.channel_value_satoshis,
22112211
obscure_factor,
2212-
holder_commitment_tx, best_block);
2212+
holder_commitment_tx, best_block, self.counterparty_node_id);
22132213

22142214
channel_monitor.provide_latest_counterparty_commitment_tx(counterparty_initial_commitment_txid, Vec::new(), self.cur_counterparty_commitment_transaction_number, self.counterparty_cur_commitment_point.unwrap(), logger);
22152215

@@ -2286,7 +2286,7 @@ impl<Signer: Sign> Channel<Signer> {
22862286
&self.channel_transaction_parameters,
22872287
funding_redeemscript.clone(), self.channel_value_satoshis,
22882288
obscure_factor,
2289-
holder_commitment_tx, best_block);
2289+
holder_commitment_tx, best_block, self.counterparty_node_id);
22902290

22912291
channel_monitor.provide_latest_counterparty_commitment_tx(counterparty_initial_bitcoin_tx.txid, Vec::new(), self.cur_counterparty_commitment_transaction_number, self.counterparty_cur_commitment_point.unwrap(), logger);
22922292

0 commit comments

Comments
 (0)