Skip to content

Commit 8805d06

Browse files
committed
Move RGS GraphSyncError into the top-level module
The top-level module is only a few hundred lines, so there's not a lot of reason to hide the `GraphSyncError` in its own module. Instead, we simply move it to the top-level `lib.rs`, which doesn't change the public API as it was previously re-exported at the top level.
1 parent 5d5c818 commit 8805d06

File tree

3 files changed

+44
-51
lines changed

3 files changed

+44
-51
lines changed

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

Lines changed: 0 additions & 40 deletions
This file was deleted.

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

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,54 @@ extern crate alloc;
7272
use std::fs::File;
7373
use core::ops::Deref;
7474
use core::sync::atomic::{AtomicBool, Ordering};
75+
use core::fmt::Debug;
76+
use core::fmt::Formatter;
7577

7678
use lightning::io;
79+
use lightning::ln::msgs::{DecodeError, LightningError};
7780
use lightning::routing::gossip::NetworkGraph;
7881
use lightning::util::logger::Logger;
7982

80-
pub use crate::error::GraphSyncError;
81-
82-
/// Error types that these functions can return
83-
mod error;
84-
8583
/// Core functionality of this crate
8684
mod processing;
8785

86+
/// All-encompassing standard error type that processing can return
87+
pub enum GraphSyncError {
88+
/// Error trying to read the update data, typically due to an erroneous data length indication
89+
/// that is greater than the actual amount of data provided
90+
DecodeError(DecodeError),
91+
/// Error applying the patch to the network graph, usually the result of updates that are too
92+
/// old or missing prerequisite data to the application of updates out of order
93+
LightningError(LightningError),
94+
}
95+
96+
impl From<lightning::io::Error> for GraphSyncError {
97+
fn from(error: lightning::io::Error) -> Self {
98+
Self::DecodeError(DecodeError::Io(error.kind()))
99+
}
100+
}
101+
102+
impl From<DecodeError> for GraphSyncError {
103+
fn from(error: DecodeError) -> Self {
104+
Self::DecodeError(error)
105+
}
106+
}
107+
108+
impl From<LightningError> for GraphSyncError {
109+
fn from(error: LightningError) -> Self {
110+
Self::LightningError(error)
111+
}
112+
}
113+
114+
impl Debug for GraphSyncError {
115+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
116+
match self {
117+
GraphSyncError::DecodeError(e) => f.write_fmt(format_args!("DecodeError: {:?}", e)),
118+
GraphSyncError::LightningError(e) => f.write_fmt(format_args!("LightningError: {:?}", e))
119+
}
120+
}
121+
}
122+
88123
/// The main Rapid Gossip Sync object.
89124
///
90125
/// See [crate-level documentation] for usage.
@@ -167,7 +202,7 @@ mod tests {
167202
use lightning::ln::msgs::DecodeError;
168203
use lightning::routing::gossip::NetworkGraph;
169204
use lightning::util::test_utils::TestLogger;
170-
use crate::RapidGossipSync;
205+
use crate::{GraphSyncError, RapidGossipSync};
171206

172207
#[test]
173208
fn test_sync_from_file() {
@@ -265,7 +300,7 @@ mod tests {
265300
let start = std::time::Instant::now();
266301
let sync_result = rapid_sync
267302
.sync_network_graph_with_file_path("./res/full_graph.lngossip");
268-
if let Err(crate::error::GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
303+
if let Err(GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
269304
let error_string = format!("Input file lightning-rapid-gossip-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-285cb27df79-2022-07-21.bin\n\n{:?}", io_error);
270305
#[cfg(not(require_route_graph_test))]
271306
{

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use lightning::{log_debug, log_warn, log_trace, log_given_level, log_gossip};
1414
use lightning::util::ser::{BigSize, Readable};
1515
use lightning::io;
1616

17-
use crate::error::GraphSyncError;
18-
use crate::RapidGossipSync;
17+
use crate::{GraphSyncError, RapidGossipSync};
1918

2019
#[cfg(all(feature = "std", not(test)))]
2120
use std::time::{SystemTime, UNIX_EPOCH};
@@ -269,9 +268,8 @@ mod tests {
269268
use lightning::routing::gossip::NetworkGraph;
270269
use lightning::util::test_utils::TestLogger;
271270

272-
use crate::error::GraphSyncError;
273271
use crate::processing::STALE_RGS_UPDATE_AGE_LIMIT_SECS;
274-
use crate::RapidGossipSync;
272+
use crate::{GraphSyncError, RapidGossipSync};
275273

276274
const VALID_RGS_BINARY: [u8; 300] = [
277275
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,

0 commit comments

Comments
 (0)