@@ -73,7 +73,7 @@ pub(crate) mod fake_scid {
73
73
use core:: convert:: TryInto ;
74
74
use core:: ops:: Deref ;
75
75
76
- const TEST_SEGWIT_ACTIVATION_HEIGHT : u32 = 0 ;
76
+ const TEST_SEGWIT_ACTIVATION_HEIGHT : u32 = 1 ;
77
77
const MAINNET_SEGWIT_ACTIVATION_HEIGHT : u32 = 481_824 ;
78
78
const MAX_TX_INDEX : u32 = 2_500 ;
79
79
const MAX_NAMESPACES : u8 = 8 ; // We allocate 3 bits for the namespace identifier.
@@ -151,12 +151,13 @@ pub(crate) mod fake_scid {
151
151
}
152
152
153
153
/// 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 {
155
155
let block_height = scid_utils:: block_from_scid ( & scid) ;
156
156
let tx_index = scid_utils:: tx_index_from_scid ( & scid) ;
157
157
let namespace = Namespace :: Phantom ;
158
158
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
160
161
}
161
162
162
163
#[ cfg( test) ]
@@ -194,11 +195,12 @@ pub(crate) mod fake_scid {
194
195
fn test_is_valid_phantom ( ) {
195
196
let namespace = Namespace :: Phantom ;
196
197
let fake_scid_rand_bytes = [ 0 ; 32 ] ;
198
+ let testnet_genesis = genesis_block ( Network :: Testnet ) . header . block_hash ( ) ;
197
199
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 ) ) ;
202
204
}
203
205
204
206
#[ test]
0 commit comments