@@ -317,39 +317,49 @@ func (app *Application) ExecuteTx(*api.Context, *transaction.Transaction) error
317317func (app * Application ) EndBlock (ctx * api.Context ) (types.ResponseEndBlock , error ) {
318318 var resp types.ResponseEndBlock
319319
320+ validatorUpdates , err := updateValidators (ctx , resp )
321+ if err != nil {
322+ return resp , err
323+ }
324+
325+ resp .ValidatorUpdates = validatorUpdates
326+
327+ return resp , nil
328+ }
329+
330+ func updateValidators (ctx * api.Context , resp types.ResponseEndBlock ) ([]types.ValidatorUpdate , error ) {
320331 state := schedulerState .NewMutableState (ctx .State ())
321332 pendingValidators , err := state .PendingValidators (ctx )
322333 if err != nil {
323- return resp , fmt .Errorf ("cometbft/scheduler: failed to query pending validators: %w" , err )
334+ return nil , fmt .Errorf ("cometbft/scheduler: failed to query pending validators: %w" , err )
324335 }
325336 if pendingValidators == nil {
326337 // No validator updates to apply.
327- return resp , nil
338+ return nil , nil
328339 }
329340
330341 currentValidators , err := state .CurrentValidators (ctx )
331342 if err != nil {
332- return resp , fmt .Errorf ("cometbft/scheduler: failed to query current validators: %w" , err )
343+ return nil , fmt .Errorf ("cometbft/scheduler: failed to query current validators: %w" , err )
333344 }
334345
335346 // Clear out the pending validator update.
336347 if err = state .PutPendingValidators (ctx , nil ); err != nil {
337- return resp , fmt .Errorf ("cometbft/scheduler: failed to clear validators: %w" , err )
348+ return nil , fmt .Errorf ("cometbft/scheduler: failed to clear validators: %w" , err )
338349 }
339350
340351 // CometBFT expects a vector of ValidatorUpdate that expresses
341352 // the difference between the current validator set (tracked manually
342353 // from InitChain), and the new validator set, which is a huge pain
343354 // in the ass.
344355
345- resp . ValidatorUpdates = diffValidators (ctx .Logger (), currentValidators , pendingValidators )
356+ validatorUpdates : = diffValidators (ctx .Logger (), currentValidators , pendingValidators )
346357
347358 // Stash the updated validator set.
348359 if err = state .PutCurrentValidators (ctx , pendingValidators ); err != nil {
349- return resp , fmt .Errorf ("cometbft/scheduler: failed to set validators: %w" , err )
360+ return nil , fmt .Errorf ("cometbft/scheduler: failed to set validators: %w" , err )
350361 }
351-
352- return resp , nil
362+ return validatorUpdates , nil
353363}
354364
355365func diffValidators (logger * logging.Logger , current , pending map [signature.PublicKey ]* scheduler.Validator ) []types.ValidatorUpdate {
0 commit comments