Skip to content

Commit

Permalink
Remove KeysInterface trait.
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed Jan 12, 2023
1 parent 5221e4a commit 5824e22
Show file tree
Hide file tree
Showing 30 changed files with 98 additions and 119 deletions.
4 changes: 1 addition & 3 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, chainmonitor, chan
use lightning::chain::channelmonitor::{ChannelMonitor, MonitorEvent};
use lightning::chain::transaction::OutPoint;
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
use lightning::chain::keysinterface::{KeyMaterial, KeysInterface, InMemorySigner, Recipient, EntropySource, NodeSigner, SignerProvider};
use lightning::chain::keysinterface::{KeyMaterial, InMemorySigner, Recipient, EntropySource, NodeSigner, SignerProvider};
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::ln::channelmanager::{self, ChainParameters, ChannelDetails, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs, PaymentId};
use lightning::ln::channel::FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
Expand Down Expand Up @@ -270,8 +270,6 @@ impl SignerProvider for KeyProvider {
}
}

impl KeysInterface for KeyProvider {}

impl KeyProvider {
fn make_enforcement_state_cell(&self, commitment_seed: [u8; 32]) -> Arc<Mutex<EnforcementState>> {
let mut revoked_commitments = self.enforcement_states.lock().unwrap();
Expand Down
6 changes: 2 additions & 4 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen};
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
use lightning::chain::chainmonitor;
use lightning::chain::transaction::OutPoint;
use lightning::chain::keysinterface::{InMemorySigner, Recipient, KeyMaterial, KeysInterface, EntropySource, NodeSigner, SignerProvider};
use lightning::chain::keysinterface::{InMemorySigner, Recipient, KeyMaterial, EntropySource, NodeSigner, SignerProvider};
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, PaymentId};
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor,IgnoringMessageHandler};
Expand Down Expand Up @@ -387,8 +387,6 @@ impl SignerProvider for KeyProvider {
}
}

impl KeysInterface for KeyProvider {}

#[inline]
pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
let input = Arc::new(InputData {
Expand Down Expand Up @@ -444,7 +442,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
best_block: BestBlock::from_genesis(network),
};
let channelmanager = Arc::new(ChannelManager::new(fee_est.clone(), monitor.clone(), broadcast.clone(), &router, Arc::clone(&logger), keys_manager.clone(), config, params));
// Adding new calls to `KeysInterface::get_secure_random_bytes` during startup can change all the
// Adding new calls to `EntropySource::get_secure_random_bytes` during startup can change all the
// keys subsequently generated in this test. Rather than regenerating all the messages manually,
// it's easier to just increment the counter here so the keys don't change.
keys_manager.counter.fetch_sub(3, Ordering::AcqRel);
Expand Down
4 changes: 1 addition & 3 deletions fuzz/src/onion_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey};
use bitcoin::secp256k1::ecdh::SharedSecret;
use bitcoin::secp256k1::ecdsa::RecoverableSignature;

use lightning::chain::keysinterface::{Recipient, KeyMaterial, KeysInterface, EntropySource, NodeSigner, SignerProvider};
use lightning::chain::keysinterface::{Recipient, KeyMaterial, EntropySource, NodeSigner, SignerProvider};
use lightning::ln::msgs::{self, DecodeError, OnionMessageHandler};
use lightning::ln::script::ShutdownScript;
use lightning::util::enforcing_trait_impls::EnforcingSigner;
Expand Down Expand Up @@ -140,8 +140,6 @@ impl SignerProvider for KeyProvider {
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { unreachable!() }
}

impl KeysInterface for KeyProvider {}

