Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bchamagne committed Mar 20, 2023
1 parent ff2c4c3 commit 8b73004
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions lib/archethic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,14 @@ defmodule Archethic do
)
|> Stream.filter(&match?({:ok, _}, &1))
|> Stream.map(fn {:ok, res} -> res end)
|> aggregate_start_mining_responses()
|> Enum.reduce(
%{
ok: 0,
network_chains_resync_needed: false,
p2p_resync_needed: false
},
&reduce_start_mining_responses/2
)
|> then(fn aggregated_responses ->
maybe_start_resync(aggregated_responses)

Expand All @@ -148,35 +155,24 @@ defmodule Archethic do
end)
end

defp aggregate_start_mining_responses(responses) do
Enum.reduce(
responses,
%{
ok: 0,
network_chains_resync_needed: false,
p2p_resync_needed: false
},
fn
{:ok, %Ok{}}, acc ->
%{acc | ok: acc.ok + 1}
defp reduce_start_mining_responses({:ok, %Ok{}}, acc) do
%{acc | ok: acc.ok + 1}
end

{:ok, %Error{reason: :network_chains_sync}}, acc ->
%{acc | network_chains_resync_needed: true}
defp reduce_start_mining_responses({:ok, %Error{reason: :network_chains_sync}}, acc) do
%{acc | network_chains_resync_needed: true}
end

{:ok, %Error{reason: :p2p_sync}}, acc ->
%{acc | p2p_resync_needed: true}
defp reduce_start_mining_responses({:ok, %Error{reason: :p2p_sync}}, acc) do
%{acc | p2p_resync_needed: true}
end

{:ok, %Error{reason: :both_sync}}, acc ->
%{
acc
| network_chains_resync_needed: true,
p2p_resync_needed: true
}
defp reduce_start_mining_responses({:ok, %Error{reason: :both_sync}}, acc) do
%{acc | network_chains_resync_needed: true, p2p_resync_needed: true}
end

_, acc ->
acc
end
)
defp reduce_start_mining_responses(_, acc) do
acc
end

defp maybe_start_resync(aggregated_responses) do
Expand Down

0 comments on commit 8b73004

Please sign in to comment.