@@ -73,7 +73,7 @@ pub(crate) mod fake_scid {
7373 use core:: convert:: TryInto ;
7474 use core:: ops:: Deref ;
7575
76- const TEST_SEGWIT_ACTIVATION_HEIGHT : u32 = 0 ;
76+ const TEST_SEGWIT_ACTIVATION_HEIGHT : u32 = 1 ;
7777 const MAINNET_SEGWIT_ACTIVATION_HEIGHT : u32 = 481_824 ;
7878 const MAX_TX_INDEX : u32 = 2_500 ;
7979 const MAX_NAMESPACES : u8 = 8 ; // We allocate 3 bits for the namespace identifier.
@@ -151,12 +151,13 @@ pub(crate) mod fake_scid {
151151 }
152152
153153 /// Returns whether the given fake scid falls into the given namespace.
154- pub fn is_valid_phantom ( fake_scid_rand_bytes : & [ u8 ; 32 ] , scid : u64 ) -> bool {
154+ pub fn is_valid_phantom ( fake_scid_rand_bytes : & [ u8 ; 32 ] , scid : u64 , genesis_hash : & BlockHash ) -> bool {
155155 let block_height = scid_utils:: block_from_scid ( & scid) ;
156156 let tx_index = scid_utils:: tx_index_from_scid ( & scid) ;
157157 let namespace = Namespace :: Phantom ;
158158 let valid_vout = namespace. get_encrypted_vout ( block_height, tx_index, fake_scid_rand_bytes) ;
159- valid_vout == scid_utils:: vout_from_scid ( & scid) as u8
159+ block_height >= segwit_activation_height ( genesis_hash)
160+ && valid_vout == scid_utils:: vout_from_scid ( & scid) as u8
160161 }
161162
162163 #[ cfg( test) ]
@@ -194,11 +195,12 @@ pub(crate) mod fake_scid {
194195 fn test_is_valid_phantom ( ) {
195196 let namespace = Namespace :: Phantom ;
196197 let fake_scid_rand_bytes = [ 0 ; 32 ] ;
198+ let testnet_genesis = genesis_block ( Network :: Testnet ) . header . block_hash ( ) ;
197199 let valid_encrypted_vout = namespace. get_encrypted_vout ( 0 , 0 , & fake_scid_rand_bytes) ;
198- let valid_fake_scid = scid_utils:: scid_from_parts ( 0 , 0 , valid_encrypted_vout as u64 ) . unwrap ( ) ;
199- assert ! ( is_valid_phantom( & fake_scid_rand_bytes, valid_fake_scid) ) ;
200- let invalid_fake_scid = scid_utils:: scid_from_parts ( 0 , 0 , 12 ) . unwrap ( ) ;
201- assert ! ( !is_valid_phantom( & fake_scid_rand_bytes, invalid_fake_scid) ) ;
200+ let valid_fake_scid = scid_utils:: scid_from_parts ( 1 , 0 , valid_encrypted_vout as u64 ) . unwrap ( ) ;
201+ assert ! ( is_valid_phantom( & fake_scid_rand_bytes, valid_fake_scid, & testnet_genesis ) ) ;
202+ let invalid_fake_scid = scid_utils:: scid_from_parts ( 1 , 0 , 12 ) . unwrap ( ) ;
203+ assert ! ( !is_valid_phantom( & fake_scid_rand_bytes, invalid_fake_scid, & testnet_genesis ) ) ;
202204 }
203205
204206 #[ test]
0 commit comments