Skip to content

Commit ff1341d

Browse files
authored
Merge pull request #1757 from TheBlueMatt/2022-10-rgs-111-no-std
[0.0.111-bindings] Correct `rapid-gossip-sync` `no-std` build and test
2 parents e8e0e77 + 69175d1 commit ff1341d

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

lightning-rapid-gossip-sync/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ std = ["lightning/std"]
1616
_bench_unstable = []
1717

1818
[dependencies]
19-
lightning = { version = "0.0.111", path = "../lightning" }
19+
lightning = { version = "0.0.111", path = "../lightning", default-features = false }
2020
bitcoin = { version = "0.29.0", default-features = false }
2121

2222
[dev-dependencies]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::fmt::Debug;
2-
use std::fmt::Formatter;
2+
use core::fmt::Formatter;
33
use lightning::ln::msgs::{DecodeError, LightningError};
44

55
/// All-encompassing standard error type that processing can return
@@ -12,8 +12,8 @@ pub enum GraphSyncError {
1212
LightningError(LightningError),
1313
}
1414

15-
impl From<std::io::Error> for GraphSyncError {
16-
fn from(error: std::io::Error) -> Self {
15+
impl From<lightning::io::Error> for GraphSyncError {
16+
fn from(error: lightning::io::Error) -> Self {
1717
Self::DecodeError(DecodeError::Io(error.kind()))
1818
}
1919
}
@@ -31,7 +31,7 @@ impl From<LightningError> for GraphSyncError {
3131
}
3232

3333
impl Debug for GraphSyncError {
34-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
34+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
3535
match self {
3636
GraphSyncError::DecodeError(e) => f.write_fmt(format_args!("DecodeError: {:?}", e)),
3737
GraphSyncError::LightningError(e) => f.write_fmt(format_args!("LightningError: {:?}", e))

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,16 @@
6060
//! ```
6161
//! [sync_network_graph_with_file_path]: RapidGossipSync::sync_network_graph_with_file_path
6262
63+
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
64+
6365
// Allow and import test features for benching
6466
#![cfg_attr(all(test, feature = "_bench_unstable"), feature(test))]
6567
#[cfg(all(test, feature = "_bench_unstable"))]
6668
extern crate test;
6769

70+
#[cfg(not(feature = "std"))]
71+
extern crate alloc;
72+
6873
#[cfg(feature = "std")]
6974
use std::fs::File;
7075
use core::ops::Deref;
@@ -156,6 +161,7 @@ mod tests {
156161
use crate::RapidGossipSync;
157162

158163
#[test]
164+
#[cfg(feature = "std")]
159165
fn test_sync_from_file() {
160166
struct FileSyncTest {
161167
directory: String,
@@ -243,6 +249,7 @@ mod tests {
243249
}
244250

245251
#[test]
252+
#[cfg(feature = "std")]
246253
fn measure_native_read_from_file() {
247254
let block_hash = genesis_block(Network::Bitcoin).block_hash();
248255
let logger = TestLogger::new();

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ use lightning::io;
1616
use crate::error::GraphSyncError;
1717
use crate::RapidGossipSync;
1818

19+
#[cfg(not(feature = "std"))]
20+
use alloc::{vec::Vec, borrow::ToOwned};
21+
1922
/// The purpose of this prefix is to identify the serialization format, should other rapid gossip
2023
/// sync formats arise in the future.
2124
///
@@ -47,7 +50,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
4750
let backdated_timestamp = latest_seen_timestamp.saturating_sub(24 * 3600 * 7);
4851

4952
let node_id_count: u32 = Readable::read(read_cursor)?;
50-
let mut node_ids: Vec<PublicKey> = Vec::with_capacity(std::cmp::min(
53+
let mut node_ids: Vec<PublicKey> = Vec::with_capacity(core::cmp::min(
5154
node_id_count,
5255
MAX_INITIAL_NODE_ID_VECTOR_CAPACITY,
5356
) as usize);
@@ -132,7 +135,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
132135
htlc_maximum_msat: default_htlc_maximum_msat,
133136
fee_base_msat: default_fee_base_msat,
134137
fee_proportional_millionths: default_fee_proportional_millionths,
135-
excess_data: vec![],
138+
excess_data: Vec::new(),
136139
}
137140
} else {
138141
// incremental update, field flags will indicate mutated values
@@ -162,7 +165,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
162165
htlc_maximum_msat: directional_info.htlc_maximum_msat,
163166
fee_base_msat: directional_info.fees.base_msat,
164167
fee_proportional_millionths: directional_info.fees.proportional_millionths,
165-
excess_data: vec![],
168+
excess_data: Vec::new(),
166169
}
167170
};
168171

0 commit comments

Comments
 (0)