diff --git a/lib/archethic/crypto/keystore/node/software_impl.ex b/lib/archethic/crypto/keystore/node/software_impl.ex index 3948d5b54..34cda3143 100644 --- a/lib/archethic/crypto/keystore/node/software_impl.ex +++ b/lib/archethic/crypto/keystore/node/software_impl.ex @@ -233,7 +233,7 @@ defmodule Archethic.Crypto.NodeKeystore.SoftwareImpl do @impl GenServer # FIXME: use genserver message because ets table is protected - def handle_cast(:migrate_1_5_6, state) do + def handle_cast(:migrate_1_5_9, state) do node_seed = Origin.retrieve_node_seed() :ets.insert(@keystore_table, {:node_seed, node_seed}) :ets.delete(@keystore_table, :sign_fun) @@ -243,9 +243,9 @@ defmodule Archethic.Crypto.NodeKeystore.SoftwareImpl do {:noreply, state} end - # FIXME: to remove after 1.5.6 + # FIXME: to remove after 1.5.9 @doc false - def migrate_ets_table_1_5_6 do - GenServer.cast(__MODULE__, :migrate_1_5_6) + def migrate_ets_table_1_5_9 do + GenServer.cast(__MODULE__, :migrate_1_5_9) end end diff --git a/lib/archethic/crypto/keystore/shared_secrets/software_impl.ex b/lib/archethic/crypto/keystore/shared_secrets/software_impl.ex index 4c51a08d7..cb1fc5cd9 100644 --- a/lib/archethic/crypto/keystore/shared_secrets/software_impl.ex +++ b/lib/archethic/crypto/keystore/shared_secrets/software_impl.ex @@ -270,9 +270,9 @@ defmodule Archethic.Crypto.SharedSecretsKeystore.SoftwareImpl do @impl GenServer def code_change(_old_vsn, state, _extra), do: {:ok, state} - # FIXME: to remove after 1.5.6 + # FIXME: to remove after 1.5.9 @doc false - def migrate_ets_table_1_5_6 do + def migrate_ets_table_1_5_9 do :node_shared_secrets |> TransactionChain.list_addresses_by_type() |> Stream.take(-2) diff --git a/lib/archethic/p2p/mem_table.ex b/lib/archethic/p2p/mem_table.ex index 5205ec065..ffdcf47fe 100644 --- a/lib/archethic/p2p/mem_table.ex +++ b/lib/archethic/p2p/mem_table.ex @@ -488,9 +488,9 @@ defmodule Archethic.P2P.MemTable do end end - # FIXME: to remove after 1.5.6 + # FIXME: to remove after 1.5.9 @doc false - def migrate_ets_table_1_5_6 do + def migrate_ets_table_1_5_9 do # Inject the mining public key as nil awaiting the migration scripts to be executed ms = [ {{:"$1", :"$2", :"$3", :"$4", :"$5", :"$6", :"$7", :"$8", :"$9", :"$10", :"$11", :"$12", diff --git a/priv/migration_tasks/prod/1.5.6@add_mining_bls_key.exs b/priv/migration_tasks/prod/1.5.6@add_mining_bls_key.exs deleted file mode 100644 index e1498f15a..000000000 --- a/priv/migration_tasks/prod/1.5.6@add_mining_bls_key.exs +++ /dev/null @@ -1,57 +0,0 @@ -# defmodule Migration_1_5_6 do -# @moduledoc false - -# alias Archethic.Crypto -# alias Archethic.P2P -# alias Archethic.P2P.Node - -# alias Archethic.TransactionChain -# alias Archethic.TransactionChain.Transaction -# alias Archethic.TransactionChain.TransactionData - -# alias Archethic.Utils - -# require Logger - -# def run() do -# %Node{ip: ip, port: p2p_port, http_port: http_port, transport: transport, reward_address: reward_address, origin_public_key: origin_public_key} = P2P.get_node_info() - -# mining_public_key = Crypto.mining_node_public_key() -# key_certificate = Crypto.get_key_certificate(origin_public_key) - -# genesis_address = Crypto.first_node_public_key() |> Crypto.derive_address() -# {:ok, %Transaction{data: %TransactionData{code: code}}} = -# TransactionChain.get_last_transaction(genesis_address, data: [:code]) - -# tx = -# Transaction.new(:node, %TransactionData{ -# code: code, -# content: -# Node.encode_transaction_content( -# ip, -# p2p_port, -# http_port, -# transport, -# reward_address, -# origin_public_key, -# key_certificate, -# mining_public_key -# ) -# }) - -# :ok = Archethic.send_new_transaction(tx, forward?: true) - -# nodes = -# P2P.authorized_and_available_nodes() -# |> Enum.filter(&P2P.node_connected?/1) -# |> P2P.nearest_nodes() - -# case Utils.await_confirmation(tx.address, nodes) do -# {:ok, _} -> -# Logger.info("Mining node updated") - -# {:error, reason} -> -# Logger.warning("Cannot update node transaction - #{inspect reason}") -# end -# end -# end diff --git a/priv/migration_tasks/prod/1.5.9@add_mining_bls_key.exs b/priv/migration_tasks/prod/1.5.9@add_mining_bls_key.exs new file mode 100644 index 000000000..dbcf02543 --- /dev/null +++ b/priv/migration_tasks/prod/1.5.9@add_mining_bls_key.exs @@ -0,0 +1,57 @@ +defmodule Migration_1_5_9 do + @moduledoc false + + alias Archethic.Crypto + alias Archethic.P2P + alias Archethic.P2P.Node + + alias Archethic.TransactionChain + alias Archethic.TransactionChain.Transaction + alias Archethic.TransactionChain.TransactionData + + alias Archethic.Utils + + require Logger + + def run() do + %Node{ip: ip, port: p2p_port, http_port: http_port, transport: transport, reward_address: reward_address, origin_public_key: origin_public_key} = P2P.get_node_info() + + mining_public_key = Crypto.mining_node_public_key() + key_certificate = Crypto.get_key_certificate(origin_public_key) + + genesis_address = Crypto.first_node_public_key() |> Crypto.derive_address() + {:ok, %Transaction{data: %TransactionData{code: code}}} = + TransactionChain.get_last_transaction(genesis_address, data: [:code]) + + tx = + Transaction.new(:node, %TransactionData{ + code: code, + content: + Node.encode_transaction_content( + ip, + p2p_port, + http_port, + transport, + reward_address, + origin_public_key, + key_certificate, + mining_public_key + ) + }) + + :ok = Archethic.send_new_transaction(tx, forward?: true) + + nodes = + P2P.authorized_and_available_nodes() + |> Enum.filter(&P2P.node_connected?/1) + |> P2P.nearest_nodes() + + case Utils.await_confirmation(tx.address, nodes) do + {:ok, _} -> + Logger.info("Mining node updated") + + {:error, reason} -> + Logger.warning("Cannot update node transaction - #{inspect reason}") + end + end +end diff --git a/rel/appups/archethic/1.5.5_to_1.5.6.appup b/rel/appups/archethic/1.5.8_to_1.5.9.appup similarity index 75% rename from rel/appups/archethic/1.5.5_to_1.5.6.appup rename to rel/appups/archethic/1.5.8_to_1.5.9.appup index e89dfe661..64280d98f 100644 --- a/rel/appups/archethic/1.5.5_to_1.5.6.appup +++ b/rel/appups/archethic/1.5.8_to_1.5.9.appup @@ -1,15 +1,21 @@ -{"1.5.6", - [{"1.5.5", +{"1.5.9", + [{"1.5.8", [{apply,{'Elixir.Archethic.PubSub',notify_node_status,[node_down]}}, {load_module,'Elixir.Archethic.Cldr.Currency',brutal_purge,soft_purge,[]}, {load_module,'Elixir.Archethic.Cldr.Number.Transliterate',brutal_purge, soft_purge,[]}, + {load_module,'Elixir.Archethic.Contracts.Interpreter.Library.Common.List', + brutal_purge,soft_purge,[]}, + {load_module,'Elixir.Archethic.Contracts.Interpreter.Library.Common.Math', + brutal_purge,soft_purge,[]}, {load_module,'Elixir.Archethic.Crypto.ID',brutal_purge,soft_purge,[]}, {load_module,'Elixir.Archethic.Crypto.NodeKeystore',brutal_purge, soft_purge,[]}, - {load_module,'Elixir.Archethic.P2P.Message.ValidateSmartContractCall', - brutal_purge,soft_purge,[]}, + {load_module,'Elixir.Archethic.P2P.Message.ShardRepair',brutal_purge, + soft_purge,[]}, {load_module,'Elixir.Archethic.P2P.Node',brutal_purge,soft_purge,[]}, + {load_module,'Elixir.ArchethicWeb.Explorer.LayoutView',brutal_purge, + soft_purge,[]}, {load_module,'Elixir.ArchethicWeb.Explorer.WorldMapLive',brutal_purge, soft_purge,[]}, {load_module,'Elixir.ArchethicWeb.ExplorerRouter',brutal_purge,soft_purge, @@ -17,6 +23,10 @@ {load_module,'Elixir.Archethic.Crypto',brutal_purge,soft_purge, ['Elixir.Archethic.Crypto.ID', 'Elixir.Archethic.Crypto.NodeKeystore']}, + {update,'Elixir.Archethic.Contracts.Worker', + {advanced,[]}, + brutal_purge,soft_purge, + ['Elixir.Archethic.Crypto']}, {update,'Elixir.Archethic.Crypto.SharedSecretsKeystore.SoftwareImpl', {advanced,[]}, brutal_purge,soft_purge, @@ -29,6 +39,10 @@ {advanced,[]}, brutal_purge,soft_purge, ['Elixir.Archethic.P2P.Node']}, + {update,'Elixir.Archethic.SelfRepair.Notifier', + {advanced,[]}, + brutal_purge,soft_purge, + ['Elixir.Archethic.Crypto']}, {load_module,'Elixir.ArchethicWeb.Explorer.NodeDetailsLive',brutal_purge, soft_purge, ['Elixir.Archethic.Crypto']}, @@ -53,9 +67,15 @@ {advanced,[]}, brutal_purge,soft_purge, ['Elixir.Archethic.Crypto','Elixir.Archethic.P2P.Node']}, + {load_module,'Elixir.ArchethicWeb.Explorer.ExplorerView',brutal_purge, + soft_purge, + ['Elixir.Archethic.Crypto','Elixir.Archethic.P2P.Node']}, {load_module,'Elixir.ArchethicWeb.Explorer.SettingsLive',brutal_purge, soft_purge, ['Elixir.Archethic.Crypto','Elixir.Archethic.P2P.Node']}, + {load_module,'Elixir.Archethic.Bootstrap',brutal_purge,soft_purge, + ['Elixir.Archethic.Bootstrap.TransactionHandler', + 'Elixir.Archethic.Crypto','Elixir.Archethic.P2P.Node']}, {update,'Elixir.Archethic.P2P.MemTableLoader', {advanced,[]}, brutal_purge,soft_purge, @@ -74,16 +94,22 @@ {apply,{'Elixir.Archethic.Crypto.NodeKeystore.SoftwareImpl', migrate_ets_table_1_5_6, []}}, {apply,{'Elixir.Archethic.Crypto.SharedSecretsKeystore.SoftwareImpl', migrate_ets_table_1_5_6, []}}, {apply,{'Elixir.Archethic.PubSub',notify_node_status, [node_up]}}]}], - [{"1.5.5", + [{"1.5.8", [{load_module,'Elixir.Archethic.Cldr.Currency',brutal_purge,soft_purge,[]}, {load_module,'Elixir.Archethic.Cldr.Number.Transliterate',brutal_purge, soft_purge,[]}, + {load_module,'Elixir.Archethic.Contracts.Interpreter.Library.Common.List', + brutal_purge,soft_purge,[]}, + {load_module,'Elixir.Archethic.Contracts.Interpreter.Library.Common.Math', + brutal_purge,soft_purge,[]}, {load_module,'Elixir.Archethic.Crypto.ID',brutal_purge,soft_purge,[]}, {load_module,'Elixir.Archethic.Crypto.NodeKeystore',brutal_purge, soft_purge,[]}, - {load_module,'Elixir.Archethic.P2P.Message.ValidateSmartContractCall', - brutal_purge,soft_purge,[]}, + {load_module,'Elixir.Archethic.P2P.Message.ShardRepair',brutal_purge, + soft_purge,[]}, {load_module,'Elixir.Archethic.P2P.Node',brutal_purge,soft_purge,[]}, + {load_module,'Elixir.ArchethicWeb.Explorer.LayoutView',brutal_purge, + soft_purge,[]}, {load_module,'Elixir.ArchethicWeb.Explorer.WorldMapLive',brutal_purge, soft_purge,[]}, {load_module,'Elixir.ArchethicWeb.ExplorerRouter',brutal_purge,soft_purge, @@ -91,6 +117,10 @@ {load_module,'Elixir.Archethic.Crypto',brutal_purge,soft_purge, ['Elixir.Archethic.Crypto.ID', 'Elixir.Archethic.Crypto.NodeKeystore']}, + {update,'Elixir.Archethic.Contracts.Worker', + {advanced,[]}, + brutal_purge,soft_purge, + ['Elixir.Archethic.Crypto']}, {update,'Elixir.Archethic.Crypto.SharedSecretsKeystore.SoftwareImpl', {advanced,[]}, brutal_purge,soft_purge, @@ -103,6 +133,10 @@ {advanced,[]}, brutal_purge,soft_purge, ['Elixir.Archethic.P2P.Node']}, + {update,'Elixir.Archethic.SelfRepair.Notifier', + {advanced,[]}, + brutal_purge,soft_purge, + ['Elixir.Archethic.Crypto']}, {load_module,'Elixir.ArchethicWeb.Explorer.NodeDetailsLive',brutal_purge, soft_purge, ['Elixir.Archethic.Crypto']}, @@ -127,9 +161,15 @@ {advanced,[]}, brutal_purge,soft_purge, ['Elixir.Archethic.Crypto','Elixir.Archethic.P2P.Node']}, + {load_module,'Elixir.ArchethicWeb.Explorer.ExplorerView',brutal_purge, + soft_purge, + ['Elixir.Archethic.Crypto','Elixir.Archethic.P2P.Node']}, {load_module,'Elixir.ArchethicWeb.Explorer.SettingsLive',brutal_purge, soft_purge, ['Elixir.Archethic.Crypto','Elixir.Archethic.P2P.Node']}, + {load_module,'Elixir.Archethic.Bootstrap',brutal_purge,soft_purge, + ['Elixir.Archethic.Bootstrap.TransactionHandler', + 'Elixir.Archethic.Crypto','Elixir.Archethic.P2P.Node']}, {update,'Elixir.Archethic.P2P.MemTableLoader', {advanced,[]}, brutal_purge,soft_purge,