@@ -14,7 +14,7 @@ use crypto::digest::Digest;
14
14
use crypto:: hkdf:: { hkdf_extract, hkdf_expand} ;
15
15
16
16
use ln:: msgs;
17
- use ln:: msgs:: { HandleError , MsgEncodable } ;
17
+ use ln:: msgs:: { ErrorAction , HandleError , MsgEncodable } ;
18
18
use ln:: channelmonitor:: ChannelMonitor ;
19
19
use ln:: channelmanager:: { PendingForwardHTLCInfo , HTLCFailReason } ;
20
20
use ln:: chan_utils:: { TxCreationKeys , HTLCOutputInCommitment , HTLC_SUCCESS_TX_WEIGHT , HTLC_TIMEOUT_TX_WEIGHT } ;
@@ -1916,7 +1916,10 @@ impl Channel {
1916
1916
/// Called by channelmanager based on chain blocks being connected.
1917
1917
/// Note that we only need to use this to detect funding_signed, anything else is handled by
1918
1918
/// the channel_monitor.
1919
- pub fn block_connected ( & mut self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ u32 ] ) -> Option < msgs:: FundingLocked > {
1919
+ /// In case of Err, the channel may have been closed, at which point the standard requirements
1920
+ /// apply - no calls may be made except those explicitly stated to be allowed post-shutdown.
1921
+ /// Only returns an ErrorAction of DisconnectPeer, if Err.
1922
+ pub fn block_connected ( & mut self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ u32 ] ) -> Result < Option < msgs:: FundingLocked > , HandleError > {
1920
1923
let non_shutdown_state = self . channel_state & ( !BOTH_SIDES_SHUTDOWN_MASK ) ;
1921
1924
if self . funding_tx_confirmations > 0 {
1922
1925
if header. bitcoin_hash ( ) != self . last_block_connected {
@@ -1940,10 +1943,10 @@ impl Channel {
1940
1943
//a protocol oversight, but I assume I'm just missing something.
1941
1944
let next_per_commitment_secret = self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ;
1942
1945
let next_per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & next_per_commitment_secret) . unwrap ( ) ;
1943
- return Some ( msgs:: FundingLocked {
1946
+ return Ok ( Some ( msgs:: FundingLocked {
1944
1947
channel_id : self . channel_id ,
1945
1948
next_per_commitment_point : next_per_commitment_point,
1946
- } ) ;
1949
+ } ) ) ;
1947
1950
}
1948
1951
}
1949
1952
}
@@ -1955,6 +1958,7 @@ impl Channel {
1955
1958
tx. output [ txo_idx] . value != self . channel_value_satoshis {
1956
1959
self . channel_state = ChannelState :: ShutdownComplete as u32 ;
1957
1960
self . channel_update_count += 1 ;
1961
+ return Err ( HandleError { err : "funding tx had wrong script/value" , action : Some ( ErrorAction :: DisconnectPeer { msg : None } ) } ) ;
1958
1962
} else {
1959
1963
self . funding_tx_confirmations = 1 ;
1960
1964
self . short_channel_id = Some ( ( ( height as u64 ) << ( 5 * 8 ) ) |
@@ -1964,7 +1968,7 @@ impl Channel {
1964
1968
}
1965
1969
}
1966
1970
}
1967
- None
1971
+ Ok ( None )
1968
1972
}
1969
1973
1970
1974
/// Called by channelmanager based on chain blocks being disconnected.
0 commit comments