mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 15:02:20 +01:00
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.
This commit is contained in:
parent
e09767ba2d
commit
819a8653af
17 changed files with 69 additions and 69 deletions
|
@ -29,11 +29,11 @@ use bitcoin::hashes::sha256::Hash as Sha256;
|
||||||
use bitcoin::hash_types::{BlockHash, WPubkeyHash};
|
use bitcoin::hash_types::{BlockHash, WPubkeyHash};
|
||||||
|
|
||||||
use lightning::chain;
|
use lightning::chain;
|
||||||
|
use lightning::chain::channelmonitor;
|
||||||
|
use lightning::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, MonitorEvent};
|
||||||
use lightning::chain::transaction::OutPoint;
|
use lightning::chain::transaction::OutPoint;
|
||||||
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
|
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
|
||||||
use lightning::chain::keysinterface::{KeysInterface, InMemoryChannelKeys};
|
use lightning::chain::keysinterface::{KeysInterface, InMemoryChannelKeys};
|
||||||
use lightning::ln::channelmonitor;
|
|
||||||
use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, MonitorEvent};
|
|
||||||
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret, ChannelManagerReadArgs};
|
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret, ChannelManagerReadArgs};
|
||||||
use lightning::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
|
use lightning::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
|
||||||
use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, UpdateAddHTLC, Init};
|
use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, UpdateAddHTLC, Init};
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
use bitcoin::hash_types::BlockHash;
|
use bitcoin::hash_types::BlockHash;
|
||||||
|
|
||||||
|
use lightning::chain::channelmonitor;
|
||||||
use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
|
use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
|
||||||
use lightning::ln::channelmonitor;
|
|
||||||
use lightning::util::ser::{Readable, Writer};
|
use lightning::util::ser::{Readable, Writer};
|
||||||
|
|
||||||
use utils::test_logger;
|
use utils::test_logger;
|
||||||
|
|
|
@ -27,9 +27,9 @@ use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
|
||||||
|
|
||||||
use lightning::chain;
|
use lightning::chain;
|
||||||
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
|
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
|
||||||
|
use lightning::chain::channelmonitor;
|
||||||
use lightning::chain::transaction::OutPoint;
|
use lightning::chain::transaction::OutPoint;
|
||||||
use lightning::chain::keysinterface::{InMemoryChannelKeys, KeysInterface};
|
use lightning::chain::keysinterface::{InMemoryChannelKeys, KeysInterface};
|
||||||
use lightning::ln::channelmonitor;
|
|
||||||
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret};
|
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret};
|
||||||
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
|
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
|
||||||
use lightning::routing::router::get_route;
|
use lightning::routing::router::get_route;
|
||||||
|
@ -900,6 +900,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 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, 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::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 counterparty 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 counterparty commitment tx (00000000000000000000000000000000000000000000000000000000000000a1:0) in 0000000000000000000000000000000000000000000000000000000000000018 resolves outbound HTLC with payment hash ff00000000000000000000000000000000000000000000000000000000000000 with timeout".to_string())), Some(&1)); // 10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
//! type Logger = dyn lightning::util::logger::Logger;
|
//! type Logger = dyn lightning::util::logger::Logger;
|
||||||
//! type ChainAccess = dyn lightning::chain::Access;
|
//! type ChainAccess = dyn lightning::chain::Access;
|
||||||
//! type ChainFilter = dyn lightning::chain::Filter;
|
//! type ChainFilter = dyn lightning::chain::Filter;
|
||||||
//! type ChainMonitor = lightning::ln::channelmonitor::ChainMonitor<lightning::chain::keysinterface::InMemoryChannelKeys, Arc<ChainFilter>, Arc<TxBroadcaster>, Arc<FeeEstimator>, Arc<Logger>>;
|
//! type ChainMonitor = lightning::chain::channelmonitor::ChainMonitor<lightning::chain::keysinterface::InMemoryChannelKeys, Arc<ChainFilter>, Arc<TxBroadcaster>, Arc<FeeEstimator>, Arc<Logger>>;
|
||||||
//! type ChannelManager = lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor, TxBroadcaster, FeeEstimator, Logger>;
|
//! type ChannelManager = lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor, TxBroadcaster, FeeEstimator, Logger>;
|
||||||
//! type PeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChainMonitor, TxBroadcaster, FeeEstimator, ChainAccess, Logger>;
|
//! type PeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChainMonitor, TxBroadcaster, FeeEstimator, ChainAccess, Logger>;
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
//! security-domain-separated system design, you should consider having multiple paths for
|
//! security-domain-separated system design, you should consider having multiple paths for
|
||||||
//! ChannelMonitors to get out of the HSM and onto monitoring devices.
|
//! ChannelMonitors to get out of the HSM and onto monitoring devices.
|
||||||
//!
|
//!
|
||||||
//! [`chain::Watch`]: ../../chain/trait.Watch.html
|
//! [`chain::Watch`]: ../trait.Watch.html
|
||||||
|
|
||||||
use bitcoin::blockdata::block::BlockHeader;
|
use bitcoin::blockdata::block::BlockHeader;
|
||||||
use bitcoin::blockdata::transaction::{TxOut,Transaction};
|
use bitcoin::blockdata::transaction::{TxOut,Transaction};
|
||||||
|
@ -64,7 +64,7 @@ use std::io::Error;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct ChannelMonitorUpdate {
|
pub struct ChannelMonitorUpdate {
|
||||||
pub(super) updates: Vec<ChannelMonitorUpdateStep>,
|
pub(crate) updates: Vec<ChannelMonitorUpdateStep>,
|
||||||
/// The sequence number of this update. Updates *must* be replayed in-order according to this
|
/// 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
|
/// 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.
|
/// increasing and increase by one for each new update.
|
||||||
|
@ -180,12 +180,12 @@ pub enum MonitorEvent {
|
||||||
/// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
|
/// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
|
||||||
/// preimage claim backward will lead to loss of funds.
|
/// preimage claim backward will lead to loss of funds.
|
||||||
///
|
///
|
||||||
/// [`chain::Watch`]: ../../chain/trait.Watch.html
|
/// [`chain::Watch`]: ../trait.Watch.html
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct HTLCUpdate {
|
pub struct HTLCUpdate {
|
||||||
pub(super) payment_hash: PaymentHash,
|
pub(crate) payment_hash: PaymentHash,
|
||||||
pub(super) payment_preimage: Option<PaymentPreimage>,
|
pub(crate) payment_preimage: Option<PaymentPreimage>,
|
||||||
pub(super) source: HTLCSource
|
pub(crate) source: HTLCSource
|
||||||
}
|
}
|
||||||
impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
|
impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
|
||||||
|
|
||||||
|
@ -195,8 +195,8 @@ impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
|
||||||
/// [`chain::Watch`]. May be used in conjunction with [`ChannelManager`] to monitor channels locally
|
/// [`chain::Watch`]. May be used in conjunction with [`ChannelManager`] to monitor channels locally
|
||||||
/// or used independently to monitor channels remotely.
|
/// or used independently to monitor channels remotely.
|
||||||
///
|
///
|
||||||
/// [`chain::Watch`]: ../../chain/trait.Watch.html
|
/// [`chain::Watch`]: ../trait.Watch.html
|
||||||
/// [`ChannelManager`]: ../channelmanager/struct.ChannelManager.html
|
/// [`ChannelManager`]: ../../ln/channelmanager/struct.ChannelManager.html
|
||||||
pub struct ChainMonitor<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref>
|
pub struct ChainMonitor<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref>
|
||||||
where C::Target: chain::Filter,
|
where C::Target: chain::Filter,
|
||||||
T::Target: BroadcasterInterface,
|
T::Target: BroadcasterInterface,
|
||||||
|
@ -228,8 +228,8 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref> ChainMonit
|
||||||
/// to obtain updated `txdata`.
|
/// to obtain updated `txdata`.
|
||||||
///
|
///
|
||||||
/// [`ChannelMonitor::block_connected`]: struct.ChannelMonitor.html#method.block_connected
|
/// [`ChannelMonitor::block_connected`]: struct.ChannelMonitor.html#method.block_connected
|
||||||
/// [`chain::Watch::release_pending_monitor_events`]: ../../chain/trait.Watch.html#tymethod.release_pending_monitor_events
|
/// [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events
|
||||||
/// [`chain::Filter`]: ../../chain/trait.Filter.html
|
/// [`chain::Filter`]: ../trait.Filter.html
|
||||||
pub fn block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) -> bool {
|
pub fn block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) -> bool {
|
||||||
let mut has_new_outputs_to_watch = false;
|
let mut has_new_outputs_to_watch = false;
|
||||||
{
|
{
|
||||||
|
@ -270,7 +270,7 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref> ChainMonit
|
||||||
/// always need to fetch full blocks absent another means for determining which blocks contain
|
/// always need to fetch full blocks absent another means for determining which blocks contain
|
||||||
/// transactions relevant to the watched channels.
|
/// transactions relevant to the watched channels.
|
||||||
///
|
///
|
||||||
/// [`chain::Filter`]: ../../chain/trait.Filter.html
|
/// [`chain::Filter`]: ../trait.Filter.html
|
||||||
pub fn new(chain_source: Option<C>, broadcaster: T, logger: L, feeest: F) -> Self {
|
pub fn new(chain_source: Option<C>, broadcaster: T, logger: L, feeest: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
monitors: Mutex::new(HashMap::new()),
|
monitors: Mutex::new(HashMap::new()),
|
||||||
|
@ -285,7 +285,7 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref> ChainMonit
|
||||||
///
|
///
|
||||||
/// Calls back to [`chain::Filter`] with the funding transaction and outputs to watch.
|
/// Calls back to [`chain::Filter`] with the funding transaction and outputs to watch.
|
||||||
///
|
///
|
||||||
/// [`chain::Filter`]: ../../chain/trait.Filter.html
|
/// [`chain::Filter`]: ../trait.Filter.html
|
||||||
fn add_monitor(&self, outpoint: OutPoint, monitor: ChannelMonitor<ChanSigner>) -> Result<(), MonitorUpdateError> {
|
fn add_monitor(&self, outpoint: OutPoint, monitor: ChannelMonitor<ChanSigner>) -> Result<(), MonitorUpdateError> {
|
||||||
let mut monitors = self.monitors.lock().unwrap();
|
let mut monitors = self.monitors.lock().unwrap();
|
||||||
let entry = match monitors.entry(outpoint) {
|
let entry = match monitors.entry(outpoint) {
|
||||||
|
@ -654,7 +654,7 @@ const MIN_SERIALIZATION_VERSION: u8 = 1;
|
||||||
|
|
||||||
#[cfg_attr(test, derive(PartialEq))]
|
#[cfg_attr(test, derive(PartialEq))]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(super) enum ChannelMonitorUpdateStep {
|
pub(crate) enum ChannelMonitorUpdateStep {
|
||||||
LatestHolderCommitmentTXInfo {
|
LatestHolderCommitmentTXInfo {
|
||||||
commitment_tx: HolderCommitmentTransaction,
|
commitment_tx: HolderCommitmentTransaction,
|
||||||
htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>,
|
htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>,
|
||||||
|
@ -1117,7 +1117,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
||||||
pub(super) fn new(keys: ChanSigner, shutdown_pubkey: &PublicKey,
|
pub(crate) fn new(keys: ChanSigner, shutdown_pubkey: &PublicKey,
|
||||||
on_counterparty_tx_csv: u16, destination_script: &Script, funding_info: (OutPoint, Script),
|
on_counterparty_tx_csv: u16, destination_script: &Script, funding_info: (OutPoint, Script),
|
||||||
counterparty_htlc_base_key: &PublicKey, counterparty_delayed_payment_base_key: &PublicKey,
|
counterparty_htlc_base_key: &PublicKey, counterparty_delayed_payment_base_key: &PublicKey,
|
||||||
on_holder_tx_csv: u16, funding_redeemscript: Script, channel_value_satoshis: u64,
|
on_holder_tx_csv: u16, funding_redeemscript: Script, channel_value_satoshis: u64,
|
||||||
|
@ -1202,7 +1202,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
||||||
/// Inserts a revocation secret into this channel monitor. Prunes old preimages if neither
|
/// Inserts a revocation secret into this channel monitor. Prunes old preimages if neither
|
||||||
/// needed by holder commitment transactions HTCLs nor by counterparty ones. Unless we haven't already seen
|
/// needed by holder commitment transactions HTCLs nor by counterparty ones. Unless we haven't already seen
|
||||||
/// counterparty commitment transaction's secret, they are de facto pruned (we can use revocation key).
|
/// counterparty 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) {
|
if let Err(()) = self.commitment_secrets.provide_secret(idx, secret) {
|
||||||
return Err(MonitorUpdateError("Previous secret did not match new one"));
|
return Err(MonitorUpdateError("Previous secret did not match new one"));
|
||||||
}
|
}
|
||||||
|
@ -1254,7 +1254,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
||||||
/// The monitor watches for it to be broadcasted and then uses the HTLC information (and
|
/// 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.
|
/// 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.
|
/// We cache also the mapping hash:commitment number to lighten pruning of old preimages by watchtowers.
|
||||||
pub(super) fn provide_latest_counterparty_commitment_tx_info<L: Deref>(&mut self, unsigned_commitment_tx: &Transaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)>, commitment_number: u64, their_revocation_point: PublicKey, logger: &L) where L::Target: Logger {
|
pub(crate) fn provide_latest_counterparty_commitment_tx_info<L: Deref>(&mut self, unsigned_commitment_tx: &Transaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)>, 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
|
// 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.
|
// 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
|
// (only maybe, sadly we cant do the same for local info, as we need to be aware of
|
||||||
|
@ -1303,7 +1303,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
||||||
/// is important that any clones of this channel monitor (including remote clones) by kept
|
/// is important that any clones of this channel monitor (including remote clones) by kept
|
||||||
/// up-to-date as our holder commitment transaction is updated.
|
/// up-to-date as our holder commitment transaction is updated.
|
||||||
/// Panics if set_on_holder_tx_csv has never been called.
|
/// Panics if set_on_holder_tx_csv has never been called.
|
||||||
pub(super) fn provide_latest_holder_commitment_tx_info(&mut self, commitment_tx: HolderCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
|
fn provide_latest_holder_commitment_tx_info(&mut self, commitment_tx: HolderCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
|
||||||
let txid = commitment_tx.txid();
|
let txid = commitment_tx.txid();
|
||||||
let sequence = commitment_tx.unsigned_tx.input[0].sequence as u64;
|
let sequence = commitment_tx.unsigned_tx.input[0].sequence as u64;
|
||||||
let locktime = commitment_tx.unsigned_tx.lock_time as u64;
|
let locktime = commitment_tx.unsigned_tx.lock_time as u64;
|
||||||
|
@ -1329,11 +1329,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
||||||
|
|
||||||
/// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
|
/// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
|
||||||
/// commitment_tx_infos which contain the payment hash have been revoked.
|
/// 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());
|
self.payment_preimages.insert(payment_hash.clone(), payment_preimage.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn broadcast_latest_holder_commitment_txn<B: Deref, L: Deref>(&mut self, broadcaster: &B, logger: &L)
|
pub(crate) fn broadcast_latest_holder_commitment_txn<B: Deref, L: Deref>(&mut self, broadcaster: &B, logger: &L)
|
||||||
where B::Target: BroadcasterInterface,
|
where B::Target: BroadcasterInterface,
|
||||||
L::Target: Logger,
|
L::Target: Logger,
|
||||||
{
|
{
|
||||||
|
@ -1418,7 +1418,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
||||||
/// Get the list of HTLCs who's status has been updated on chain. This should be called by
|
/// Get the list of HTLCs who's status has been updated on chain. This should be called by
|
||||||
/// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
|
/// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
|
||||||
///
|
///
|
||||||
/// [`chain::Watch::release_pending_monitor_events`]: ../../chain/trait.Watch.html#tymethod.release_pending_monitor_events
|
/// [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events
|
||||||
pub fn get_and_clear_pending_monitor_events(&mut self) -> Vec<MonitorEvent> {
|
pub fn get_and_clear_pending_monitor_events(&mut self) -> Vec<MonitorEvent> {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
mem::swap(&mut ret, &mut self.pending_monitor_events);
|
mem::swap(&mut ret, &mut self.pending_monitor_events);
|
||||||
|
@ -1438,19 +1438,19 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Can only fail if idx is < get_min_seen_secret
|
/// 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)
|
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()
|
self.commitment_secrets.get_min_seen_secret()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn get_cur_counterparty_commitment_number(&self) -> u64 {
|
pub(crate) fn get_cur_counterparty_commitment_number(&self) -> u64 {
|
||||||
self.current_counterparty_commitment_number
|
self.current_counterparty_commitment_number
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn get_cur_holder_commitment_number(&self) -> u64 {
|
pub(crate) fn get_cur_holder_commitment_number(&self) -> u64 {
|
||||||
self.current_holder_commitment_number
|
self.current_holder_commitment_number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2595,9 +2595,9 @@ mod tests {
|
||||||
use bitcoin::hashes::hex::FromHex;
|
use bitcoin::hashes::hex::FromHex;
|
||||||
use bitcoin::hash_types::Txid;
|
use bitcoin::hash_types::Txid;
|
||||||
use hex;
|
use hex;
|
||||||
|
use chain::channelmonitor::ChannelMonitor;
|
||||||
use chain::transaction::OutPoint;
|
use chain::transaction::OutPoint;
|
||||||
use ln::channelmanager::{PaymentPreimage, PaymentHash};
|
use ln::channelmanager::{PaymentPreimage, PaymentHash};
|
||||||
use ln::channelmonitor::ChannelMonitor;
|
|
||||||
use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
|
use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
|
||||||
use ln::chan_utils;
|
use ln::chan_utils;
|
||||||
use ln::chan_utils::{HTLCOutputInCommitment, HolderCommitmentTransaction};
|
use ln::chan_utils::{HTLCOutputInCommitment, HolderCommitmentTransaction};
|
|
@ -13,11 +13,12 @@ use bitcoin::blockdata::script::Script;
|
||||||
use bitcoin::blockdata::transaction::TxOut;
|
use bitcoin::blockdata::transaction::TxOut;
|
||||||
use bitcoin::hash_types::{BlockHash, Txid};
|
use bitcoin::hash_types::{BlockHash, Txid};
|
||||||
|
|
||||||
|
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, MonitorEvent};
|
||||||
use chain::keysinterface::ChannelKeys;
|
use chain::keysinterface::ChannelKeys;
|
||||||
use chain::transaction::OutPoint;
|
use chain::transaction::OutPoint;
|
||||||
use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, MonitorEvent};
|
|
||||||
|
|
||||||
pub mod chaininterface;
|
pub mod chaininterface;
|
||||||
|
pub mod channelmonitor;
|
||||||
pub mod transaction;
|
pub mod transaction;
|
||||||
pub mod keysinterface;
|
pub mod keysinterface;
|
||||||
|
|
||||||
|
@ -62,9 +63,9 @@ pub enum AccessError {
|
||||||
/// funds in the channel. See [`ChannelMonitorUpdateErr`] for more details about how to handle
|
/// funds in the channel. See [`ChannelMonitorUpdateErr`] for more details about how to handle
|
||||||
/// multiple instances.
|
/// multiple instances.
|
||||||
///
|
///
|
||||||
/// [`ChannelMonitor`]: ../ln/channelmonitor/struct.ChannelMonitor.html
|
/// [`ChannelMonitor`]: channelmonitor/struct.ChannelMonitor.html
|
||||||
/// [`ChannelMonitorUpdateErr`]: ../ln/channelmonitor/enum.ChannelMonitorUpdateErr.html
|
/// [`ChannelMonitorUpdateErr`]: channelmonitor/enum.ChannelMonitorUpdateErr.html
|
||||||
/// [`PermanentFailure`]: ../ln/channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.PermanentFailure
|
/// [`PermanentFailure`]: channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.PermanentFailure
|
||||||
pub trait Watch: Send + Sync {
|
pub trait Watch: Send + Sync {
|
||||||
/// Keys needed by monitors for creating and signing transactions.
|
/// Keys needed by monitors for creating and signing transactions.
|
||||||
type Keys: ChannelKeys;
|
type Keys: ChannelKeys;
|
||||||
|
@ -75,9 +76,9 @@ pub trait Watch: Send + Sync {
|
||||||
/// with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
|
/// with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
|
||||||
/// calling [`block_connected`] and [`block_disconnected`] on the monitor.
|
/// calling [`block_connected`] and [`block_disconnected`] on the monitor.
|
||||||
///
|
///
|
||||||
/// [`get_outputs_to_watch`]: ../ln/channelmonitor/struct.ChannelMonitor.html#method.get_outputs_to_watch
|
/// [`get_outputs_to_watch`]: channelmonitor/struct.ChannelMonitor.html#method.get_outputs_to_watch
|
||||||
/// [`block_connected`]: ../ln/channelmonitor/struct.ChannelMonitor.html#method.block_connected
|
/// [`block_connected`]: channelmonitor/struct.ChannelMonitor.html#method.block_connected
|
||||||
/// [`block_disconnected`]: ../ln/channelmonitor/struct.ChannelMonitor.html#method.block_disconnected
|
/// [`block_disconnected`]: channelmonitor/struct.ChannelMonitor.html#method.block_disconnected
|
||||||
fn watch_channel(&self, funding_txo: OutPoint, monitor: ChannelMonitor<Self::Keys>) -> Result<(), ChannelMonitorUpdateErr>;
|
fn watch_channel(&self, funding_txo: OutPoint, monitor: ChannelMonitor<Self::Keys>) -> Result<(), ChannelMonitorUpdateErr>;
|
||||||
|
|
||||||
/// Updates a channel identified by `funding_txo` by applying `update` to its monitor.
|
/// Updates a channel identified by `funding_txo` by applying `update` to its monitor.
|
||||||
|
@ -85,8 +86,8 @@ pub trait Watch: Send + Sync {
|
||||||
/// Implementations must call [`update_monitor`] with the given update. See
|
/// Implementations must call [`update_monitor`] with the given update. See
|
||||||
/// [`ChannelMonitorUpdateErr`] for invariants around returning an error.
|
/// [`ChannelMonitorUpdateErr`] for invariants around returning an error.
|
||||||
///
|
///
|
||||||
/// [`update_monitor`]: ../ln/channelmonitor/struct.ChannelMonitor.html#method.update_monitor
|
/// [`update_monitor`]: channelmonitor/struct.ChannelMonitor.html#method.update_monitor
|
||||||
/// [`ChannelMonitorUpdateErr`]: ../ln/channelmonitor/enum.ChannelMonitorUpdateErr.html
|
/// [`ChannelMonitorUpdateErr`]: channelmonitor/enum.ChannelMonitorUpdateErr.html
|
||||||
fn update_channel(&self, funding_txo: OutPoint, update: ChannelMonitorUpdate) -> Result<(), ChannelMonitorUpdateErr>;
|
fn update_channel(&self, funding_txo: OutPoint, update: ChannelMonitorUpdate) -> Result<(), ChannelMonitorUpdateErr>;
|
||||||
|
|
||||||
/// Returns any monitor events since the last call. Subsequent calls must only return new
|
/// Returns any monitor events since the last call. Subsequent calls must only return new
|
||||||
|
@ -112,7 +113,7 @@ pub trait Watch: Send + Sync {
|
||||||
/// invocation that has called the `Filter` must return [`TemporaryFailure`].
|
/// invocation that has called the `Filter` must return [`TemporaryFailure`].
|
||||||
///
|
///
|
||||||
/// [`Watch`]: trait.Watch.html
|
/// [`Watch`]: trait.Watch.html
|
||||||
/// [`TemporaryFailure`]: ../ln/channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.TemporaryFailure
|
/// [`TemporaryFailure`]: channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.TemporaryFailure
|
||||||
/// [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki
|
/// [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki
|
||||||
/// [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
|
/// [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
|
||||||
pub trait Filter: Send + Sync {
|
pub trait Filter: Send + Sync {
|
||||||
|
|
|
@ -81,7 +81,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
|
/// Allows us to keep track of all of the revocation secrets of counterarties in just 50*32 bytes
|
||||||
/// or so.
|
/// or so.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(super) struct CounterpartyCommitmentSecrets {
|
pub(crate) struct CounterpartyCommitmentSecrets {
|
||||||
old_secrets: [([u8; 32], u64); 49],
|
old_secrets: [([u8; 32], u64); 49],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ impl PartialEq for CounterpartyCommitmentSecrets {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CounterpartyCommitmentSecrets {
|
impl CounterpartyCommitmentSecrets {
|
||||||
pub(super) fn new() -> Self {
|
pub(crate) fn new() -> Self {
|
||||||
Self { old_secrets: [([0; 32], 1 << 48); 49], }
|
Self { old_secrets: [([0; 32], 1 << 48); 49], }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ impl CounterpartyCommitmentSecrets {
|
||||||
48
|
48
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn get_min_seen_secret(&self) -> u64 {
|
pub(crate) fn get_min_seen_secret(&self) -> u64 {
|
||||||
//TODO This can be optimized?
|
//TODO This can be optimized?
|
||||||
let mut min = 1 << 48;
|
let mut min = 1 << 48;
|
||||||
for &(_, idx) in self.old_secrets.iter() {
|
for &(_, idx) in self.old_secrets.iter() {
|
||||||
|
@ -123,7 +123,7 @@ impl CounterpartyCommitmentSecrets {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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;
|
let mut res: [u8; 32] = secret;
|
||||||
for i in 0..bits {
|
for i in 0..bits {
|
||||||
let bitpos = bits - 1 - i;
|
let bitpos = bits - 1 - i;
|
||||||
|
@ -135,7 +135,7 @@ impl CounterpartyCommitmentSecrets {
|
||||||
res
|
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);
|
let pos = Self::place_secret(idx);
|
||||||
for i in 0..pos {
|
for i in 0..pos {
|
||||||
let (old_secret, old_idx) = self.old_secrets[i as usize];
|
let (old_secret, old_idx) = self.old_secrets[i as usize];
|
||||||
|
@ -151,7 +151,7 @@ impl CounterpartyCommitmentSecrets {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Can only fail if idx is < get_min_seen_secret
|
/// 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() {
|
for i in 0..self.old_secrets.len() {
|
||||||
if (idx & (!((1 << i) - 1))) == self.old_secrets[i].1 {
|
if (idx & (!((1 << i) - 1))) == self.old_secrets[i].1 {
|
||||||
return Some(Self::derive_secret(self.old_secrets[i].0, i as u8, idx))
|
return Some(Self::derive_secret(self.old_secrets[i].0, i as u8, idx))
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
//! There are a bunch of these as their handling is relatively error-prone so they are split out
|
//! 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.
|
//! here. See also the chanmon_fail_consistency fuzz test.
|
||||||
|
|
||||||
|
use chain::channelmonitor::ChannelMonitorUpdateErr;
|
||||||
use chain::transaction::OutPoint;
|
use chain::transaction::OutPoint;
|
||||||
use ln::channelmanager::{RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
|
use ln::channelmanager::{RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
|
||||||
use ln::channelmonitor::ChannelMonitorUpdateErr;
|
|
||||||
use ln::features::InitFeatures;
|
use ln::features::InitFeatures;
|
||||||
use ln::msgs;
|
use ln::msgs;
|
||||||
use ln::msgs::{ChannelMessageHandler, ErrorAction, RoutingMessageHandler};
|
use ln::msgs::{ChannelMessageHandler, ErrorAction, RoutingMessageHandler};
|
||||||
|
|
|
@ -25,11 +25,11 @@ use bitcoin::secp256k1;
|
||||||
use ln::features::{ChannelFeatures, InitFeatures};
|
use ln::features::{ChannelFeatures, InitFeatures};
|
||||||
use ln::msgs;
|
use ln::msgs;
|
||||||
use ln::msgs::{DecodeError, OptionalField, DataLossProtect};
|
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::channelmanager::{PendingHTLCStatus, HTLCSource, HTLCFailReason, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentPreimage, PaymentHash, BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT};
|
||||||
use ln::chan_utils::{CounterpartyCommitmentSecrets, HolderCommitmentTransaction, TxCreationKeys, HTLCOutputInCommitment, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT, make_funding_redeemscript, ChannelPublicKeys, PreCalculatedTxCreationKeys};
|
use ln::chan_utils::{CounterpartyCommitmentSecrets, HolderCommitmentTransaction, TxCreationKeys, HTLCOutputInCommitment, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT, make_funding_redeemscript, ChannelPublicKeys, PreCalculatedTxCreationKeys};
|
||||||
use ln::chan_utils;
|
use ln::chan_utils;
|
||||||
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
|
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
|
||||||
|
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, HTLC_FAIL_BACK_BUFFER};
|
||||||
use chain::transaction::{OutPoint, TransactionData};
|
use chain::transaction::{OutPoint, TransactionData};
|
||||||
use chain::keysinterface::{ChannelKeys, KeysInterface};
|
use chain::keysinterface::{ChannelKeys, KeysInterface};
|
||||||
use util::transaction_utils;
|
use util::transaction_utils;
|
||||||
|
|
|
@ -36,9 +36,9 @@ use bitcoin::secp256k1;
|
||||||
use chain;
|
use chain;
|
||||||
use chain::Watch;
|
use chain::Watch;
|
||||||
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
|
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, MonitorEvent};
|
||||||
use chain::transaction::{OutPoint, TransactionData};
|
use chain::transaction::{OutPoint, TransactionData};
|
||||||
use ln::channel::{Channel, ChannelError};
|
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, MonitorEvent};
|
|
||||||
use ln::features::{InitFeatures, NodeFeatures};
|
use ln::features::{InitFeatures, NodeFeatures};
|
||||||
use routing::router::{Route, RouteHop};
|
use routing::router::{Route, RouteHop};
|
||||||
use ln::msgs;
|
use ln::msgs;
|
||||||
|
@ -129,7 +129,7 @@ pub(super) enum HTLCForwardInfo {
|
||||||
|
|
||||||
/// Tracks the inbound corresponding to an outbound HTLC
|
/// Tracks the inbound corresponding to an outbound HTLC
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub(super) struct HTLCPreviousHopData {
|
pub(crate) struct HTLCPreviousHopData {
|
||||||
short_channel_id: u64,
|
short_channel_id: u64,
|
||||||
htlc_id: u64,
|
htlc_id: u64,
|
||||||
incoming_packet_shared_secret: [u8; 32],
|
incoming_packet_shared_secret: [u8; 32],
|
||||||
|
@ -148,7 +148,7 @@ struct ClaimableHTLC {
|
||||||
|
|
||||||
/// Tracks the inbound corresponding to an outbound HTLC
|
/// Tracks the inbound corresponding to an outbound HTLC
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub(super) enum HTLCSource {
|
pub(crate) enum HTLCSource {
|
||||||
PreviousHopData(HTLCPreviousHopData),
|
PreviousHopData(HTLCPreviousHopData),
|
||||||
OutboundRoute {
|
OutboundRoute {
|
||||||
path: Vec<RouteHop>,
|
path: Vec<RouteHop>,
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
//! nodes for functional tests.
|
//! nodes for functional tests.
|
||||||
|
|
||||||
use chain::Watch;
|
use chain::Watch;
|
||||||
|
use chain::channelmonitor::ChannelMonitor;
|
||||||
use chain::transaction::OutPoint;
|
use chain::transaction::OutPoint;
|
||||||
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
|
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
|
||||||
use ln::channelmonitor::ChannelMonitor;
|
|
||||||
use routing::router::{Route, get_route};
|
use routing::router::{Route, get_route};
|
||||||
use routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
|
use routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
|
||||||
use ln::features::InitFeatures;
|
use ln::features::InitFeatures;
|
||||||
|
|
|
@ -12,12 +12,12 @@
|
||||||
//! claim outputs on-chain.
|
//! claim outputs on-chain.
|
||||||
|
|
||||||
use chain::Watch;
|
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::transaction::OutPoint;
|
||||||
use chain::keysinterface::{ChannelKeys, KeysInterface, SpendableOutputDescriptor};
|
use chain::keysinterface::{ChannelKeys, KeysInterface, SpendableOutputDescriptor};
|
||||||
use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
|
use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
|
||||||
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure, BREAKDOWN_TIMEOUT};
|
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, 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::channel::{Channel, ChannelError};
|
||||||
use ln::{chan_utils, onion_utils};
|
use ln::{chan_utils, onion_utils};
|
||||||
use routing::router::{Route, RouteHop, get_route};
|
use routing::router::{Route, RouteHop, get_route};
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
//! call into your NetGraphMsgHandler.
|
//! call into your NetGraphMsgHandler.
|
||||||
|
|
||||||
pub mod channelmanager;
|
pub mod channelmanager;
|
||||||
pub mod channelmonitor;
|
|
||||||
pub mod msgs;
|
pub mod msgs;
|
||||||
pub mod peer_handler;
|
pub mod peer_handler;
|
||||||
pub mod chan_utils;
|
pub mod chan_utils;
|
||||||
|
|
|
@ -22,11 +22,11 @@ use bitcoin::secp256k1::{Secp256k1, Signature};
|
||||||
use bitcoin::secp256k1;
|
use bitcoin::secp256k1;
|
||||||
|
|
||||||
use ln::msgs::DecodeError;
|
use ln::msgs::DecodeError;
|
||||||
use ln::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER, InputMaterial, ClaimRequest};
|
|
||||||
use ln::channelmanager::PaymentPreimage;
|
use ln::channelmanager::PaymentPreimage;
|
||||||
use ln::chan_utils;
|
use ln::chan_utils;
|
||||||
use ln::chan_utils::{TxCreationKeys, HolderCommitmentTransaction};
|
use ln::chan_utils::{TxCreationKeys, HolderCommitmentTransaction};
|
||||||
use chain::chaininterface::{FeeEstimator, BroadcasterInterface, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT};
|
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 chain::keysinterface::ChannelKeys;
|
||||||
use util::logger::Logger;
|
use util::logger::Logger;
|
||||||
use util::ser::{Readable, Writer, Writeable};
|
use util::ser::{Readable, Writer, Writeable};
|
||||||
|
@ -405,7 +405,7 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for OnchainTxHandler<ChanSigne
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
|
impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
|
||||||
pub(super) fn new(destination_script: Script, keys: ChanSigner, on_holder_tx_csv: u16) -> Self {
|
pub(crate) fn new(destination_script: Script, keys: ChanSigner, on_holder_tx_csv: u16) -> Self {
|
||||||
|
|
||||||
let key_storage = keys;
|
let key_storage = keys;
|
||||||
|
|
||||||
|
@ -425,7 +425,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
let mut tx_weight = 2; // count segwit flags
|
||||||
for inp in inputs {
|
for inp in inputs {
|
||||||
// We use expected weight (and not actual) as signatures and time lock delays may vary
|
// We use expected weight (and not actual) as signatures and time lock delays may vary
|
||||||
|
@ -829,7 +829,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn block_disconnected<B: Deref, F: Deref, L: Deref>(&mut self, height: u32, broadcaster: B, fee_estimator: F, logger: L)
|
pub(crate) fn block_disconnected<B: Deref, F: Deref, L: Deref>(&mut self, height: u32, broadcaster: B, fee_estimator: F, logger: L)
|
||||||
where B::Target: BroadcasterInterface,
|
where B::Target: BroadcasterInterface,
|
||||||
F::Target: FeeEstimator,
|
F::Target: FeeEstimator,
|
||||||
L::Target: Logger,
|
L::Target: Logger,
|
||||||
|
@ -877,7 +877,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn provide_latest_holder_tx(&mut self, tx: HolderCommitmentTransaction) {
|
pub(crate) fn provide_latest_holder_tx(&mut self, tx: HolderCommitmentTransaction) {
|
||||||
self.prev_holder_commitment = self.holder_commitment.take();
|
self.prev_holder_commitment = self.holder_commitment.take();
|
||||||
self.holder_commitment = Some(tx);
|
self.holder_commitment = Some(tx);
|
||||||
}
|
}
|
||||||
|
@ -919,7 +919,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
|
||||||
// have empty holder commitment transaction if a ChannelMonitor is asked to force-close just after Channel::get_outbound_funding_created,
|
// have empty holder 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
|
// before providing a initial commitment transaction. For outbound channel, init ChannelMonitor at Channel::funding_signed, there is nothing
|
||||||
// to monitor before.
|
// to monitor before.
|
||||||
pub(super) fn get_fully_signed_holder_tx(&mut self, funding_redeemscript: &Script) -> Option<Transaction> {
|
pub(crate) fn get_fully_signed_holder_tx(&mut self, funding_redeemscript: &Script) -> Option<Transaction> {
|
||||||
if let Some(ref mut holder_commitment) = self.holder_commitment {
|
if let Some(ref mut holder_commitment) = self.holder_commitment {
|
||||||
match self.key_storage.sign_holder_commitment(holder_commitment, &self.secp_ctx) {
|
match self.key_storage.sign_holder_commitment(holder_commitment, &self.secp_ctx) {
|
||||||
Ok(sig) => Some(holder_commitment.add_holder_sig(funding_redeemscript, sig)),
|
Ok(sig) => Some(holder_commitment.add_holder_sig(funding_redeemscript, sig)),
|
||||||
|
@ -931,7 +931,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature="unsafe_revoked_tx_signing"))]
|
#[cfg(any(test, feature="unsafe_revoked_tx_signing"))]
|
||||||
pub(super) fn get_fully_signed_copy_holder_tx(&mut self, funding_redeemscript: &Script) -> Option<Transaction> {
|
pub(crate) fn get_fully_signed_copy_holder_tx(&mut self, funding_redeemscript: &Script) -> Option<Transaction> {
|
||||||
if let Some(ref mut holder_commitment) = self.holder_commitment {
|
if let Some(ref mut holder_commitment) = self.holder_commitment {
|
||||||
let holder_commitment = holder_commitment.clone();
|
let holder_commitment = holder_commitment.clone();
|
||||||
match self.key_storage.sign_holder_commitment(&holder_commitment, &self.secp_ctx) {
|
match self.key_storage.sign_holder_commitment(&holder_commitment, &self.secp_ctx) {
|
||||||
|
@ -943,7 +943,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn get_fully_signed_htlc_tx(&mut self, outp: &::bitcoin::OutPoint, preimage: &Option<PaymentPreimage>) -> Option<Transaction> {
|
pub(crate) fn get_fully_signed_htlc_tx(&mut self, outp: &::bitcoin::OutPoint, preimage: &Option<PaymentPreimage>) -> Option<Transaction> {
|
||||||
let mut htlc_tx = None;
|
let mut htlc_tx = None;
|
||||||
if self.holder_commitment.is_some() {
|
if self.holder_commitment.is_some() {
|
||||||
let commitment_txid = self.holder_commitment.as_ref().unwrap().txid();
|
let commitment_txid = self.holder_commitment.as_ref().unwrap().txid();
|
||||||
|
@ -971,7 +971,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
|
#[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
|
||||||
pub(super) fn unsafe_get_fully_signed_htlc_tx(&mut self, outp: &::bitcoin::OutPoint, preimage: &Option<PaymentPreimage>) -> Option<Transaction> {
|
pub(crate) fn unsafe_get_fully_signed_htlc_tx(&mut self, outp: &::bitcoin::OutPoint, preimage: &Option<PaymentPreimage>) -> Option<Transaction> {
|
||||||
let latest_had_sigs = self.holder_htlc_sigs.is_some();
|
let latest_had_sigs = self.holder_htlc_sigs.is_some();
|
||||||
let prev_had_sigs = self.prev_holder_htlc_sigs.is_some();
|
let prev_had_sigs = self.prev_holder_htlc_sigs.is_some();
|
||||||
let ret = self.get_fully_signed_htlc_tx(outp, preimage);
|
let ret = self.get_fully_signed_htlc_tx(outp, preimage);
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
//! These tests work by standing up full nodes and route payments across the network, checking the
|
//! These tests work by standing up full nodes and route payments across the network, checking the
|
||||||
//! returned errors decode to the correct thing.
|
//! returned errors decode to the correct thing.
|
||||||
|
|
||||||
|
use chain::channelmonitor::{CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS};
|
||||||
use ln::channelmanager::{HTLCForwardInfo, PaymentPreimage, PaymentHash};
|
use ln::channelmanager::{HTLCForwardInfo, PaymentPreimage, PaymentHash};
|
||||||
use ln::channelmonitor::{CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS};
|
|
||||||
use ln::onion_utils;
|
use ln::onion_utils;
|
||||||
use routing::router::{Route, get_route};
|
use routing::router::{Route, get_route};
|
||||||
use ln::features::InitFeatures;
|
use ln::features::InitFeatures;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
//! Further functional tests which test blockchain reorganizations.
|
//! 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::features::InitFeatures;
|
||||||
use ln::msgs::{ChannelMessageHandler, ErrorAction, HTLCFailChannelUpdate};
|
use ln::msgs::{ChannelMessageHandler, ErrorAction, HTLCFailChannelUpdate};
|
||||||
use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsProvider};
|
use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsProvider};
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
use chain;
|
use chain;
|
||||||
use chain::chaininterface;
|
use chain::chaininterface;
|
||||||
use chain::chaininterface::ConfirmationTarget;
|
use chain::chaininterface::ConfirmationTarget;
|
||||||
|
use chain::channelmonitor;
|
||||||
|
use chain::channelmonitor::MonitorEvent;
|
||||||
use chain::transaction::OutPoint;
|
use chain::transaction::OutPoint;
|
||||||
use chain::keysinterface;
|
use chain::keysinterface;
|
||||||
use ln::channelmonitor;
|
|
||||||
use ln::features::{ChannelFeatures, InitFeatures};
|
use ln::features::{ChannelFeatures, InitFeatures};
|
||||||
use ln::msgs;
|
use ln::msgs;
|
||||||
use ln::msgs::OptionalField;
|
use ln::msgs::OptionalField;
|
||||||
use ln::channelmonitor::MonitorEvent;
|
|
||||||
use util::enforcing_trait_impls::EnforcingChannelKeys;
|
use util::enforcing_trait_impls::EnforcingChannelKeys;
|
||||||
use util::events;
|
use util::events;
|
||||||
use util::logger::{Logger, Level, Record};
|
use util::logger::{Logger, Level, Record};
|
||||||
|
|
Loading…
Add table
Reference in a new issue