Skip to content

Commit b336b2e

Browse files
committed
Lift std check to function definition
1 parent cff1b4b commit b336b2e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@
5656
//! let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
5757
//! let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
5858
//! let snapshot_contents: &[u8] = &[0; 0];
59-
//! let new_last_sync_timestamp_result = rapid_sync.update_network_graph(snapshot_contents);
59+
//! // In no-std you need to provide the current time in unix epoch seconds
60+
//! // otherwise you can use update_network_graph
61+
//! let current_time_unix = 0;
62+
//! let new_last_sync_timestamp_result = rapid_sync.update_network_graph_no_std(snapshot_contents, Some(current_time_unix));
6063
//! ```
6164
6265
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
@@ -128,6 +131,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
128131
/// Returns the last sync timestamp to be used the next time rapid sync data is queried.
129132
///
130133
/// `update_data`: `&[u8]` binary stream that comprises the update data
134+
#[cfg(feature = "std")]
131135
pub fn update_network_graph(&self, update_data: &[u8]) -> Result<u32, GraphSyncError> {
132136
let mut read_cursor = io::Cursor::new(update_data);
133137
self.update_network_graph_from_byte_stream(&mut read_cursor)

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ const MAX_INITIAL_NODE_ID_VECTOR_CAPACITY: u32 = 50_000;
3838
const STALE_RGS_UPDATE_AGE_LIMIT_SECS: u64 = 60 * 60 * 24 * 14;
3939

4040
impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L::Target: Logger {
41+
#[cfg(feature = "std")]
4142
pub(crate) fn update_network_graph_from_byte_stream<R: io::Read>(
4243
&self,
4344
read_cursor: &mut R,
4445
) -> Result<u32, GraphSyncError> {
4546
#[allow(unused_mut, unused_assignments)]
4647
let mut current_time_unix = None;
47-
#[cfg(all(feature = "std", not(test)))]
48+
#[cfg(not(test))]
4849
{
4950
// Note that many tests rely on being able to set arbitrarily old timestamps, thus we
5051
// disable this check during tests!
@@ -252,7 +253,9 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
252253
mod tests {
253254
use bitcoin::Network;
254255

256+
#[cfg(feature = "std")]
255257
use lightning::ln::msgs::DecodeError;
258+
256259
use lightning::routing::gossip::NetworkGraph;
257260
use lightning::util::test_utils::TestLogger;
258261

@@ -280,6 +283,7 @@ mod tests {
280283
const VALID_BINARY_TIMESTAMP: u64 = 1642291930;
281284

282285
#[test]
286+
#[cfg(feature = "std")]
283287
fn network_graph_fails_to_update_from_clipped_input() {
284288
let logger = TestLogger::new();
285289
let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
@@ -311,6 +315,7 @@ mod tests {
311315
}
312316

313317
#[test]
318+
#[cfg(feature = "std")]
314319
fn incremental_only_update_ignores_missing_channel() {
315320
let incremental_update_input = vec![
316321
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,
@@ -331,6 +336,7 @@ mod tests {
331336
}
332337

333338
#[test]
339+
#[cfg(feature = "std")]
334340
fn incremental_only_update_fails_without_prior_updates() {
335341
let announced_update_input = vec![
336342
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,
@@ -358,6 +364,7 @@ mod tests {
358364
}
359365

360366
#[test]
367+
#[cfg(feature = "std")]
361368
fn incremental_only_update_fails_without_prior_same_direction_updates() {
362369
let initialization_input = vec![
363370
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,
@@ -413,6 +420,7 @@ mod tests {
413420
}
414421

415422
#[test]
423+
#[cfg(feature = "std")]
416424
fn incremental_update_succeeds_with_prior_announcements_and_full_updates() {
417425
let initialization_input = vec![
418426
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,
@@ -472,6 +480,7 @@ mod tests {
472480
}
473481

474482
#[test]
483+
#[cfg(feature = "std")]
475484
fn update_succeeds_when_duplicate_gossip_is_applied() {
476485
let initialization_input = vec![
477486
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,
@@ -515,6 +524,7 @@ mod tests {
515524
}
516525

517526
#[test]
527+
#[cfg(feature = "std")]
518528
fn full_update_succeeds() {
519529
let logger = TestLogger::new();
520530
let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
@@ -624,6 +634,7 @@ mod tests {
624634
}
625635

626636
#[test]
637+
#[cfg(feature = "std")]
627638
pub fn update_fails_with_unknown_version() {
628639
let unknown_version_input = vec![
629640
76, 68, 75, 2, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,

0 commit comments

Comments
 (0)