Skip to content

Commit 1e54c9c

Browse files
authored
Merge pull request #88 from arik-so/versioned-dummies
Generate v1 and v2 dummy snapshots
2 parents f37e149 + 9346b63 commit 1e54c9c

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ pub(crate) async fn connect_to_db() -> Client {
160160
/// of our granularity constant. Note that for that purpose, this method could be very dangerous,
161161
/// because if consumed, the `timestamp` value calculated here will overwrite the timestamp that
162162
/// the client previously had, which could result in duplicated or omitted gossip down the line.
163-
fn serialize_empty_blob(current_timestamp: u64) -> Vec<u8> {
163+
fn serialize_empty_blob(current_timestamp: u64, serialization_version: u8) -> Vec<u8> {
164164
let mut blob = GOSSIP_PREFIX.to_vec();
165+
serialization_version.write(&mut blob).unwrap();
165166

166167
let network = config::network();
167168
let chain_hash = ChainHash::using_genesis_block(network);
@@ -170,6 +171,10 @@ fn serialize_empty_blob(current_timestamp: u64) -> Vec<u8> {
170171
let blob_timestamp = Snapshotter::<Arc<RGSSLogger>>::round_down_to_nearest_multiple(current_timestamp, SYMLINK_GRANULARITY_INTERVAL as u64) as u32;
171172
blob_timestamp.write(&mut blob).unwrap();
172173

174+
if serialization_version >= 2 {
175+
0u8.write(&mut blob).unwrap(); // default node feature count
176+
}
177+
173178
0u32.write(&mut blob).unwrap(); // node count
174179
0u32.write(&mut blob).unwrap(); // announcement count
175180
0u32.write(&mut blob).unwrap(); // update count

src/snapshot.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ impl<L: Deref + Clone> Snapshotter<L> where L::Target: Logger {
138138
{
139139
// create dummy symlink
140140
let dummy_filename = "empty_delta.lngossip";
141-
let dummy_snapshot = super::serialize_empty_blob(reference_timestamp);
142-
let dummy_snapshot_path = format!("{}/{}", pending_snapshot_directory, dummy_filename);
143-
fs::write(&dummy_snapshot_path, dummy_snapshot).unwrap();
141+
let dummy_snapshot_v1 = super::serialize_empty_blob(reference_timestamp, 1);
142+
let dummy_snapshot_v2 = super::serialize_empty_blob(reference_timestamp, 2);
143+
let dummy_snapshot_path_v1 = format!("{}/{}", pending_snapshot_directory, dummy_filename);
144+
let dummy_snapshot_path_v2 = format!("{}/v2/{}", pending_snapshot_directory, dummy_filename);
145+
fs::write(&dummy_snapshot_path_v1, dummy_snapshot_v1).unwrap();
146+
fs::write(&dummy_snapshot_path_v2, dummy_snapshot_v2).unwrap();
144147

145148
let dummy_symlink_path = format!("{}/{}.bin", pending_symlink_directory, reference_timestamp);
146149
let relative_dummy_snapshot_path = format!("{}/{}", relative_symlink_to_snapshot_path, dummy_filename);

src/tests/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use lightning::ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement,
1616
use lightning::routing::gossip::{NetworkGraph, NodeAlias, NodeId};
1717
use lightning::util::ser::Writeable;
1818
use lightning_rapid_gossip_sync::RapidGossipSync;
19-
use crate::{calculate_delta, config, serialize_delta};
19+
use crate::{calculate_delta, config, serialize_delta, serialize_empty_blob};
2020
use crate::persistence::GossipPersister;
2121
use crate::snapshot::Snapshotter;
2222
use crate::types::{GossipMessage, tests::TestLogger};
@@ -221,6 +221,19 @@ async fn test_persistence_runtime() {
221221
}
222222

223223

224+
#[test]
225+
fn test_no_op() {
226+
let logger = Arc::new(TestLogger::with_id("test_no_op".to_string()));
227+
for serialization_version in 1..3 {
228+
let serialization = serialize_empty_blob(current_time() as u64, serialization_version);
229+
230+
let client_graph = NetworkGraph::new(Network::Bitcoin, logger.clone());
231+
let client_graph_arc = Arc::new(client_graph);
232+
let rgs = RapidGossipSync::new(client_graph_arc.clone(), logger.clone());
233+
rgs.update_network_graph(&serialization).unwrap();
234+
}
235+
}
236+
224237
#[tokio::test]
225238
async fn test_trivial_setup() {
226239
let _sanitizer = SchemaSanitizer::new();

0 commit comments

Comments
 (0)