From 0e70a09b617a60d182e77c2bea783b628131b9b8 Mon Sep 17 00:00:00 2001 From: Apoorv Date: Thu, 18 Aug 2022 20:05:00 +0530 Subject: [PATCH] enforce resync of nss and orcale chain --- lib/archethic/bootstrap.ex | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/archethic/bootstrap.ex b/lib/archethic/bootstrap.ex index 32a890396e..837cc031b5 100644 --- a/lib/archethic/bootstrap.ex +++ b/lib/archethic/bootstrap.ex @@ -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 """ @@ -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,