@@ -12,7 +12,7 @@ extern crate lightning;
12
12
extern crate bitcoin;
13
13
extern crate libc;
14
14
15
- use bitcoin:: { BlockHash , Txid } ;
15
+ use bitcoin:: hash_types :: { BlockHash , Txid } ;
16
16
use bitcoin:: hashes:: hex:: { FromHex , ToHex } ;
17
17
use crate :: util:: DiskWriteable ;
18
18
use lightning:: chain;
@@ -24,7 +24,6 @@ use lightning::chain::transaction::OutPoint;
24
24
use lightning:: ln:: channelmanager:: ChannelManager ;
25
25
use lightning:: util:: logger:: Logger ;
26
26
use lightning:: util:: ser:: { ReadableArgs , Writeable } ;
27
- use std:: collections:: HashMap ;
28
27
use std:: fs;
29
28
use std:: io:: { Cursor , Error } ;
30
29
use std:: ops:: Deref ;
@@ -103,14 +102,14 @@ impl FilesystemPersister {
103
102
/// Read `ChannelMonitor`s from disk.
104
103
pub fn read_channelmonitors < Signer : Sign , K : Deref > (
105
104
& self , keys_manager : K
106
- ) -> Result < HashMap < OutPoint , ( BlockHash , ChannelMonitor < Signer > ) > , std:: io:: Error >
105
+ ) -> Result < Vec < ( BlockHash , ChannelMonitor < Signer > ) > , std:: io:: Error >
107
106
where K :: Target : KeysInterface < Signer =Signer > + Sized
108
107
{
109
108
let path = self . path_to_monitor_data ( ) ;
110
109
if !Path :: new ( & path) . exists ( ) {
111
- return Ok ( HashMap :: new ( ) ) ;
110
+ return Ok ( Vec :: new ( ) ) ;
112
111
}
113
- let mut outpoint_to_channelmonitor = HashMap :: new ( ) ;
112
+ let mut res = Vec :: new ( ) ;
114
113
for file_option in fs:: read_dir ( path) . unwrap ( ) {
115
114
let file = file_option. unwrap ( ) ;
116
115
let owned_file_name = file. file_name ( ) ;
@@ -142,18 +141,18 @@ impl FilesystemPersister {
142
141
let mut buffer = Cursor :: new ( & contents) ;
143
142
match <( BlockHash , ChannelMonitor < Signer > ) >:: read ( & mut buffer, & * keys_manager) {
144
143
Ok ( ( blockhash, channel_monitor) ) => {
145
- outpoint_to_channelmonitor . insert (
146
- OutPoint { txid : txid . unwrap ( ) , index : index . unwrap ( ) } ,
147
- ( blockhash , channel_monitor ) ,
148
- ) ;
144
+ if channel_monitor . get_funding_txo ( ) . 0 . txid != txid . unwrap ( ) || channel_monitor . get_funding_txo ( ) . 0 . index != index . unwrap ( ) {
145
+ return Err ( std :: io :: Error :: new ( std :: io :: ErrorKind :: InvalidData , "ChannelMonitor was stored in the wrong file" ) ) ;
146
+ }
147
+ res . push ( ( blockhash , channel_monitor ) ) ;
149
148
}
150
149
Err ( e) => return Err ( std:: io:: Error :: new (
151
150
std:: io:: ErrorKind :: InvalidData ,
152
151
format ! ( "Failed to deserialize ChannelMonitor: {}" , e) ,
153
152
) )
154
153
}
155
154
}
156
- Ok ( outpoint_to_channelmonitor )
155
+ Ok ( res )
157
156
}
158
157
}
159
158
@@ -225,21 +224,21 @@ mod tests {
225
224
// Check that the persisted channel data is empty before any channels are
226
225
// open.
227
226
let mut persisted_chan_data_0 = persister_0. read_channelmonitors ( nodes[ 0 ] . keys_manager ) . unwrap ( ) ;
228
- assert_eq ! ( persisted_chan_data_0. keys ( ) . len( ) , 0 ) ;
227
+ assert_eq ! ( persisted_chan_data_0. len( ) , 0 ) ;
229
228
let mut persisted_chan_data_1 = persister_1. read_channelmonitors ( nodes[ 1 ] . keys_manager ) . unwrap ( ) ;
230
- assert_eq ! ( persisted_chan_data_1. keys ( ) . len( ) , 0 ) ;
229
+ assert_eq ! ( persisted_chan_data_1. len( ) , 0 ) ;
231
230
232
231
// Helper to make sure the channel is on the expected update ID.
233
232
macro_rules! check_persisted_data {
234
233
( $expected_update_id: expr) => {
235
234
persisted_chan_data_0 = persister_0. read_channelmonitors( nodes[ 0 ] . keys_manager) . unwrap( ) ;
236
- assert_eq!( persisted_chan_data_0. keys ( ) . len( ) , 1 ) ;
237
- for ( _, mon) in persisted_chan_data_0. values ( ) {
235
+ assert_eq!( persisted_chan_data_0. len( ) , 1 ) ;
236
+ for ( _, mon) in persisted_chan_data_0. iter ( ) {
238
237
assert_eq!( mon. get_latest_update_id( ) , $expected_update_id) ;
239
238
}
240
239
persisted_chan_data_1 = persister_1. read_channelmonitors( nodes[ 1 ] . keys_manager) . unwrap( ) ;
241
- assert_eq!( persisted_chan_data_1. keys ( ) . len( ) , 1 ) ;
242
- for ( _, mon) in persisted_chan_data_1. values ( ) {
240
+ assert_eq!( persisted_chan_data_1. len( ) , 1 ) ;
241
+ for ( _, mon) in persisted_chan_data_1. iter ( ) {
243
242
assert_eq!( mon. get_latest_update_id( ) , $expected_update_id) ;
244
243
}
245
244
}
0 commit comments