Skip to content

Commit cb99b04

Browse files
committed
Format and genesis_time addition to libp2p starts on tests
1 parent b5c75b4 commit cb99b04

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

lib/lambda_ethereum_consensus/beacon/clock.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule LambdaEthereumConsensus.Beacon.Ticker do
1212

1313
@spec register_to_tick(atom() | [atom()]) :: :ok
1414
def register_to_tick(to_tick) when is_atom(to_tick), do: register_to_tick([to_tick])
15+
1516
def register_to_tick(to_tick) when is_list(to_tick) do
1617
GenServer.cast(__MODULE__, {:register_to_tick, to_tick})
1718
end
@@ -39,6 +40,12 @@ defmodule LambdaEthereumConsensus.Beacon.Ticker do
3940
schedule_next_tick()
4041
time = :os.system_time(:second)
4142

43+
# TODO: This assumes that on_tick/1 is implemented for all modules in to_tick
44+
# this could be later a behaviour but I'm not sure we want to maintain this ticker
45+
# in the long run. It's important that on_tick/1 is a very fast operation and
46+
# that any intensive computation is done asynchronously (e.g calling a cast).
47+
# We could also consider using a tasks to run on_tick/1 in parallel, but for
48+
# now this is enough to avoid complexity.
4249
Enum.each(to_tick, & &1.on_tick(time))
4350

4451
{:noreply, to_tick}

lib/lambda_ethereum_consensus/validator/duties.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ defmodule LambdaEthereumConsensus.Validator.Duties do
6969
attester_duties
7070
# Drop the first element, which is the previous epoch's duty
7171
|> Stream.drop(1)
72-
|> Enum.each(fn %{index_in_committee: i, committee_index: ci, slot: slot, should_aggregate?: sa} ->
72+
|> Enum.each(fn %{
73+
index_in_committee: i,
74+
committee_index: ci,
75+
slot: slot,
76+
should_aggregate?: sa
77+
} ->
7378
Logger.info(
7479
"[Validator] #{validator_index} has to attest in committee #{ci} of slot #{slot} with index #{i}, and should_aggregate?: #{sa}"
7580
)

lib/lambda_ethereum_consensus/validator/validator.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ defmodule LambdaEthereumConsensus.Validator do
246246
attestation = produce_attestation(current_duty, state.root, state.validator.privkey)
247247

248248
log_md = [slot: attestation.data.slot, attestation: attestation, subnet_id: subnet_id]
249-
debug_log_msg = "publishing attestation on committee index: #{current_duty.committee_index} | as #{current_duty.index_in_committee}/#{current_duty.committee_length - 1} and pubkey: #{LambdaEthereumConsensus.Utils.format_shorten_binary(validator.pubkey)}"
249+
250+
debug_log_msg =
251+
"publishing attestation on committee index: #{current_duty.committee_index} | as #{current_duty.index_in_committee}/#{current_duty.committee_length - 1} and pubkey: #{LambdaEthereumConsensus.Utils.format_shorten_binary(validator.pubkey)}"
252+
250253
log_debug(validator.index, debug_log_msg, log_md)
251254

252255
Gossip.Attestation.publish(subnet_id, attestation)
@@ -303,7 +306,8 @@ defmodule LambdaEthereumConsensus.Validator do
303306
|> Stream.map(&Map.fetch!(&1, :aggregation_bits))
304307
|> Enum.reduce(&BitField.bitwise_or/2)
305308

306-
{:ok, signature} = unique_attestations |> Enum.map(&Map.fetch!(&1, :signature)) |> Bls.aggregate()
309+
{:ok, signature} =
310+
unique_attestations |> Enum.map(&Map.fetch!(&1, :signature)) |> Bls.aggregate()
307311

308312
%{List.first(attestations) | aggregation_bits: aggregation_bits, signature: signature}
309313
end

lib/lambda_ethereum_consensus/validator/validator_manager.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ defmodule LambdaEthereumConsensus.Validator.ValidatorManager do
4747
{:ok, validators}
4848
end
4949

50-
@spec notify_new_block(Types.slot(), Types.root()) :: :ok
51-
def notify_new_block(slot, head_root) do
50+
@spec notify_new_block({Types.slot(), Types.root()}) :: :ok
51+
def notify_new_block({slot, head_root}) do
5252
# Making this alone a cast sometimes solves the issue for a while
5353
# GenServer.cast(__MODULE__, {:notify_all, {:new_block, slot, head_root}})
5454
notify_validators({:new_block, slot, head_root})

test/unit/beacon_api/beacon_api_v1_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ defmodule Unit.BeaconApiTest.V1 do
159159
alias LambdaEthereumConsensus.P2P.Metadata
160160
patch(ForkChoice, :get_fork_version, fn -> ChainSpec.get("DENEB_FORK_VERSION") end)
161161

162-
start_link_supervised!(Libp2pPort)
162+
start_link_supervised!({Libp2pPort, genesis_time: 42})
163163
Metadata.init()
164164
identity = Libp2pPort.get_node_identity()
165165
metadata = Metadata.get_metadata()

test/unit/libp2p_port_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Unit.Libp2pPortTest do
1717
end
1818

1919
defp start_port(name \\ Libp2pPort, init_args \\ []) do
20-
start_link_supervised!({Libp2pPort, [opts: [name: name]] ++ init_args}, id: name)
20+
start_link_supervised!({Libp2pPort, [opts: [name: name], genesis_time: 42] ++ init_args}, id: name)
2121
end
2222

2323
@tag :tmp_dir

0 commit comments

Comments
 (0)