Skip to content

Commit a0e6a4b

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 3321d88 commit a0e6a4b

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.
@@ -175,12 +175,12 @@ pub enum MonitorEvent {
175175
/// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
176176
/// preimage claim backward will lead to loss of funds.
177177
///
178-
/// [`chain::Watch`]: ../../chain/trait.Watch.html
178+
/// [`chain::Watch`]: ../trait.Watch.html
179179
#[derive(Clone, PartialEq)]
180180
pub struct HTLCUpdate {
181-
pub(super) payment_hash: PaymentHash,
182-
pub(super) payment_preimage: Option<PaymentPreimage>,
183-
pub(super) source: HTLCSource
181+
pub(crate) payment_hash: PaymentHash,
182+
pub(crate) payment_preimage: Option<PaymentPreimage>,
183+
pub(crate) source: HTLCSource
184184
}
185185
impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
186186

@@ -190,8 +190,8 @@ impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
190190
/// [`chain::Watch`]. May be used in conjunction with [`ChannelManager`] to monitor channels locally
191191
/// or used independently to monitor channels remotely.
192192
///
193-
/// [`chain::Watch`]: ../../chain/trait.Watch.html
194-
/// [`ChannelManager`]: ../channelmanager/struct.ChannelManager.html
193+
/// [`chain::Watch`]: ../trait.Watch.html
194+
/// [`ChannelManager`]: ../../ln/channelmanager/struct.ChannelManager.html
195195
pub struct ChainMonitor<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref>
196196
where C::Target: chain::Filter,
197197
T::Target: BroadcasterInterface,
@@ -222,8 +222,8 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref> ChainMonit
222222
/// block to obtain updated `txdata` and recall `block_connected`.
223223
///
224224
/// [`ChannelMonitor::block_connected`]: struct.ChannelMonitor.html#method.block_connected
225-
/// [`chain::Watch::release_pending_monitor_events`]: ../../chain/trait.Watch.html#tymethod.release_pending_monitor_events
226-
/// [`chain::Filter`]: ../../chain/trait.Filter.html
225+
/// [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events
226+
/// [`chain::Filter`]: ../trait.Filter.html
227227
pub fn block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) -> bool {
228228
let mut has_new_outputs_to_watch = false;
229229
{
@@ -264,7 +264,7 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref> ChainMonit
264264
/// always need to fetch full blocks absent another means for determining which blocks contain
265265
/// transactions relevant to the watched channels.
266266
///
267-
/// [`chain::Filter`]: ../../chain/trait.Filter.html
267+
/// [`chain::Filter`]: ../trait.Filter.html
268268
pub fn new(chain_source: Option<C>, broadcaster: T, logger: L, feeest: F) -> Self {
269269
Self {
270270
monitors: Mutex::new(HashMap::new()),
@@ -279,7 +279,7 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref> ChainMonit
279279
///
280280
/// Calls back to [`chain::Filter`] with the funding transaction and outputs to watch.
281281
///
282-
/// [`chain::Filter`]: ../../chain/trait.Filter.html
282+
/// [`chain::Filter`]: ../trait.Filter.html
283283
fn add_monitor(&self, outpoint: OutPoint, monitor: ChannelMonitor<ChanSigner>) -> Result<(), MonitorUpdateError> {
284284
let mut monitors = self.monitors.lock().unwrap();
285285
let entry = match monitors.entry(outpoint) {
@@ -648,7 +648,7 @@ const MIN_SERIALIZATION_VERSION: u8 = 1;
648648

649649
#[cfg_attr(test, derive(PartialEq))]
650650
#[derive(Clone)]
651-
pub(super) enum ChannelMonitorUpdateStep {
651+
pub(crate) enum ChannelMonitorUpdateStep {
652652
LatestHolderCommitmentTXInfo {
653653
commitment_tx: HolderCommitmentTransaction,
654654
htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>,
@@ -1111,7 +1111,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
11111111
}
11121112

11131113
impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1114-
pub(super) fn new(keys: ChanSigner, shutdown_pubkey: &PublicKey,
1114+
pub(crate) fn new(keys: ChanSigner, shutdown_pubkey: &PublicKey,
11151115
on_counterparty_tx_csv: u16, destination_script: &Script, funding_info: (OutPoint, Script),
11161116
counterparty_htlc_base_key: &PublicKey, counterparty_delayed_payment_base_key: &PublicKey,
11171117
on_holder_tx_csv: u16, funding_redeemscript: Script, channel_value_satoshis: u64,
@@ -1196,7 +1196,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11961196
/// Inserts a revocation secret into this channel monitor. Prunes old preimages if neither
11971197
/// needed by holder commitment transactions HTCLs nor by counterparty ones. Unless we haven't already seen
11981198
/// counterparty commitment transaction's secret, they are de facto pruned (we can use revocation key).
1199-
pub(super) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), MonitorUpdateError> {
1199+
fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), MonitorUpdateError> {
12001200
if let Err(()) = self.commitment_secrets.provide_secret(idx, secret) {
12011201
return Err(MonitorUpdateError("Previous secret did not match new one"));
12021202
}
@@ -1248,7 +1248,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
12481248
/// The monitor watches for it to be broadcasted and then uses the HTLC information (and
12491249
/// possibly future revocation/preimage information) to claim outputs where possible.
12501250
/// We cache also the mapping hash:commitment number to lighten pruning of old preimages by watchtowers.
1251-
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 {
1251+
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 {
12521252
// TODO: Encrypt the htlc_outputs data with the single-hash of the commitment transaction
12531253
// so that a remote monitor doesn't learn anything unless there is a malicious close.
12541254
// (only maybe, sadly we cant do the same for local info, as we need to be aware of
@@ -1297,7 +1297,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
12971297
/// is important that any clones of this channel monitor (including remote clones) by kept
12981298
/// up-to-date as our holder commitment transaction is updated.
12991299
/// Panics if set_on_holder_tx_csv has never been called.
1300-
pub(super) fn provide_latest_holder_commitment_tx_info(&mut self, commitment_tx: HolderCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
1300+
fn provide_latest_holder_commitment_tx_info(&mut self, commitment_tx: HolderCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
13011301
let txid = commitment_tx.txid();
13021302
let sequence = commitment_tx.unsigned_tx.input[0].sequence as u64;
13031303
let locktime = commitment_tx.unsigned_tx.lock_time as u64;
@@ -1323,11 +1323,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13231323

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

1330-
pub(super) fn broadcast_latest_holder_commitment_txn<B: Deref, L: Deref>(&mut self, broadcaster: &B, logger: &L)
1330+
pub(crate) fn broadcast_latest_holder_commitment_txn<B: Deref, L: Deref>(&mut self, broadcaster: &B, logger: &L)
13311331
where B::Target: BroadcasterInterface,
13321332
L::Target: Logger,
13331333
{
@@ -1412,7 +1412,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14121412
/// Get the list of HTLCs who's status has been updated on chain. This should be called by
14131413
/// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
14141414
///
1415-
/// [`chain::Watch::release_pending_monitor_events`]: ../../chain/trait.Watch.html#tymethod.release_pending_monitor_events
1415+
/// [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events
14161416
pub fn get_and_clear_pending_monitor_events(&mut self) -> Vec<MonitorEvent> {
14171417
let mut ret = Vec::new();
14181418
mem::swap(&mut ret, &mut self.pending_monitor_events);
@@ -1432,19 +1432,19 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14321432
}
14331433

14341434
/// Can only fail if idx is < get_min_seen_secret
1435-
pub(super) fn get_secret(&self, idx: u64) -> Option<[u8; 32]> {
1435+
fn get_secret(&self, idx: u64) -> Option<[u8; 32]> {
14361436
self.commitment_secrets.get_secret(idx)
14371437
}
14381438

1439-
pub(super) fn get_min_seen_secret(&self) -> u64 {
1439+
pub(crate) fn get_min_seen_secret(&self) -> u64 {
14401440
self.commitment_secrets.get_min_seen_secret()
14411441
}
14421442

1443-
pub(super) fn get_cur_counterparty_commitment_number(&self) -> u64 {
1443+
pub(crate) fn get_cur_counterparty_commitment_number(&self) -> u64 {
14441444
self.current_counterparty_commitment_number
14451445
}
14461446

1447-
pub(super) fn get_cur_holder_commitment_number(&self) -> u64 {
1447+
pub(crate) fn get_cur_holder_commitment_number(&self) -> u64 {
14481448
self.current_holder_commitment_number
14491449
}
14501450

@@ -2589,9 +2589,9 @@ mod tests {
25892589
use bitcoin::hashes::hex::FromHex;
25902590
use bitcoin::hash_types::Txid;
25912591
use hex;
2592+
use chain::channelmonitor::ChannelMonitor;
25922593
use chain::transaction::OutPoint;
25932594
use ln::channelmanager::{PaymentPreimage, PaymentHash};
2594-
use ln::channelmonitor::ChannelMonitor;
25952595
use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
25962596
use ln::chan_utils;
25972597
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,9 +76,9 @@ 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.
@@ -92,8 +93,8 @@ pub trait Watch: Send + Sync {
9293
/// a commitment broadcast. This storage is used to claim outputs of rejected state confirmed
9394
/// onchain by another watchtower, lagging behind on block processing.
9495
///
95-
/// [`update_monitor`]: ../ln/channelmonitor/struct.ChannelMonitor.html#method.update_monitor
96-
/// [`ChannelMonitorUpdateErr`]: ../ln/channelmonitor/enum.ChannelMonitorUpdateErr.html
96+
/// [`update_monitor`]: channelmonitor/struct.ChannelMonitor.html#method.update_monitor
97+
/// [`ChannelMonitorUpdateErr`]: channelmonitor/enum.ChannelMonitorUpdateErr.html
9798
fn update_channel(&self, funding_txo: OutPoint, update: ChannelMonitorUpdate) -> Result<(), ChannelMonitorUpdateErr>;
9899

99100
/// 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)