@@ -20,10 +20,6 @@ pub struct State {
2020
2121 // fees seen this epoch
2222 epoch_fees : u64 ,
23-
24- // Total blocks minted till block number
25- // Keyed by vrf_key_hash
26- total_blocks_minted : HashMap < KeyHash , u64 > ,
2723}
2824
2925impl State {
@@ -35,7 +31,6 @@ impl State {
3531 blocks_minted : HashMap :: new ( ) ,
3632 epoch_blocks : 0 ,
3733 epoch_fees : 0 ,
38- total_blocks_minted : HashMap :: new ( ) ,
3934 }
4035 }
4136
@@ -46,7 +41,6 @@ impl State {
4641 let vrf_key_hash = keyhash ( vrf_vkey) ;
4742 // Count one on this hash
4843 * ( self . blocks_minted . entry ( vrf_key_hash. clone ( ) ) . or_insert ( 0 ) ) += 1 ;
49- * ( self . total_blocks_minted . entry ( vrf_key_hash. clone ( ) ) . or_insert ( 0 ) ) += 1 ;
5044 }
5145 }
5246
@@ -87,19 +81,8 @@ impl State {
8781 }
8882 }
8983
90- /// Get epoch's total blocks minted for each vrf key hash till current block number
91- pub fn get_total_blocks_minted_by_pools ( & self , vrf_key_hashes : & Vec < KeyHash > ) -> Vec < u64 > {
92- vrf_key_hashes
93- . iter ( )
94- . map ( |key_hash| self . total_blocks_minted . get ( key_hash) . map ( |v| * v as u64 ) . unwrap_or ( 0 ) )
95- . collect ( )
96- }
97-
98- pub fn get_blocks_minted_data_by_pool ( & self , vrf_key_hash : & KeyHash ) -> ( u64 , u64 ) {
99- (
100- self . total_blocks_minted . get ( vrf_key_hash) . map ( |v| * v as u64 ) . unwrap_or ( 0 ) ,
101- self . blocks_minted . get ( vrf_key_hash) . map ( |v| * v as u64 ) . unwrap_or ( 0 ) ,
102- )
84+ pub fn get_blocks_minted_by_pool ( & self , vrf_key_hash : & KeyHash ) -> u64 {
85+ self . blocks_minted . get ( vrf_key_hash) . map ( |v| * v as u64 ) . unwrap_or ( 0 )
10386 }
10487}
10588
@@ -166,7 +149,6 @@ mod tests {
166149 assert_eq ! ( state. epoch_blocks, 2 ) ;
167150 assert_eq ! ( state. blocks_minted. len( ) , 1 ) ;
168151 assert_eq ! ( state. blocks_minted. get( & keyhash( vrf) ) , Some ( & 2 ) ) ;
169- assert_eq ! ( state. total_blocks_minted. get( & keyhash( vrf) ) , Some ( & 2 ) ) ;
170152 }
171153
172154 #[ test]
@@ -190,9 +172,8 @@ mod tests {
190172 Some ( 2 )
191173 ) ;
192174
193- let blocks_minted_data = state. get_blocks_minted_data_by_pool ( & keyhash ( b"vrf_2" ) ) ;
194- assert_eq ! ( blocks_minted_data. 0 , 2 ) ;
195- assert_eq ! ( blocks_minted_data. 1 , 2 ) ;
175+ let blocks_minted = state. get_blocks_minted_by_pool ( & keyhash ( b"vrf_2" ) ) ;
176+ assert_eq ! ( blocks_minted, 2 ) ;
196177 }
197178
198179 #[ test]
@@ -231,9 +212,8 @@ mod tests {
231212 assert_eq ! ( state. epoch_fees, 0 ) ;
232213 assert ! ( state. blocks_minted. is_empty( ) ) ;
233214
234- let blocks_minted_data = state. get_blocks_minted_data_by_pool ( & keyhash ( b"vrf_1" ) ) ;
235- assert_eq ! ( blocks_minted_data. 0 , 1 ) ;
236- assert_eq ! ( blocks_minted_data. 1 , 0 ) ;
215+ let blocks_minted = state. get_blocks_minted_by_pool ( & keyhash ( b"vrf_1" ) ) ;
216+ assert_eq ! ( blocks_minted, 0 ) ;
237217 }
238218
239219 #[ tokio:: test]
@@ -252,35 +232,15 @@ mod tests {
252232 block. number += 1 ;
253233 state. handle_mint ( & block, Some ( b"vrf_1" ) ) ;
254234 state. handle_fees ( & block, 123 ) ;
235+ assert_eq ! ( state. get_blocks_minted_by_pool( & keyhash( b"vrf_1" ) ) , 2 ) ;
255236 history. lock ( ) . await . commit ( block. number , state) ;
256237
257- let mut state = history. lock ( ) . await . get_current_state ( ) ;
258- block = make_block ( 2 ) ;
259- let _ = state. end_epoch ( & block) ;
260- state. handle_mint ( & block, Some ( b"vrf_1" ) ) ;
261- state. handle_fees ( & block, 123 ) ;
262- history. lock ( ) . await . commit ( block. number , state) ;
263-
264- let state = history. lock ( ) . await . get_current_state ( ) ;
265- assert_eq ! ( state. epoch_blocks, 1 ) ;
266- assert_eq ! ( state. epoch_fees, 123 ) ;
267- assert_eq ! (
268- 3 ,
269- state. get_total_blocks_minted_by_pools( & vec![ keyhash( b"vrf_1" ) ] ) [ 0 ]
270- ) ;
271-
272- // roll back of epoch 2
273- block = make_rolled_back_block ( 2 ) ;
238+ block = make_rolled_back_block ( 0 ) ;
274239 let mut state = history. lock ( ) . await . get_rolled_back_state ( block. number ) ;
275- let _ = state. end_epoch ( & block) ;
276240 state. handle_mint ( & block, Some ( b"vrf_2" ) ) ;
277241 state. handle_fees ( & block, 123 ) ;
242+ assert_eq ! ( state. get_blocks_minted_by_pool( & keyhash( b"vrf_1" ) ) , 0 ) ;
243+ assert_eq ! ( state. get_blocks_minted_by_pool( & keyhash( b"vrf_2" ) ) , 1 ) ;
278244 history. lock ( ) . await . commit ( block. number , state) ;
279-
280- let state = history. lock ( ) . await . get_current_state ( ) ;
281- assert_eq ! (
282- 2 ,
283- state. get_total_blocks_minted_by_pools( & vec![ keyhash( b"vrf_1" ) ] ) [ 0 ]
284- ) ;
285245 }
286246}
0 commit comments