Skip to content

Commit fb8fe52

Browse files
committed
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.
1 parent f0641d7 commit fb8fe52

17 files changed

+68
-68
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ use bitcoin::hashes::sha256::Hash as Sha256;
2929
use bitcoin::hash_types::{BlockHash, WPubkeyHash};
3030

3131
use lightning::chain;
32+
use lightning::chain::channelmonitor;
33+
use lightning::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, MonitorEvent};
3234
use lightning::chain::transaction::OutPoint;
3335
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
3436
use lightning::chain::keysinterface::{KeysInterface, InMemoryChannelKeys};
35-
use lightning::ln::channelmonitor;
36-
use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, MonitorEvent};
3737
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret, ChannelManagerReadArgs};
3838
use lightning::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
3939
use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, UpdateAddHTLC, Init};

fuzz/src/chanmon_deser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use bitcoin::hash_types::BlockHash;
55

6+
use lightning::chain::channelmonitor;
67
use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
7-
use lightning::ln::channelmonitor;
88
use lightning::util::ser::{Readable, Writer};
99

1010
use utils::test_logger;

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
2727

2828
use lightning::chain;
2929
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
30+
use lightning::chain::channelmonitor;
3031
use lightning::chain::transaction::OutPoint;
3132
use lightning::chain::keysinterface::{InMemoryChannelKeys, KeysInterface};
32-
use lightning::ln::channelmonitor;
3333
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret};
3434
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
3535
use lightning::routing::router::get_route;
@@ -900,6 +900,6 @@ mod tests {
900900
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
901901
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
902902
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
903-
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
903+
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
904904
}
905905
}

lightning-net-tokio/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
//! type Logger = dyn lightning::util::logger::Logger;
3737
//! type ChainAccess = dyn lightning::chain::Access;
3838
//! type ChainFilter = dyn lightning::chain::Filter;
39-
//! type ChainMonitor = lightning::ln::channelmonitor::ChainMonitor<lightning::chain::keysinterface::InMemoryChannelKeys, Arc<ChainFilter>, Arc<TxBroadcaster>, Arc<FeeEstimator>, Arc<Logger>>;
39+
//! type ChainMonitor = lightning::chain::channelmonitor::ChainMonitor<lightning::chain::keysinterface::InMemoryChannelKeys, Arc<ChainFilter>, Arc<TxBroadcaster>, Arc<FeeEstimator>, Arc<Logger>>;
4040
//! type ChannelManager = lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor, TxBroadcaster, FeeEstimator, Logger>;
4141
//! type PeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChainMonitor, TxBroadcaster, FeeEstimator, ChainAccess, Logger>;
4242
//!

