Skip to content

Commit

Permalink
enforce oracle txn and NSS tx
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorv-2204 committed Aug 17, 2022
1 parent 9823e16 commit 401e2c9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
38 changes: 38 additions & 0 deletions 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,49 @@ 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
Archethic.Utils.async_no_link_pmap(
type_list,
&fn type = &1 ->
last_addr =
case TransactionChain.list_addresses_by_type(type) do
[] ->
nil

tx_list ->
IO.inspect(tx_list, Label: "txn__list__")

tx_list
|> Enum.at(0)
|> TransactionChain.get_last_address()
end

case {last_addr, Archethic.P2P.authorized_and_available_nodes()} do
{nil, _} ->
:ok

{_, []} ->
:ok

{last_addr, node_list} ->
Enum.map(
TransactionChain.stream_remotely(last_addr, node_list, last_addr),
fn tx when tx != [] and tx != nil ->
Archethic.Replication.validate_and_store_transaction_chain(tx)
end
)
end
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
2 changes: 1 addition & 1 deletion src/c/nat/miniupnp

0 comments on commit 401e2c9

Please sign in to comment.