#[cfg(test)]
mod tests {
use lightning::util::logger::{Logger, Record};
Expand Down
8 changes: 4 additions & 4 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern crate lightning_rapid_gossip_sync;
use lightning::chain;
use lightning::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
use lightning::chain::chainmonitor::{ChainMonitor, Persist};
use lightning::chain::keysinterface::{KeysInterface, SignerProvider};
use lightning::chain::keysinterface::{EntropySource, NodeSigner, SignerProvider};
use lightning::ln::channelmanager::ChannelManager;
use lightning::ln::msgs::{ChannelMessageHandler, OnionMessageHandler, RoutingMessageHandler};
use lightning::ln::peer_handler::{CustomMessageHandler, PeerManager, SocketDescriptor};
Expand Down Expand Up @@ -374,7 +374,7 @@ where
CF::Target: 'static + chain::Filter,
CW::Target: 'static + chain::Watch<<K::Target as SignerProvider>::Signer>,
T::Target: 'static + BroadcasterInterface,
K::Target: 'static + KeysInterface,
K::Target: 'static + EntropySource + NodeSigner + SignerProvider,
F::Target: 'static + FeeEstimator,
R::Target: 'static + Router,
L::Target: 'static + Logger,
Expand Down Expand Up @@ -490,7 +490,7 @@ impl BackgroundProcessor {
CF::Target: 'static + chain::Filter,
CW::Target: 'static + chain::Watch<<K::Target as SignerProvider>::Signer>,
T::Target: 'static + BroadcasterInterface,
K::Target: 'static + KeysInterface,
K::Target: 'static + EntropySource + NodeSigner + SignerProvider,
F::Target: 'static + FeeEstimator,
R::Target: 'static + Router,
L::Target: 'static + Logger,
Expand Down Expand Up @@ -575,7 +575,7 @@ mod tests {
use bitcoin::network::constants::Network;
use lightning::chain::{BestBlock, Confirm, chainmonitor};
use lightning::chain::channelmonitor::ANTI_REORG_DELAY;
use lightning::chain::keysinterface::{InMemorySigner, Recipient, EntropySource, KeysInterface, KeysManager, NodeSigner};
use lightning::chain::keysinterface::{InMemorySigner, Recipient, EntropySource, KeysManager, NodeSigner};
use lightning::chain::transaction::OutPoint;
use lightning::get_event_msg;
use lightning::ln::channelmanager::{self, BREAKDOWN_TIMEOUT, ChainParameters, ChannelManager, SimpleArcChannelManager};
Expand Down
4 changes: 2 additions & 2 deletions lightning-block-sync/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ BlockSourceResult<ValidatedBlockHeader> where B::Target: BlockSource {
/// use lightning::chain::chaininterface::BroadcasterInterface;
/// use lightning::chain::chaininterface::FeeEstimator;
/// use lightning::chain::keysinterface;
/// use lightning::chain::keysinterface::KeysInterface;
/// use lightning::chain::keysinterface::{EntropySource, NodeSigner, SignerProvider};
/// use lightning::ln::channelmanager::{ChannelManager, ChannelManagerReadArgs};
/// use lightning::routing::router::Router;
/// use lightning::util::config::UserConfig;
Expand All @@ -61,7 +61,7 @@ BlockSourceResult<ValidatedBlockHeader> where B::Target: BlockSource {
///
/// async fn init_sync<
/// B: BlockSource,
/// K: KeysInterface,
/// K: EntropySource + NodeSigner + SignerProvider,
/// T: BroadcasterInterface,
/// F: FeeEstimator,
/// R: Router,
Expand Down
29 changes: 14 additions & 15 deletions lightning-invoice/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bech32::ToBase32;
use bitcoin_hashes::Hash;
use lightning::chain;
use lightning::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
use lightning::chain::keysinterface::{Recipient, KeysInterface, NodeSigner, SignerProvider};
use lightning::chain::keysinterface::{Recipient, NodeSigner, SignerProvider, EntropySource};
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::ln::channelmanager::{ChannelDetails, ChannelManager, PaymentId, PaymentSendFailure, MIN_FINAL_CLTV_EXPIRY};
#[cfg(feature = "std")]
Expand Down Expand Up @@ -42,7 +42,7 @@ use core::time::Duration;
/// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
/// in excess of the current time.
///
/// Note that the provided `keys_manager`'s `KeysInterface` implementation must support phantom
/// Note that the provided `keys_manager`'s `NodeSigner` implementation must support phantom
/// invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this
/// requirement).
///
Expand All @@ -57,7 +57,7 @@ pub fn create_phantom_invoice<K: Deref, L: Deref>(
logger: L, network: Currency,
) -> Result<Invoice, SignOrCreationError<()>>
where
K::Target: KeysInterface,
K::Target: EntropySource + NodeSigner,
L::Target: Logger,
{
let description = Description::new(description).map_err(SignOrCreationError::CreationError)?;
Expand Down Expand Up @@ -91,7 +91,7 @@ where
/// `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
/// in excess of the current time.
///
/// Note that the provided `keys_manager`'s `KeysInterface` implementation must support phantom
/// Note that the provided `keys_manager`'s `NodeSigner` implementation must support phantom
/// invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this
/// requirement).
///
Expand All @@ -106,7 +106,7 @@ pub fn create_phantom_invoice_with_description_hash<K: Deref, L: Deref>(
logger: L, network: Currency
) -> Result<Invoice, SignOrCreationError<()>>
where
K::Target: KeysInterface,
K::Target: EntropySource + NodeSigner,
L::Target: Logger,
{
_create_phantom_invoice::<K, L>(
Expand All @@ -122,7 +122,7 @@ fn _create_phantom_invoice<K: Deref, L: Deref>(
logger: L, network: Currency,
) -> Result<Invoice, SignOrCreationError<()>>
where
K::Target: KeysInterface,
K::Target: EntropySource + NodeSigner,
L::Target: Logger,
{
use std::time::{SystemTime, UNIX_EPOCH};
Expand Down Expand Up @@ -239,7 +239,7 @@ pub fn create_invoice_from_channelmanager<M: Deref, T: Deref, K: Deref, F: Deref
where
M::Target: chain::Watch<<K::Target as SignerProvider>::Signer>,
T::Target: BroadcasterInterface,
K::Target: KeysInterface,
K::Target: EntropySource + NodeSigner + SignerProvider,
F::Target: FeeEstimator,
R::Target: Router,
L::Target: Logger,
Expand Down Expand Up @@ -271,7 +271,7 @@ pub fn create_invoice_from_channelmanager_with_description_hash<M: Deref, T: Der
where
M::Target: chain::Watch<<K::Target as SignerProvider>::Signer>,
T::Target: BroadcasterInterface,
K::Target: KeysInterface,
K::Target: EntropySource + NodeSigner + SignerProvider,
F::Target: FeeEstimator,
R::Target: Router,
L::Target: Logger,
Expand Down Expand Up @@ -299,7 +299,7 @@ pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_sin
where
M::Target: chain::Watch<<K::Target as SignerProvider>::Signer>,
T::Target: BroadcasterInterface,
K::Target: KeysInterface,
K::Target: EntropySource + NodeSigner + SignerProvider,
F::Target: FeeEstimator,
R::Target: Router,
L::Target: Logger,
Expand All @@ -322,7 +322,7 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T:
where
M::Target: chain::Watch<<K::Target as SignerProvider>::Signer>,
T::Target: BroadcasterInterface,
K::Target: KeysInterface,
K::Target: EntropySource + NodeSigner + SignerProvider,
F::Target: FeeEstimator,
R::Target: Router,
L::Target: Logger,
Expand All @@ -344,7 +344,7 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T: Der
where
M::Target: chain::Watch<<K::Target as SignerProvider>::Signer>,
T::Target: BroadcasterInterface,
K::Target: KeysInterface,
K::Target: EntropySource + NodeSigner + SignerProvider,
F::Target: FeeEstimator,
R::Target: Router,
L::Target: Logger,
Expand All @@ -370,7 +370,7 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_
where
M::Target: chain::Watch<<K::Target as SignerProvider>::Signer>,
T::Target: BroadcasterInterface,
K::Target: KeysInterface,
K::Target: EntropySource + NodeSigner + SignerProvider,
F::Target: FeeEstimator,
R::Target: Router,
L::Target: Logger,
Expand All @@ -395,7 +395,7 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
where
M::Target: chain::Watch<<K::Target as SignerProvider>::Signer>,
T::Target: BroadcasterInterface,
K::Target: KeysInterface,
K::Target: EntropySource + NodeSigner + SignerProvider,
F::Target: FeeEstimator,
R::Target: Router,
L::Target: Logger,
Expand Down Expand Up @@ -576,7 +576,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, R: Deref, L: Deref> Payer for Chann
where
M::Target: chain::Watch<<K::Target as SignerProvider>::Signer>,
T::Target: BroadcasterInterface,
K::Target: KeysInterface,
K::Target: EntropySource + NodeSigner + SignerProvider,
F::Target: FeeEstimator,
R::Target: Router,
L::Target: Logger,
Expand Down Expand Up @@ -630,7 +630,6 @@ mod test {
use lightning::util::events::{MessageSendEvent, MessageSendEventsProvider, Event};
use lightning::util::test_utils;
use lightning::util::config::UserConfig;
use lightning::chain::keysinterface::KeysInterface;
use crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch;
use std::collections::HashSet;

Expand Down
4 changes: 2 additions & 2 deletions lightning-persister/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern crate libc;
use bitcoin::hash_types::{BlockHash, Txid};
use bitcoin::hashes::hex::FromHex;
use lightning::chain::channelmonitor::ChannelMonitor;
use lightning::chain::keysinterface::{KeysInterface, SignerProvider};
use lightning::chain::keysinterface::{EntropySource, SignerProvider};
use lightning::util::ser::{ReadableArgs, Writeable};
use lightning::util::persist::KVStorePersister;
use std::fs;
Expand Down Expand Up @@ -62,7 +62,7 @@ impl FilesystemPersister {
pub fn read_channelmonitors<K: Deref> (
&self, keys_manager: K
) -> std::io::Result<Vec<(BlockHash, ChannelMonitor<<K::Target as SignerProvider>::Signer>)>>
where K::Target: KeysInterface + Sized,
where K::Target: EntropySource + SignerProvider + Sized,
{
let mut path = PathBuf::from(&self.path_to_channel_data);
path.push("monitors");
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use crate::chain;
use crate::chain::{BestBlock, WatchedOutput};
use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator, LowerBoundedFeeEstimator};
use crate::chain::transaction::{OutPoint, TransactionData};
use crate::chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, Sign, KeysInterface};
use crate::chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, Sign, SignerProvider, EntropySource};
#[cfg(anchors)]
use crate::chain::onchaintx::ClaimEvent;
use crate::chain::onchaintx::OnchainTxHandler;
Expand Down Expand Up @@ -3704,7 +3704,7 @@ where

const MAX_ALLOC_SIZE: usize = 64*1024;

impl<'a, K: KeysInterface> ReadableArgs<&'a K>
impl<'a, K: EntropySource + SignerProvider> ReadableArgs<&'a K>
for (BlockHash, ChannelMonitor<K::Signer>) {
fn read<R: io::Read>(reader: &mut R, keys_manager: &'a K) -> Result<Self, DecodeError> {
macro_rules! unwrap_obj {
Expand Down
15 changes: 4 additions & 11 deletions lightning/src/chain/keysinterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl_writeable_tlv_based!(StaticPaymentOutputDescriptor, {
/// [`SpendableOutputs`]: crate::util::events::Event::SpendableOutputs
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SpendableOutputDescriptor {
/// An output to a script which was provided via [`KeysInterface`] directly, either from
/// An output to a script which was provided via [`SignerProvider`] directly, either from
/// [`get_destination_script`] or [`get_shutdown_scriptpubkey`], thus you should already
/// know how to spend it. No secret keys are provided as LDK was never given any key.
/// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
Expand Down Expand Up @@ -517,7 +517,7 @@ pub trait SignerProvider {
/// [`BaseSign::channel_keys_id`].
fn derive_channel_signer(&self, channel_value_satoshis: u64, channel_keys_id: [u8; 32]) -> Self::Signer;

/// Reads a [`Signer`] for this [`KeysInterface`] from the given input stream.
/// Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
/// This is only called during deserialization of other objects which contain
/// [`Sign`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
/// The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
Expand Down Expand Up @@ -545,9 +545,6 @@ pub trait SignerProvider {
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript;
}

/// A trait to describe an object which can get user secrets and key material.
pub trait KeysInterface: EntropySource + NodeSigner + SignerProvider {}

#[derive(Clone)]
/// A simple implementation of [`Sign`] that just keeps the private keys in memory.
///
Expand Down Expand Up @@ -954,8 +951,8 @@ impl ReadableArgs<SecretKey> for InMemorySigner {
}
}

/// Simple [`KeysInterface`] implementation that takes a 32-byte seed for use as a BIP 32 extended
/// key and derives keys from that.
/// Simple implementation of [`EntropySource`], [`NodeSigner`], and [`SignerProvider`] that takes a
/// 32-byte seed for use as a BIP 32 extended key and derives keys from that.
///
/// Your `node_id` is seed/0'.
/// Unilateral closes may use seed/1'.
Expand Down Expand Up @@ -1331,8 +1328,6 @@ impl SignerProvider for KeysManager {
}
}

impl KeysInterface for KeysManager {}

/// Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
/// payments.
///
Expand Down Expand Up @@ -1425,8 +1420,6 @@ impl SignerProvider for PhantomKeysManager {
}
}

impl KeysInterface for PhantomKeysManager {}

impl PhantomKeysManager {
/// Constructs a [`PhantomKeysManager`] given a 32-byte seed and an additional `cross_node_seed`
/// that is shared across all nodes that intend to participate in [phantom node payments]
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/chain/onchaintx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use bitcoin::hash_types::{Txid, BlockHash};
use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature};
use bitcoin::secp256k1;

use crate::chain::keysinterface::BaseSign;
use crate::chain::keysinterface::{BaseSign, EntropySource, SignerProvider};
use crate::ln::msgs::DecodeError;
use crate::ln::PaymentPreimage;
#[cfg(anchors)]
Expand All @@ -31,7 +31,7 @@ use crate::ln::chan_utils::{ChannelTransactionParameters, HolderCommitmentTransa
use crate::chain::chaininterface::ConfirmationTarget;
use crate::chain::chaininterface::{FeeEstimator, BroadcasterInterface, LowerBoundedFeeEstimator};
use crate::chain::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER};
use crate::chain::keysinterface::{Sign, KeysInterface};
use crate::chain::keysinterface::Sign;
#[cfg(anchors)]
use crate::chain::package::PackageSolvingData;
use crate::chain::package::PackageTemplate;
Expand Down Expand Up @@ -322,7 +322,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
}
}

impl<'a, K: KeysInterface> ReadableArgs<(&'a K, u64, [u8; 32])> for OnchainTxHandler<K::Signer> {
impl<'a, K: EntropySource + SignerProvider> ReadableArgs<(&'a K, u64, [u8; 32])> for OnchainTxHandler<K::Signer> {
fn read<R: io::Read>(reader: &mut R, args: (&'a K, u64, [u8; 32])) -> Result<Self, DecodeError> {
let keys_manager = args.0;
let channel_value_satoshis = args.1;
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ mod tests {
use crate::ln::chan_utils::{get_htlc_redeemscript, get_to_countersignatory_with_anchors_redeemscript, CommitmentTransaction, TxCreationKeys, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, HTLCOutputInCommitment};
use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1};
use crate::util::test_utils;
use crate::chain::keysinterface::{KeysInterface, BaseSign, SignerProvider};
use crate::chain::keysinterface::{BaseSign, SignerProvider};
use bitcoin::{Network, Txid};
use bitcoin::hashes::Hash;
use crate::ln::PaymentHash;
Expand Down
Loading

0 comments on commit 5824e22

Please sign in to comment.