Skip to content

Commit

Permalink
Fix origin genesis addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Neylix committed Feb 13, 2024
1 parent d47e87f commit 8defd5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
5 changes: 2 additions & 3 deletions lib/archethic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ defmodule Archethic do
alias Archethic.SelfRepair
alias Archethic.SelfRepair.NetworkChain
alias Archethic.SelfRepair.NetworkView
alias Archethic.SharedSecrets
alias Archethic.TaskSupervisor
alias Archethic.TransactionChain
alias Archethic.TransactionChain.Transaction
Expand Down Expand Up @@ -99,8 +98,8 @@ defmodule Archethic do
:ok ->
true

{:error, addresses} ->
SharedSecrets.genesis_address(:node_shared_secrets) |> SelfRepair.resync(addresses, [])
{:error, [{genesis_address, address}]} ->
SelfRepair.resync(genesis_address, [address], [])
false

:error ->
Expand Down
18 changes: 8 additions & 10 deletions lib/archethic/self_repair/network_chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ defmodule Archethic.SelfRepair.NetworkChain do
def synchronous_resync(type) do
:telemetry.execute([:archethic, :self_repair, :resync], %{count: 1}, %{network_chain: type})

genesis_address = get_genesis_address(type)

case verify_synchronization(type) do
{:error, addresses} when is_list(addresses) ->
Task.Supervisor.async_stream_nolink(
Archethic.TaskSupervisor,
addresses,
&SelfRepair.replicate_transaction(&1, genesis_address),
fn {genesis_address, address} ->
SelfRepair.replicate_transaction(address, genesis_address)
end,
ordered: false,
on_timeout: :kill_task
)
Expand All @@ -99,7 +99,10 @@ defmodule Archethic.SelfRepair.NetworkChain do
@doc """
Verify if the last stored transaction is the last one on the network
"""
@spec verify_synchronization(atom()) :: :ok | :error | {:error, list(Crypto.prepended_hash())}
@spec verify_synchronization(atom()) ::
:ok
| :error
| {:error, list({Crypto.prepended_hash(), Crypto.prepended_hash()})}
def verify_synchronization(:origin) do
genesis_addresses = SharedSecrets.genesis_address(:origin)

Expand Down Expand Up @@ -129,11 +132,6 @@ defmodule Archethic.SelfRepair.NetworkChain do
do_verify_synchronization(genesis_address, last_schedule_date)
end

defp get_genesis_address(:oracle), do: OracleChain.genesis_address()

defp get_genesis_address(type) when type in [:origin, :node_shared_secrets],
do: SharedSecrets.genesis_address(type)

defp do_verify_synchronization(nil, _), do: :ok

defp do_verify_synchronization(genesis_address, last_schedule_date) do
Expand Down Expand Up @@ -167,7 +165,7 @@ defmodule Archethic.SelfRepair.NetworkChain do
acceptance_resolver: &(&1.timestamp > local_last_address_timestamp)
) do
{:ok, remote_last_address} ->
{:error, [remote_last_address]}
{:error, [{genesis_address, remote_last_address}]}

{:error, :acceptance_failed} ->
:ok
Expand Down

0 comments on commit 8defd5e

Please sign in to comment.