Skip to content

Commit

Permalink
refactor for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorv-2204 committed Sep 6, 2022
1 parent 3e440f9 commit 419b5b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
23 changes: 13 additions & 10 deletions lib/archethic/bootstrap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions test/archethic/bootstrap_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand All @@ -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()
)
Expand Down Expand Up @@ -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()
)
Expand Down

0 comments on commit 419b5b9

Please sign in to comment.