@@ -5,7 +5,7 @@ use chain::chaininterface;
5
5
use chain:: transaction:: OutPoint ;
6
6
use chain:: keysinterface:: KeysInterface ;
7
7
use ln:: channelmonitor:: { ChannelMonitor , ManyChannelMonitor } ;
8
- use ln:: channelmanager:: { ChannelManager , RAACommitmentOrder , PaymentPreimage , PaymentHash } ;
8
+ use ln:: channelmanager:: { ChannelManager , ChannelManagerReadArgs , RAACommitmentOrder , PaymentPreimage , PaymentHash } ;
9
9
use ln:: router:: { Route , Router } ;
10
10
use ln:: features:: InitFeatures ;
11
11
use ln:: msgs;
@@ -17,7 +17,7 @@ use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsPro
17
17
use util:: errors:: APIError ;
18
18
use util:: logger:: Logger ;
19
19
use util:: config:: UserConfig ;
20
- use util:: ser:: ReadableArgs ;
20
+ use util:: ser:: { ReadableArgs , Writeable } ;
21
21
22
22
use bitcoin:: util:: hash:: BitcoinHash ;
23
23
use bitcoin:: blockdata:: block:: BlockHeader ;
@@ -37,7 +37,7 @@ use std::cell::RefCell;
37
37
use std:: rc:: Rc ;
38
38
use std:: sync:: { Arc , Mutex } ;
39
39
use std:: mem;
40
- use std:: collections:: HashSet ;
40
+ use std:: collections:: { HashSet , HashMap } ;
41
41
42
42
pub const CHAN_CONFIRM_DEPTH : u32 = 100 ;
43
43
pub fn confirm_transaction < ' a , ' b : ' a > ( notifier : & ' a chaininterface:: BlockNotifierRef < ' b > , chain : & chaininterface:: ChainWatchInterfaceUtil , tx : & Transaction , chan_id : u32 ) {
@@ -95,20 +95,45 @@ impl<'a, 'b> Drop for Node<'a, 'b> {
95
95
// Check that if we serialize and then deserialize all our channel monitors we the same
96
96
// set of outputs to watch for on chain as we have now. Note that if we write tests
97
97
// that fully close channels and remove the monitors at some point this may break.
98
- let new_watch = Arc :: new ( chaininterface:: ChainWatchInterfaceUtil :: new ( Network :: Testnet , Arc :: clone ( & self . logger ) as Arc < Logger > ) ) ;
99
98
let feeest = Arc :: new ( test_utils:: TestFeeEstimator { sat_per_kw : 253 } ) ;
100
- let new_monitor = test_utils:: TestChannelMonitor :: new ( new_watch. clone ( ) , self . tx_broadcaster . clone ( ) , self . logger . clone ( ) , feeest) ;
101
99
let old_monitors = self . chan_monitor . simple_monitor . monitors . lock ( ) . unwrap ( ) ;
100
+ let mut new_monitors = Vec :: new ( ) ;
102
101
for ( _, monitor) in old_monitors. iter ( ) {
103
102
let mut w = test_utils:: TestVecWriter ( Vec :: new ( ) ) ;
104
103
monitor. write_for_disk ( & mut w) . unwrap ( ) ;
105
104
let ( _, new_mon) = <( Sha256d , ChannelMonitor < EnforcingChannelKeys > ) >:: read (
106
105
& mut :: std:: io:: Cursor :: new ( & w. 0 ) , Arc :: clone ( & self . logger ) as Arc < Logger > ) . unwrap ( ) ;
106
+ new_monitors. push ( new_mon) ;
107
+ }
108
+
109
+ // Before using all the new monitors to check the watch outpoints, use the full set of
110
+ // them to ensure we can write and reload our ChannelManager.
111
+ {
112
+ let mut channel_monitors = HashMap :: new ( ) ;
113
+ for monitor in new_monitors. iter_mut ( ) {
114
+ channel_monitors. insert ( monitor. get_funding_txo ( ) . unwrap ( ) , monitor) ;
115
+ }
116
+
117
+ let mut w = test_utils:: TestVecWriter ( Vec :: new ( ) ) ;
118
+ self . node . write ( & mut w) . unwrap ( ) ;
119
+ <( Sha256d , ChannelManager < EnforcingChannelKeys , & test_utils:: TestChannelMonitor > ) >:: read ( & mut :: std:: io:: Cursor :: new ( w. 0 ) , ChannelManagerReadArgs {
120
+ default_config : UserConfig :: default ( ) ,
121
+ keys_manager : self . keys_manager . clone ( ) ,
122
+ fee_estimator : Arc :: new ( test_utils:: TestFeeEstimator { sat_per_kw : 253 } ) ,
123
+ monitor : self . chan_monitor ,
124
+ tx_broadcaster : self . tx_broadcaster . clone ( ) ,
125
+ logger : Arc :: new ( test_utils:: TestLogger :: new ( ) ) ,
126
+ channel_monitors : & mut channel_monitors,
127
+ } ) . unwrap ( ) ;
128
+ }
129
+
130
+ let new_watch = Arc :: new ( chaininterface:: ChainWatchInterfaceUtil :: new ( Network :: Testnet , Arc :: clone ( & self . logger ) as Arc < Logger > ) ) ;
131
+ let new_monitor = test_utils:: TestChannelMonitor :: new ( new_watch. clone ( ) , self . tx_broadcaster . clone ( ) , self . logger . clone ( ) , feeest) ;
132
+ for new_mon in new_monitors. drain ( ..) {
107
133
if let Err ( _) = new_monitor. add_update_monitor ( new_mon. get_funding_txo ( ) . unwrap ( ) , new_mon) {
108
134
panic ! ( ) ;
109
135
}
110
136
}
111
-
112
137
if * new_watch != * self . chain_monitor {
113
138
panic ! ( ) ;
114
139
}
0 commit comments