@@ -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
+ )
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,21 +1886,33 @@ 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 broadcast 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 broadcast claims for prev tx because signer is unavailable, will retry" ) ;
1896
+ }
1892
1897
}
1893
1898
}
1899
+ Ok ( ( ) )
1894
1900
}
1895
1901
1896
1902
pub ( crate ) fn broadcast_latest_holder_commitment_txn < B : Deref , L : Deref > ( & mut self , broadcaster : & B , logger : & L )
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 ) ) ;
1905
1918
}
@@ -1945,7 +1958,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1945
1958
} ,
1946
1959
ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } => {
1947
1960
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)
1961
+ // No further error handling needed
1962
+ let _ = self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage, broadcaster, fee_estimator, logger) ;
1949
1963
} ,
1950
1964
ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } => {
1951
1965
log_trace ! ( logger, "Updating ChannelMonitor with commitment secret" ) ;
@@ -2291,10 +2305,11 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2291
2305
}
2292
2306
}
2293
2307
2294
- pub fn get_latest_holder_commitment_txn < L : Deref > ( & mut self , logger : & L ) -> Vec < Transaction > where L :: Target : Logger {
2308
+ pub fn get_latest_holder_commitment_txn < L : Deref > ( & mut self , logger : & L ) -> Result < Vec < Transaction > , SignError >
2309
+ where L :: Target : Logger {
2295
2310
log_debug ! ( logger, "Getting signed latest holder commitment transaction!" ) ;
2296
2311
self . holder_tx_signed = true ;
2297
- let commitment_tx = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) ;
2312
+ let commitment_tx = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) ? ;
2298
2313
let txid = commitment_tx. txid ( ) ;
2299
2314
let mut holder_transactions = vec ! [ commitment_tx] ;
2300
2315
for htlc in self . current_holder_commitment_tx . htlc_outputs . iter ( ) {
@@ -2313,14 +2328,14 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2313
2328
continue ;
2314
2329
} else { None } ;
2315
2330
if let Some ( htlc_tx) = self . onchain_tx_handler . get_fully_signed_htlc_tx (
2316
- & :: bitcoin:: OutPoint { txid, vout } , & preimage) {
2331
+ & :: bitcoin:: OutPoint { txid, vout } , & preimage) ? {
2317
2332
holder_transactions. push ( htlc_tx) ;
2318
2333
}
2319
2334
}
2320
2335
}
2321
2336
// 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
2337
// The data will be re-generated and tracked in check_spend_holder_transaction if we get a confirmation.
2323
- holder_transactions
2338
+ Ok ( holder_transactions)
2324
2339
}
2325
2340
2326
2341
#[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
@@ -2504,17 +2519,24 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2504
2519
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
2520
claimable_outpoints. push ( commitment_package) ;
2506
2521
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
2522
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) ) ;
2523
+ match self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) {
2524
+ Ok ( commitment_tx) => {
2525
+ // Because we're broadcasting a commitment transaction, we should construct the package
2526
+ // assuming it gets confirmed in the next block. Sadly, we have code which considers
2527
+ // "not yet confirmed" things as discardable, so we cannot do that here.
2528
+ let ( mut new_outpoints, _) = self . get_broadcasted_holder_claims ( & self . current_holder_commitment_tx , self . best_block . height ( ) ) ;
2529
+ let new_outputs = self . get_broadcasted_holder_watch_outputs ( & self . current_holder_commitment_tx , & commitment_tx) ;
2530
+ if !new_outputs. is_empty ( ) {
2531
+ watch_outputs. push ( ( self . current_holder_commitment_tx . txid . clone ( ) , new_outputs) ) ;
2532
+ }
2533
+ claimable_outpoints. append ( & mut new_outpoints) ;
2534
+
2535
+ }
2536
+ Err ( _) => {
2537
+ log_warn ! ( logger, "Unable to broadcast holder commitment tx because the signer is not available, will retry" ) ;
2538
+ }
2516
2539
}
2517
- claimable_outpoints. append ( & mut new_outpoints) ;
2518
2540
}
2519
2541
2520
2542
// Find which on-chain events have reached their confirmation threshold.
@@ -2587,7 +2609,9 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2587
2609
}
2588
2610
}
2589
2611
2590
- self . onchain_tx_handler . update_claims_view ( & txn_matched, claimable_outpoints, conf_height, self . best_block . height ( ) , broadcaster, fee_estimator, logger) ;
2612
+ if self . onchain_tx_handler . update_claims_view ( & txn_matched, claimable_outpoints, conf_height, self . best_block . height ( ) , broadcaster, fee_estimator, logger) . is_err ( ) {
2613
+ log_warn ! ( logger, "Unable to broadcast claims because signer was not available, will retry" ) ;
2614
+ }
2591
2615
2592
2616
// Determine new outputs to watch by comparing against previously known outputs to watch,
2593
2617
// updating the latter in the process.
@@ -3580,7 +3604,7 @@ mod tests {
3580
3604
monitor. provide_latest_counterparty_commitment_tx ( dummy_txid, preimages_slice_to_htlc_outputs ! ( preimages[ 17 ..20 ] ) , 281474976710653 , dummy_key, & logger) ;
3581
3605
monitor. provide_latest_counterparty_commitment_tx ( dummy_txid, preimages_slice_to_htlc_outputs ! ( preimages[ 18 ..20 ] ) , 281474976710652 , dummy_key, & logger) ;
3582
3606
for & ( ref preimage, ref hash) in preimages. iter ( ) {
3583
- monitor. provide_payment_preimage ( hash, preimage, & broadcaster, & fee_estimator, & logger) ;
3607
+ monitor. provide_payment_preimage ( hash, preimage, & broadcaster, & fee_estimator, & logger) . unwrap ( ) ;
3584
3608
}
3585
3609
3586
3610
// Now provide a secret, pruning preimages 10-15
0 commit comments