Add `no-std` support for RGS
authorElias Rohrer <ero@tnull.de>
Wed, 14 Sep 2022 08:17:56 +0000 (10:17 +0200)
committerElias Rohrer <ero@tnull.de>
Thu, 15 Sep 2022 07:27:34 +0000 (09:27 +0200)
lightning-rapid-gossip-sync/Cargo.toml
lightning-rapid-gossip-sync/src/lib.rs
lightning-rapid-gossip-sync/src/processing.rs
no-std-check/Cargo.toml

index b8bc8437bca04f2c96e08a12f5464635195c6993..30a641b30d1735cc229def767c25783b1ca74fa7 100644 (file)
@@ -10,6 +10,9 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.
 """
 
 [features]
+default = ["std"]
+no-std = ["lightning/no-std"]
+std = ["lightning/std"]
 _bench_unstable = []
 
 [dependencies]
index a8de1e43ae119c62e79cda9cc5f2370fd44e8860..eb6e285712ac2199ce6063edb0d96a7f1659e368 100644 (file)
 #[cfg(all(test, feature = "_bench_unstable"))]
 extern crate test;
 
+#[cfg(feature = "std")]
 use std::fs::File;
-use std::ops::Deref;
-use std::sync::atomic::{AtomicBool, Ordering};
+use core::ops::Deref;
+use core::sync::atomic::{AtomicBool, Ordering};
 
+use lightning::io;
 use lightning::routing::gossip::NetworkGraph;
 use lightning::util::logger::Logger;
 
@@ -107,6 +109,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
        ///
        /// `sync_path`: Path to the file where the gossip update data is located
        ///
+       #[cfg(feature = "std")]
        pub fn sync_network_graph_with_file_path(
                &self,
                sync_path: &str,
@@ -115,6 +118,17 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
                self.update_network_graph_from_byte_stream(&mut file)
        }
 
+       /// Update network graph from binary data.
+       /// Returns the last sync timestamp to be used the next time rapid sync data is queried.
+       ///
+       /// `network_graph`: network graph to be updated
+       ///
+       /// `update_data`: `&[u8]` binary stream that comprises the update data
+       pub fn update_network_graph(&self, update_data: &[u8]) -> Result<u32, GraphSyncError> {
+               let mut read_cursor = io::Cursor::new(update_data);
+               self.update_network_graph_from_byte_stream(&mut read_cursor)
+       }
+
        /// Gets a reference to the underlying [`NetworkGraph`] which was provided in
        /// [`RapidGossipSync::new`].
        ///
index 818e19fe4b42fa6f12a31597b8ca4798eee2b5cb..18f9916316a5ffe9c7e0bf4dde7231bfea626789 100644 (file)
@@ -1,8 +1,6 @@
-use std::cmp::max;
-use std::io;
-use std::io::Read;
-use std::ops::Deref;
-use std::sync::atomic::Ordering;
+use core::cmp::max;
+use core::ops::Deref;
+use core::sync::atomic::Ordering;
 
 use bitcoin::BlockHash;
 use bitcoin::secp256k1::PublicKey;
@@ -13,6 +11,7 @@ use lightning::ln::msgs::{
 use lightning::routing::gossip::NetworkGraph;
 use lightning::util::logger::Logger;
 use lightning::util::ser::{BigSize, Readable};
+use lightning::io;
 
 use crate::error::GraphSyncError;
 use crate::RapidGossipSync;
@@ -28,19 +27,7 @@ const GOSSIP_PREFIX: [u8; 4] = [76, 68, 75, 1];
 const MAX_INITIAL_NODE_ID_VECTOR_CAPACITY: u32 = 50_000;
 
 impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L::Target: Logger {
-       /// Update network graph from binary data.
-       /// Returns the last sync timestamp to be used the next time rapid sync data is queried.
-       ///
-       /// `network_graph`: network graph to be updated
-       ///
-       /// `update_data`: `&[u8]` binary stream that comprises the update data
-       pub fn update_network_graph(&self, update_data: &[u8]) -> Result<u32, GraphSyncError> {
-               let mut read_cursor = io::Cursor::new(update_data);
-               self.update_network_graph_from_byte_stream(&mut read_cursor)
-       }
-
-
-       pub(crate) fn update_network_graph_from_byte_stream<R: Read>(
+       pub(crate) fn update_network_graph_from_byte_stream<R: io::Read>(
                &self,
                mut read_cursor: &mut R,
        ) -> Result<u32, GraphSyncError> {
index 15d2c196cb58c94c1ca63b5bd403b0e1a959c763..947838633c50267e12493dc5fb4b9e5a523185ed 100644 (file)
@@ -4,8 +4,9 @@ version = "0.1.0"
 edition = "2018"
 
 [features]
-default = ["lightning/no-std", "lightning-invoice/no-std"]
+default = ["lightning/no-std", "lightning-invoice/no-std", "lightning-rapid-gossip-sync/no-std"]
 
 [dependencies]
 lightning = { path = "../lightning", default-features = false }
 lightning-invoice = { path = "../lightning-invoice", default-features = false }
+lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync", default-features = false }