From abe35338a699b0f498f24dd5b41b393a097a621d Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 7 Aug 2020 10:58:15 -0700 Subject: [PATCH] Move channelmonitor.rs from ln to chain module Given the chain::Watch interface is defined in terms of ChannelMonitor and ChannelMonitorUpdateErr, move channelmonitor.rs from the ln module to the chain module. --- fuzz/src/chanmon_consistency.rs | 4 +-- fuzz/src/chanmon_deser.rs | 2 +- fuzz/src/full_stack.rs | 4 +-- lightning-net-tokio/src/lib.rs | 2 +- lightning/src/{ln => chain}/channelmonitor.rs | 36 +++++++++---------- lightning/src/chain/mod.rs | 3 +- lightning/src/ln/chan_utils.rs | 12 +++---- lightning/src/ln/chanmon_update_fail_tests.rs | 2 +- lightning/src/ln/channel.rs | 2 +- lightning/src/ln/channelmanager.rs | 6 ++-- lightning/src/ln/functional_test_utils.rs | 2 +- lightning/src/ln/functional_tests.rs | 4 +-- lightning/src/ln/mod.rs | 1 - lightning/src/ln/onchaintx.rs | 20 +++++------ lightning/src/ln/reorg_tests.rs | 2 +- lightning/src/util/test_utils.rs | 4 +-- 16 files changed, 53 insertions(+), 53 deletions(-) rename lightning/src/{ln => chain}/channelmonitor.rs (99%) diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 7ef635923..a703abf6f 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -21,11 +21,11 @@ use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::hash_types::{BlockHash, WPubkeyHash}; use lightning::chain; +use lightning::chain::channelmonitor; +use lightning::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, HTLCUpdate}; use lightning::chain::transaction::OutPoint; use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator}; 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::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, UpdateAddHTLC, Init}; diff --git a/fuzz/src/chanmon_deser.rs b/fuzz/src/chanmon_deser.rs index 3f4ff5ad0..5a76340ff 100644 --- a/fuzz/src/chanmon_deser.rs +++ b/fuzz/src/chanmon_deser.rs @@ -3,8 +3,8 @@ use bitcoin::hash_types::BlockHash; +use lightning::chain::channelmonitor; use lightning::util::enforcing_trait_impls::EnforcingChannelKeys; -use lightning::ln::channelmonitor; use lightning::util::ser::{Readable, Writer}; use utils::test_logger; diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 908e14599..13d61f9b1 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -19,9 +19,9 @@ use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash}; use lightning::chain; use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator}; +use lightning::chain::channelmonitor; use lightning::chain::transaction::OutPoint; 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::routing::router::get_route; @@ -898,6 +898,6 @@ mod tests { assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030200000000000000000000000000000000000000000000000000000000000000 with 1 adds, 0 fulfills, 0 fails for channel 3900000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&3)); // 7 assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030000000000000000000000000000000000000000000000000000000000000000 with 0 adds, 1 fulfills, 0 fails for channel 3d00000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&1)); // 8 assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030000000000000000000000000000000000000000000000000000000000000000 with 0 adds, 0 fulfills, 1 fails for channel 3d00000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&2)); // 9 - assert_eq!(log_entries.get(&("lightning::ln::channelmonitor".to_string(), "Input spending remote commitment tx (00000000000000000000000000000000000000000000000000000000000000a1:0) in 0000000000000000000000000000000000000000000000000000000000000018 resolves outbound HTLC with payment hash ff00000000000000000000000000000000000000000000000000000000000000 with timeout".to_string())), Some(&1)); // 10 + assert_eq!(log_entries.get(&("lightning::chain::channelmonitor".to_string(), "Input spending remote commitment tx (00000000000000000000000000000000000000000000000000000000000000a1:0) in 0000000000000000000000000000000000000000000000000000000000000018 resolves outbound HTLC with payment hash ff00000000000000000000000000000000000000000000000000000000000000 with timeout".to_string())), Some(&1)); // 10 } } diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index b5282db88..86ed5c114 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -27,7 +27,7 @@ //! type Logger = dyn lightning::util::logger::Logger; //! type ChainAccess = dyn lightning::chain::Access; //! type ChainNotify = dyn lightning::chain::Notify; -//! type ChainMonitor = lightning::ln::channelmonitor::ChainMonitor, Arc, Arc, Arc>; +//! type ChainMonitor = lightning::chain::channelmonitor::ChainMonitor, Arc, Arc, Arc>; //! type ChannelManager = lightning::ln::channelmanager::SimpleArcChannelManager; //! type PeerManager = lightning::ln::peer_handler::SimpleArcPeerManager; //! diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs similarity index 99% rename from lightning/src/ln/channelmonitor.rs rename to lightning/src/chain/channelmonitor.rs index 0f41945bd..f4b8e1979 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -54,7 +54,7 @@ use std::ops::Deref; #[derive(Clone)] #[must_use] pub struct ChannelMonitorUpdate { - pub(super) updates: Vec, + pub(crate) updates: Vec, /// The sequence number of this update. Updates *must* be replayed in-order according to this /// sequence number (and updates may panic if they are not). The update_id values are strictly /// increasing and increase by one for each new update. @@ -149,9 +149,9 @@ pub struct MonitorUpdateError(pub &'static str); /// [`chain::Watch`]: ../../chain/trait.Watch.html #[derive(Clone, PartialEq)] pub struct HTLCUpdate { - pub(super) payment_hash: PaymentHash, - pub(super) payment_preimage: Option, - pub(super) source: HTLCSource + pub(crate) payment_hash: PaymentHash, + pub(crate) payment_preimage: Option, + pub(crate) source: HTLCSource } impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source }); @@ -692,7 +692,7 @@ const MIN_SERIALIZATION_VERSION: u8 = 1; #[cfg_attr(test, derive(PartialEq))] #[derive(Clone)] -pub(super) enum ChannelMonitorUpdateStep { +pub(crate) enum ChannelMonitorUpdateStep { LatestLocalCommitmentTXInfo { commitment_tx: LocalCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option, Option)>, @@ -1145,7 +1145,7 @@ impl ChannelMonitor { } impl ChannelMonitor { - pub(super) fn new(keys: ChanSigner, shutdown_pubkey: &PublicKey, + pub(crate) fn new(keys: ChanSigner, shutdown_pubkey: &PublicKey, on_remote_tx_csv: u16, destination_script: &Script, funding_info: (OutPoint, Script), remote_htlc_base_key: &PublicKey, remote_delayed_payment_base_key: &PublicKey, on_local_tx_csv: u16, funding_redeemscript: Script, channel_value_satoshis: u64, @@ -1232,7 +1232,7 @@ impl ChannelMonitor { /// Inserts a revocation secret into this channel monitor. Prunes old preimages if neither /// needed by local commitment transactions HTCLs nor by remote ones. Unless we haven't already seen remote /// commitment transaction's secret, they are de facto pruned (we can use revocation key). - pub(super) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), MonitorUpdateError> { + fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), MonitorUpdateError> { if let Err(()) = self.commitment_secrets.provide_secret(idx, secret) { return Err(MonitorUpdateError("Previous secret did not match new one")); } @@ -1284,7 +1284,7 @@ impl ChannelMonitor { /// The monitor watches for it to be broadcasted and then uses the HTLC information (and /// possibly future revocation/preimage information) to claim outputs where possible. /// We cache also the mapping hash:commitment number to lighten pruning of old preimages by watchtowers. - pub(super) fn provide_latest_remote_commitment_tx_info(&mut self, unsigned_commitment_tx: &Transaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option>)>, commitment_number: u64, their_revocation_point: PublicKey, logger: &L) where L::Target: Logger { + pub(crate) fn provide_latest_remote_commitment_tx_info(&mut self, unsigned_commitment_tx: &Transaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option>)>, commitment_number: u64, their_revocation_point: PublicKey, logger: &L) where L::Target: Logger { // TODO: Encrypt the htlc_outputs data with the single-hash of the commitment transaction // so that a remote monitor doesn't learn anything unless there is a malicious close. // (only maybe, sadly we cant do the same for local info, as we need to be aware of @@ -1333,7 +1333,7 @@ impl ChannelMonitor { /// is important that any clones of this channel monitor (including remote clones) by kept /// up-to-date as our local commitment transaction is updated. /// Panics if set_on_local_tx_csv has never been called. - pub(super) fn provide_latest_local_commitment_tx_info(&mut self, commitment_tx: LocalCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option, Option)>) -> Result<(), MonitorUpdateError> { + fn provide_latest_local_commitment_tx_info(&mut self, commitment_tx: LocalCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option, Option)>) -> Result<(), MonitorUpdateError> { if self.local_tx_signed { return Err(MonitorUpdateError("A local commitment tx has already been signed, no new local commitment txn can be sent to our counterparty")); } @@ -1366,11 +1366,11 @@ impl ChannelMonitor { /// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all /// commitment_tx_infos which contain the payment hash have been revoked. - pub(super) fn provide_payment_preimage(&mut self, payment_hash: &PaymentHash, payment_preimage: &PaymentPreimage) { + pub(crate) fn provide_payment_preimage(&mut self, payment_hash: &PaymentHash, payment_preimage: &PaymentPreimage) { self.payment_preimages.insert(payment_hash.clone(), payment_preimage.clone()); } - pub(super) fn broadcast_latest_local_commitment_txn(&mut self, broadcaster: &B, logger: &L) + pub(crate) fn broadcast_latest_local_commitment_txn(&mut self, broadcaster: &B, logger: &L) where B::Target: BroadcasterInterface, L::Target: Logger, { @@ -1380,7 +1380,7 @@ impl ChannelMonitor { } /// Used in Channel to cheat wrt the update_ids since it plays games, will be removed soon! - pub(super) fn update_monitor_ooo(&mut self, mut updates: ChannelMonitorUpdate, logger: &L) -> Result<(), MonitorUpdateError> where L::Target: Logger { + pub(crate) fn update_monitor_ooo(&mut self, mut updates: ChannelMonitorUpdate, logger: &L) -> Result<(), MonitorUpdateError> where L::Target: Logger { for update in updates.updates.drain(..) { match update { ChannelMonitorUpdateStep::LatestLocalCommitmentTXInfo { commitment_tx, htlc_outputs } => { @@ -1491,19 +1491,19 @@ impl ChannelMonitor { } /// Can only fail if idx is < get_min_seen_secret - pub(super) fn get_secret(&self, idx: u64) -> Option<[u8; 32]> { + fn get_secret(&self, idx: u64) -> Option<[u8; 32]> { self.commitment_secrets.get_secret(idx) } - pub(super) fn get_min_seen_secret(&self) -> u64 { + pub(crate) fn get_min_seen_secret(&self) -> u64 { self.commitment_secrets.get_min_seen_secret() } - pub(super) fn get_cur_remote_commitment_number(&self) -> u64 { + pub(crate) fn get_cur_remote_commitment_number(&self) -> u64 { self.current_remote_commitment_number } - pub(super) fn get_cur_local_commitment_number(&self) -> u64 { + pub(crate) fn get_cur_local_commitment_number(&self) -> u64 { self.current_local_commitment_number } @@ -2032,7 +2032,7 @@ impl ChannelMonitor { self.last_block_hash = block_hash; } - pub(super) fn would_broadcast_at_height(&self, height: u32, logger: &L) -> bool where L::Target: Logger { + pub(crate) fn would_broadcast_at_height(&self, height: u32, logger: &L) -> bool where L::Target: Logger { // We need to consider all HTLCs which are: // * in any unrevoked remote commitment transaction, as they could broadcast said // transactions and we'd end up in a race, or @@ -2584,9 +2584,9 @@ mod tests { use bitcoin::hashes::hex::FromHex; use bitcoin::hash_types::Txid; use hex; + use chain::channelmonitor::ChannelMonitor; use chain::transaction::OutPoint; use ln::channelmanager::{PaymentPreimage, PaymentHash}; - use ln::channelmonitor::ChannelMonitor; use ln::onchaintx::{OnchainTxHandler, InputDescriptors}; use ln::chan_utils; use ln::chan_utils::{HTLCOutputInCommitment, LocalCommitmentTransaction}; diff --git a/lightning/src/chain/mod.rs b/lightning/src/chain/mod.rs index 85a9da084..6365aac2d 100644 --- a/lightning/src/chain/mod.rs +++ b/lightning/src/chain/mod.rs @@ -4,11 +4,12 @@ use bitcoin::blockdata::script::Script; use bitcoin::blockdata::transaction::TxOut; use bitcoin::hash_types::{BlockHash, Txid}; +use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, HTLCUpdate}; use chain::keysinterface::ChannelKeys; use chain::transaction::OutPoint; -use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, HTLCUpdate}; pub mod chaininterface; +pub mod channelmonitor; pub mod transaction; pub mod keysinterface; diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index ba175733a..d984cda27 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -71,7 +71,7 @@ pub fn build_commitment_secret(commitment_seed: &[u8; 32], idx: u64) -> [u8; 32] /// Allows us to keep track of all of the revocation secrets of counterarties in just 50*32 bytes /// or so. #[derive(Clone)] -pub(super) struct CounterpartyCommitmentSecrets { +pub(crate) struct CounterpartyCommitmentSecrets { old_secrets: [([u8; 32], u64); 49], } @@ -87,7 +87,7 @@ impl PartialEq for CounterpartyCommitmentSecrets { } impl CounterpartyCommitmentSecrets { - pub(super) fn new() -> Self { + pub(crate) fn new() -> Self { Self { old_secrets: [([0; 32], 1 << 48); 49], } } @@ -101,7 +101,7 @@ impl CounterpartyCommitmentSecrets { 48 } - pub(super) fn get_min_seen_secret(&self) -> u64 { + pub(crate) fn get_min_seen_secret(&self) -> u64 { //TODO This can be optimized? let mut min = 1 << 48; for &(_, idx) in self.old_secrets.iter() { @@ -113,7 +113,7 @@ impl CounterpartyCommitmentSecrets { } #[inline] - pub(super) fn derive_secret(secret: [u8; 32], bits: u8, idx: u64) -> [u8; 32] { + fn derive_secret(secret: [u8; 32], bits: u8, idx: u64) -> [u8; 32] { let mut res: [u8; 32] = secret; for i in 0..bits { let bitpos = bits - 1 - i; @@ -125,7 +125,7 @@ impl CounterpartyCommitmentSecrets { res } - pub(super) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), ()> { + pub(crate) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), ()> { let pos = Self::place_secret(idx); for i in 0..pos { let (old_secret, old_idx) = self.old_secrets[i as usize]; @@ -141,7 +141,7 @@ impl CounterpartyCommitmentSecrets { } /// Can only fail if idx is < get_min_seen_secret - pub(super) fn get_secret(&self, idx: u64) -> Option<[u8; 32]> { + pub(crate) fn get_secret(&self, idx: u64) -> Option<[u8; 32]> { for i in 0..self.old_secrets.len() { if (idx & (!((1 << i) - 1))) == self.old_secrets[i].1 { return Some(Self::derive_secret(self.old_secrets[i].0, i as u8, idx)) diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 1a53fc639..d22fca8d4 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -3,9 +3,9 @@ //! There are a bunch of these as their handling is relatively error-prone so they are split out //! here. See also the chanmon_fail_consistency fuzz test. +use chain::channelmonitor::ChannelMonitorUpdateErr; use chain::transaction::OutPoint; use ln::channelmanager::{RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure}; -use ln::channelmonitor::ChannelMonitorUpdateErr; use ln::features::InitFeatures; use ln::msgs; use ln::msgs::{ChannelMessageHandler, ErrorAction, RoutingMessageHandler}; diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index d717182b6..859e07435 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -17,11 +17,11 @@ use bitcoin::secp256k1; use ln::features::{ChannelFeatures, InitFeatures}; use ln::msgs; use ln::msgs::{DecodeError, OptionalField, DataLossProtect}; -use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, HTLC_FAIL_BACK_BUFFER}; use ln::channelmanager::{PendingHTLCStatus, HTLCSource, HTLCFailReason, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentPreimage, PaymentHash, BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT}; use ln::chan_utils::{CounterpartyCommitmentSecrets, LocalCommitmentTransaction, TxCreationKeys, HTLCOutputInCommitment, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT, make_funding_redeemscript, ChannelPublicKeys}; use ln::chan_utils; use chain::chaininterface::{FeeEstimator,ConfirmationTarget}; +use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, HTLC_FAIL_BACK_BUFFER}; use chain::transaction::OutPoint; use chain::keysinterface::{ChannelKeys, KeysInterface}; use util::transaction_utils; diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index c853150f6..166a09d57 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -29,9 +29,9 @@ use bitcoin::secp256k1; use chain; use chain::Watch; use chain::chaininterface::{BroadcasterInterface, FeeEstimator}; +use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, HTLC_FAIL_BACK_BUFFER, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY}; use chain::transaction::OutPoint; use ln::channel::{Channel, ChannelError}; -use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, HTLC_FAIL_BACK_BUFFER, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY}; use ln::features::{InitFeatures, NodeFeatures}; use routing::router::{Route, RouteHop}; use ln::msgs; @@ -120,7 +120,7 @@ pub(super) enum HTLCForwardInfo { /// Tracks the inbound corresponding to an outbound HTLC #[derive(Clone, PartialEq)] -pub(super) struct HTLCPreviousHopData { +pub(crate) struct HTLCPreviousHopData { short_channel_id: u64, htlc_id: u64, incoming_packet_shared_secret: [u8; 32], @@ -139,7 +139,7 @@ struct ClaimableHTLC { /// Tracks the inbound corresponding to an outbound HTLC #[derive(Clone, PartialEq)] -pub(super) enum HTLCSource { +pub(crate) enum HTLCSource { PreviousHopData(HTLCPreviousHopData), OutboundRoute { path: Vec, diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index d0ee5f672..66bae1d41 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -2,9 +2,9 @@ //! nodes for functional tests. use chain::Watch; +use chain::channelmonitor::ChannelMonitor; use chain::transaction::OutPoint; use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure}; -use ln::channelmonitor::ChannelMonitor; use routing::router::{Route, get_route}; use routing::network_graph::{NetGraphMsgHandler, NetworkGraph}; use ln::features::InitFeatures; diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 098f63941..b817e7e38 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -3,12 +3,12 @@ //! claim outputs on-chain. use chain::Watch; +use chain::channelmonitor; +use chain::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY}; use chain::transaction::OutPoint; use chain::keysinterface::{ChannelKeys, KeysInterface, SpendableOutputDescriptor}; use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC}; use ln::channelmanager::{ChannelManager,ChannelManagerReadArgs,HTLCForwardInfo,RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure, BREAKDOWN_TIMEOUT}; -use ln::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY}; -use ln::channelmonitor; use ln::channel::{Channel, ChannelError}; use ln::{chan_utils, onion_utils}; use routing::router::{Route, RouteHop, get_route}; diff --git a/lightning/src/ln/mod.rs b/lightning/src/ln/mod.rs index ecf40d75e..2f1f5096f 100644 --- a/lightning/src/ln/mod.rs +++ b/lightning/src/ln/mod.rs @@ -10,7 +10,6 @@ //! call into your NetGraphMsgHandler. pub mod channelmanager; -pub mod channelmonitor; pub mod msgs; pub mod peer_handler; pub mod chan_utils; diff --git a/lightning/src/ln/onchaintx.rs b/lightning/src/ln/onchaintx.rs index 4b1a08f1d..fe426cb17 100644 --- a/lightning/src/ln/onchaintx.rs +++ b/lightning/src/ln/onchaintx.rs @@ -13,11 +13,11 @@ use bitcoin::secp256k1::{Secp256k1, Signature}; use bitcoin::secp256k1; use ln::msgs::DecodeError; -use ln::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER, InputMaterial, ClaimRequest}; use ln::channelmanager::PaymentPreimage; use ln::chan_utils; use ln::chan_utils::{TxCreationKeys, LocalCommitmentTransaction}; use chain::chaininterface::{FeeEstimator, BroadcasterInterface, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT}; +use chain::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER, InputMaterial, ClaimRequest}; use chain::keysinterface::ChannelKeys; use util::logger::Logger; use util::ser::{Readable, Writer, Writeable}; @@ -396,7 +396,7 @@ impl Readable for OnchainTxHandler OnchainTxHandler { - pub(super) fn new(destination_script: Script, keys: ChanSigner, on_local_tx_csv: u16) -> Self { + pub(crate) fn new(destination_script: Script, keys: ChanSigner, on_local_tx_csv: u16) -> Self { let key_storage = keys; @@ -416,7 +416,7 @@ impl OnchainTxHandler { } } - pub(super) fn get_witnesses_weight(inputs: &[InputDescriptors]) -> usize { + pub(crate) fn get_witnesses_weight(inputs: &[InputDescriptors]) -> usize { let mut tx_weight = 2; // count segwit flags for inp in inputs { // We use expected weight (and not actual) as signatures and time lock delays may vary @@ -648,7 +648,7 @@ impl OnchainTxHandler { None } - pub(super) fn block_connected(&mut self, txn_matched: &[(usize, &Transaction)], claimable_outpoints: Vec, height: u32, broadcaster: B, fee_estimator: F, logger: L) + pub(crate) fn block_connected(&mut self, txn_matched: &[(usize, &Transaction)], claimable_outpoints: Vec, height: u32, broadcaster: B, fee_estimator: F, logger: L) where B::Target: BroadcasterInterface, F::Target: FeeEstimator, L::Target: Logger, @@ -820,7 +820,7 @@ impl OnchainTxHandler { } } - pub(super) fn block_disconnected(&mut self, height: u32, broadcaster: B, fee_estimator: F, logger: L) + pub(crate) fn block_disconnected(&mut self, height: u32, broadcaster: B, fee_estimator: F, logger: L) where B::Target: BroadcasterInterface, F::Target: FeeEstimator, L::Target: Logger, @@ -868,7 +868,7 @@ impl OnchainTxHandler { } } - pub(super) fn provide_latest_local_tx(&mut self, tx: LocalCommitmentTransaction) -> Result<(), ()> { + pub(crate) fn provide_latest_local_tx(&mut self, tx: LocalCommitmentTransaction) -> Result<(), ()> { // To prevent any unsafe state discrepancy between offchain and onchain, once local // commitment transaction has been signed due to an event (either block height for // HTLC-timeout or channel force-closure), don't allow any further update of local @@ -919,7 +919,7 @@ impl OnchainTxHandler { // have empty local commitment transaction if a ChannelMonitor is asked to force-close just after Channel::get_outbound_funding_created, // before providing a initial commitment transaction. For outbound channel, init ChannelMonitor at Channel::funding_signed, there is nothing // to monitor before. - pub(super) fn get_fully_signed_local_tx(&mut self, funding_redeemscript: &Script) -> Option { + pub(crate) fn get_fully_signed_local_tx(&mut self, funding_redeemscript: &Script) -> Option { if let Some(ref mut local_commitment) = self.local_commitment { match self.key_storage.sign_local_commitment(local_commitment, &self.secp_ctx) { Ok(sig) => Some(local_commitment.add_local_sig(funding_redeemscript, sig)), @@ -931,7 +931,7 @@ impl OnchainTxHandler { } #[cfg(test)] - pub(super) fn get_fully_signed_copy_local_tx(&mut self, funding_redeemscript: &Script) -> Option { + pub(crate) fn get_fully_signed_copy_local_tx(&mut self, funding_redeemscript: &Script) -> Option { if let Some(ref mut local_commitment) = self.local_commitment { let local_commitment = local_commitment.clone(); match self.key_storage.sign_local_commitment(&local_commitment, &self.secp_ctx) { @@ -943,7 +943,7 @@ impl OnchainTxHandler { } } - pub(super) fn get_fully_signed_htlc_tx(&mut self, outp: &::bitcoin::OutPoint, preimage: &Option) -> Option { + pub(crate) fn get_fully_signed_htlc_tx(&mut self, outp: &::bitcoin::OutPoint, preimage: &Option) -> Option { let mut htlc_tx = None; if self.local_commitment.is_some() { let commitment_txid = self.local_commitment.as_ref().unwrap().txid(); @@ -971,7 +971,7 @@ impl OnchainTxHandler { } #[cfg(test)] - pub(super) fn unsafe_get_fully_signed_htlc_tx(&mut self, outp: &::bitcoin::OutPoint, preimage: &Option) -> Option { + pub(crate) fn unsafe_get_fully_signed_htlc_tx(&mut self, outp: &::bitcoin::OutPoint, preimage: &Option) -> Option { let latest_had_sigs = self.local_htlc_sigs.is_some(); let prev_had_sigs = self.prev_local_htlc_sigs.is_some(); let ret = self.get_fully_signed_htlc_tx(outp, preimage); diff --git a/lightning/src/ln/reorg_tests.rs b/lightning/src/ln/reorg_tests.rs index 067828ecf..d4371a2b9 100644 --- a/lightning/src/ln/reorg_tests.rs +++ b/lightning/src/ln/reorg_tests.rs @@ -1,6 +1,6 @@ //! Further functional tests which test blockchain reorganizations. -use ln::channelmonitor::ANTI_REORG_DELAY; +use chain::channelmonitor::ANTI_REORG_DELAY; use ln::features::InitFeatures; use ln::msgs::{ChannelMessageHandler, ErrorAction, HTLCFailChannelUpdate}; use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsProvider}; diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 3473d9dda..fb0d532e1 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -1,13 +1,13 @@ use chain; use chain::chaininterface; use chain::chaininterface::ConfirmationTarget; +use chain::channelmonitor; +use chain::channelmonitor::HTLCUpdate; use chain::transaction::OutPoint; use chain::keysinterface; -use ln::channelmonitor; use ln::features::{ChannelFeatures, InitFeatures}; use ln::msgs; use ln::msgs::OptionalField; -use ln::channelmonitor::HTLCUpdate; use util::enforcing_trait_impls::EnforcingChannelKeys; use util::events; use util::logger::{Logger, Level, Record}; -- 2.39.5