-
Notifications
You must be signed in to change notification settings - Fork 412
Use the TxOutRef
type for the ChannelMonitor
's funding_txo field.
#33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fece28a
to
b2934c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really not sure how I feel about this generally. While using a struct is definitely nicer, using the usize-index TxOutRef from rust-bitcoin makes for a bunch of platform-dependant conversions, and since lightning restricts us to u16-indexes we end up down-converting from internal datastructures to lightning-specific stuff in a few places that worry me. Specifically, if an attacker were to eg provide a channelmonitor to a watchtower with a value too large it could make the watchtower panic. Maybe use our own with u16 indexes instead?
src/ln/channel.rs
Outdated
@@ -1930,7 +1930,7 @@ impl Channel { | |||
self.funding_tx_confirmations = 1; | |||
self.short_channel_id = Some(((height as u64) << (5*8)) | | |||
((*index_in_block as u64) << (2*8)) | | |||
((self.channel_monitor.get_funding_txo().unwrap().1 as u64) << (2*8))); | |||
((self.channel_monitor.get_funding_txo().unwrap().index as u64) << (2*8))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should just use txo_idx here now, then.
src/ln/channelmanager.rs
Outdated
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(), | ||
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(), | ||
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(), | ||
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(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You broken alignment here by converting spaces to tabs mid-line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for this I'm going to fix it up, Vim is messing with the alignment.
src/ln/channelmanager.rs
Outdated
@@ -661,12 +661,12 @@ impl ChannelManager { | |||
|
|||
/// Call this upon creation of a funding transaction for the given channel. | |||
/// Panics if a funding transaction has already been provided for this channel. | |||
pub fn funding_transaction_generated(&self, temporary_channel_id: &Uint256, funding_txo: (Sha256dHash, u16)) { | |||
pub fn funding_transaction_generated(&self, temporary_channel_id: &Uint256, funding_txo: TxOutRef) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, I dont like this. Practically no one should ever create a funding transaction (or any transaction) with more than 2**16 outputs, but its not technically impossible, so letting the user provide a usize instead of a u16 feels icky cause we're going a down-convert without making the user aware of it.
src/ln/channelmanager.rs
Outdated
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(), | ||
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(), | ||
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(), | ||
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(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broke alignment here, too.
src/ln/channelmanager.rs
Outdated
@@ -1578,7 +1578,7 @@ impl ChannelMessageHandler for ChannelManager { | |||
|
|||
let mut hmac = Hmac::new(Sha256::new(), &um); | |||
hmac.input(&err_packet.encode()[32..]); | |||
let mut calc_tag = [0u8; 32]; | |||
let mut calc_tag = [0u8; 32]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea what this is (you can remove the extra space, though, if you want).
src/ln/channelmanager.rs
Outdated
funding_output = (Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), 0); | ||
funding_output = TxOutRef { | ||
txid: Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), | ||
index: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad alignment here.
src/ln/channelmonitor.rs
Outdated
@@ -370,7 +370,7 @@ impl ChannelMonitor { | |||
/// avoid this (or call unset_funding_info) on a monitor you wish to send to a watchtower as it | |||
/// provides slightly better privacy. | |||
pub fn set_funding_info(&mut self, funding_txid: Sha256dHash, funding_output_index: u16) { | |||
self.funding_txo = Some((funding_txid, funding_output_index)); | |||
self.funding_txo = Some(TxOutRef { txid: funding_txid, index: funding_output_index as usize }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not change the function's signature, too?
@@ -748,7 +748,7 @@ impl ChannelMonitor { | |||
fn block_connected(&self, txn_matched: &[&Transaction], height: u32, broadcaster: &BroadcasterInterface) { | |||
for tx in txn_matched { | |||
for txin in tx.input.iter() { | |||
if self.funding_txo.is_none() || (txin.prev_hash == self.funding_txo.unwrap().0 && txin.prev_index == self.funding_txo.unwrap().1 as u32) { | |||
if self.funding_txo.is_none() || (txin.prev_hash == self.funding_txo.unwrap().txid && txin.prev_index == self.funding_txo.unwrap().index as u32) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make a note somewhere (maybe just file an issue when this is merged?) that whoever writes the serializer/deserializer for ChannelMonitor must use u32s or u16s for indexes (though I'm kinda not a fan of either, given the usize is platform-dependant).
248a312
to
e80932d
Compare
Failed travis as fuzz/ compilation looks broken. |
82b9bc7
to
940babe
Compare
This structure replaces the (Sha256dHash, u16) tuple that was being used for the funding output. Signed-off-by: Jean Pierre Dudey <[email protected]>
No description provided.