Skip to content

Commit efed7d3

Browse files
committed
Respond to Matt's additional comments.
1 parent ef712e3 commit efed7d3

File tree

6 files changed

+27
-33
lines changed

6 files changed

+27
-33
lines changed

.github/workflows/build.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141
run: |
142142
cargo test --verbose --color always -p lightning
143143
cargo test --verbose --color always -p lightning-invoice
144-
cargo test --verbose --color always -p lightning-graph-sync
144+
cargo test --verbose --color always -p lightning-rapid-gossip-sync
145145
cargo build --verbose --color always -p lightning-persister
146146
cargo build --verbose --color always -p lightning-background-processor
147147
- name: Test C Bindings Modifications on Rust ${{ matrix.toolchain }}
@@ -232,9 +232,9 @@ jobs:
232232
EXPECTED_ROUTING_GRAPH_SNAPSHOT_SHASUM: 05a5361278f68ee2afd086cc04a1f927a63924be451f3221d380533acfacc303
233233
- name: Fetch rapid graph sync reference input
234234
run: |
235-
curl --verbose -L -o lightning-graph-sync/res/full_graph.lngossip https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin
236-
echo "Sha sum: $(sha256sum lightning-graph-sync/res/full_graph.lngossip | awk '{ print $1 }')"
237-
if [ "$(sha256sum lightning-graph-sync/res/full_graph.lngossip | awk '{ print $1 }')" != "${EXPECTED_RAPID_GOSSIP_SHASUM}" ]; then
235+
curl --verbose -L -o lightning-rapid-gossip-sync/res/full_graph.lngossip https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin
236+
echo "Sha sum: $(sha256sum lightning-rapid-gossip-sync/res/full_graph.lngossip | awk '{ print $1 }')"
237+
if [ "$(sha256sum lightning-rapid-gossip-sync/res/full_graph.lngossip | awk '{ print $1 }')" != "${EXPECTED_RAPID_GOSSIP_SHASUM}" ]; then
238238
echo "Bad hash"
239239
exit 1
240240
fi

fuzz/src/process_network_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use utils::test_logger;
55
fn do_test(data: &[u8]) {
66
let block_hash = bitcoin::BlockHash::default();
77
let network_graph = lightning::routing::network_graph::NetworkGraph::new(block_hash);
8-
lightning_graph_sync::processing::update_network_graph(&network_graph, data);
8+
lightning_rapid_gossip_sync::processing::update_network_graph(&network_graph, data);
99
}
1010

1111
/// Method that needs to be added manually, {name}_test

lightning-rapid-gossip-sync/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ _bench_unstable = []
1414

1515
[dependencies]
1616
lightning = { version = "0.0.106", path = "../lightning" }
17-
bitcoin = { version = "0.28.1", default-features = false, features = ["secp-recovery"] }
17+
bitcoin = { version = "0.28.1", default-features = false }
1818

1919
[dev-dependencies]
2020
lightning = { version = "0.0.106", path = "../lightning", features = ["_test_utils"] }

lightning-rapid-gossip-sync/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ You will also notice that `NodeAnnouncement` messages are omitted altogether as
3939
implicitly extracted from the channel announcements and updates.
4040

4141
The data is then applied to the current network graph, artificially dated to the timestamp of the
42-
latest seen message, be it an announcement or an update, from the server's perspective. The network
43-
graph should not be pruned until the graph sync completes.
42+
latest seen message less one week, be it an announcement or an update, from the server's
43+
perspective. The network graph should not be pruned until the graph sync completes.
4444

4545
### Custom Channel Announcement
4646

@@ -83,8 +83,8 @@ non-default or to have mutated.
8383

8484
## Delta Calculation
8585

86-
The way a server is meant to calculate this rapid gossip sync data is by using the latest timestamp
87-
an change, be it either an announcement or an update, was seen. That timestamp is included in each
86+
The way a server is meant to calculate this rapid gossip sync data is by taking the latest time
87+
any change, be it either an announcement or an update, was seen. That timestamp is included in each
8888
rapid sync message, so all the client needs to do is cache one variable.
8989

9090
If a particular channel update had never occurred before, the full update is sent. If a channel has
@@ -98,8 +98,8 @@ broadcast on the network may be taken into account when calculating the delta.
9898
## Performance
9999

100100
Given the primary purpose of this utility is a faster graph sync, we thought it might be helpful to
101-
provide some examples of various delta sets. These examples were calculated as of May 19th with a
102-
network graph comprised of 80,000 channel announcements and 160,000 directed channel updates.
101+
provide some examples of various delta sets. These examples were calculated as of May 19th 2022
102+
with a network graph comprised of 80,000 channel announcements and 160,000 directed channel updates.
103103

104104
| Full sync | |
105105
|-----------------------------|--------|

