From 419b5b9843db58ec81ae13a425738de34ce66c46 Mon Sep 17 00:00:00 2001 From: Apoorv Date: Tue, 6 Sep 2022 17:05:28 +0530 Subject: [PATCH] refactor for readability --- lib/archethic/bootstrap.ex | 23 +++++++++++++---------- test/archethic/bootstrap_test.exs | 6 +++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/archethic/bootstrap.ex b/lib/archethic/bootstrap.ex index 01dcf4214a..e6213f9989 100644 --- a/lib/archethic/bootstrap.ex +++ b/lib/archethic/bootstrap.ex @@ -211,7 +211,16 @@ defmodule Archethic.Bootstrap do end Archethic.Bootstrap.NetworkConstraints.persist_genesis_address() + resync_network_chain() + Sync.publish_end_of_sync() + SelfRepair.start_scheduler() + + :persistent_term.put(:archethic_up, :up) + Listener.listen() + end + + def resync_network_chain() do if P2P.authorized_node?() && P2P.available_node?() do # evict this node nodes = @@ -220,23 +229,17 @@ defmodule Archethic.Bootstrap do &(&1.first_public_key == Crypto.first_node_public_key()) ) - resync_network_chain([:oracle, :node_shared_secrets], nodes) + do_resync_network_chain([:oracle, :node_shared_secrets], nodes) end - - Sync.publish_end_of_sync() - SelfRepair.start_scheduler() - - :persistent_term.put(:archethic_up, :up) - Listener.listen() end - @spec resync_network_chain(list(atom), list(P2P.Node.t()) | []) :: :ok - def resync_network_chain(_type_list, _nodes = []), + @spec do_resync_network_chain(list(atom), list(P2P.Node.t()) | []) :: :ok + def do_resync_network_chain(_type_list, _nodes = []), do: Logger.info("Enforced Resync of Network Txs: failure, No-Nodes") # by type: Get gen addr, get last address (remotely & locally) # compare, if dont match, fetch last tx remotely - def resync_network_chain(type_list, nodes) when is_list(nodes) do + def do_resync_network_chain(type_list, nodes) when is_list(nodes) do Task.Supervisor.async_stream_nolink(Archethic.TaskSupervisor, type_list, fn type -> with addr when is_binary(addr) <- get_genesis_addr(type), {:ok, rem_last_addr} <- TransactionChain.resolve_last_address(addr), diff --git a/test/archethic/bootstrap_test.exs b/test/archethic/bootstrap_test.exs index 7547f08576..825efcc59c 100644 --- a/test/archethic/bootstrap_test.exs +++ b/test/archethic/bootstrap_test.exs @@ -489,7 +489,7 @@ defmodule Archethic.BootstrapTest do :persistent_term.put(:node_shared_secrets_gen_addr, nil) :ok = - Bootstrap.resync_network_chain( + Bootstrap.do_resync_network_chain( [:node_shared_secrets], _nodes = P2P.authorized_and_available_nodes() ) @@ -507,7 +507,7 @@ defmodule Archethic.BootstrapTest do |> stub(:get_last_chain_address, fn _, _ -> {nss_chain.txn4.address, DateTime.utc_now()} end) :ok = - Bootstrap.resync_network_chain( + Bootstrap.do_resync_network_chain( [:node_shared_secrets], _nodes = P2P.authorized_and_available_nodes() ) @@ -553,7 +553,7 @@ defmodule Archethic.BootstrapTest do end) :ok = - Bootstrap.resync_network_chain( + Bootstrap.do_resync_network_chain( [:node_shared_secrets], _nodes = P2P.authorized_and_available_nodes() )