@@ -299,6 +299,13 @@ impl<ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L:
299
299
}
300
300
pending_htlcs_updated
301
301
}
302
+
303
+ fn get_monitor_did_broadcast ( & self , funding_txo : OutPoint ) -> Result < bool , ChannelMonitorUpdateErr > {
304
+ match self . monitors . lock ( ) . unwrap ( ) . get ( & funding_txo) {
305
+ Some ( monitor) => Ok ( monitor. broadcasted ( ) ) ,
306
+ None => Err ( ChannelMonitorUpdateErr :: PermanentFailure )
307
+ }
308
+ }
302
309
}
303
310
304
311
impl < Key : Send + cmp:: Eq + hash:: Hash , ChanSigner : ChannelKeys , T : Deref , F : Deref , L : Deref , C : Deref > events:: EventsProvider for SimpleManyChannelMonitor < Key , ChanSigner , T , F , L , C >
@@ -813,6 +820,9 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
813
820
// may occur, and we fail any such monitor updates.
814
821
local_tx_signed : bool ,
815
822
823
+ // Whether the commitment transaction associated with this channel has been broadcasted.
824
+ broadcasted : bool ,
825
+
816
826
// We simply modify last_block_hash in Channel's block_connected so that serialization is
817
827
// consistent but hopefully the users' copy handles block_connected in a consistent way.
818
828
// (we do *not*, however, update them in update_monitor to ensure any local user copies keep
@@ -884,6 +894,9 @@ pub trait ManyChannelMonitor: Send + Sync {
884
894
/// ChannelMonitor::get_and_clear_pending_htlcs_updated() for each ChannelMonitor and return
885
895
/// the full list.
886
896
fn get_and_clear_pending_htlcs_updated ( & self ) -> Vec < HTLCUpdate > ;
897
+
898
+ /// Gets whether the monitor broadcasted the channel's commitment transaction.
899
+ fn get_monitor_did_broadcast ( & self , funding_txo : OutPoint ) -> Result < bool , ChannelMonitorUpdateErr > ;
887
900
}
888
901
889
902
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
@@ -1113,6 +1126,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
1113
1126
1114
1127
self . lockdown_from_offchain . write ( writer) ?;
1115
1128
self . local_tx_signed . write ( writer) ?;
1129
+ self . broadcasted . write ( writer) ?;
1116
1130
1117
1131
Ok ( ( ) )
1118
1132
}
@@ -1197,6 +1211,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1197
1211
1198
1212
lockdown_from_offchain : false ,
1199
1213
local_tx_signed : false ,
1214
+ broadcasted : false ,
1200
1215
1201
1216
last_block_hash : Default :: default ( ) ,
1202
1217
secp_ctx : Secp256k1 :: new ( ) ,
@@ -1350,6 +1365,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1350
1365
{
1351
1366
for tx in self . get_latest_local_commitment_txn ( logger) . iter ( ) {
1352
1367
broadcaster. broadcast_transaction ( tx) ;
1368
+ self . broadcasted = true ;
1353
1369
}
1354
1370
}
1355
1371
@@ -1966,7 +1982,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1966
1982
}
1967
1983
}
1968
1984
}
1969
- self . onchain_tx_handler . block_connected ( txn_matched, claimable_outpoints, height, & * broadcaster, & * fee_estimator, & * logger) ;
1985
+ self . broadcasted = self . onchain_tx_handler . block_connected ( txn_matched, claimable_outpoints, height, & * broadcaster, & * fee_estimator, & * logger) ;
1970
1986
1971
1987
self . last_block_hash = block_hash. clone ( ) ;
1972
1988
for & ( ref txid, ref output_scripts) in watch_outputs. iter ( ) {
@@ -1988,11 +2004,16 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1988
2004
//- maturing spendable output has transaction paying us has been disconnected
1989
2005
}
1990
2006
1991
- self . onchain_tx_handler . block_disconnected ( height, broadcaster, fee_estimator, logger) ;
2007
+ self . broadcasted = self . onchain_tx_handler . block_disconnected ( height, broadcaster, fee_estimator, logger) ;
1992
2008
1993
2009
self . last_block_hash = block_hash. clone ( ) ;
1994
2010
}
1995
2011
2012
+ /// Whether our local commitment transaction has been broadcasted.
2013
+ fn broadcasted ( & self ) -> bool {
2014
+ self . broadcasted
2015
+ }
2016
+
1996
2017
pub ( super ) fn would_broadcast_at_height < L : Deref > ( & self , height : u32 , logger : & L ) -> bool where L :: Target : Logger {
1997
2018
// We need to consider all HTLCs which are:
1998
2019
// * in any unrevoked remote commitment transaction, as they could broadcast said
@@ -2483,6 +2504,7 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for (BlockHash, ChannelMonitor
2483
2504
2484
2505
let lockdown_from_offchain = Readable :: read ( reader) ?;
2485
2506
let local_tx_signed = Readable :: read ( reader) ?;
2507
+ let broadcasted = Readable :: read ( reader) ?;
2486
2508
2487
2509
Ok ( ( last_block_hash. clone ( ) , ChannelMonitor {
2488
2510
latest_update_id,
@@ -2527,6 +2549,8 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for (BlockHash, ChannelMonitor
2527
2549
lockdown_from_offchain,
2528
2550
local_tx_signed,
2529
2551
2552
+ broadcasted,
2553
+
2530
2554
last_block_hash,
2531
2555
secp_ctx : Secp256k1 :: new ( ) ,
2532
2556
} ) )
0 commit comments