6
6
// license as that which applies to the original source files from which this
7
7
// source was automatically generated.
8
8
9
- //! This crate exposes functionality to rapidly sync gossip data, aimed primarily at mobile
9
+ //! This crate exposes client functionality to rapidly sync gossip data, aimed primarily at mobile
10
10
//! devices.
11
11
//!
12
- //! The server sends a compressed response containing differential gossip data. The gossip data is
13
- //! formatted compactly, omitting signatures and opportunistically incremental where previous
14
- //! channel updates are known (a mechanism that is enabled when the timestamp of the last known
15
- //! channel update is communicated) . A reference server implementation can be found
16
- //! [here ](https://github.com/lightningdevkit/rapid-gossip-sync-server).
12
+ //! The rapid gossip sync server will provide a compressed response containing differential gossip
13
+ //! data. The gossip data is formatted compactly, omitting signatures and opportunistically
14
+ //! incremental where previous channel updates are known. This mechanism is enabled when the
15
+ //! timestamp of the last known channel update is communicated. A reference server implementation
16
+ //! can be found [on Github ](https://github.com/lightningdevkit/rapid-gossip-sync-server).
17
17
//!
18
- //! An example server request could look as simple as the following. Note that the first ever rapid
19
- //! sync should use `0` for `last_sync_timestamp`:
18
+ //! The primary benefit of this syncing mechanism is that it allows a low-powered client to offload
19
+ //! the validation of gossip signatures to a semi-trusted server. This enables the client to
20
+ //! privately calculate routes for payments, and to do so much faster than requiring a full
21
+ //! peer-to-peer gossip sync to complete.
22
+ //!
23
+ //! The server calculates its response on the basis of a client-provided `latest_seen` timestamp,
24
+ //! i.e., the server will return all rapid gossip sync data it has seen after the given timestamp.
25
+ //!
26
+ //! # Getting Started
27
+ //! Firstly, the data needs to be retrieved from the server. For example, you could use the server
28
+ //! at <https://rapidsync.lightningdevkit.org> with the following request format:
20
29
//!
21
30
//! ```shell
22
31
//! curl -o rapid_sync.lngossip https://rapidsync.lightningdevkit.org/snapshot/<last_sync_timestamp>
23
32
//! ```
33
+ //! Note that the first ever rapid sync should use `0` for `last_sync_timestamp`.
24
34
//!
25
- //! Then, call the network processing function. In this example, we process the update by reading
26
- //! its contents from disk, which we do by calling the `sync_network_graph_with_file_path` method:
35
+ //! After the gossip data snapshot has been downloaded, one of the client's graph processing
36
+ //! functions needs to be called. In this example, we process the update by reading its contents
37
+ //! from disk, which we do by calling [sync_network_graph_with_file_path]:
27
38
//!
28
39
//! ```
29
40
//! use bitcoin::blockdata::constants::genesis_block;
43
54
//! let rapid_sync = RapidGossipSync::new(&network_graph);
44
55
//! let new_last_sync_timestamp_result = rapid_sync.sync_network_graph_with_file_path(\"./rapid_sync.lngossip\");
45
56
//! ```
46
- //!
47
- //! The primary benefit this syncing mechanism provides is that given a trusted server, a
48
- //! low-powered client can offload the validation of gossip signatures. This enables a client to
49
- //! privately calculate routes for payments, and do so much faster and earlier than requiring a full
50
- //! peer-to-peer gossip sync to complete.
51
- //!
52
- //! The reason the rapid sync server requires trust is that it could provide bogus data, though at
53
- //! worst, all that would result in is a fake network topology, which wouldn't enable the server to
54
- //! steal or siphon off funds. It could, however, reduce the client's privacy by forcing all
55
- //! payments to be routed via channels the server controls.
56
- //!
57
- //! The way a server is meant to calculate this rapid gossip sync data is by using a `latest_seen`
58
- //! timestamp provided by the client. It's not included in either channel announcement or update,
59
- //! (not least due to announcements not including any timestamps at all, but only a block height)
60
- //! but rather, it's a timestamp of when the server saw a particular message.
57
+ //! [sync_network_graph_with_file_path]: RapidGossipSync::sync_network_graph_with_file_path
61
58
62
59
use alloc:: str:: FromStr ;
63
60
use core:: ffi:: c_void;
@@ -73,7 +70,8 @@ pub mod processing;
73
70
use lightning_rapid_gossip_sync:: RapidGossipSync as nativeRapidGossipSyncImport;
74
71
pub ( crate ) type nativeRapidGossipSync = nativeRapidGossipSyncImport < & ' static lightning:: routing:: gossip:: NetworkGraph < crate :: lightning:: util:: logger:: Logger > , crate :: lightning:: util:: logger:: Logger > ;
75
72
76
- /// Rapid Gossip Sync struct
73
+ /// The main Rapid Gossip Sync object.
74
+ ///
77
75
/// See [crate-level documentation] for usage.
78
76
///
79
77
/// [crate-level documentation]: crate
@@ -123,30 +121,29 @@ impl RapidGossipSync {
123
121
ret
124
122
}
125
123
}
126
- /// Instantiate a new [`RapidGossipSync`] instance
124
+ /// Instantiate a new [`RapidGossipSync`] instance.
127
125
#[ must_use]
128
126
#[ no_mangle]
129
127
pub extern "C" fn RapidGossipSync_new ( network_graph : & crate :: lightning:: routing:: gossip:: NetworkGraph ) -> crate :: lightning_rapid_gossip_sync:: RapidGossipSync {
130
128
let mut ret = lightning_rapid_gossip_sync:: RapidGossipSync :: new ( network_graph. get_native_ref ( ) ) ;
131
129
crate :: lightning_rapid_gossip_sync:: RapidGossipSync { inner : ObjOps :: heap_alloc ( ret) , is_owned : true }
132
130
}
133
131
134
- /// Sync gossip data from a file
132
+ /// Update network graph from binary data.
135
133
/// Returns the last sync timestamp to be used the next time rapid sync data is queried.
136
134
///
137
- /// `network_graph`: The network graph to apply the updates to
138
- ///
139
- /// `sync_path`: Path to the file where the gossip update data is located
135
+ /// `network_graph`: network graph to be updated
140
136
///
137
+ /// `update_data`: `&[u8]` binary stream that comprises the update data
141
138
#[ must_use]
142
139
#[ no_mangle]
143
- pub extern "C" fn RapidGossipSync_sync_network_graph_with_file_path ( this_arg : & crate :: lightning_rapid_gossip_sync:: RapidGossipSync , mut sync_path : crate :: c_types:: Str ) -> crate :: c_types:: derived:: CResult_u32GraphSyncErrorZ {
144
- let mut ret = unsafe { & * ObjOps :: untweak_ptr ( this_arg. inner ) } . sync_network_graph_with_file_path ( sync_path . into_str ( ) ) ;
140
+ pub extern "C" fn RapidGossipSync_update_network_graph ( this_arg : & crate :: lightning_rapid_gossip_sync:: RapidGossipSync , mut update_data : crate :: c_types:: u8slice ) -> crate :: c_types:: derived:: CResult_u32GraphSyncErrorZ {
141
+ let mut ret = unsafe { & * ObjOps :: untweak_ptr ( this_arg. inner ) } . update_network_graph ( update_data . to_slice ( ) ) ;
145
142
let mut local_ret = match ret { Ok ( mut o) => crate :: c_types:: CResultTempl :: ok ( { o } ) . into ( ) , Err ( mut e) => crate :: c_types:: CResultTempl :: err ( { crate :: lightning_rapid_gossip_sync:: error:: GraphSyncError :: native_into ( e) } ) . into ( ) } ;
146
143
local_ret
147
144
}
148
145
149
- /// Returns whether a rapid gossip sync has completed at least once
146
+ /// Returns whether a rapid gossip sync has completed at least once.
150
147
#[ must_use]
151
148
#[ no_mangle]
152
149
pub extern "C" fn RapidGossipSync_is_initial_sync_complete ( this_arg : & crate :: lightning_rapid_gossip_sync:: RapidGossipSync ) -> bool {
0 commit comments