Skip to content

Commit

Permalink
HC: Don't crash if there are no local stakers (#4238)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanssv committed Jan 18, 2024
1 parent 4842946 commit f960a84
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions apps/aecore/src/aec_consensus_hc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,15 @@ pick_lazy_leader(TopHash) ->
{ok, AllStakers} ->
SignModule = get_sign_module(),
LocalStakers = lists:filter(fun SignModule:is_key_present/1, AllStakers),
Staker = lists:nth(rand:uniform(length(LocalStakers)), LocalStakers),
SignModule:set_candidate(Staker),
{ok, Staker};
case LocalStakers of
[] ->
timer:sleep(1000),
error;
_ ->
Staker = lists:nth(rand:uniform(length(LocalStakers)), LocalStakers),
SignModule:set_candidate(Staker),
{ok, Staker}
end;
_ ->
timer:sleep(1000),
error
Expand Down

0 comments on commit f960a84

Please sign in to comment.