@@ -5,6 +5,7 @@ use chain::chaininterface;
5
5
use chain:: transaction:: OutPoint ;
6
6
use chain:: keysinterface:: KeysInterface ;
7
7
use ln:: channelmanager:: { ChannelManager , RAACommitmentOrder , PaymentPreimage , PaymentHash } ;
8
+ use ln:: channelmonitor:: { ChannelMonitor , ManyChannelMonitor } ;
8
9
use ln:: router:: { Route , Router } ;
9
10
use ln:: features:: InitFeatures ;
10
11
use ln:: msgs;
@@ -15,6 +16,7 @@ use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsPro
15
16
use util:: errors:: APIError ;
16
17
use util:: logger:: Logger ;
17
18
use util:: config:: UserConfig ;
19
+ use util:: ser:: ReadableArgs ;
18
20
19
21
use bitcoin:: util:: hash:: BitcoinHash ;
20
22
use bitcoin:: blockdata:: block:: BlockHeader ;
@@ -76,6 +78,27 @@ impl Drop for Node {
76
78
assert ! ( self . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
77
79
assert ! ( self . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
78
80
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
+ }
79
102
}
80
103
}
81
104
}
0 commit comments