@@ -182,14 +182,10 @@ impl ConsensusEngine for Tendermint {
182182 return Ok ( ( ) )
183183 }
184184
185- match term {
186- 0 => {
187- // First term change
188- stake:: on_term_close ( block. state_mut ( ) , block_number, & [ ] ) ?;
189- }
185+ let inactive_validators = match term {
186+ 0 => Vec :: new ( ) ,
190187 _ => {
191188 let rewards = stake:: drain_previous_rewards ( & mut block. state_mut ( ) ) ?;
192-
193189 let start_of_the_current_term = metadata. last_term_finished_block_num ( ) + 1 ;
194190 let client = self
195191 . client
@@ -199,15 +195,7 @@ impl ConsensusEngine for Tendermint {
199195 . upgrade ( )
200196 . ok_or ( EngineError :: CannotOpenBlock ) ?;
201197
202- let inactive_validators = if term == 1 {
203- assert ! ( rewards. is_empty( ) ) ;
204-
205- let validators = stake:: Validators :: load_from_state ( block. state ( ) ) ?
206- . into_iter ( )
207- . map ( |val| public_to_address ( val. pubkey ( ) ) )
208- . collect ( ) ;
209- inactive_validators ( & * client, start_of_the_current_term, block. header ( ) , validators)
210- } else {
198+ if term > 1 {
211199 let start_of_the_previous_term = {
212200 let end_of_the_two_level_previous_term = client
213201 . last_term_finished_block_num ( ( metadata. last_term_finished_block_num ( ) - 1 ) . into ( ) )
@@ -236,18 +224,20 @@ impl ConsensusEngine for Tendermint {
236224 for ( address, reward) in pending_rewards {
237225 self . machine . add_balance ( block, & address, reward) ?;
238226 }
239-
240- let validators = stake:: Validators :: load_from_state ( block. state ( ) ) ?
241- . into_iter ( )
242- . map ( |val| public_to_address ( val. pubkey ( ) ) )
243- . collect ( ) ;
244- inactive_validators ( & * client, start_of_the_current_term, block. header ( ) , validators)
245- } ;
227+ }
246228
247229 stake:: move_current_to_previous_intermediate_rewards ( & mut block. state_mut ( ) ) ?;
248- stake:: on_term_close ( block. state_mut ( ) , block_number, & inactive_validators) ?;
230+
231+ let validators = stake:: Validators :: load_from_state ( block. state ( ) ) ?
232+ . into_iter ( )
233+ . map ( |val| public_to_address ( val. pubkey ( ) ) )
234+ . collect ( ) ;
235+ inactive_validators ( & * client, start_of_the_current_term, block. header ( ) , validators)
249236 }
250- }
237+ } ;
238+
239+ stake:: on_term_close ( block. state_mut ( ) , block_number, & inactive_validators) ?;
240+
251241 Ok ( ( ) )
252242 }
253243
0 commit comments