@@ -5,6 +5,7 @@ use chain::chaininterface;
55use chain:: transaction:: OutPoint ;
66use chain:: keysinterface:: KeysInterface ;
77use ln:: channelmanager:: { ChannelManager , RAACommitmentOrder , PaymentPreimage , PaymentHash } ;
8+ use ln:: channelmonitor:: { ChannelMonitor , ManyChannelMonitor } ;
89use ln:: router:: { Route , Router } ;
910use ln:: features:: InitFeatures ;
1011use ln:: msgs;
@@ -15,6 +16,7 @@ use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsPro
1516use util:: errors:: APIError ;
1617use util:: logger:: Logger ;
1718use util:: config:: UserConfig ;
19+ use util:: ser:: ReadableArgs ;
1820
1921use bitcoin:: util:: hash:: BitcoinHash ;
2022use bitcoin:: blockdata:: block:: BlockHeader ;
@@ -76,6 +78,27 @@ impl Drop for Node {
7678 assert ! ( self . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
7779 assert ! ( self . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
7880 assert ! ( self . chan_monitor. added_monitors. lock( ) . unwrap( ) . is_empty( ) ) ;
81+
82+ // Check that if we serialize and then deserialize all our channel monitors we the same
83+ // set of outputs to watch for on chain as we have now. Note that if we write tests
84+ // that fully close channels and remove the monitors at some point this may break.
85+ let new_watch = Arc :: new ( chaininterface:: ChainWatchInterfaceUtil :: new ( Network :: Testnet , Arc :: clone ( & self . logger ) as Arc < Logger > ) ) ;
86+ let feeest = Arc :: new ( test_utils:: TestFeeEstimator { sat_per_kw : 253 } ) ;
87+ let new_monitor = test_utils:: TestChannelMonitor :: new ( new_watch. clone ( ) , self . tx_broadcaster . clone ( ) , self . logger . clone ( ) , feeest) ;
88+ let old_monitors = self . chan_monitor . simple_monitor . monitors . lock ( ) . unwrap ( ) ;
89+ for ( _, monitor) in old_monitors. iter ( ) {
90+ let mut w = test_utils:: TestVecWriter ( Vec :: new ( ) ) ;
91+ monitor. write_for_disk ( & mut w) . unwrap ( ) ;
92+ let ( _, new_mon) = <( Sha256d , ChannelMonitor ) >:: read (
93+ & mut :: std:: io:: Cursor :: new ( & w. 0 ) , Arc :: clone ( & self . logger ) as Arc < Logger > ) . unwrap ( ) ;
94+ if let Err ( _) = new_monitor. add_update_monitor ( new_mon. get_funding_txo ( ) . unwrap ( ) , new_mon) {
95+ panic ! ( ) ;
96+ }
97+ }
98+
99+ if * new_watch != * self . chain_monitor {
100+ panic ! ( ) ;
101+ }
79102 }
80103 }
81104}
0 commit comments