Skip to content

Commit 90710d6

Browse files
tnullTheBlueMatt
authored andcommitted
Add no-std support for RGS
1 parent 8d77ee8 commit 90710d6

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

lightning-rapid-gossip-sync/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.
1010
"""
1111

1212
[features]
13+
default = ["std"]
14+
no-std = ["lightning/no-std"]
15+
std = ["lightning/std"]
1316
_bench_unstable = []
1417

1518
[dependencies]

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@
6565
#[cfg(all(test, feature = "_bench_unstable"))]
6666
extern crate test;
6767

68+
#[cfg(feature = "std")]
6869
use std::fs::File;
69-
use std::ops::Deref;
70-
use std::sync::atomic::{AtomicBool, Ordering};
70+
use core::ops::Deref;
71+
use core::sync::atomic::{AtomicBool, Ordering};
7172

73+
use lightning::io;
7274
use lightning::routing::gossip::NetworkGraph;
7375
use lightning::util::logger::Logger;
7476

@@ -107,6 +109,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
107109
///
108110
/// `sync_path`: Path to the file where the gossip update data is located
109111
///
112+
#[cfg(feature = "std")]
110113
pub fn sync_network_graph_with_file_path(
111114
&self,
112115
sync_path: &str,
@@ -115,6 +118,17 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
115118
self.update_network_graph_from_byte_stream(&mut file)
116119
}
117120

121+
/// Update network graph from binary data.
122+
/// Returns the last sync timestamp to be used the next time rapid sync data is queried.
123+
///
124+
/// `network_graph`: network graph to be updated
125+
///
126+
/// `update_data`: `&[u8]` binary stream that comprises the update data
127+
pub fn update_network_graph(&self, update_data: &[u8]) -> Result<u32, GraphSyncError> {
128+
let mut read_cursor = io::Cursor::new(update_data);
129+
self.update_network_graph_from_byte_stream(&mut read_cursor)
130+
}
131+
118132
/// Gets a reference to the underlying [`NetworkGraph`] which was provided in
119133
/// [`RapidGossipSync::new`].
120134
///

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::cmp::max;
2-
use std::io;
3-
use std::io::Read;
4-
use std::ops::Deref;
5-
use std::sync::atomic::Ordering;
1+
use core::cmp::max;
2+
use core::ops::Deref;
3+
use core::sync::atomic::Ordering;
64

75
use bitcoin::BlockHash;
86
use bitcoin::secp256k1::PublicKey;
@@ -13,6 +11,7 @@ use lightning::ln::msgs::{
1311
use lightning::routing::gossip::NetworkGraph;
1412
use lightning::util::logger::Logger;
1513
use lightning::util::ser::{BigSize, Readable};
14+
use lightning::io;
1615

1716
use crate::error::GraphSyncError;
1817
use crate::RapidGossipSync;
@@ -28,19 +27,7 @@ const GOSSIP_PREFIX: [u8; 4] = [76, 68, 75, 1];
2827
const MAX_INITIAL_NODE_ID_VECTOR_CAPACITY: u32 = 50_000;
2928

3029
impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L::Target: Logger {
31-
/// Update network graph from binary data.
32-
/// Returns the last sync timestamp to be used the next time rapid sync data is queried.
33-
///
34-
/// `network_graph`: network graph to be updated
35-
///
36-
/// `update_data`: `&[u8]` binary stream that comprises the update data
37-
pub fn update_network_graph(&self, update_data: &[u8]) -> Result<u32, GraphSyncError> {
38-
let mut read_cursor = io::Cursor::new(update_data);
39-
self.update_network_graph_from_byte_stream(&mut read_cursor)
40-
}
41-
42-
43-
pub(crate) fn update_network_graph_from_byte_stream<R: Read>(
30+
pub(crate) fn update_network_graph_from_byte_stream<R: io::Read>(
4431
&self,
4532
mut read_cursor: &mut R,
4633
) -> Result<u32, GraphSyncError> {

no-std-check/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ version = "0.1.0"
44
edition = "2018"
55

66
[features]
7-
default = ["lightning/no-std", "lightning-invoice/no-std"]
7+
default = ["lightning/no-std", "lightning-invoice/no-std", "lightning-rapid-gossip-sync/no-std"]
88

99
[dependencies]
1010
lightning = { path = "../lightning", default-features = false }
1111
lightning-invoice = { path = "../lightning-invoice", default-features = false }
12+
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync", default-features = false }

0 commit comments

Comments
 (0)