@@ -42,7 +42,7 @@ use chain;
42
42
use chain:: { BestBlock , WatchedOutput } ;
43
43
use chain:: chaininterface:: { BroadcasterInterface , FeeEstimator } ;
44
44
use chain:: transaction:: { OutPoint , TransactionData } ;
45
- use chain:: keysinterface:: { SpendableOutputDescriptor , StaticPaymentOutputDescriptor , DelayedPaymentOutputDescriptor , Sign , KeysInterface } ;
45
+ use chain:: keysinterface:: { SpendableOutputDescriptor , StaticPaymentOutputDescriptor , DelayedPaymentOutputDescriptor , Sign , KeysInterface , SignError } ;
46
46
use chain:: onchaintx:: OnchainTxHandler ;
47
47
use chain:: package:: { CounterpartyOfferedHTLCOutput , CounterpartyReceivedHTLCOutput , HolderFundingOutput , HolderHTLCOutput , PackageSolvingData , PackageTemplate , RevokedOutput , RevokedHTLCOutput } ;
48
48
use chain:: Filter ;
@@ -1098,7 +1098,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
1098
1098
broadcaster : & B ,
1099
1099
fee_estimator : & F ,
1100
1100
logger : & L ,
1101
- ) where
1101
+ ) -> Result < ( ) , SignError > where
1102
1102
B :: Target : BroadcasterInterface ,
1103
1103
F :: Target : FeeEstimator ,
1104
1104
L :: Target : Logger ,
@@ -1111,7 +1111,8 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
1111
1111
& self ,
1112
1112
broadcaster : & B ,
1113
1113
logger : & L ,
1114
- ) where
1114
+ ) -> Result < ( ) , SignError >
1115
+ where
1115
1116
B :: Target : BroadcasterInterface ,
1116
1117
L :: Target : Logger ,
1117
1118
{
@@ -1210,7 +1211,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
1210
1211
/// substantial amount of time (a month or even a year) to get back funds. Best may be to contact
1211
1212
/// out-of-band the other node operator to coordinate with him if option is available to you.
1212
1213
/// In any-case, choice is up to the user.
1213
- pub fn get_latest_holder_commitment_txn < L : Deref > ( & self , logger : & L ) -> Vec < Transaction >
1214
+ pub fn get_latest_holder_commitment_txn < L : Deref > ( & self , logger : & L ) -> Result < Vec < Transaction > , SignError >
1214
1215
where L :: Target : Logger {
1215
1216
self . inner . lock ( ) . unwrap ( ) . get_latest_holder_commitment_txn ( logger)
1216
1217
}
@@ -1847,7 +1848,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1847
1848
1848
1849
/// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
1849
1850
/// commitment_tx_infos which contain the payment hash have been revoked.
1850
- fn provide_payment_preimage < B : Deref , F : Deref , L : Deref > ( & mut self , payment_hash : & PaymentHash , payment_preimage : & PaymentPreimage , broadcaster : & B , fee_estimator : & F , logger : & L )
1851
+ fn provide_payment_preimage < B : Deref , F : Deref , L : Deref > ( & mut self , payment_hash : & PaymentHash , payment_preimage : & PaymentPreimage , broadcaster : & B , fee_estimator : & F , logger : & L ) -> Result < ( ) , SignError >
1851
1852
where B :: Target : BroadcasterInterface ,
1852
1853
F :: Target : FeeEstimator ,
1853
1854
L :: Target : Logger ,
@@ -1859,19 +1860,19 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1859
1860
macro_rules! claim_htlcs {
1860
1861
( $commitment_number: expr, $txid: expr) => {
1861
1862
let htlc_claim_reqs = self . get_counterparty_htlc_output_claim_reqs( $commitment_number, $txid, None ) ;
1862
- self . onchain_tx_handler. update_claims_view( & Vec :: new( ) , htlc_claim_reqs, self . best_block. height( ) , self . best_block. height( ) , broadcaster, fee_estimator, logger) ;
1863
+ self . onchain_tx_handler. update_claims_view( & Vec :: new( ) , htlc_claim_reqs, self . best_block. height( ) , self . best_block. height( ) , broadcaster, fee_estimator, logger) ? ;
1863
1864
}
1864
1865
}
1865
1866
if let Some ( txid) = self . current_counterparty_commitment_txid {
1866
1867
if let Some ( commitment_number) = self . counterparty_commitment_txn_on_chain . get ( & txid) {
1867
1868
claim_htlcs ! ( * commitment_number, txid) ;
1868
- return ;
1869
+ return Ok ( ( ) ) ;
1869
1870
}
1870
1871
}
1871
1872
if let Some ( txid) = self . prev_counterparty_commitment_txid {
1872
1873
if let Some ( commitment_number) = self . counterparty_commitment_txn_on_chain . get ( & txid) {
1873
1874
claim_htlcs ! ( * commitment_number, txid) ;
1874
- return ;
1875
+ return Ok ( ( ) ) ;
1875
1876
}
1876
1877
}
1877
1878
@@ -1885,23 +1886,36 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1885
1886
// block. Even if not, its a reasonable metric for the bump criteria on the HTLC
1886
1887
// transactions.
1887
1888
let ( claim_reqs, _) = self . get_broadcasted_holder_claims ( & self . current_holder_commitment_tx , self . best_block . height ( ) ) ;
1888
- self . onchain_tx_handler . update_claims_view ( & Vec :: new ( ) , claim_reqs, self . best_block . height ( ) , self . best_block . height ( ) , broadcaster, fee_estimator, logger) ;
1889
+ if self . onchain_tx_handler . update_claims_view ( & Vec :: new ( ) , claim_reqs, self . best_block . height ( ) , self . best_block . height ( ) , broadcaster, fee_estimator, logger) . is_err ( ) {
1890
+ log_warn ! ( logger, "Unable to update claims because signer is unavailable, will retry" ) ;
1891
+ }
1889
1892
if let Some ( ref tx) = self . prev_holder_signed_commitment_tx {
1890
1893
let ( claim_reqs, _) = self . get_broadcasted_holder_claims ( & tx, self . best_block . height ( ) ) ;
1891
- self . onchain_tx_handler . update_claims_view ( & Vec :: new ( ) , claim_reqs, self . best_block . height ( ) , self . best_block . height ( ) , broadcaster, fee_estimator, logger) ;
1894
+ if self . onchain_tx_handler . update_claims_view ( & Vec :: new ( ) , claim_reqs, self . best_block . height ( ) , self . best_block . height ( ) , broadcaster, fee_estimator, logger) . is_err ( ) {
1895
+ log_warn ! ( logger, "Unable to update claims for prev tx because signer is unavailable, will retry" ) ;
1896
+ }
1892
1897
}
1893
1898
}
1899
+ Ok ( ( ) )
1894
1900
}
1895
1901
1896
- pub ( crate ) fn broadcast_latest_holder_commitment_txn < B : Deref , L : Deref > ( & mut self , broadcaster : & B , logger : & L )
1902
+ pub ( crate ) fn broadcast_latest_holder_commitment_txn < B : Deref , L : Deref > ( & mut self , broadcaster : & B , logger : & L ) -> Result < ( ) , SignError >
1897
1903
where B :: Target : BroadcasterInterface ,
1898
1904
L :: Target : Logger ,
1899
1905
{
1900
- for tx in self . get_latest_holder_commitment_txn ( logger) . iter ( ) {
1901
- log_info ! ( logger, "Broadcasting local {}" , log_tx!( tx) ) ;
1902
- broadcaster. broadcast_transaction ( tx) ;
1906
+ match self . get_latest_holder_commitment_txn ( logger) {
1907
+ Ok ( txs) => {
1908
+ for tx in txs. iter ( ) {
1909
+ log_info ! ( logger, "Broadcasting local {}" , log_tx!( tx) ) ;
1910
+ broadcaster. broadcast_transaction ( tx) ;
1911
+ }
1912
+ }
1913
+ Err ( _) => {
1914
+ log_warn ! ( logger, "Unable to broadcast holder tx because signer is unavailable, will retry" ) ;
1915
+ }
1903
1916
}
1904
1917
self . pending_monitor_events . push ( MonitorEvent :: CommitmentTxConfirmed ( self . funding_info . 0 ) ) ;
1918
+ Ok ( ( ) )
1905
1919
}
1906
1920
1907
1921
pub fn update_monitor < B : Deref , F : Deref , L : Deref > ( & mut self , updates : & ChannelMonitorUpdate , broadcaster : & B , fee_estimator : & F , logger : & L ) -> Result < ( ) , ( ) >
@@ -1945,7 +1959,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1945
1959
} ,
1946
1960
ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } => {
1947
1961
log_trace ! ( logger, "Updating ChannelMonitor with payment preimage" ) ;
1948
- self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage, broadcaster, fee_estimator, logger)
1962
+ // Logging is handled already, no further error handling needed
1963
+ let _ = self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage, broadcaster, fee_estimator, logger) ;
1949
1964
} ,
1950
1965
ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } => {
1951
1966
log_trace ! ( logger, "Updating ChannelMonitor with commitment secret" ) ;
@@ -1959,7 +1974,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1959
1974
log_trace ! ( logger, "Updating ChannelMonitor: channel force closed, should broadcast: {}" , should_broadcast) ;
1960
1975
self . lockdown_from_offchain = true ;
1961
1976
if * should_broadcast {
1962
- self . broadcast_latest_holder_commitment_txn ( broadcaster, logger) ;
1977
+ // Logging is handled already, no further error handling needed
1978
+ let _ = self . broadcast_latest_holder_commitment_txn ( broadcaster, logger) ;
1963
1979
} else if !self . holder_tx_signed {
1964
1980
log_error ! ( logger, "You have a toxic holder commitment transaction avaible in channel monitor, read comment in ChannelMonitor::get_latest_holder_commitment_txn to be informed of manual action to take" ) ;
1965
1981
} else {
@@ -2291,10 +2307,11 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2291
2307
}
2292
2308
}
2293
2309
2294
- pub fn get_latest_holder_commitment_txn < L : Deref > ( & mut self , logger : & L ) -> Vec < Transaction > where L :: Target : Logger {
2310
+ pub fn get_latest_holder_commitment_txn < L : Deref > ( & mut self , logger : & L ) -> Result < Vec < Transaction > , SignError >
2311
+ where L :: Target : Logger {
2295
2312
log_debug ! ( logger, "Getting signed latest holder commitment transaction!" ) ;
2296
2313
self . holder_tx_signed = true ;
2297
- let commitment_tx = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) ;
2314
+ let commitment_tx = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) ? ;
2298
2315
let txid = commitment_tx. txid ( ) ;
2299
2316
let mut holder_transactions = vec ! [ commitment_tx] ;
2300
2317
for htlc in self . current_holder_commitment_tx . htlc_outputs . iter ( ) {
@@ -2313,14 +2330,14 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2313
2330
continue ;
2314
2331
} else { None } ;
2315
2332
if let Some ( htlc_tx) = self . onchain_tx_handler . get_fully_signed_htlc_tx (
2316
- & :: bitcoin:: OutPoint { txid, vout } , & preimage) {
2333
+ & :: bitcoin:: OutPoint { txid, vout } , & preimage) ? {
2317
2334
holder_transactions. push ( htlc_tx) ;
2318
2335
}
2319
2336
}
2320
2337
}
2321
2338
// We throw away the generated waiting_first_conf data as we aren't (yet) confirmed and we don't actually know what the caller wants to do.
2322
2339
// The data will be re-generated and tracked in check_spend_holder_transaction if we get a confirmation.
2323
- holder_transactions
2340
+ Ok ( holder_transactions)
2324
2341
}
2325
2342
2326
2343
#[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
@@ -2504,17 +2521,24 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2504
2521
let commitment_package = PackageTemplate :: build_package ( self . funding_info . 0 . txid . clone ( ) , self . funding_info . 0 . index as u32 , PackageSolvingData :: HolderFundingOutput ( funding_outp) , self . best_block . height ( ) , false , self . best_block . height ( ) ) ;
2505
2522
claimable_outpoints. push ( commitment_package) ;
2506
2523
self . pending_monitor_events . push ( MonitorEvent :: CommitmentTxConfirmed ( self . funding_info . 0 ) ) ;
2507
- let commitment_tx = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) ;
2508
2524
self . holder_tx_signed = true ;
2509
- // Because we're broadcasting a commitment transaction, we should construct the package
2510
- // assuming it gets confirmed in the next block. Sadly, we have code which considers
2511
- // "not yet confirmed" things as discardable, so we cannot do that here.
2512
- let ( mut new_outpoints, _) = self . get_broadcasted_holder_claims ( & self . current_holder_commitment_tx , self . best_block . height ( ) ) ;
2513
- let new_outputs = self . get_broadcasted_holder_watch_outputs ( & self . current_holder_commitment_tx , & commitment_tx) ;
2514
- if !new_outputs. is_empty ( ) {
2515
- watch_outputs. push ( ( self . current_holder_commitment_tx . txid . clone ( ) , new_outputs) ) ;
2525
+ match self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) {
2526
+ Ok ( commitment_tx) => {
2527
+ // Because we're broadcasting a commitment transaction, we should construct the package
2528
+ // assuming it gets confirmed in the next block. Sadly, we have code which considers
2529
+ // "not yet confirmed" things as discardable, so we cannot do that here.
2530
+ let ( mut new_outpoints, _) = self . get_broadcasted_holder_claims ( & self . current_holder_commitment_tx , self . best_block . height ( ) ) ;
2531
+ let new_outputs = self . get_broadcasted_holder_watch_outputs ( & self . current_holder_commitment_tx , & commitment_tx) ;
2532
+ if !new_outputs. is_empty ( ) {
2533
+ watch_outputs. push ( ( self . current_holder_commitment_tx . txid . clone ( ) , new_outputs) ) ;
2534
+ }
2535
+ claimable_outpoints. append ( & mut new_outpoints) ;
2536
+
2537
+ }
2538
+ Err ( _) => {
2539
+ log_warn ! ( logger, "Unable to broadcast holder commitment tx because the signer is not available, will try again" ) ;
2540
+ }
2516
2541
}
2517
- claimable_outpoints. append ( & mut new_outpoints) ;
2518
2542
}
2519
2543
2520
2544
// Find which on-chain events have reached their confirmation threshold.
@@ -2587,7 +2611,9 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2587
2611
}
2588
2612
}
2589
2613
2590
- self . onchain_tx_handler . update_claims_view ( & txn_matched, claimable_outpoints, conf_height, self . best_block . height ( ) , broadcaster, fee_estimator, logger) ;
2614
+ if self . onchain_tx_handler . update_claims_view ( & txn_matched, claimable_outpoints, conf_height, self . best_block . height ( ) , broadcaster, fee_estimator, logger) . is_err ( ) {
2615
+ log_warn ! ( logger, "Unable to broadcast claims because signer was not available, will try later" ) ;
2616
+ }
2591
2617
2592
2618
// Determine new outputs to watch by comparing against previously known outputs to watch,
2593
2619
// updating the latter in the process.
@@ -3580,7 +3606,7 @@ mod tests {
3580
3606
monitor. provide_latest_counterparty_commitment_tx ( dummy_txid, preimages_slice_to_htlc_outputs ! ( preimages[ 17 ..20 ] ) , 281474976710653 , dummy_key, & logger) ;
3581
3607
monitor. provide_latest_counterparty_commitment_tx ( dummy_txid, preimages_slice_to_htlc_outputs ! ( preimages[ 18 ..20 ] ) , 281474976710652 , dummy_key, & logger) ;
3582
3608
for & ( ref preimage, ref hash) in preimages. iter ( ) {
3583
- monitor. provide_payment_preimage ( hash, preimage, & broadcaster, & fee_estimator, & logger) ;
3609
+ monitor. provide_payment_preimage ( hash, preimage, & broadcaster, & fee_estimator, & logger) . unwrap ( ) ;
3584
3610
}
3585
3611
3586
3612
// Now provide a secret, pruning preimages 10-15
0 commit comments