From 8ec9c036d95e402eed386ab58307b8063a1182dd Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Thu, 26 Jan 2023 10:29:54 -0800 Subject: [PATCH] Allow for back-to-back rescue blocks by fixing penalty calculations --- src/blockchain_election.erl | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/blockchain_election.erl b/src/blockchain_election.erl index cd19e53607..a3284d7707 100644 --- a/src/blockchain_election.erl +++ b/src/blockchain_election.erl @@ -436,14 +436,19 @@ validator_penalties(Group, Ledger) -> #{start_height := Start, curr_height := End} = election_info(Ledger), - PenaltyTuples = - [begin - {ok, #block_info_v2{height = Height, - penalties = PenaltyTuple}} - = blockchain_ledger_v1:get_block_info(Ht, Ledger), - {PenaltyTuple, Height} - end - || Ht <- lists:seq(Start + 2, End)], + ActualStart = Start + 2, + PenaltyTuples = case ActualStart > End of + true -> + []; + false -> + [begin + {ok, #block_info_v2{height = Height, + penalties = PenaltyTuple}} + = blockchain_ledger_v1:get_block_info(Ht, Ledger), + {PenaltyTuple, Height} + end + || Ht <- lists:seq(ActualStart, End)] + end, IndexedPenalties = get_penalties_v2(PenaltyTuples, length(Group), Ledger), maps:fold(fun(I, Pen, Acc) ->