@@ -7,13 +7,15 @@ use lightning::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, Cha
7
7
use lightning:: chain:: channelmonitor;
8
8
use lightning:: chain:: keysinterface:: ChannelKeys ;
9
9
use lightning:: chain:: transaction:: OutPoint ;
10
- use lightning:: util:: ser:: { Writeable , Readable } ;
10
+ use lightning:: util:: ser:: Writeable ;
11
11
use std:: fs;
12
12
use std:: io:: Error ;
13
13
use std:: path:: { Path , PathBuf } ;
14
14
15
15
#[ cfg( test) ]
16
16
use {
17
+ lightning:: chain:: keysinterface:: KeysInterface ,
18
+ lightning:: util:: ser:: ReadableArgs ,
17
19
bitcoin:: { BlockHash , Txid } ,
18
20
bitcoin:: hashes:: hex:: FromHex ,
19
21
std:: collections:: HashMap ,
@@ -43,9 +45,9 @@ trait DiskWriteable {
43
45
fn write ( & self , writer : & mut fs:: File ) -> Result < ( ) , Error > ;
44
46
}
45
47
46
- impl < ChanSigner : ChannelKeys + Writeable > DiskWriteable for ChannelMonitor < ChanSigner > {
48
+ impl < ChanSigner : ChannelKeys > DiskWriteable for ChannelMonitor < ChanSigner > {
47
49
fn write ( & self , writer : & mut fs:: File ) -> Result < ( ) , Error > {
48
- self . serialize_for_disk ( writer)
50
+ Writeable :: write ( self , writer)
49
51
}
50
52
}
51
53
@@ -94,8 +96,8 @@ impl FilesystemPersister {
94
96
}
95
97
96
98
#[ cfg( test) ]
97
- fn load_channel_data < ChanSigner : ChannelKeys + Readable + Writeable > ( & self ) ->
98
- Result < HashMap < OutPoint , ChannelMonitor < ChanSigner > > , ChannelMonitorUpdateErr > {
99
+ fn load_channel_data < Keys : KeysInterface > ( & self , keys : & Keys ) ->
100
+ Result < HashMap < OutPoint , ChannelMonitor < Keys :: ChanKeySigner > > , ChannelMonitorUpdateErr > {
99
101
if let Err ( _) = fs:: create_dir_all ( & self . path_to_channel_data ) {
100
102
return Err ( ChannelMonitorUpdateErr :: PermanentFailure ) ;
101
103
}
@@ -118,7 +120,7 @@ impl FilesystemPersister {
118
120
if contents. is_err ( ) { return Err ( ChannelMonitorUpdateErr :: PermanentFailure ) ; }
119
121
120
122
if let Ok ( ( _, loaded_monitor) ) =
121
- <( BlockHash , ChannelMonitor < ChanSigner > ) >:: read ( & mut Cursor :: new ( & contents. unwrap ( ) ) ) {
123
+ <( BlockHash , ChannelMonitor < Keys :: ChanKeySigner > ) >:: read ( & mut Cursor :: new ( & contents. unwrap ( ) ) , keys ) {
122
124
res. insert ( OutPoint { txid : txid. unwrap ( ) , index : index. unwrap ( ) } , loaded_monitor) ;
123
125
} else {
124
126
return Err ( ChannelMonitorUpdateErr :: PermanentFailure ) ;
@@ -128,7 +130,7 @@ impl FilesystemPersister {
128
130
}
129
131
}
130
132
131
- impl < ChanSigner : ChannelKeys + Readable + Writeable + Send + Sync > channelmonitor:: Persist < ChanSigner > for FilesystemPersister {
133
+ impl < ChanSigner : ChannelKeys + Send + Sync > channelmonitor:: Persist < ChanSigner > for FilesystemPersister {
132
134
fn persist_new_channel ( & self , funding_txo : OutPoint , monitor : & ChannelMonitor < ChanSigner > ) -> Result < ( ) , ChannelMonitorUpdateErr > {
133
135
self . write_channel_data ( funding_txo, monitor)
134
136
. map_err ( |_| ChannelMonitorUpdateErr :: PermanentFailure )
@@ -168,7 +170,6 @@ mod tests {
168
170
use lightning:: ln:: features:: InitFeatures ;
169
171
use lightning:: ln:: functional_test_utils:: * ;
170
172
use lightning:: ln:: msgs:: ErrorAction ;
171
- use lightning:: util:: enforcing_trait_impls:: EnforcingChannelKeys ;
172
173
use lightning:: util:: events:: { MessageSendEventsProvider , MessageSendEvent } ;
173
174
use lightning:: util:: ser:: Writer ;
174
175
use lightning:: util:: test_utils;
@@ -206,20 +207,20 @@ mod tests {
206
207
207
208
// Check that the persisted channel data is empty before any channels are
208
209
// open.
209
- let mut persisted_chan_data_0 = persister_0. load_channel_data :: < EnforcingChannelKeys > ( ) . unwrap ( ) ;
210
+ let mut persisted_chan_data_0 = persister_0. load_channel_data ( nodes [ 0 ] . keys_manager ) . unwrap ( ) ;
210
211
assert_eq ! ( persisted_chan_data_0. keys( ) . len( ) , 0 ) ;
211
- let mut persisted_chan_data_1 = persister_1. load_channel_data :: < EnforcingChannelKeys > ( ) . unwrap ( ) ;
212
+ let mut persisted_chan_data_1 = persister_1. load_channel_data ( nodes [ 1 ] . keys_manager ) . unwrap ( ) ;
212
213
assert_eq ! ( persisted_chan_data_1. keys( ) . len( ) , 0 ) ;
213
214
214
215
// Helper to make sure the channel is on the expected update ID.
215
216
macro_rules! check_persisted_data {
216
217
( $expected_update_id: expr) => {
217
- persisted_chan_data_0 = persister_0. load_channel_data:: < EnforcingChannelKeys > ( ) . unwrap( ) ;
218
+ persisted_chan_data_0 = persister_0. load_channel_data( nodes [ 0 ] . keys_manager ) . unwrap( ) ;
218
219
assert_eq!( persisted_chan_data_0. keys( ) . len( ) , 1 ) ;
219
220
for mon in persisted_chan_data_0. values( ) {
220
221
assert_eq!( mon. get_latest_update_id( ) , $expected_update_id) ;
221
222
}
222
- persisted_chan_data_1 = persister_1. load_channel_data:: < EnforcingChannelKeys > ( ) . unwrap( ) ;
223
+ persisted_chan_data_1 = persister_1. load_channel_data( nodes [ 1 ] . keys_manager ) . unwrap( ) ;
223
224
assert_eq!( persisted_chan_data_1. keys( ) . len( ) , 1 ) ;
224
225
for mon in persisted_chan_data_1. values( ) {
225
226
assert_eq!( mon. get_latest_update_id( ) , $expected_update_id) ;
0 commit comments