X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fln%2Fchannel.rs;h=acee06409c3f8479137b1561ac1b2d636cf6c9e2;hb=7e255b5cf5256638b5ec6e507c68d9cfa0ba2047;hp=6fdc1462a419b2885c8a125986d64cfde94d86a7;hpb=d5e316f5a0e7a7996cd42d71946231bbd580b0ac;p=rust-lightning diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 6fdc1462..acee0640 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -14,7 +14,7 @@ use crypto::digest::Digest; use crypto::hkdf::{hkdf_extract,hkdf_expand}; use ln::msgs; -use ln::msgs::{HandleError, MsgEncodable}; +use ln::msgs::{ErrorAction, HandleError, MsgEncodable}; use ln::channelmonitor::ChannelMonitor; use ln::channelmanager::{PendingForwardHTLCInfo, HTLCFailReason}; use ln::chan_utils::{TxCreationKeys,HTLCOutputInCommitment,HTLC_SUCCESS_TX_WEIGHT,HTLC_TIMEOUT_TX_WEIGHT}; @@ -1356,7 +1356,7 @@ impl Channel { Err(HandleError{err: "Remote tried to fulfill/fail an HTLC we couldn't find", action: None}) } - pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result { + pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(), HandleError> { if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) { return Err(HandleError{err: "Got add HTLC message when channel was not in an operational state", action: None}); } @@ -1366,9 +1366,8 @@ impl Channel { let mut payment_hash = [0; 32]; sha.result(&mut payment_hash); - self.channel_monitor.provide_payment_preimage(&payment_hash, &msg.payment_preimage); self.mark_outbound_htlc_removed(msg.htlc_id, Some(payment_hash), None)?; - Ok(self.channel_monitor.clone()) + Ok(()) } pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<[u8; 32], HandleError> { @@ -1917,7 +1916,10 @@ impl Channel { /// Called by channelmanager based on chain blocks being connected. /// Note that we only need to use this to detect funding_signed, anything else is handled by /// the channel_monitor. - pub fn block_connected(&mut self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]) -> Option { + /// In case of Err, the channel may have been closed, at which point the standard requirements + /// apply - no calls may be made except those explicitly stated to be allowed post-shutdown. + /// Only returns an ErrorAction of DisconnectPeer, if Err. + pub fn block_connected(&mut self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]) -> Result, HandleError> { let non_shutdown_state = self.channel_state & (!BOTH_SIDES_SHUTDOWN_MASK); if self.funding_tx_confirmations > 0 { if header.bitcoin_hash() != self.last_block_connected { @@ -1941,10 +1943,10 @@ impl Channel { //a protocol oversight, but I assume I'm just missing something. let next_per_commitment_secret = self.build_local_commitment_secret(self.cur_local_commitment_transaction_number); let next_per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &next_per_commitment_secret).unwrap(); - return Some(msgs::FundingLocked { + return Ok(Some(msgs::FundingLocked { channel_id: self.channel_id, next_per_commitment_point: next_per_commitment_point, - }); + })); } } } @@ -1956,6 +1958,7 @@ impl Channel { tx.output[txo_idx].value != self.channel_value_satoshis { self.channel_state = ChannelState::ShutdownComplete as u32; self.channel_update_count += 1; + return Err(HandleError{err: "funding tx had wrong script/value", action: Some(ErrorAction::DisconnectPeer{msg: None})}); } else { self.funding_tx_confirmations = 1; self.short_channel_id = Some(((height as u64) << (5*8)) | @@ -1965,7 +1968,7 @@ impl Channel { } } } - None + Ok(None) } /// Called by channelmanager based on chain blocks being disconnected.