Skip to content

Commit

Permalink
resync nss oracle chain : post bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorv-2204 committed Aug 18, 2022
1 parent 6e377d8 commit e31956e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
39 changes: 38 additions & 1 deletion lib/archethic/bootstrap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Archethic.Bootstrap do
require Logger

use Task
alias Archethic.TransactionChain

@doc """
Start the bootstrapping as a task
Expand Down Expand Up @@ -206,12 +207,48 @@ 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
# Bootstrap process should not crash
try do
nodes = Archethic.P2P.authorized_and_available_nodes()
Logger.debug("Resync Starting")

Archethic.Utils.async_no_link_pmap(
type_list,
&fn type = &1 ->
Logger.debug("Resync #{type}")

try do
TransactionChain.list_addresses_by_type(type)
|> Enum.at(0)
|> TransactionChain.fetch_last_address_remotely(nodes)
|> elem(1)
|> TransactionChain.fetch_transaction_remotely(nodes)
|> elem(1)
|> Archethic.Replication.validate_and_store_transaction_chain()

:ok
rescue
error ->
Logger.debug("Resync of chain #{type} failed #{error} ")
:ok
end
end
)
rescue
error ->
Logger.debug("Resync failed nodes NA. #{error}")
:ok
end
end

defp first_initialization(
ip,
port,
Expand Down
7 changes: 7 additions & 0 deletions lib/archethic/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,11 @@ defmodule Archethic.Utils do
end)
end)
end

@spec async_no_link_pmap(any, any) :: list
def async_no_link_pmap(collection, func) do
collection
|> Enum.map(&Task.Supervisor.async_nolink(Archethic.TaskSupervisor, fn -> func.(&1) end))
|> Task.await_many()
end
end

0 comments on commit e31956e

Please sign in to comment.