Skip to content

Commit

Permalink
enforce resync of nss and orcale chain
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorv-2204 committed Aug 18, 2022
1 parent 6e377d8 commit 0e70a09
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/archethic/bootstrap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ defmodule Archethic.Bootstrap do
alias Archethic.SelfRepair

require Logger

use Task

alias Archethic.TransactionChain
alias Archethic.Replication

@doc """
Start the bootstrapping as a task
"""
Expand Down Expand Up @@ -206,12 +208,32 @@ defmodule Archethic.Bootstrap do
Logger.info("Synchronization finished")
end

resync_network_chain([:oracle, :node_shared_secrets])

Sync.publish_end_of_sync()
SelfRepair.start_scheduler()

:persistent_term.put(:archethic_up, :up)
end

def resync_network_chain(type_list) do
Task.Supervisor.async_stream_nolink(Archethic.TaskSupervisor, type_list, fn type ->
with nodes <- P2P.authorized_and_available_nodes(),
addr when not is_nil(addr) <-
TransactionChain.list_addresses_by_type(type) |> Enum.at(0),
{:ok, last_addr} <- TransactionChain.fetch_last_address_remotely(addr, nodes),
{:ok, last_tx} <- TransactionChain.fetch_transaction_remotely(last_addr, nodes),
:ok <- Replication.validate_and_store_transaction_chain(last_tx) do
Logger.info("Resync Success")
Logger.info(type: type)
else
error ->
Logger.info("Resync failure")
Logger.info(error: error, type: type)
end
end)
|> Stream.run()
end

defp first_initialization(
ip,
port,
Expand Down

0 comments on commit 0e70a09

Please sign in to comment.