From 5bd7f24634a983326924f200bfff7c7c0fa56601 Mon Sep 17 00:00:00 2001 From: Gleb Naumenko Date: Sat, 2 May 2020 09:37:38 -0400 Subject: [PATCH] Move router to a separate module --- fuzz/src/chanmon_consistency.rs | 3 ++- fuzz/src/full_stack.rs | 2 +- fuzz/src/router.rs | 2 +- lightning/src/lib.rs | 2 ++ lightning/src/ln/channelmanager.rs | 4 ++-- lightning/src/ln/functional_test_utils.rs | 2 +- lightning/src/ln/functional_tests.rs | 2 +- lightning/src/ln/mod.rs | 1 - lightning/src/ln/onion_utils.rs | 4 ++-- lightning/src/routing/mod.rs | 3 +++ lightning/src/{ln => routing}/router.rs | 2 +- lightning/src/util/macro_logger.rs | 2 +- 12 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 lightning/src/routing/mod.rs rename lightning/src/{ln => routing}/router.rs (99%) diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 135249f74..e6b7805f8 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -27,7 +27,6 @@ use lightning::chain::keysinterface::{KeysInterface, InMemoryChannelKeys}; use lightning::ln::channelmonitor; use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, HTLCUpdate}; use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret, ChannelManagerReadArgs}; -use lightning::ln::router::{Route, RouteHop}; use lightning::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, UpdateAddHTLC, Init}; use lightning::util::enforcing_trait_impls::EnforcingChannelKeys; @@ -36,6 +35,8 @@ use lightning::util::logger::Logger; use lightning::util::config::UserConfig; use lightning::util::events::{EventsProvider, MessageSendEventsProvider}; use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer}; +use lightning::routing::router::{Route, RouteHop}; + use utils::test_logger; diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index afdb5a838..cf8a86680 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -23,7 +23,7 @@ use lightning::chain::keysinterface::{InMemoryChannelKeys, KeysInterface}; use lightning::ln::channelmonitor; use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret}; use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor}; -use lightning::ln::router::Router; +use lightning::routing::router::Router; use lightning::util::events::{EventsProvider,Event}; use lightning::util::enforcing_trait_impls::EnforcingChannelKeys; use lightning::util::logger::Logger; diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index 2ff160e4e..7dd439bef 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -8,7 +8,7 @@ use lightning::ln::channelmanager::ChannelDetails; use lightning::ln::features::InitFeatures; use lightning::ln::msgs; use lightning::ln::msgs::RoutingMessageHandler; -use lightning::ln::router::{Router, RouteHint}; +use lightning::routing::router::{Router, RouteHint}; use lightning::util::logger::Logger; use lightning::util::ser::Readable; diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index 039f2f3ac..23645ab18 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -26,3 +26,5 @@ extern crate bitcoin; pub mod util; pub mod chain; pub mod ln; +pub mod routing; + diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index bbb7ea300..4d7f5aa8b 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -4,7 +4,7 @@ //! responsible for tracking which channels are open, HTLCs are in flight and reestablishing those //! upon reconnect to the relevant peer(s). //! -//! It does not manage routing logic (see ln::router for that) nor does it manage constructing +//! It does not manage routing logic (see routing::router for that) nor does it manage constructing //! on-chain transactions (it only monitors the chain to watch for any force-closes that might //! imply it needs to fail HTLCs/payments/channels it manages). @@ -31,7 +31,7 @@ use chain::transaction::OutPoint; use ln::channel::{Channel, ChannelError}; use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, ManyChannelMonitor, HTLC_FAIL_BACK_BUFFER, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY}; use ln::features::{InitFeatures, NodeFeatures}; -use ln::router::{Route, RouteHop}; +use routing::router::{Route, RouteHop}; use ln::msgs; use ln::onion_utils; use ln::msgs::{ChannelMessageHandler, DecodeError, LightningError}; diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 4a56ea412..50dd6b956 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -6,7 +6,7 @@ use chain::transaction::OutPoint; use chain::keysinterface::KeysInterface; use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure}; use ln::channelmonitor::{ChannelMonitor, ManyChannelMonitor}; -use ln::router::{Route, Router, RouterReadArgs}; +use routing::router::{Route, Router, RouterReadArgs}; use ln::features::InitFeatures; use ln::msgs; use ln::msgs::{ChannelMessageHandler,RoutingMessageHandler}; diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index af4989583..5abddcf03 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -12,7 +12,7 @@ use ln::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD use ln::channelmonitor; use ln::channel::{Channel, ChannelError}; use ln::{chan_utils, onion_utils}; -use ln::router::{Route, RouteHop}; +use routing::router::{Route, RouteHop}; use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use ln::msgs; use ln::msgs::{ChannelMessageHandler,RoutingMessageHandler,HTLCFailChannelUpdate, ErrorAction}; diff --git a/lightning/src/ln/mod.rs b/lightning/src/ln/mod.rs index 38396dd74..33f1c5bc1 100644 --- a/lightning/src/ln/mod.rs +++ b/lightning/src/ln/mod.rs @@ -12,7 +12,6 @@ pub mod channelmanager; pub mod channelmonitor; pub mod msgs; -pub mod router; pub mod peer_handler; pub mod chan_utils; pub mod features; diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 4128d0990..52e7d2fef 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -1,6 +1,6 @@ use ln::channelmanager::{PaymentHash, PaymentSecret, HTLCSource}; use ln::msgs; -use ln::router::RouteHop; +use routing::router::RouteHop; use util::byte_utils; use util::chacha20::ChaCha20; use util::errors::{self, APIError}; @@ -472,7 +472,7 @@ pub(super) fn process_onion_failure(secp_ctx: &Secp256k1< mod tests { use ln::channelmanager::PaymentHash; use ln::features::{ChannelFeatures, NodeFeatures}; - use ln::router::{Route, RouteHop}; + use routing::router::{Route, RouteHop}; use ln::msgs; use util::ser::{Writeable, Writer}; diff --git a/lightning/src/routing/mod.rs b/lightning/src/routing/mod.rs new file mode 100644 index 000000000..9e72d7c3e --- /dev/null +++ b/lightning/src/routing/mod.rs @@ -0,0 +1,3 @@ +//! Structs and impls for receiving messages about the network and storing the topology live here. + +pub mod router; diff --git a/lightning/src/ln/router.rs b/lightning/src/routing/router.rs similarity index 99% rename from lightning/src/ln/router.rs rename to lightning/src/routing/router.rs index 037303d91..fef99fcc1 100644 --- a/lightning/src/ln/router.rs +++ b/lightning/src/routing/router.rs @@ -1077,7 +1077,7 @@ impl Router { mod tests { use chain::chaininterface; use ln::channelmanager; - use ln::router::{Router,NodeInfo,NetworkMap,ChannelInfo,DirectionalChannelInfo,RouteHint}; + use routing::router::{Router,NodeInfo,NetworkMap,ChannelInfo,DirectionalChannelInfo,RouteHint}; use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use ln::msgs::{ErrorAction, LightningError, RoutingMessageHandler, UnsignedNodeAnnouncement, NodeAnnouncement, UnsignedChannelAnnouncement, ChannelAnnouncement, UnsignedChannelUpdate, ChannelUpdate, HTLCFailChannelUpdate}; diff --git a/lightning/src/util/macro_logger.rs b/lightning/src/util/macro_logger.rs index b94540446..bea3685b5 100644 --- a/lightning/src/util/macro_logger.rs +++ b/lightning/src/util/macro_logger.rs @@ -5,7 +5,7 @@ use bitcoin::hash_types::Txid; use bitcoin::blockdata::transaction::Transaction; use bitcoin::secp256k1::key::PublicKey; -use ln::router::Route; +use routing::router::Route; use ln::chan_utils::HTLCType; use std; -- 2.39.5