lightning-rapid-gossip-sync/src/lib.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! This crate exposes functionality to rapidly sync gossip data, aimed primarily at mobile
1111
//! devices.
1212
//!
13-
//! The server sends a compressed response containing gossip data. The gossip data is
13+
//! The server sends a compressed response containing differential gossip data. The gossip data is
1414
//! formatted compactly, omitting signatures and opportunistically incremental where previous
1515
//! channel updates are known (a mechanism that is enabled when the timestamp of the last known
1616
//! channel update is communicated). A reference server implementation can be found
@@ -21,23 +21,15 @@
2121
//! privately calculate routes for payments, and do so much faster and earlier than requiring a full
2222
//! peer-to-peer gossip sync to complete.
2323
//!
24-
//! The reason the rapid sync server requires a modicum of trust is that it could provide bogus
25-
//! data, though at worst, all that would result in is a fake network topology, which wouldn't
26-
//! enable the server to steal or siphon off funds. It could, however, reduce the client's privacy
27-
//! by increasing the likelihood payments will are routed via channels the server controls.
24+
//! The reason the rapid sync server requires trust is that it could provide bogus data, though at
25+
//! worst, all that would result in is a fake network topology, which wouldn't enable the server to
26+
//! steal or siphon off funds. It could, however, reduce the client's privacy by forcing all
27+
//! payments to be routed via channels the server controls.
2828
//!
2929
//! The way a server is meant to calculate this rapid gossip sync data is by using a `latest_seen`
3030
//! timestamp provided by the client. It's not included in either channel announcement or update,
3131
//! (not least due to announcements not including any timestamps at all, but only a block height)
3232
//! but rather, it's a timestamp of when the server saw a particular message.
33-
//!
34-
//! If a particular channel update had never occurred before, the full update is sent. If a channel
35-
//! has had updates prior to the provided timestamp, the latest update prior to the timestamp is
36-
//! taken as a reference, and the delta is calculated against it.
37-
//!
38-
//! In practice, snapshots of server data will be calculated at regular intervals, such that deltas
39-
//! are cached and needn't be calculated on the fly. All the client needs to provide to the server
40-
//! is the timestamp included in the previously received (and hence snapshotted) delta.
4133
4234
// Allow and import test features for benching
4335
#![cfg_attr(all(test, feature = "_bench_unstable"), feature(test))]
@@ -65,7 +57,7 @@ pub mod processing;
6557
pub fn sync_network_graph_with_file_path(
6658
network_graph: &network_graph::NetworkGraph,
6759
sync_path: &str,
68-
) -> Result<(), GraphSyncError> {
60+
) -> Result<(u32), GraphSyncError> {
6961
let mut file = File::open(sync_path)?;
7062
processing::update_network_graph_from_byte_stream(&network_graph, &mut file)
7163
}

lightning-rapid-gossip-sync/src/processing.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ const MAX_INITIAL_NODE_ID_VECTOR_CAPACITY: u32 = 50_000;
3131
pub fn update_network_graph(
3232
network_graph: &network_graph::NetworkGraph,
3333
update_data: &[u8],
34-
) -> Result<(), GraphSyncError> {
34+
) -> Result<(u32), GraphSyncError> {
3535
let mut read_cursor = io::Cursor::new(update_data);
3636
update_network_graph_from_byte_stream(&network_graph, &mut read_cursor)
3737
}
3838

3939
pub(crate) fn update_network_graph_from_byte_stream<R: Read>(
4040
network_graph: &network_graph::NetworkGraph,
4141
mut read_cursor: &mut R,
42-
) -> Result<(), GraphSyncError> {
42+
) -> Result<(u32), GraphSyncError> {
4343
let mut prefix = [0u8; 4];
4444
read_cursor.read_exact(&mut prefix)?;
4545

@@ -52,6 +52,8 @@ pub(crate) fn update_network_graph_from_byte_stream<R: Read>(
5252

5353
let chain_hash: BlockHash = Readable::read(read_cursor)?;
5454
let latest_seen_timestamp: u32 = Readable::read(read_cursor)?;
55+
// backdate the applied timestamp by a week
56+
let backdated_timestamp = latest_seen_timestamp - 24 * 3600 * 7;
5557

5658
let node_id_count: u32 = Readable::read(read_cursor)?;
5759
let mut node_ids: Vec<PublicKey> = Vec::with_capacity(std::cmp::min(
@@ -85,7 +87,7 @@ pub(crate) fn update_network_graph_from_byte_stream<R: Read>(
8587

8688
let announcement_result = network_graph.add_channel_from_partial_announcement(
8789
short_channel_id,
88-
latest_seen_timestamp as u64,
90+
backdated_timestamp as u64,
8991
features,
9092
node_id_1,
9193
node_id_2,
@@ -103,7 +105,7 @@ pub(crate) fn update_network_graph_from_byte_stream<R: Read>(
103105

104106
let update_count: u32 = Readable::read(read_cursor)?;
105107
if update_count == 0 {
106-
return Ok(());
108+
return Ok((latest_seen_timestamp));
107109
}
108110

109111
// obtain default values for non-incremental updates
@@ -135,7 +137,7 @@ pub(crate) fn update_network_graph_from_byte_stream<R: Read>(
135137
UnsignedChannelUpdate {
136138
chain_hash,
137139
short_channel_id,
138-
timestamp: latest_seen_timestamp,
140+
timestamp: backdated_timestamp,
139141
flags: standard_channel_flags,
140142
cltv_expiry_delta: default_cltv_expiry_delta,
141143
htlc_minimum_msat: default_htlc_minimum_msat,
@@ -172,7 +174,7 @@ pub(crate) fn update_network_graph_from_byte_stream<R: Read>(
172174
UnsignedChannelUpdate {
173175
chain_hash,
174176
short_channel_id,
175-
timestamp: latest_seen_timestamp,
177+
timestamp: backdated_timestamp,
176178
flags: standard_channel_flags,
177179
cltv_expiry_delta: directional_info.cltv_expiry_delta,
178180
htlc_minimum_msat: directional_info.htlc_minimum_msat,
@@ -216,7 +218,7 @@ pub(crate) fn update_network_graph_from_byte_stream<R: Read>(
216218
network_graph.update_channel_unsigned(&synthetic_update)?;
217219
}
218220

219-
Ok(())
221+
Ok((latest_seen_timestamp))
220222
}
221223

222224
#[cfg(test)]

0 commit comments

Comments
 (0)