lightning/src/ln/channelmonitor.rs renamed to lightning/src/chain/channelmonitor.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//! security-domain-separated system design, you should consider having multiple paths for
2121
//! ChannelMonitors to get out of the HSM and onto monitoring devices.
2222
//!
23-
//! [`chain::Watch`]: ../../chain/trait.Watch.html
23+
//! [`chain::Watch`]: ../trait.Watch.html
2424
2525
use bitcoin::blockdata::block::BlockHeader;
2626
use bitcoin::blockdata::transaction::{TxOut,Transaction};
@@ -64,7 +64,7 @@ use std::io::Error;
6464
#[derive(Clone)]
6565
#[must_use]
6666
pub struct ChannelMonitorUpdate {
67-
pub(super) updates: Vec<ChannelMonitorUpdateStep>,
67+
pub(crate) updates: Vec<ChannelMonitorUpdateStep>,
6868
/// The sequence number of this update. Updates *must* be replayed in-order according to this
6969
/// sequence number (and updates may panic if they are not). The update_id values are strictly
7070
/// increasing and increase by one for each new update.
@@ -180,12 +180,12 @@ pub enum MonitorEvent {
180180
/// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
181181
/// preimage claim backward will lead to loss of funds.
182182
///
183-
/// [`chain::Watch`]: ../../chain/trait.Watch.html
183+
/// [`chain::Watch`]: ../trait.Watch.html
184184
#[derive(Clone, PartialEq)]
185185
pub struct HTLCUpdate {
186-
pub(super) payment_hash: PaymentHash,
187-
pub(super) payment_preimage: Option<PaymentPreimage>,
188-
pub(super) source: HTLCSource
186+
pub(crate) payment_hash: PaymentHash,
187+
pub(crate) payment_preimage: Option<PaymentPreimage>,
188+
pub(crate) source: HTLCSource
189189
}
190190
impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
191191

@@ -195,8 +195,8 @@ impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
195195
/// [`chain::Watch`]. May be used in conjunction with [`ChannelManager`] to monitor channels locally
196196
/// or used independently to monitor channels remotely.
197197
///
198-
/// [`chain::Watch`]: ../../chain/trait.Watch.html
199-
/// [`ChannelManager`]: ../channelmanager/struct.ChannelManager.html
198+
/// [`chain::Watch`]: ../trait.Watch.html
199+
/// [`ChannelManager`]: ../../ln/channelmanager/struct.ChannelManager.html
200200
pub struct ChainMonitor<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref>
201201
where C::Target: chain::Filter,
202202
T::Target: BroadcasterInterface,
@@ -227,8 +227,8 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref> ChainMonit
227227
/// block to obtain updated `txdata` and recall `block_connected`.
228228
///
229229
/// [`ChannelMonitor::block_connected`]: struct.ChannelMonitor.html#method.block_connected
230-
/// [`chain::Watch::release_pending_monitor_events`]: ../../chain/trait.Watch.html#tymethod.release_pending_monitor_events
231-
/// [`chain::Filter`]: ../../chain/trait.Filter.html
230+
/// [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events
231+
/// [`chain::Filter`]: ../trait.Filter.html
232232
pub fn block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) -> bool {
233233
let mut has_new_outputs_to_watch = false;
234234
{
@@ -269,7 +269,7 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref> ChainMonit
269269
/// always need to fetch full blocks absent another means for determining which blocks contain
270270
/// transactions relevant to the watched channels.
271271
///
272-
/// [`chain::Filter`]: ../../chain/trait.Filter.html
272+
/// [`chain::Filter`]: ../trait.Filter.html
273273
pub fn new(chain_source: Option<C>, broadcaster: T, logger: L, feeest: F) -> Self {
274274
Self {
275275
monitors: Mutex::new(HashMap::new()),
@@ -284,7 +284,7 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref> ChainMonit
284284
///
285285
/// Calls back to [`chain::Filter`] with the funding transaction and outputs to watch.
286286
///
287-
/// [`chain::Filter`]: ../../chain/trait.Filter.html
287+
/// [`chain::Filter`]: ../trait.Filter.html
288288
fn add_monitor(&self, outpoint: OutPoint, monitor: ChannelMonitor<ChanSigner>) -> Result<(), MonitorUpdateError> {
289289
let mut monitors = self.monitors.lock().unwrap();
290290
let entry = match monitors.entry(outpoint) {
@@ -653,7 +653,7 @@ const MIN_SERIALIZATION_VERSION: u8 = 1;
653653

654654
#[cfg_attr(test, derive(PartialEq))]
655655
#[derive(Clone)]
656-
pub(super) enum ChannelMonitorUpdateStep {
656+
pub(crate) enum ChannelMonitorUpdateStep {
657657
LatestHolderCommitmentTXInfo {
658658
commitment_tx: HolderCommitmentTransaction,
659659
htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>,
@@ -1116,7 +1116,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
11161116
}
11171117

11181118
impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1119-
pub(super) fn new(keys: ChanSigner, shutdown_pubkey: &PublicKey,
1119+
pub(crate) fn new(keys: ChanSigner, shutdown_pubkey: &PublicKey,
11201120
on_counterparty_tx_csv: u16, destination_script: &Script, funding_info: (OutPoint, Script),
11211121
counterparty_htlc_base_key: &PublicKey, counterparty_delayed_payment_base_key: &PublicKey,
11221122
on_holder_tx_csv: u16, funding_redeemscript: Script, channel_value_satoshis: u64,
@@ -1201,7 +1201,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
12011201
/// Inserts a revocation secret into this channel monitor. Prunes old preimages if neither
12021202
/// needed by holder commitment transactions HTCLs nor by counterparty ones. Unless we haven't already seen
12031203
/// counterparty commitment transaction's secret, they are de facto pruned (we can use revocation key).
1204-
pub(super) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), MonitorUpdateError> {
1204+
fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), MonitorUpdateError> {
12051205
if let Err(()) = self.commitment_secrets.provide_secret(idx, secret) {
12061206
return Err(MonitorUpdateError("Previous secret did not match new one"));
12071207
}
@@ -1253,7 +1253,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
12531253
/// The monitor watches for it to be broadcasted and then uses the HTLC information (and
12541254
/// possibly future revocation/preimage information) to claim outputs where possible.
12551255
/// We cache also the mapping hash:commitment number to lighten pruning of old preimages by watchtowers.
1256-
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 {
1256+
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 {
12571257
// TODO: Encrypt the htlc_outputs data with the single-hash of the commitment transaction
12581258
// so that a remote monitor doesn't learn anything unless there is a malicious close.
12591259
// (only maybe, sadly we cant do the same for local info, as we need to be aware of
@@ -1302,7 +1302,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13021302
/// is important that any clones of this channel monitor (including remote clones) by kept
13031303
/// up-to-date as our holder commitment transaction is updated.
13041304
/// Panics if set_on_holder_tx_csv has never been called.
1305-
pub(super) fn provide_latest_holder_commitment_tx_info(&mut self, commitment_tx: HolderCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
1305+
fn provide_latest_holder_commitment_tx_info(&mut self, commitment_tx: HolderCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
13061306
let txid = commitment_tx.txid();
13071307
let sequence = commitment_tx.unsigned_tx.input[0].sequence as u64;
13081308
let locktime = commitment_tx.unsigned_tx.lock_time as u64;
@@ -1328,11 +1328,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13281328

13291329
/// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
13301330
/// commitment_tx_infos which contain the payment hash have been revoked.
1331-
pub(super) fn provide_payment_preimage(&mut self, payment_hash: &PaymentHash, payment_preimage: &PaymentPreimage) {
1331+
pub(crate) fn provide_payment_preimage(&mut self, payment_hash: &PaymentHash, payment_preimage: &PaymentPreimage) {
13321332
self.payment_preimages.insert(payment_hash.clone(), payment_preimage.clone());
13331333
}
13341334

1335-
pub(super) fn broadcast_latest_holder_commitment_txn<B: Deref, L: Deref>(&mut self, broadcaster: &B, logger: &L)
1335+
pub(crate) fn broadcast_latest_holder_commitment_txn<B: Deref, L: Deref>(&mut self, broadcaster: &B, logger: &L)
13361336
where B::Target: BroadcasterInterface,
13371337
L::Target: Logger,
13381338
{
@@ -1417,7 +1417,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14171417
/// Get the list of HTLCs who's status has been updated on chain. This should be called by
14181418
/// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
14191419
///
1420-
/// [`chain::Watch::release_pending_monitor_events`]: ../../chain/trait.Watch.html#tymethod.release_pending_monitor_events
1420+
/// [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events
14211421
pub fn get_and_clear_pending_monitor_events(&mut self) -> Vec<MonitorEvent> {
14221422
let mut ret = Vec::new();
14231423
mem::swap(&mut ret, &mut self.pending_monitor_events);
@@ -1437,19 +1437,19 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14371437
}
14381438

14391439
/// Can only fail if idx is < get_min_seen_secret
1440-
pub(super) fn get_secret(&self, idx: u64) -> Option<[u8; 32]> {
1440+
fn get_secret(&self, idx: u64) -> Option<[u8; 32]> {
14411441
self.commitment_secrets.get_secret(idx)
14421442
}
14431443

1444-
pub(super) fn get_min_seen_secret(&self) -> u64 {
1444+
pub(crate) fn get_min_seen_secret(&self) -> u64 {
14451445
self.commitment_secrets.get_min_seen_secret()
14461446
}
14471447

1448-
pub(super) fn get_cur_counterparty_commitment_number(&self) -> u64 {
1448+
pub(crate) fn get_cur_counterparty_commitment_number(&self) -> u64 {
14491449
self.current_counterparty_commitment_number
14501450
}
14511451

1452-
pub(super) fn get_cur_holder_commitment_number(&self) -> u64 {
1452+
pub(crate) fn get_cur_holder_commitment_number(&self) -> u64 {
14531453
self.current_holder_commitment_number
14541454
}
14551455

@@ -2594,9 +2594,9 @@ mod tests {
25942594
use bitcoin::hashes::hex::FromHex;
25952595
use bitcoin::hash_types::Txid;
25962596
use hex;
2597+
use chain::channelmonitor::ChannelMonitor;
25972598
use chain::transaction::OutPoint;
25982599
use ln::channelmanager::{PaymentPreimage, PaymentHash};
2599-
use ln::channelmonitor::ChannelMonitor;
26002600
use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
26012601
use ln::chan_utils;
26022602
use ln::chan_utils::{HTLCOutputInCommitment, HolderCommitmentTransaction};

lightning/src/chain/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ use bitcoin::blockdata::script::Script;
1313
use bitcoin::blockdata::transaction::TxOut;
1414
use bitcoin::hash_types::{BlockHash, Txid};
1515

16+
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, MonitorEvent};
1617
use chain::keysinterface::ChannelKeys;
1718
use chain::transaction::OutPoint;
18-
use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, MonitorEvent};
1919

2020
pub mod chaininterface;
21+
pub mod channelmonitor;
2122
pub mod transaction;
2223
pub mod keysinterface;
2324

@@ -62,9 +63,9 @@ pub enum AccessError {
6263
/// funds in the channel. See [`ChannelMonitorUpdateErr`] for more details about how to handle
6364
/// multiple instances.
6465
///
65-
/// [`ChannelMonitor`]: ../ln/channelmonitor/struct.ChannelMonitor.html
66-
/// [`ChannelMonitorUpdateErr`]: ../ln/channelmonitor/enum.ChannelMonitorUpdateErr.html
67-
/// [`PermanentFailure`]: ../ln/channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.PermanentFailure
66+
/// [`ChannelMonitor`]: channelmonitor/struct.ChannelMonitor.html
67+
/// [`ChannelMonitorUpdateErr`]: channelmonitor/enum.ChannelMonitorUpdateErr.html
68+
/// [`PermanentFailure`]: channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.PermanentFailure
6869
pub trait Watch: Send + Sync {
6970
/// Keys needed by monitors for creating and signing transactions.
7071
type Keys: ChannelKeys;
@@ -75,18 +76,18 @@ pub trait Watch: Send + Sync {
7576
/// with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
7677
/// calling [`block_connected`] and [`block_disconnected`] on the monitor.
7778
///
78-
/// [`get_outputs_to_watch`]: ../ln/channelmonitor/struct.ChannelMonitor.html#method.get_outputs_to_watch
79-
/// [`block_connected`]: ../ln/channelmonitor/struct.ChannelMonitor.html#method.block_connected
80-
/// [`block_disconnected`]: ../ln/channelmonitor/struct.ChannelMonitor.html#method.block_disconnected
79+
/// [`get_outputs_to_watch`]: channelmonitor/struct.ChannelMonitor.html#method.get_outputs_to_watch
80+
/// [`block_connected`]: channelmonitor/struct.ChannelMonitor.html#method.block_connected
81+
/// [`block_disconnected`]: channelmonitor/struct.ChannelMonitor.html#method.block_disconnected
8182
fn watch_channel(&self, funding_txo: OutPoint, monitor: ChannelMonitor<Self::Keys>) -> Result<(), ChannelMonitorUpdateErr>;
8283

8384
/// Updates a channel identified by `funding_txo` by applying `update` to its monitor.
8485
///
8586
/// Implementations must call [`update_monitor`] with the given update. See
8687
/// [`ChannelMonitorUpdateErr`] for invariants around returning an error.
8788
///
88-
/// [`update_monitor`]: ../ln/channelmonitor/struct.ChannelMonitor.html#method.update_monitor
89-
/// [`ChannelMonitorUpdateErr`]: ../ln/channelmonitor/enum.ChannelMonitorUpdateErr.html
89+
/// [`update_monitor`]: channelmonitor/struct.ChannelMonitor.html#method.update_monitor
90+
/// [`ChannelMonitorUpdateErr`]: channelmonitor/enum.ChannelMonitorUpdateErr.html
9091
fn update_channel(&self, funding_txo: OutPoint, update: ChannelMonitorUpdate) -> Result<(), ChannelMonitorUpdateErr>;
9192

9293
/// Returns any monitor events since the last call. Subsequent calls must only return new

lightning/src/ln/chan_utils.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn build_commitment_secret(commitment_seed: &[u8; 32], idx: u64) -> [u8; 32]
8181
/// Allows us to keep track of all of the revocation secrets of counterarties in just 50*32 bytes
8282
/// or so.
8383
#[derive(Clone)]
84-
pub(super) struct CounterpartyCommitmentSecrets {
84+
pub(crate) struct CounterpartyCommitmentSecrets {
8585
old_secrets: [([u8; 32], u64); 49],
8686
}
8787

@@ -97,7 +97,7 @@ impl PartialEq for CounterpartyCommitmentSecrets {
9797
}
9898

9999
impl CounterpartyCommitmentSecrets {
100-
pub(super) fn new() -> Self {
100+
pub(crate) fn new() -> Self {
101101
Self { old_secrets: [([0; 32], 1 << 48); 49], }
102102
}
103103

@@ -111,7 +111,7 @@ impl CounterpartyCommitmentSecrets {
111111
48
112112
}
113113

114-
pub(super) fn get_min_seen_secret(&self) -> u64 {
114+
pub(crate) fn get_min_seen_secret(&self) -> u64 {
115115
//TODO This can be optimized?
116116
let mut min = 1 << 48;
117117
for &(_, idx) in self.old_secrets.iter() {
@@ -123,7 +123,7 @@ impl CounterpartyCommitmentSecrets {
123123
}
124124

125125
#[inline]
126-
pub(super) fn derive_secret(secret: [u8; 32], bits: u8, idx: u64) -> [u8; 32] {
126+
fn derive_secret(secret: [u8; 32], bits: u8, idx: u64) -> [u8; 32] {
127127
let mut res: [u8; 32] = secret;
128128
for i in 0..bits {
129129
let bitpos = bits - 1 - i;
@@ -135,7 +135,7 @@ impl CounterpartyCommitmentSecrets {
135135
res
136136
}
137137

138-
pub(super) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), ()> {
138+
pub(crate) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), ()> {
139139
let pos = Self::place_secret(idx);
140140
for i in 0..pos {
141141
let (old_secret, old_idx) = self.old_secrets[i as usize];
@@ -151,7 +151,7 @@ impl CounterpartyCommitmentSecrets {
151151
}
152152

153153
/// Can only fail if idx is < get_min_seen_secret
154-
pub(super) fn get_secret(&self, idx: u64) -> Option<[u8; 32]> {
154+
pub(crate) fn get_secret(&self, idx: u64) -> Option<[u8; 32]> {
155155
for i in 0..self.old_secrets.len() {
156156
if (idx & (!((1 << i) - 1))) == self.old_secrets[i].1 {
157157
return Some(Self::derive_secret(self.old_secrets[i].0, i as u8, idx))

0 commit comments

Comments
 (0)