Skip to content

Commit 5918df8

Browse files
authored
Merge pull request #36 from TheBlueMatt/2018-08-33-cleanups
Cleanups after #33, plus one unrelated bugfix spotted in #33 review
2 parents 98e5c5e + d62abad commit 5918df8

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/chain/transaction.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use bitcoin::util::hash::Sha256dHash;
22
use bitcoin::util::uint::Uint256;
33

44
/// A reference to a transaction output.
5+
/// Differs from bitcoin::blockdata::transaction::TxOutRef as the index is a u16 instead of usize
6+
/// due to LN's restrictions on index values. Should reduce (possibly) unsafe conversions this way.
57
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
68
pub struct OutPoint {
79
/// The referenced transaction's txid.
@@ -16,9 +18,9 @@ impl OutPoint {
1618
OutPoint { txid, index }
1719
}
1820

19-
/// Convert an `OutPoint` to a lightning channel id.
20-
pub fn to_channel_id(&self) -> Uint256 {
21-
// TODO: or le?
22-
self.txid.into_be() ^ Uint256::from_u64(self.index as u64).unwrap()
23-
}
21+
/// Convert an `OutPoint` to a lightning channel id.
22+
pub fn to_channel_id(&self) -> Uint256 {
23+
// TODO: or le?
24+
self.txid.into_be() ^ Uint256::from_u64(self.index as u64).unwrap()
25+
}
2426
}

src/ln/channel.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,8 +1151,8 @@ impl Channel {
11511151
panic!("Should not have advanced channel commitment tx numbers prior to funding_created");
11521152
}
11531153

1154-
let funding_info = OutPoint::new(msg.funding_txid, msg.funding_output_index);
1155-
self.channel_monitor.set_funding_info(funding_info);
1154+
let funding_txo = OutPoint::new(msg.funding_txid, msg.funding_output_index);
1155+
self.channel_monitor.set_funding_info(funding_txo);
11561156

11571157
let (remote_initial_commitment_tx, our_signature) = match self.funding_created_signature(&msg.signature) {
11581158
Ok(res) => res,
@@ -1166,7 +1166,6 @@ impl Channel {
11661166

11671167
self.channel_monitor.provide_latest_remote_commitment_tx_info(&remote_initial_commitment_tx, Vec::new(), self.cur_remote_commitment_transaction_number);
11681168
self.channel_state = ChannelState::FundingSent as u32;
1169-
let funding_txo = self.channel_monitor.get_funding_txo().unwrap();
11701169
self.channel_id = funding_txo.to_channel_id();
11711170
self.cur_remote_commitment_transaction_number -= 1;
11721171
self.cur_local_commitment_transaction_number -= 1;
@@ -1930,9 +1929,9 @@ impl Channel {
19301929
self.channel_update_count += 1;
19311930
} else {
19321931
self.funding_tx_confirmations = 1;
1933-
self.short_channel_id = Some(((height as u64) << (5*8)) |
1932+
self.short_channel_id = Some(((height as u64) << (5*8)) |
19341933
((*index_in_block as u64) << (2*8)) |
1935-
((self.channel_monitor.get_funding_txo().unwrap().index as u64) << (2*8)));
1934+
((txo_idx as u64) << (0*8)));
19361935
}
19371936
}
19381937
}
@@ -2071,7 +2070,6 @@ impl Channel {
20712070
// Now that we're past error-generating stuff, update our local state:
20722071
self.channel_monitor.provide_latest_remote_commitment_tx_info(&commitment_tx, Vec::new(), self.cur_remote_commitment_transaction_number);
20732072
self.channel_state = ChannelState::FundingCreated as u32;
2074-
let funding_txo = self.channel_monitor.get_funding_txo().unwrap();
20752073
self.channel_id = funding_txo.to_channel_id();
20762074
self.cur_remote_commitment_transaction_number -= 1;
20772075

@@ -2332,7 +2330,7 @@ mod tests {
23322330
use ln::channel::{Channel,ChannelKeys,HTLCOutput,HTLCState,HTLCOutputInCommitment,TxCreationKeys};
23332331
use ln::chan_utils;
23342332
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
2335-
use chain::transaction::OutPoint;
2333+
use chain::transaction::OutPoint;
23362334
use secp256k1::{Secp256k1,Message,Signature};
23372335
use secp256k1::key::{SecretKey,PublicKey};
23382336
use crypto::sha2::Sha256;
@@ -2868,7 +2866,7 @@ mod tests {
28682866
let mut seed = [0; 32];
28692867
seed[0..32].clone_from_slice(&hex_bytes("0000000000000000000000000000000000000000000000000000000000000000").unwrap());
28702868
assert_eq!(chan_utils::build_commitment_secret(seed, 281474976710655),
2871-
hex_bytes("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap()[..]);
2869+
hex_bytes("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap()[..]);
28722870

28732871
seed[0..32].clone_from_slice(&hex_bytes("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap());
28742872
assert_eq!(chan_utils::build_commitment_secret(seed, 281474976710655),

src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bitcoin::blockdata::block::BlockHeader;
1+
use bitcoin::blockdata::block::BlockHeader;
22
use bitcoin::blockdata::transaction::Transaction;
33
use bitcoin::blockdata::constants::genesis_block;
44
use bitcoin::network::constants::Network;

0 commit comments

Comments
 (0)