Skip to content

Commit 45a6f33

Browse files
authored
Merge pull request #1967 from arik-so/2023-01-rename-signer-traits
Split out `EcdsaChannelSigner` method from `BaseSign`, and rename it to `ChannelSigner`
2 parents e0a0add + 712c60e commit 45a6f33

13 files changed

+127
-112
lines changed

lightning/src/chain/chainmonitor.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::chain::{ChannelMonitorUpdateStatus, Filter, WatchedOutput};
3131
use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
3232
use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, Balance, MonitorEvent, TransactionOutputs, LATENCY_GRACE_PERIOD_BLOCKS};
3333
use crate::chain::transaction::{OutPoint, TransactionData};
34-
use crate::chain::keysinterface::Sign;
34+
use crate::chain::keysinterface::WriteableEcdsaChannelSigner;
3535
use crate::util::atomic_counter::AtomicCounter;
3636
use crate::util::logger::Logger;
3737
use crate::util::errors::APIError;
@@ -68,7 +68,7 @@ impl MonitorUpdateId {
6868
pub(crate) fn from_monitor_update(update: &ChannelMonitorUpdate) -> Self {
6969
Self { contents: UpdateOrigin::OffChain(update.update_id) }
7070
}
71-
pub(crate) fn from_new_monitor<ChannelSigner: Sign>(monitor: &ChannelMonitor<ChannelSigner>) -> Self {
71+
pub(crate) fn from_new_monitor<ChannelSigner: WriteableEcdsaChannelSigner>(monitor: &ChannelMonitor<ChannelSigner>) -> Self {
7272
Self { contents: UpdateOrigin::OffChain(monitor.get_latest_update_id()) }
7373
}
7474
}
@@ -93,7 +93,7 @@ impl MonitorUpdateId {
9393
/// [`ChannelMonitorUpdateStatus::PermanentFailure`], in which case the channel will likely be
9494
/// closed without broadcasting the latest state. See
9595
/// [`ChannelMonitorUpdateStatus::PermanentFailure`] for more details.
96-
pub trait Persist<ChannelSigner: Sign> {
96+
pub trait Persist<ChannelSigner: WriteableEcdsaChannelSigner> {
9797
/// Persist a new channel's data in response to a [`chain::Watch::watch_channel`] call. This is
9898
/// called by [`ChannelManager`] for new channels, or may be called directly, e.g. on startup.
9999
///
@@ -147,7 +147,7 @@ pub trait Persist<ChannelSigner: Sign> {
147147
fn update_persisted_channel(&self, channel_id: OutPoint, update: Option<&ChannelMonitorUpdate>, data: &ChannelMonitor<ChannelSigner>, update_id: MonitorUpdateId) -> ChannelMonitorUpdateStatus;
148148
}
149149

150-
struct MonitorHolder<ChannelSigner: Sign> {
150+
struct MonitorHolder<ChannelSigner: WriteableEcdsaChannelSigner> {
151151
monitor: ChannelMonitor<ChannelSigner>,
152152
/// The full set of pending monitor updates for this Channel.
153153
///
@@ -182,7 +182,7 @@ struct MonitorHolder<ChannelSigner: Sign> {
182182
last_chain_persist_height: AtomicUsize,
183183
}
184184

185-
impl<ChannelSigner: Sign> MonitorHolder<ChannelSigner> {
185+
impl<ChannelSigner: WriteableEcdsaChannelSigner> MonitorHolder<ChannelSigner> {
186186
fn has_pending_offchain_updates(&self, pending_monitor_updates_lock: &MutexGuard<Vec<MonitorUpdateId>>) -> bool {
187187
pending_monitor_updates_lock.iter().any(|update_id|
188188
if let UpdateOrigin::OffChain(_) = update_id.contents { true } else { false })
@@ -197,12 +197,12 @@ impl<ChannelSigner: Sign> MonitorHolder<ChannelSigner> {
197197
///
198198
/// Note that this holds a mutex in [`ChainMonitor`] and may block other events until it is
199199
/// released.
200-
pub struct LockedChannelMonitor<'a, ChannelSigner: Sign> {
200+
pub struct LockedChannelMonitor<'a, ChannelSigner: WriteableEcdsaChannelSigner> {
201201
lock: RwLockReadGuard<'a, HashMap<OutPoint, MonitorHolder<ChannelSigner>>>,
202202
funding_txo: OutPoint,
203203
}
204204

205-
impl<ChannelSigner: Sign> Deref for LockedChannelMonitor<'_, ChannelSigner> {
205+
impl<ChannelSigner: WriteableEcdsaChannelSigner> Deref for LockedChannelMonitor<'_, ChannelSigner> {
206206
type Target = ChannelMonitor<ChannelSigner>;
207207
fn deref(&self) -> &ChannelMonitor<ChannelSigner> {
208208
&self.lock.get(&self.funding_txo).expect("Checked at construction").monitor
@@ -218,7 +218,7 @@ impl<ChannelSigner: Sign> Deref for LockedChannelMonitor<'_, ChannelSigner> {
218218
///
219219
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
220220
/// [module-level documentation]: crate::chain::chainmonitor
221-
pub struct ChainMonitor<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
221+
pub struct ChainMonitor<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
222222
where C::Target: chain::Filter,
223223
T::Target: BroadcasterInterface,
224224
F::Target: FeeEstimator,
@@ -242,7 +242,7 @@ pub struct ChainMonitor<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: De
242242
highest_chain_height: AtomicUsize,
243243
}
244244

245-
impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> ChainMonitor<ChannelSigner, C, T, F, L, P>
245+
impl<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> ChainMonitor<ChannelSigner, C, T, F, L, P>
246246
where C::Target: chain::Filter,
247247
T::Target: BroadcasterInterface,
248248
F::Target: FeeEstimator,
@@ -516,7 +516,7 @@ where C::Target: chain::Filter,
516516
}
517517
}
518518

519-
impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
519+
impl<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
520520
chain::Listen for ChainMonitor<ChannelSigner, C, T, F, L, P>
521521
where
522522
C::Target: chain::Filter,
@@ -543,7 +543,7 @@ where
543543
}
544544
}
545545

546-
impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
546+
impl<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
547547
chain::Confirm for ChainMonitor<ChannelSigner, C, T, F, L, P>
548548
where
549549
C::Target: chain::Filter,
@@ -592,7 +592,7 @@ where
592592
}
593593
}
594594

595-
impl<ChannelSigner: Sign, C: Deref , T: Deref , F: Deref , L: Deref , P: Deref >
595+
impl<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref , T: Deref , F: Deref , L: Deref , P: Deref >
596596
chain::Watch<ChannelSigner> for ChainMonitor<ChannelSigner, C, T, F, L, P>
597597
where C::Target: chain::Filter,
598598
T::Target: BroadcasterInterface,
@@ -735,7 +735,7 @@ where C::Target: chain::Filter,
735735
}
736736
}
737737

738-
impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> events::EventsProvider for ChainMonitor<ChannelSigner, C, T, F, L, P>
738+
impl<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> events::EventsProvider for ChainMonitor<ChannelSigner, C, T, F, L, P>
739739
where C::Target: chain::Filter,
740740
T::Target: BroadcasterInterface,
741741
F::Target: FeeEstimator,

lightning/src/chain/channelmonitor.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use crate::chain;
4242
use crate::chain::{BestBlock, WatchedOutput};
4343
use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator, LowerBoundedFeeEstimator};
4444
use crate::chain::transaction::{OutPoint, TransactionData};
45-
use crate::chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, Sign, SignerProvider, EntropySource};
45+
use crate::chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, WriteableEcdsaChannelSigner, SignerProvider, EntropySource};
4646
#[cfg(anchors)]
4747
use crate::chain::onchaintx::ClaimEvent;
4848
use crate::chain::onchaintx::OnchainTxHandler;
@@ -706,14 +706,14 @@ impl Readable for IrrevocablyResolvedHTLC {
706706
/// the "reorg path" (ie disconnecting blocks until you find a common ancestor from both the
707707
/// returned block hash and the the current chain and then reconnecting blocks to get to the
708708
/// best chain) upon deserializing the object!
709-
pub struct ChannelMonitor<Signer: Sign> {
709+
pub struct ChannelMonitor<Signer: WriteableEcdsaChannelSigner> {
710710
#[cfg(test)]
711711
pub(crate) inner: Mutex<ChannelMonitorImpl<Signer>>,
712712
#[cfg(not(test))]
713713
inner: Mutex<ChannelMonitorImpl<Signer>>,
714714
}
715715

716-
pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
716+
pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
717717
latest_update_id: u64,
718718
commitment_transaction_number_obscure_factor: u64,
719719

@@ -857,7 +857,7 @@ pub type TransactionOutputs = (Txid, Vec<(u32, TxOut)>);
857857
#[cfg(any(test, fuzzing, feature = "_test_utils"))]
858858
/// Used only in testing and fuzzing to check serialization roundtrips don't change the underlying
859859
/// object
860-
impl<Signer: Sign> PartialEq for ChannelMonitor<Signer> {
860+
impl<Signer: WriteableEcdsaChannelSigner> PartialEq for ChannelMonitor<Signer> {
861861
fn eq(&self, other: &Self) -> bool {
862862
let inner = self.inner.lock().unwrap();
863863
let other = other.inner.lock().unwrap();
@@ -868,7 +868,7 @@ impl<Signer: Sign> PartialEq for ChannelMonitor<Signer> {
868868
#[cfg(any(test, fuzzing, feature = "_test_utils"))]
869869
/// Used only in testing and fuzzing to check serialization roundtrips don't change the underlying
870870
/// object
871-
impl<Signer: Sign> PartialEq for ChannelMonitorImpl<Signer> {
871+
impl<Signer: WriteableEcdsaChannelSigner> PartialEq for ChannelMonitorImpl<Signer> {
872872
fn eq(&self, other: &Self) -> bool {
873873
if self.latest_update_id != other.latest_update_id ||
874874
self.commitment_transaction_number_obscure_factor != other.commitment_transaction_number_obscure_factor ||
@@ -912,7 +912,7 @@ impl<Signer: Sign> PartialEq for ChannelMonitorImpl<Signer> {
912912
}
913913
}
914914

915-
impl<Signer: Sign> Writeable for ChannelMonitor<Signer> {
915+
impl<Signer: WriteableEcdsaChannelSigner> Writeable for ChannelMonitor<Signer> {
916916
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
917917
self.inner.lock().unwrap().write(writer)
918918
}
@@ -922,7 +922,7 @@ impl<Signer: Sign> Writeable for ChannelMonitor<Signer> {
922922
const SERIALIZATION_VERSION: u8 = 1;
923923
const MIN_SERIALIZATION_VERSION: u8 = 1;
924924

925-
impl<Signer: Sign> Writeable for ChannelMonitorImpl<Signer> {
925+
impl<Signer: WriteableEcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
926926
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
927927
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
928928

@@ -1090,7 +1090,7 @@ impl<Signer: Sign> Writeable for ChannelMonitorImpl<Signer> {
10901090
}
10911091
}
10921092

1093-
impl<Signer: Sign> ChannelMonitor<Signer> {
1093+
impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
10941094
/// For lockorder enforcement purposes, we need to have a single site which constructs the
10951095
/// `inner` mutex, otherwise cases where we lock two monitors at the same time (eg in our
10961096
/// PartialEq implementation) we may decide a lockorder violation has occurred.
@@ -1521,7 +1521,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
15211521
}
15221522
}
15231523

1524-
impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1524+
impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
15251525
/// Helper for get_claimable_balances which does the work for an individual HTLC, generating up
15261526
/// to one `Balance` for the HTLC.
15271527
fn get_htlc_balance(&self, htlc: &HTLCOutputInCommitment, holder_commitment: bool,
@@ -1684,7 +1684,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16841684
}
16851685
}
16861686

1687-
impl<Signer: Sign> ChannelMonitor<Signer> {
1687+
impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
16881688
/// Gets the balances in this channel which are either claimable by us if we were to
16891689
/// force-close the channel now or which are claimable on-chain (possibly awaiting
16901690
/// confirmation).
@@ -2082,7 +2082,7 @@ pub fn deliberately_bogus_accepted_htlc_witness() -> Vec<Vec<u8>> {
20822082
vec![Vec::new(), Vec::new(), Vec::new(), Vec::new(), deliberately_bogus_accepted_htlc_witness_program().into()].into()
20832083
}
20842084

2085-
impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2085+
impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
20862086
/// Inserts a revocation secret into this channel monitor. Prunes old preimages if neither
20872087
/// needed by holder commitment transactions HTCLs nor by counterparty ones. Unless we haven't already seen
20882088
/// counterparty commitment transaction's secret, they are de facto pruned (we can use revocation key).
@@ -3664,7 +3664,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
36643664
}
36653665
}
36663666

3667-
impl<Signer: Sign, T: Deref, F: Deref, L: Deref> chain::Listen for (ChannelMonitor<Signer>, T, F, L)
3667+
impl<Signer: WriteableEcdsaChannelSigner, T: Deref, F: Deref, L: Deref> chain::Listen for (ChannelMonitor<Signer>, T, F, L)
36683668
where
36693669
T::Target: BroadcasterInterface,
36703670
F::Target: FeeEstimator,
@@ -3679,7 +3679,7 @@ where
36793679
}
36803680
}
36813681

3682-
impl<Signer: Sign, T: Deref, F: Deref, L: Deref> chain::Confirm for (ChannelMonitor<Signer>, T, F, L)
3682+
impl<Signer: WriteableEcdsaChannelSigner, T: Deref, F: Deref, L: Deref> chain::Confirm for (ChannelMonitor<Signer>, T, F, L)
36833683
where
36843684
T::Target: BroadcasterInterface,
36853685
F::Target: FeeEstimator,

0 commit comments

Comments
 (0)