Skip to content

Commit b2934c0

Browse files
committed
Use the TxOutRef type for the ChannelMonitor's funding_txo field.
Signed-off-by: Jean Pierre Dudey <[email protected]>
1 parent d8474c9 commit b2934c0

File tree

6 files changed

+54
-49
lines changed

6 files changed

+54
-49
lines changed

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extern crate lightning;
44
extern crate secp256k1;
55

66
use bitcoin::blockdata::block::BlockHeader;
7-
use bitcoin::blockdata::transaction::{Transaction, TxOut};
7+
use bitcoin::blockdata::transaction::{Transaction, TxOut, TxOutRef};
88
use bitcoin::blockdata::script::Script;
99
use bitcoin::network::constants::Network;
1010
use bitcoin::network::serialize::{serialize, BitcoinHash};
@@ -93,7 +93,7 @@ impl FeeEstimator for FuzzEstimator {
9393

9494
struct TestChannelMonitor {}
9595
impl channelmonitor::ManyChannelMonitor for TestChannelMonitor {
96-
fn add_update_monitor(&self, _funding_txo: (Sha256dHash, u16), _monitor: channelmonitor::ChannelMonitor) -> Result<(), channelmonitor::ChannelMonitorUpdateErr> {
96+
fn add_update_monitor(&self, _funding_txo: TxOutRef, _monitor: channelmonitor::ChannelMonitor) -> Result<(), channelmonitor::ChannelMonitorUpdateErr> {
9797
//TODO!
9898
Ok(())
9999
}
@@ -280,7 +280,10 @@ pub fn do_test(data: &[u8]) {
280280
let mut tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: vec![TxOut {
281281
value: funding_generation.1, script_pubkey: funding_generation.2,
282282
}] };
283-
let funding_output = (Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), 0);
283+
let funding_output = TxOutRef {
284+
txid: Sha256dHash::from_data(&serialize(&tx).unwrap()[..]),
285+
index: 0
286+
};
284287
channelmanager.funding_transaction_generated(&funding_generation.0, funding_output.clone());
285288
pending_funding_signatures.insert(funding_output, tx);
286289
}

src/ln/channel.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bitcoin::blockdata::block::BlockHeader;
22
use bitcoin::blockdata::script::{Script,Builder};
3-
use bitcoin::blockdata::transaction::{TxIn, TxOut, Transaction, SigHashType};
3+
use bitcoin::blockdata::transaction::{TxIn, TxOut, TxOutRef, Transaction, SigHashType};
44
use bitcoin::blockdata::opcodes;
55
use bitcoin::util::uint::Uint256;
66
use bitcoin::util::hash::{Sha256dHash, Hash160};
@@ -599,8 +599,8 @@ impl Channel {
599599
let txins = {
600600
let mut ins: Vec<TxIn> = Vec::new();
601601
ins.push(TxIn {
602-
prev_hash: self.channel_monitor.get_funding_txo().unwrap().0,
603-
prev_index: self.channel_monitor.get_funding_txo().unwrap().1 as u32,
602+
prev_hash: self.channel_monitor.get_funding_txo().unwrap().txid,
603+
prev_index: self.channel_monitor.get_funding_txo().unwrap().index as u32,
604604
script_sig: Script::new(),
605605
sequence: ((0x80 as u32) << 8*3) | ((obscured_commitment_transaction_number >> 3*8) as u32),
606606
witness: Vec::new(),
@@ -733,8 +733,8 @@ impl Channel {
733733
let txins = {
734734
let mut ins: Vec<TxIn> = Vec::new();
735735
ins.push(TxIn {
736-
prev_hash: self.channel_monitor.get_funding_txo().unwrap().0,
737-
prev_index: self.channel_monitor.get_funding_txo().unwrap().1 as u32,
736+
prev_hash: self.channel_monitor.get_funding_txo().unwrap().txid,
737+
prev_index: self.channel_monitor.get_funding_txo().unwrap().index as u32,
738738
script_sig: Script::new(),
739739
sequence: 0xffffffff,
740740
witness: Vec::new(),
@@ -1165,7 +1165,7 @@ impl Channel {
11651165
self.channel_monitor.provide_latest_remote_commitment_tx_info(&remote_initial_commitment_tx, Vec::new());
11661166
self.channel_state = ChannelState::FundingSent as u32;
11671167
let funding_txo = self.channel_monitor.get_funding_txo().unwrap();
1168-
self.channel_id = funding_txo.0.into_be() ^ Uint256::from_u64(funding_txo.1 as u64).unwrap(); //TODO: or le?
1168+
self.channel_id = funding_txo.txid.into_be() ^ Uint256::from_u64(funding_txo.index as u64).unwrap(); //TODO: or le?
11691169
self.cur_remote_commitment_transaction_number -= 1;
11701170
self.cur_local_commitment_transaction_number -= 1;
11711171

@@ -1823,7 +1823,7 @@ impl Channel {
18231823

18241824
/// Returns the funding_txo we either got from our peer, or were given by
18251825
/// get_outbound_funding_created.
1826-
pub fn get_funding_txo(&self) -> Option<(Sha256dHash, u16)> {
1826+
pub fn get_funding_txo(&self) -> Option<TxOutRef> {
18271827
self.channel_monitor.get_funding_txo()
18281828
}
18291829

@@ -1920,8 +1920,8 @@ impl Channel {
19201920
}
19211921
if non_shutdown_state & !(ChannelState::TheirFundingLocked as u32) == ChannelState::FundingSent as u32 {
19221922
for (ref tx, index_in_block) in txn_matched.iter().zip(indexes_of_txn_matched) {
1923-
if tx.txid() == self.channel_monitor.get_funding_txo().unwrap().0 {
1924-
let txo_idx = self.channel_monitor.get_funding_txo().unwrap().1 as usize;
1923+
if tx.txid() == self.channel_monitor.get_funding_txo().unwrap().txid {
1924+
let txo_idx = self.channel_monitor.get_funding_txo().unwrap().index as usize;
19251925
if txo_idx >= tx.output.len() || tx.output[txo_idx].script_pubkey != self.get_funding_redeemscript().to_v0_p2wsh() ||
19261926
tx.output[txo_idx].value != self.channel_value_satoshis {
19271927
self.channel_state = ChannelState::ShutdownComplete as u32;
@@ -1930,7 +1930,7 @@ impl Channel {
19301930
self.funding_tx_confirmations = 1;
19311931
self.short_channel_id = Some(((height as u64) << (5*8)) |
19321932
((*index_in_block as u64) << (2*8)) |
1933-
((self.channel_monitor.get_funding_txo().unwrap().1 as u64) << (2*8)));
1933+
((self.channel_monitor.get_funding_txo().unwrap().index as u64) << (2*8)));
19341934
}
19351935
}
19361936
}
@@ -2070,7 +2070,7 @@ impl Channel {
20702070
self.channel_monitor.provide_latest_remote_commitment_tx_info(&commitment_tx, Vec::new());
20712071
self.channel_state = ChannelState::FundingCreated as u32;
20722072
let funding_txo = self.channel_monitor.get_funding_txo().unwrap();
2073-
self.channel_id = funding_txo.0.into_be() ^ Uint256::from_u64(funding_txo.1 as u64).unwrap(); //TODO: or le?
2073+
self.channel_id = funding_txo.txid.into_be() ^ Uint256::from_u64(funding_txo.index as u64).unwrap(); //TODO: or le?
20742074
self.cur_remote_commitment_transaction_number -= 1;
20752075

20762076
Ok((msgs::FundingCreated {

src/ln/channelmanager.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use bitcoin::blockdata::block::BlockHeader;
2-
use bitcoin::blockdata::transaction::Transaction;
1+
use bitcoin::blockdata::block::BlockHeader;
2+
use bitcoin::blockdata::transaction::{TxOutRef, Transaction};
33
use bitcoin::blockdata::constants::genesis_block;
44
use bitcoin::network::constants::Network;
55
use bitcoin::network::serialize::BitcoinHash;
@@ -235,12 +235,12 @@ impl ChannelManager {
235235
pub fn create_channel(&self, their_network_key: PublicKey, channel_value_satoshis: u64, user_id: u64) -> Result<msgs::OpenChannel, HandleError> {
236236
let chan_keys = if cfg!(feature = "fuzztarget") {
237237
ChannelKeys {
238-
funding_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
239-
revocation_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
240-
payment_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
238+
funding_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
239+
revocation_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
240+
payment_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
241241
delayed_payment_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
242-
htlc_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
243-
channel_close_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
242+
htlc_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
243+
channel_close_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
244244
channel_monitor_claim_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
245245
commitment_seed: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
246246
}
@@ -661,12 +661,12 @@ impl ChannelManager {
661661

662662
/// Call this upon creation of a funding transaction for the given channel.
663663
/// Panics if a funding transaction has already been provided for this channel.
664-
pub fn funding_transaction_generated(&self, temporary_channel_id: &Uint256, funding_txo: (Sha256dHash, u16)) {
664+
pub fn funding_transaction_generated(&self, temporary_channel_id: &Uint256, funding_txo: TxOutRef) {
665665
let (chan, msg, chan_monitor) = {
666666
let mut channel_state = self.channel_state.lock().unwrap();
667667
match channel_state.by_id.remove(&temporary_channel_id) {
668668
Some(mut chan) => {
669-
match chan.get_outbound_funding_created(funding_txo.0, funding_txo.1) {
669+
match chan.get_outbound_funding_created(funding_txo.txid, funding_txo.index as u16) {
670670
Ok(funding_msg) => {
671671
(chan, funding_msg.0, funding_msg.1)
672672
},
@@ -1029,7 +1029,7 @@ impl ChainListener for ChannelManager {
10291029
if let Some(funding_txo) = channel.get_funding_txo() {
10301030
for tx in txn_matched {
10311031
for inp in tx.input.iter() {
1032-
if inp.prev_hash == funding_txo.0 && inp.prev_index == funding_txo.1 as u32 {
1032+
if inp.prev_hash == funding_txo.txid && inp.prev_index == funding_txo.index as u32 {
10331033
if let Some(short_id) = channel.get_short_channel_id() {
10341034
short_to_ids_to_remove.push(short_id);
10351035
}
@@ -1094,12 +1094,12 @@ impl ChannelMessageHandler for ChannelManager {
10941094

10951095
let chan_keys = if cfg!(feature = "fuzztarget") {
10961096
ChannelKeys {
1097-
funding_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
1098-
revocation_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
1099-
payment_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
1097+
funding_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
1098+
revocation_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
1099+
payment_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
11001100
delayed_payment_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
1101-
htlc_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
1102-
channel_close_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
1101+
htlc_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
1102+
channel_close_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
11031103
channel_monitor_claim_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
11041104
commitment_seed: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
11051105
}
@@ -1578,7 +1578,7 @@ impl ChannelMessageHandler for ChannelManager {
15781578

15791579
let mut hmac = Hmac::new(Sha256::new(), &um);
15801580
hmac.input(&err_packet.encode()[32..]);
1581-
let mut calc_tag = [0u8; 32];
1581+
let mut calc_tag = [0u8; 32];
15821582
hmac.raw_result(&mut calc_tag);
15831583
if crypto::util::fixed_time_eq(&calc_tag, &err_packet.hmac) {
15841584
const UNKNOWN_CHAN: u16 = 0x4000|10;
@@ -1812,7 +1812,7 @@ mod tests {
18121812
use bitcoin::util::hash::Sha256dHash;
18131813
use bitcoin::util::uint::Uint256;
18141814
use bitcoin::blockdata::block::BlockHeader;
1815-
use bitcoin::blockdata::transaction::{Transaction, TxOut};
1815+
use bitcoin::blockdata::transaction::{Transaction, TxOut, TxOutRef};
18161816
use bitcoin::network::constants::Network;
18171817
use bitcoin::network::serialize::serialize;
18181818
use bitcoin::network::serialize::BitcoinHash;
@@ -2020,7 +2020,10 @@ mod tests {
20202020
tx = Transaction { version: chan_id as u32, lock_time: 0, input: Vec::new(), output: vec![TxOut {
20212021
value: *channel_value_satoshis, script_pubkey: output_script.clone(),
20222022
}]};
2023-
funding_output = (Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), 0);
2023+
funding_output = TxOutRef {
2024+
txid: Sha256dHash::from_data(&serialize(&tx).unwrap()[..]),
2025+
index: 0
2026+
};
20242027

20252028
node_a.node.funding_transaction_generated(&temporary_channel_id, funding_output.clone());
20262029
let mut added_monitors = node_a.chan_monitor.added_monitors.lock().unwrap();

src/ln/channelmonitor.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bitcoin::blockdata::block::BlockHeader;
2-
use bitcoin::blockdata::transaction::{TxIn,TxOut,SigHashType,Transaction};
2+
use bitcoin::blockdata::transaction::{TxIn,TxOut,TxOutRef,SigHashType,Transaction};
33
use bitcoin::blockdata::script::Script;
44
use bitcoin::util::hash::Sha256dHash;
55
use bitcoin::util::bip143;
@@ -43,7 +43,7 @@ pub enum ChannelMonitorUpdateErr {
4343
/// which we have revoked, allowing our counterparty to claim all funds in the channel!
4444
pub trait ManyChannelMonitor: Send + Sync {
4545
/// Adds or updates a monitor for the given funding_txid+funding_output_index.
46-
fn add_update_monitor(&self, funding_txo: (Sha256dHash, u16), monitor: ChannelMonitor) -> Result<(), ChannelMonitorUpdateErr>;
46+
fn add_update_monitor(&self, funding_txo: TxOutRef, monitor: ChannelMonitor) -> Result<(), ChannelMonitorUpdateErr>;
4747
}
4848

4949
/// A simple implementation of a ManyChannelMonitor and ChainListener. Can be used to create a
@@ -53,7 +53,7 @@ pub trait ManyChannelMonitor: Send + Sync {
5353
/// users cannot overwrite a given channel by providing a duplicate key. ie you should probably
5454
/// index by a PublicKey which is required to sign any updates.
5555
/// If you're using this for local monitoring of your own channels, you probably want to use
56-
/// (Sha256dHash, u16) as the key, which will give you a ManyChannelMonitor implementation.
56+
/// TxOutRef as the key, which will give you a ManyChannelMonitor implementation.
5757
pub struct SimpleManyChannelMonitor<Key> {
5858
monitors: Mutex<HashMap<Key, ChannelMonitor>>,
5959
chain_monitor: Arc<ChainWatchInterface>,
@@ -91,15 +91,15 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static> SimpleManyChannelMonitor<Key>
9191
};
9292
match monitor.funding_txo {
9393
None => self.chain_monitor.watch_all_txn(),
94-
Some((funding_txid, funding_output_index)) => self.chain_monitor.install_watch_outpoint((funding_txid, funding_output_index as u32)),
94+
Some(outpoint) => self.chain_monitor.install_watch_outpoint((outpoint.txid, outpoint.index as u32)),
9595
}
9696
monitors.insert(key, monitor);
9797
Ok(())
9898
}
9999
}
100100

101-
impl ManyChannelMonitor for SimpleManyChannelMonitor<(Sha256dHash, u16)> {
102-
fn add_update_monitor(&self, funding_txo: (Sha256dHash, u16), monitor: ChannelMonitor) -> Result<(), ChannelMonitorUpdateErr> {
101+
impl ManyChannelMonitor for SimpleManyChannelMonitor<TxOutRef> {
102+
fn add_update_monitor(&self, funding_txo: TxOutRef, monitor: ChannelMonitor) -> Result<(), ChannelMonitorUpdateErr> {
103103
match self.add_update_monitor_by_key(funding_txo, monitor) {
104104
Ok(_) => Ok(()),
105105
Err(_) => Err(ChannelMonitorUpdateErr::PermanentFailure),
@@ -140,7 +140,7 @@ struct LocalSignedTx {
140140
}
141141

142142
pub struct ChannelMonitor {
143-
funding_txo: Option<(Sha256dHash, u16)>,
143+
funding_txo: Option<TxOutRef>,
144144
commitment_transaction_number_obscure_factor: u64,
145145

146146
key_storage: KeyStorage,
@@ -370,7 +370,7 @@ impl ChannelMonitor {
370370
/// avoid this (or call unset_funding_info) on a monitor you wish to send to a watchtower as it
371371
/// provides slightly better privacy.
372372
pub fn set_funding_info(&mut self, funding_txid: Sha256dHash, funding_output_index: u16) {
373-
self.funding_txo = Some((funding_txid, funding_output_index));
373+
self.funding_txo = Some(TxOutRef { txid: funding_txid, index: funding_output_index as usize });
374374
}
375375

376376
pub fn set_their_htlc_base_key(&mut self, their_htlc_base_key: &PublicKey) {
@@ -385,7 +385,7 @@ impl ChannelMonitor {
385385
self.funding_txo = None;
386386
}
387387

388-
pub fn get_funding_txo(&self) -> Option<(Sha256dHash, u16)> {
388+
pub fn get_funding_txo(&self) -> Option<TxOutRef> {
389389
self.funding_txo
390390
}
391391

@@ -748,7 +748,7 @@ impl ChannelMonitor {
748748
fn block_connected(&self, txn_matched: &[&Transaction], height: u32, broadcaster: &BroadcasterInterface) {
749749
for tx in txn_matched {
750750
for txin in tx.input.iter() {
751-
if self.funding_txo.is_none() || (txin.prev_hash == self.funding_txo.unwrap().0 && txin.prev_index == self.funding_txo.unwrap().1 as u32) {
751+
if self.funding_txo.is_none() || (txin.prev_hash == self.funding_txo.unwrap().txid && txin.prev_index == self.funding_txo.unwrap().index as u32) {
752752
let mut txn = self.check_spend_remote_transaction(tx, height);
753753
if txn.is_empty() {
754754
txn = self.check_spend_local_transaction(tx, height);

src/util/events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use ln::msgs;
22

3+
use bitcoin::blockdata::transaction::TxOutRef;
34
use bitcoin::blockdata::script::Script;
45
use bitcoin::util::uint::Uint256;
5-
use bitcoin::util::hash::Sha256dHash;
66

77
use secp256k1::key::PublicKey;
88

@@ -24,7 +24,7 @@ pub enum Event {
2424
/// channel. Broadcasting such a transaction prior to this event may lead to our counterparty
2525
/// trivially stealing all funds in the funding transaction!
2626
FundingBroadcastSafe {
27-
funding_txo: (Sha256dHash, u16),
27+
funding_txo: TxOutRef,
2828
/// The value passed in to ChannelManager::create_channel
2929
user_channel_id: u64,
3030
},

src/util/test_utils.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use chain::chaininterface;
22
use chain::chaininterface::ConfirmationTarget;
33
use ln::channelmonitor;
44

5-
use bitcoin::blockdata::transaction::Transaction;
6-
use bitcoin::util::hash::Sha256dHash;
5+
use bitcoin::blockdata::transaction::{TxOutRef, Transaction};
76

87
use std::sync::{Arc,Mutex};
98

@@ -17,8 +16,8 @@ impl chaininterface::FeeEstimator for TestFeeEstimator {
1716
}
1817

1918
pub struct TestChannelMonitor {
20-
pub added_monitors: Mutex<Vec<((Sha256dHash, u16), channelmonitor::ChannelMonitor)>>,
21-
pub simple_monitor: Arc<channelmonitor::SimpleManyChannelMonitor<(Sha256dHash, u16)>>,
19+
pub added_monitors: Mutex<Vec<(TxOutRef, channelmonitor::ChannelMonitor)>>,
20+
pub simple_monitor: Arc<channelmonitor::SimpleManyChannelMonitor<TxOutRef>>,
2221
}
2322
impl TestChannelMonitor {
2423
pub fn new(chain_monitor: Arc<chaininterface::ChainWatchInterface>, broadcaster: Arc<chaininterface::BroadcasterInterface>) -> Self {
@@ -29,7 +28,7 @@ impl TestChannelMonitor {
2928
}
3029
}
3130
impl channelmonitor::ManyChannelMonitor for TestChannelMonitor {
32-
fn add_update_monitor(&self, funding_txo: (Sha256dHash, u16), monitor: channelmonitor::ChannelMonitor) -> Result<(), channelmonitor::ChannelMonitorUpdateErr> {
31+
fn add_update_monitor(&self, funding_txo: TxOutRef, monitor: channelmonitor::ChannelMonitor) -> Result<(), channelmonitor::ChannelMonitorUpdateErr> {
3332
self.added_monitors.lock().unwrap().push((funding_txo, monitor.clone()));
3433
self.simple_monitor.add_update_monitor(funding_txo, monitor)
3534
}

0 commit comments

Comments
 (0)