Skip to content

Commit d60cea4

Browse files
committed
Fixed an issue at Sync committee period change after second change
1 parent bb56817 commit d60cea4

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/lambda_ethereum_consensus/validator/duties.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ defmodule LambdaEthereumConsensus.Validator.Duties do
5656
ValidatorSet.validators()
5757
) :: duties()
5858
def compute_duties_for_epochs(duties_map, epochs_and_start_slots, head_root, validators) do
59-
Logger.info("[Duties] Computing duties for epochs: #{inspect(epochs_and_start_slots)}")
59+
Logger.debug("[Duties] Computing duties for epochs: #{inspect(epochs_and_start_slots)}")
6060

6161
for {epoch, slot} <- epochs_and_start_slots, reduce: duties_map do
6262
duties_map ->
@@ -73,7 +73,9 @@ defmodule LambdaEthereumConsensus.Validator.Duties do
7373
new_sync_committees =
7474
case sync_committee_compute_check(epoch, {last_epoch, Map.get(duties_map, last_epoch)}) do
7575
{:already_computed, sync_committees} -> sync_committees
76-
:not_computed -> compute_current_sync_committees(beacon, validators)
76+
{:not_computed, period} ->
77+
Logger.debug("[Duties] Computing sync committees for period: #{period} and epoch: #{epoch}.")
78+
compute_current_sync_committees(beacon, validators)
7779
end
7880

7981
new_duties = %{
@@ -123,7 +125,7 @@ defmodule LambdaEthereumConsensus.Validator.Duties do
123125

124126
if last_period == current_period,
125127
do: {:already_computed, last_duties.sync_committees},
126-
else: :not_computed
128+
else: {:not_computed, current_period}
127129
end
128130

129131
@spec compute_attesters_for_epoch(BeaconState.t(), Types.epoch(), ValidatorSet.validators()) ::

lib/lambda_ethereum_consensus/validator/validator_set.ex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ defmodule LambdaEthereumConsensus.ValidatorSet do
8484
|> update_state(epoch, slot, head_root)
8585
|> maybe_attests(epoch, slot, head_root)
8686
|> maybe_build_payload(slot + 1, head_root)
87-
|> maybe_sync_committee_broadcasts(epoch, slot, head_root)
87+
|> maybe_sync_committee_broadcasts(slot, head_root)
8888
end
8989

9090
@doc """
@@ -111,7 +111,7 @@ defmodule LambdaEthereumConsensus.ValidatorSet do
111111
set
112112
|> maybe_attests(epoch, slot, head_root)
113113
|> maybe_build_payload(slot + 1, head_root)
114-
|> maybe_sync_committee_broadcasts(epoch, slot, head_root)
114+
|> maybe_sync_committee_broadcasts(slot, head_root)
115115
end
116116

117117
defp process_tick(set, epoch, {slot, :last_third}) do
@@ -187,7 +187,10 @@ defmodule LambdaEthereumConsensus.ValidatorSet do
187187
##############################
188188
# Sync committee
189189

190-
defp maybe_sync_committee_broadcasts(set, epoch, slot, head_root) do
190+
defp maybe_sync_committee_broadcasts(set, slot, head_root) do
191+
# Sync committee is broadcasted for the next slot, so we take the duties for the correct epoch.
192+
epoch = Misc.compute_epoch_at_slot(slot + 1)
193+
191194
case Duties.current_sync_committee(set.duties, epoch, slot) do
192195
[] ->
193196
set

0 commit comments

Comments
 (0)