Skip to content

Commit b7a6e7f

Browse files
committed
Move get_destination_script and get_shutdown_scriptpubkey from KeysInterface to SignerProvider
1 parent d7e7a0b commit b7a6e7f

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ impl SignerProvider for KeyProvider {
219219
disable_revocation_policy_check: false,
220220
})
221221
}
222-
}
223222

224-
impl KeysInterface for KeyProvider {
225223
fn get_destination_script(&self) -> Script {
226224
let secp_ctx = Secp256k1::signing_only();
227225
let channel_monitor_claim_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, self.node_id]).unwrap();
@@ -237,6 +235,8 @@ impl KeysInterface for KeyProvider {
237235
}
238236
}
239237

238+
impl KeysInterface for KeyProvider {}
239+
240240
impl KeyProvider {
241241
fn make_enforcement_state_cell(&self, commitment_seed: [u8; 32]) -> Arc<Mutex<EnforcementState>> {
242242
let mut revoked_commitments = self.enforcement_states.lock().unwrap();

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,7 @@ impl SignerProvider for KeyProvider {
336336
false
337337
))
338338
}
339-
}
340339

341-
impl KeysInterface for KeyProvider {
342340
fn get_destination_script(&self) -> Script {
343341
let secp_ctx = Secp256k1::signing_only();
344342
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
@@ -354,6 +352,8 @@ impl KeysInterface for KeyProvider {
354352
}
355353
}
356354

355+
impl KeysInterface for KeyProvider {}
356+
357357
#[inline]
358358
pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
359359
let input = Arc::new(InputData {

fuzz/src/onion_message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ impl SignerProvider for KeyProvider {
117117
}
118118

119119
fn read_chan_signer(&self, _data: &[u8]) -> Result<EnforcingSigner, DecodeError> { unreachable!() }
120-
}
121120

122-
impl KeysInterface for KeyProvider {
123121
fn get_destination_script(&self) -> Script { unreachable!() }
124122

125123
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { unreachable!() }
126124
}
127125

126+
impl KeysInterface for KeyProvider {}
127+
128128
#[cfg(test)]
129129
mod tests {
130130
use lightning::util::logger::{Logger, Record};

lightning/src/chain/keysinterface.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,7 @@ pub trait SignerProvider {
543543
/// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
544544
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
545545
fn read_chan_signer(&self, reader: &[u8]) -> Result<Self::Signer, DecodeError>;
546-
}
547546

548-
/// A trait to describe an object which can get user secrets and key material.
549-
pub trait KeysInterface: EntropySource + NodeSigner + SignerProvider {
550547
/// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
551548
///
552549
/// This method should return a different value each time it is called, to avoid linking
@@ -560,6 +557,9 @@ pub trait KeysInterface: EntropySource + NodeSigner + SignerProvider {
560557
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript;
561558
}
562559

560+
/// A trait to describe an object which can get user secrets and key material.
561+
pub trait KeysInterface: EntropySource + NodeSigner + SignerProvider {}
562+
563563
#[derive(Clone)]
564564
/// A simple implementation of [`Sign`] that just keeps the private keys in memory.
565565
///
@@ -1300,9 +1300,7 @@ impl SignerProvider for KeysManager {
13001300
fn read_chan_signer(&self, reader: &[u8]) -> Result<Self::Signer, DecodeError> {
13011301
InMemorySigner::read(&mut io::Cursor::new(reader), self.node_secret.clone())
13021302
}
1303-
}
13041303

1305-
impl KeysInterface for KeysManager {
13061304
fn get_destination_script(&self) -> Script {
13071305
self.destination_script.clone()
13081306
}
@@ -1312,6 +1310,8 @@ impl KeysInterface for KeysManager {
13121310
}
13131311
}
13141312

1313+
impl KeysInterface for KeysManager {}
1314+
13151315
/// Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
13161316
/// payments.
13171317
///
@@ -1379,9 +1379,7 @@ impl SignerProvider for PhantomKeysManager {
13791379
fn read_chan_signer(&self, reader: &[u8]) -> Result<Self::Signer, DecodeError> {
13801380
self.inner.read_chan_signer(reader)
13811381
}
1382-
}
13831382

1384-
impl KeysInterface for PhantomKeysManager {
13851383
fn get_destination_script(&self) -> Script {
13861384
self.inner.get_destination_script()
13871385
}
@@ -1391,6 +1389,9 @@ impl KeysInterface for PhantomKeysManager {
13911389
}
13921390
}
13931391

1392+
impl KeysInterface for PhantomKeysManager {
1393+
}
1394+
13941395
impl PhantomKeysManager {
13951396
/// Constructs a [`PhantomKeysManager`] given a 32-byte seed and an additional `cross_node_seed`
13961397
/// that is shared across all nodes that intend to participate in [phantom node payments]

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6874,9 +6874,7 @@ mod tests {
68746874
}
68756875

68766876
fn read_chan_signer(&self, _data: &[u8]) -> Result<Self::Signer, DecodeError> { panic!(); }
6877-
}
68786877

6879-
impl KeysInterface for Keys {
68806878
fn get_destination_script(&self) -> Script {
68816879
let secp_ctx = Secp256k1::signing_only();
68826880
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
@@ -6891,6 +6889,8 @@ mod tests {
68916889
}
68926890
}
68936891

6892+
impl KeysInterface for Keys {}
6893+
68946894
#[cfg(not(feature = "grind_signatures"))]
68956895
fn public_from_secret_hex(secp_ctx: &Secp256k1<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
68966896
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode(hex).unwrap()[..]).unwrap())

lightning/src/ln/shutdown_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
//! Tests of our shutdown and closing_signed negotiation logic.
1111
12-
use crate::chain::keysinterface::{EntropySource, KeysInterface};
12+
use crate::chain::keysinterface::{EntropySource, KeysInterface, SignerProvider};
1313
use crate::chain::transaction::OutPoint;
1414
use crate::ln::channelmanager::{self, PaymentSendFailure, PaymentId};
1515
use crate::routing::router::{PaymentParameters, get_route};

lightning/src/util/test_utils.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ impl SignerProvider for OnlyReadsKeysInterface {
9999
false
100100
))
101101
}
102-
}
103102

104-
impl keysinterface::KeysInterface for OnlyReadsKeysInterface {
105103
fn get_destination_script(&self) -> Script { unreachable!(); }
106104
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { unreachable!(); }
107105
}
108106

107+
impl keysinterface::KeysInterface for OnlyReadsKeysInterface {
108+
}
109+
109110
pub struct TestChainMonitor<'a> {
110111
pub added_monitors: Mutex<Vec<(OutPoint, channelmonitor::ChannelMonitor<EnforcingSigner>)>>,
111112
pub monitor_updates: Mutex<HashMap<[u8; 32], Vec<channelmonitor::ChannelMonitorUpdate>>>,
@@ -660,9 +661,7 @@ impl SignerProvider for TestKeysInterface {
660661
self.disable_revocation_policy_check
661662
))
662663
}
663-
}
664664

665-
impl keysinterface::KeysInterface for TestKeysInterface {
666665
fn get_destination_script(&self) -> Script { self.backing.get_destination_script() }
667666

668667
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript {
@@ -676,6 +675,8 @@ impl keysinterface::KeysInterface for TestKeysInterface {
676675
}
677676
}
678677

678+
impl keysinterface::KeysInterface for TestKeysInterface {}
679+
679680
impl TestKeysInterface {
680681
pub fn new(seed: &[u8; 32], network: Network) -> Self {
681682
let now = Duration::from_secs(genesis_block(network).header.time as u64);

0 commit comments

Comments
 (0)