From: Elias Rohrer Date: Wed, 14 Sep 2022 08:17:56 +0000 (+0200) Subject: Add `no-std` support for RGS X-Git-Tag: v0.0.112~36^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=ad8c955bd4b16389e195657ed599c78374935edb;p=rust-lightning Add `no-std` support for RGS --- diff --git a/lightning-rapid-gossip-sync/Cargo.toml b/lightning-rapid-gossip-sync/Cargo.toml index b8bc8437..30a641b3 100644 --- a/lightning-rapid-gossip-sync/Cargo.toml +++ b/lightning-rapid-gossip-sync/Cargo.toml @@ -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] diff --git a/lightning-rapid-gossip-sync/src/lib.rs b/lightning-rapid-gossip-sync/src/lib.rs index a8de1e43..eb6e2857 100644 --- a/lightning-rapid-gossip-sync/src/lib.rs +++ b/lightning-rapid-gossip-sync/src/lib.rs @@ -65,10 +65,12 @@ #[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>, L: Deref> RapidGossipSync 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>, L: Deref> RapidGossipSync 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 { + 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`]. /// diff --git a/lightning-rapid-gossip-sync/src/processing.rs b/lightning-rapid-gossip-sync/src/processing.rs index 818e19fe..18f99163 100644 --- a/lightning-rapid-gossip-sync/src/processing.rs +++ b/lightning-rapid-gossip-sync/src/processing.rs @@ -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>, L: Deref> RapidGossipSync 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 { - 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( + pub(crate) fn update_network_graph_from_byte_stream( &self, mut read_cursor: &mut R, ) -> Result { diff --git a/no-std-check/Cargo.toml b/no-std-check/Cargo.toml index 15d2c196..94783863 100644 --- a/no-std-check/Cargo.toml +++ b/no-std-check/Cargo.toml @@ -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 }