@@ -13,7 +13,7 @@ use chain::chaininterface::{ChainError, ChainWatchInterface};
13
13
use ln:: features:: { ChannelFeatures , NodeFeatures } ;
14
14
use ln:: msgs:: { DecodeError , ErrorAction , LightningError , RoutingMessageHandler , NetAddress } ;
15
15
use ln:: msgs;
16
- use util:: ser:: { Writeable , Readable , Writer , ReadableArgs } ;
16
+ use util:: ser:: { Writeable , Readable , Writer } ;
17
17
use util:: logger:: Logger ;
18
18
19
19
use std:: cmp;
@@ -34,7 +34,8 @@ pub struct NetGraphMsgHandler {
34
34
}
35
35
36
36
impl NetGraphMsgHandler {
37
- /// Creates a new tracker of the actual state of the network of channels and nodes.
37
+ /// Creates a new tracker of the actual state of the network of channels and nodes,
38
+ /// assuming fresh Network Graph
38
39
pub fn new ( chain_monitor : Arc < ChainWatchInterface > , logger : Arc < Logger > ) -> Self {
39
40
NetGraphMsgHandler {
40
41
secp_ctx : Secp256k1 :: verification_only ( ) ,
@@ -48,6 +49,18 @@ impl NetGraphMsgHandler {
48
49
}
49
50
}
50
51
52
+ /// Creates a new tracker of the actual state of the network of channels and nodes,
53
+ /// assuming an existing Network Graph.
54
+ pub fn from_net_graph ( chain_monitor : Arc < ChainWatchInterface > , logger : Arc < Logger > , network_graph : RwLock < NetworkGraph > ) -> Self {
55
+ NetGraphMsgHandler {
56
+ secp_ctx : Secp256k1 :: verification_only ( ) ,
57
+ network_graph : network_graph,
58
+ full_syncs_requested : AtomicUsize :: new ( 0 ) ,
59
+ chain_monitor,
60
+ logger : logger. clone ( ) ,
61
+ }
62
+ }
63
+
51
64
/// Get network addresses by node id
52
65
pub fn get_addresses ( & self , pubkey : & PublicKey ) -> Option < Vec < NetAddress > > {
53
66
let network = self . network_graph . read ( ) . unwrap ( ) ;
@@ -198,53 +211,6 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
198
211
}
199
212
}
200
213
201
-
202
- const SERIALIZATION_VERSION : u8 = 1 ;
203
- const MIN_SERIALIZATION_VERSION : u8 = 1 ;
204
-
205
- impl Writeable for NetGraphMsgHandler {
206
- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
207
- writer. write_all ( & [ SERIALIZATION_VERSION ; 1 ] ) ?;
208
- writer. write_all ( & [ MIN_SERIALIZATION_VERSION ; 1 ] ) ?;
209
-
210
- let network = self . network_graph . read ( ) . unwrap ( ) ;
211
- network. write ( writer) ?;
212
- Ok ( ( ) )
213
- }
214
- }
215
-
216
- /// Arguments for the creation of a NetGraphMsgHandler that are not deserialized.
217
- /// At a high-level, the process for deserializing a NetGraphMsgHandler and resuming normal operation is:
218
- /// 1) Deserialize the NetGraphMsgHandler by filling in this struct and calling <NetGraphMsgHandler>::read(reaser, args).
219
- /// 2) Register the new NetGraphMsgHandler with your ChainWatchInterface
220
- pub struct NetGraphMsgHandlerReadArgs {
221
- /// The ChainWatchInterface for use in the NetGraphMsgHandler in the future.
222
- ///
223
- /// No calls to the ChainWatchInterface will be made during deserialization.
224
- pub chain_monitor : Arc < ChainWatchInterface > ,
225
- /// The Logger for use in the ChannelManager and which may be used to log information during
226
- /// deserialization.
227
- pub logger : Arc < Logger > ,
228
- }
229
-
230
- impl ReadableArgs < NetGraphMsgHandlerReadArgs > for NetGraphMsgHandler {
231
- fn read < R : :: std:: io:: Read > ( reader : & mut R , args : NetGraphMsgHandlerReadArgs ) -> Result < NetGraphMsgHandler , DecodeError > {
232
- let _ver: u8 = Readable :: read ( reader) ?;
233
- let min_ver: u8 = Readable :: read ( reader) ?;
234
- if min_ver > SERIALIZATION_VERSION {
235
- return Err ( DecodeError :: UnknownVersion ) ;
236
- }
237
- let network_graph = Readable :: read ( reader) ?;
238
- Ok ( NetGraphMsgHandler {
239
- secp_ctx : Secp256k1 :: verification_only ( ) ,
240
- network_graph : RwLock :: new ( network_graph) ,
241
- chain_monitor : args. chain_monitor ,
242
- full_syncs_requested : AtomicUsize :: new ( 0 ) ,
243
- logger : args. logger . clone ( ) ,
244
- } )
245
- }
246
- }
247
-
248
214
#[ derive( PartialEq , Debug ) ]
249
215
/// Details regarding one direction of a channel
250
216
pub struct DirectionalChannelInfo {
0 commit comments