@@ -1027,7 +1027,6 @@ pub trait ChangeDestinationSource {
10271027///
10281028/// This implementation performs no policy checks and is insufficient by itself as
10291029/// a secure external signer.
1030- #[ derive( Debug ) ]
10311030pub struct InMemorySigner {
10321031 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
10331032 /// holder's anchor output in a commitment transaction, if one is present.
@@ -1854,6 +1853,9 @@ pub struct KeysManager {
18541853 channel_master_key : Xpriv ,
18551854 channel_child_index : AtomicUsize ,
18561855
1856+ #[ cfg( test) ]
1857+ pub ( crate ) entropy_source : RandomBytes ,
1858+ #[ cfg( not( test) ) ]
18571859 entropy_source : RandomBytes ,
18581860
18591861 seed : [ u8 ; 32 ] ,
@@ -2310,6 +2312,9 @@ impl SignerProvider for KeysManager {
23102312/// Switching between this struct and [`KeysManager`] will invalidate any previously issued
23112313/// invoices and attempts to pay previous invoices will fail.
23122314pub struct PhantomKeysManager {
2315+ #[ cfg( test) ]
2316+ pub ( crate ) inner : KeysManager ,
2317+ #[ cfg( not( test) ) ]
23132318 inner : KeysManager ,
23142319 inbound_payment_key : KeyMaterial ,
23152320 phantom_secret : SecretKey ,
@@ -2475,7 +2480,6 @@ impl PhantomKeysManager {
24752480}
24762481
24772482/// An implementation of [`EntropySource`] using ChaCha20.
2478- #[ derive( Debug ) ]
24792483pub struct RandomBytes {
24802484 /// Seed from which all randomness produced is derived from.
24812485 seed : [ u8 ; 32 ] ,
@@ -2489,11 +2493,18 @@ impl RandomBytes {
24892493 pub fn new ( seed : [ u8 ; 32 ] ) -> Self {
24902494 Self { seed, index : AtomicCounter :: new ( ) }
24912495 }
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+ }
24922503}
24932504
24942505impl EntropySource for RandomBytes {
24952506 fn get_secure_random_bytes ( & self ) -> [ u8 ; 32 ] {
2496- let index = self . index . get_increment ( ) ;
2507+ let index = self . index . next ( ) ;
24972508 let mut nonce = [ 0u8 ; 16 ] ;
24982509 nonce[ ..8 ] . copy_from_slice ( & index. to_be_bytes ( ) ) ;
24992510 ChaCha20 :: get_single_block ( & self . seed , & nonce)
0 commit comments