X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fln%2Fchannel.rs;h=7cc0dea5ff7e75875d901218b44fc223e9d3dd81;hb=7b4f382e26368be7f010a081e553803b98eb9550;hp=fe92f9d6ff8ce917c48a90fe18ad7619dadb1e81;hpb=374ea1f05e301b7f2c47781ad4f7a3ac5ac909fd;p=rust-lightning diff --git a/src/ln/channel.rs b/src/ln/channel.rs index fe92f9d6..7cc0dea5 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -2,7 +2,6 @@ use bitcoin::blockdata::block::BlockHeader; use bitcoin::blockdata::script::{Script,Builder}; use bitcoin::blockdata::transaction::{TxIn, TxOut, Transaction, SigHashType}; use bitcoin::blockdata::opcodes; -use bitcoin::util::uint::Uint256; use bitcoin::util::hash::{Sha256dHash, Hash160}; use bitcoin::util::bip143; use bitcoin::network::serialize::BitcoinHash; @@ -18,9 +17,10 @@ use ln::msgs; use ln::msgs::{HandleError, MsgEncodable}; use ln::channelmonitor::ChannelMonitor; use ln::channelmanager::{PendingForwardHTLCInfo, HTLCFailReason}; -use ln::chan_utils::{TxCreationKeys,HTLCOutputInCommitment}; +use ln::chan_utils::{TxCreationKeys,HTLCOutputInCommitment,HTLC_SUCCESS_TX_WEIGHT,HTLC_TIMEOUT_TX_WEIGHT}; use ln::chan_utils; use chain::chaininterface::{FeeEstimator,ConfirmationTarget}; +use chain::transaction::OutPoint; use util::{transaction_utils,rng}; use util::sha2::Sha256; @@ -43,7 +43,7 @@ impl ChannelKeys { pub fn new_from_seed(seed: &[u8; 32]) -> Result { let mut prk = [0; 32]; hkdf_extract(Sha256::new(), b"rust-lightning key gen salt", seed, &mut prk); - let secp_ctx = Secp256k1::new(); + let secp_ctx = Secp256k1::without_caps(); let mut okm = [0; 32]; hkdf_expand(Sha256::new(), &prk, b"rust-lightning funding key info", &mut okm); @@ -230,12 +230,12 @@ const BOTH_SIDES_SHUTDOWN_MASK: u32 = (ChannelState::LocalShutdownSent as u32 | // TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking // has been completed, and then turn into a Channel to get compiler-time enforcement of things like -// calling get_channel_id() before we're set up or things like get_outbound_funding_signed on an +// calling channel_id() before we're set up or things like get_outbound_funding_signed on an // inbound channel. pub struct Channel { user_id: u64, - channel_id: Uint256, + channel_id: [u8; 32], channel_state: u32, channel_outbound: bool, secp_ctx: Secp256k1, @@ -244,6 +244,10 @@ pub struct Channel { local_keys: ChannelKeys, + // Our commitment numbers start at 2^48-1 and count down, whereas the ones used in transaction + // generation start at 0 and count up...this simplifies some parts of implementation at the + // cost of others, but should really just be changed. + cur_local_commitment_transaction_number: u64, cur_remote_commitment_transaction_number: u64, value_to_self_msat: u64, // Excluding all pending_htlcs, excluding fees @@ -254,6 +258,12 @@ pub struct Channel { channel_update_count: u32, feerate_per_kw: u64, + #[cfg(test)] + // Used in ChannelManager's tests to send a revoked transaction + pub last_local_commitment_txn: Vec, + #[cfg(not(test))] + last_local_commitment_txn: Vec, + last_sent_closing_fee: Option<(u64, u64)>, // (feerate, fee) /// The hash of the block in which the funding transaction reached our CONF_TARGET. We use this @@ -285,6 +295,8 @@ pub struct Channel { their_delayed_payment_basepoint: PublicKey, their_htlc_basepoint: PublicKey, their_cur_commitment_point: PublicKey, + + their_prev_commitment_point: Option, their_node_id: PublicKey, their_shutdown_scriptpubkey: Option