@@ -1027,7 +1027,6 @@ pub trait ChangeDestinationSource {
1027
1027
///
1028
1028
/// This implementation performs no policy checks and is insufficient by itself as
1029
1029
/// a secure external signer.
1030
- #[ derive( Debug ) ]
1031
1030
pub struct InMemorySigner {
1032
1031
/// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1033
1032
/// holder's anchor output in a commitment transaction, if one is present.
@@ -1854,6 +1853,9 @@ pub struct KeysManager {
1854
1853
channel_master_key : Xpriv ,
1855
1854
channel_child_index : AtomicUsize ,
1856
1855
1856
+ #[ cfg( test) ]
1857
+ pub ( crate ) entropy_source : RandomBytes ,
1858
+ #[ cfg( not( test) ) ]
1857
1859
entropy_source : RandomBytes ,
1858
1860
1859
1861
seed : [ u8 ; 32 ] ,
@@ -2310,6 +2312,9 @@ impl SignerProvider for KeysManager {
2310
2312
/// Switching between this struct and [`KeysManager`] will invalidate any previously issued
2311
2313
/// invoices and attempts to pay previous invoices will fail.
2312
2314
pub struct PhantomKeysManager {
2315
+ #[ cfg( test) ]
2316
+ pub ( crate ) inner : KeysManager ,
2317
+ #[ cfg( not( test) ) ]
2313
2318
inner : KeysManager ,
2314
2319
inbound_payment_key : KeyMaterial ,
2315
2320
phantom_secret : SecretKey ,
@@ -2475,7 +2480,6 @@ impl PhantomKeysManager {
2475
2480
}
2476
2481
2477
2482
/// An implementation of [`EntropySource`] using ChaCha20.
2478
- #[ derive( Debug ) ]
2479
2483
pub struct RandomBytes {
2480
2484
/// Seed from which all randomness produced is derived from.
2481
2485
seed : [ u8 ; 32 ] ,
@@ -2489,11 +2493,18 @@ impl RandomBytes {
2489
2493
pub fn new ( seed : [ u8 ; 32 ] ) -> Self {
2490
2494
Self { seed, index : AtomicCounter :: new ( ) }
2491
2495
}
2496
+
2497
+ #[ cfg( test) ]
2498
+ /// Force the counter to a value to produce the same output again. Mostly useful in tests where
2499
+ /// we need to maintain behavior with a previous version which didn't use as much RNG output.
2500
+ pub ( crate ) fn set_counter ( & self , count : u64 ) {
2501
+ self . index . set_counter ( count) ;
2502
+ }
2492
2503
}
2493
2504
2494
2505
impl EntropySource for RandomBytes {
2495
2506
fn get_secure_random_bytes ( & self ) -> [ u8 ; 32 ] {
2496
- let index = self . index . get_increment ( ) ;
2507
+ let index = self . index . next ( ) ;
2497
2508
let mut nonce = [ 0u8 ; 16 ] ;
2498
2509
nonce[ ..8 ] . copy_from_slice ( & index. to_be_bytes ( ) ) ;
2499
2510
ChaCha20 :: get_single_block ( & self . seed , & nonce)
0 commit comments