File tree Expand file tree Collapse file tree 1 file changed +14
-15
lines changed
base_layer/core/src/validation Expand file tree Collapse file tree 1 file changed +14
-15
lines changed Original file line number Diff line number Diff line change @@ -72,12 +72,11 @@ impl DifficultyCalculator {
7272}
7373
7474pub fn tari_rx_vm_key_height ( height : u64 ) -> u64 {
75- // The VM key is calculated from the block at height - (height % 2048) - 64
76- // This is to ensure that the VM key is not too far in the past
77- // and that it is not too close to the current block
78- height
79- . saturating_sub ( height % TARI_RX_VM_KEY_BLOCK_SWAP )
80- . saturating_sub ( TARI_RX_VM_KEY_REORG_SAFETY_NUMBER )
75+ if height <= TARI_RX_VM_KEY_BLOCK_SWAP + TARI_RX_VM_KEY_REORG_SAFETY_NUMBER {
76+ 0
77+ } else {
78+ ( height - TARI_RX_VM_KEY_REORG_SAFETY_NUMBER - 1 ) & !( TARI_RX_VM_KEY_BLOCK_SWAP - 1 )
79+ }
8180}
8281
8382#[ cfg( test) ]
@@ -99,27 +98,27 @@ mod test {
9998 assert_eq ! ( tari_rx_vm_key_height( height) , expected) ;
10099
101100 let height = 2048 ;
102- let expected = 1984 ;
101+ let expected = 0 ;
103102 assert_eq ! ( tari_rx_vm_key_height( height) , expected) ;
104103
105104 let height = 3048 ;
106- let expected = 1984 ;
105+ let expected = 2048 ;
107106 assert_eq ! ( tari_rx_vm_key_height( height) , expected) ;
108107
109108 let height = 4000 ;
110- let expected = 1984 ;
109+ let expected = 2048 ;
111110 assert_eq ! ( tari_rx_vm_key_height( height) , expected) ;
112111
113- let height = 4095 ;
114- let expected = 1984 ;
112+ let height = 4159 ;
113+ let expected = 2048 ;
115114 assert_eq ! ( tari_rx_vm_key_height( height) , expected) ;
116115
117- let height = 4096 ;
118- let expected = 4032 ;
116+ let height = 4160 ;
117+ let expected = 2048 ;
119118 assert_eq ! ( tari_rx_vm_key_height( height) , expected) ;
120119
121- let height = 4097 ;
122- let expected = 4032 ;
120+ let height = 4161 ;
121+ let expected = 4096 ;
123122 assert_eq ! ( tari_rx_vm_key_height( height) , expected) ;
124123 }
125124}
You can’t perform that action at this time.
0 commit comments