Skip to content

Commit

Permalink
Update conflict resolver when loading node list
Browse files Browse the repository at this point in the history
  • Loading branch information
Neylix committed Mar 20, 2023
1 parent fb1c700 commit 3313a90
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/archethic/bootstrap/sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,25 @@ defmodule Archethic.Bootstrap.Sync do
def load_node_list() do
current_nodes = P2P.authorized_and_available_nodes()

last_updated_nodes = fn acc,
new_node = %Node{
first_public_key: public_key,
last_update_date: update_date
} ->
previous_node =
%Node{last_update_date: previous_update_date} = Map.get(acc, public_key, new_node)

node =
if DateTime.compare(update_date, previous_update_date) == :gt,
do: new_node,
else: previous_node

Map.put(acc, public_key, node)
end

conflict_resolver = fn results ->
Enum.max_by(results, fn %NodeList{nodes: nodes} -> length(nodes) end)
Enum.flat_map(results, fn %NodeList{nodes: nodes} -> nodes end)
|> Enum.reduce(%{}, fn node, acc -> last_updated_nodes.(acc, node) end)
end

case P2P.quorum_read(current_nodes, %ListNodes{}, conflict_resolver) do
Expand Down

0 comments on commit 3313a90

Please sign in to comment.