Skip to content

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

Merged
merged 1 commit into from
Jun 29, 2018

Conversation

jeandudey
Copy link
Contributor

No description provided.

@jeandudey jeandudey force-pushed the funding_txo branch 2 times, most recently from fece28a to b2934c0 Compare June 27, 2018 17:43
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a 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?

@@ -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)));
Copy link
Collaborator

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.

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(),
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@@ -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) {
Copy link
Collaborator

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.

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(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broke alignment here, too.

@@ -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];
Copy link
Collaborator

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).

funding_output = (Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), 0);
funding_output = TxOutRef {
txid: Sha256dHash::from_data(&serialize(&tx).unwrap()[..]),
index: 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad alignment here.

@@ -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 });
Copy link
Collaborator

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) {
Copy link
Collaborator

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).

@jeandudey jeandudey force-pushed the funding_txo branch 2 times, most recently from 248a312 to e80932d Compare June 28, 2018 13:59
@TheBlueMatt
Copy link
Collaborator

Failed travis as fuzz/ compilation looks broken.

@jeandudey jeandudey force-pushed the funding_txo branch 3 times, most recently from 82b9bc7 to 940babe Compare June 29, 2018 02:50
This structure replaces the (Sha256dHash, u16) tuple that was being used
for the funding output.

Signed-off-by: Jean Pierre Dudey <[email protected]>
@TheBlueMatt TheBlueMatt merged commit b65aa86 into lightningdevkit:master Jun 29, 2018
TheBlueMatt added a commit to TheBlueMatt/rust-lightning that referenced this pull request Jun 29, 2018
TheBlueMatt added a commit that referenced this pull request Jun 29, 2018
Cleanups after #33, plus one unrelated bugfix spotted in #33 review
@jeandudey jeandudey deleted the funding_txo branch June 30, 2018 14:42
carlaKC pushed a commit to carlaKC/rust-lightning that referenced this pull request Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants