From 6c6896330df4472ce927e0be926b586aa5551316 Mon Sep 17 00:00:00 2001 From: Bastien CHAMAGNE Date: Mon, 5 Jun 2023 16:24:09 +0200 Subject: [PATCH] up version 1.1.0 --- lib/archethic/beacon_chain/slot.ex | 4 ++-- lib/archethic/beacon_chain/subset.ex | 4 ++-- .../beacon_chain/subset/summary_cache.ex | 19 +------------------ .../keystore/shared_secrets/software_impl.ex | 12 ++++++++++++ .../transaction_chain/transaction_summary.ex | 8 ++++---- mix.exs | 2 +- ...exs => 1.1.0@migrate_old_tx_summaries.exs} | 6 +++--- ...o_1.1.0-rc5.appup => 1.0.7_to_1.1.0.appup} | 6 ++---- 8 files changed, 27 insertions(+), 34 deletions(-) rename priv/migration_tasks/prod/{1.0.8-rc1@migrate_old_tx_summaries.exs => 1.1.0@migrate_old_tx_summaries.exs} (98%) rename rel/appups/archethic/{1.0.7_to_1.1.0-rc5.appup => 1.0.7_to_1.1.0.appup} (99%) diff --git a/lib/archethic/beacon_chain/slot.ex b/lib/archethic/beacon_chain/slot.ex index 4b33280a9..fdd56f0a7 100644 --- a/lib/archethic/beacon_chain/slot.ex +++ b/lib/archethic/beacon_chain/slot.ex @@ -636,7 +636,7 @@ defmodule Archethic.BeaconChain.Slot do """ @spec transform(binary(), t()) :: t() def transform( - "1.0.8", + "1.1.0", slot = %__MODULE__{transaction_attestations: attestations} ) do if Enum.any?(attestations, fn %ReplicationAttestation{version: version} -> version == 1 end) do @@ -645,7 +645,7 @@ defmodule Archethic.BeaconChain.Slot do TaskSupervisor, attestations, fn attestation = %ReplicationAttestation{transaction_summary: summary} -> - new_summary = TransactionSummary.transform("1.0.8", summary) + new_summary = TransactionSummary.transform("1.1.0", summary) %ReplicationAttestation{attestation | transaction_summary: new_summary} end, max_concurrency: System.schedulers_online() * 10 diff --git a/lib/archethic/beacon_chain/subset.ex b/lib/archethic/beacon_chain/subset.ex index 9bf082797..7595d38cd 100644 --- a/lib/archethic/beacon_chain/subset.ex +++ b/lib/archethic/beacon_chain/subset.ex @@ -99,7 +99,7 @@ defmodule Archethic.BeaconChain.Subset do end def handle_call(:get_current_slot, _from, state = %{current_slot: current_slot}) do - current_slot = Slot.transform("1.0.8", current_slot) + current_slot = Slot.transform("1.1.0", current_slot) {:reply, current_slot, state} end @@ -353,7 +353,7 @@ defmodule Archethic.BeaconChain.Subset do defp broadcast_beacon_slot(subset, next_time, slot) do nodes = P2P.authorized_and_available_nodes(next_time, true) - slot = Slot.transform("1.0.8", slot) + slot = Slot.transform("1.1.0", slot) subset |> Election.beacon_storage_nodes(next_time, nodes) diff --git a/lib/archethic/beacon_chain/subset/summary_cache.ex b/lib/archethic/beacon_chain/subset/summary_cache.ex index 4f1763f7d..160e8808a 100644 --- a/lib/archethic/beacon_chain/subset/summary_cache.ex +++ b/lib/archethic/beacon_chain/subset/summary_cache.ex @@ -71,7 +71,7 @@ defmodule Archethic.BeaconChain.Subset.SummaryCache do :ets.insert(@table_name, {subset, slot}) {subset, slot} -> - slot = Slot.transform("1.0.8", slot) + slot = Slot.transform("1.1.0", slot) backup_slot(slot, "") :ets.insert(@table_name, {subset, slot}) end) @@ -82,23 +82,6 @@ defmodule Archethic.BeaconChain.Subset.SummaryCache do {:ok, state} end - def code_change("1.1.0-rc1", state, _extra) do - backup_path = DateTime.utc_now() |> SummaryTimer.next_summary() |> recover_path() - backup_path_temp = backup_path <> "_temp" - File.rename(backup_path, backup_path_temp) - - Enum.each(BeaconChain.list_subsets(), fn subset -> - :ets.lookup(@table_name, subset) - |> Enum.each(fn {_subset, {slot, pub_key}} -> - backup_slot(slot, pub_key) - end) - end) - - File.rm(backup_path_temp) - - {:ok, state} - end - def code_change(_, state, _), do: {:ok, state} defp clean_previous_summary_cache(subset, previous_summary_time) do diff --git a/lib/archethic/crypto/keystore/shared_secrets/software_impl.ex b/lib/archethic/crypto/keystore/shared_secrets/software_impl.ex index 50c8db909..36659af74 100644 --- a/lib/archethic/crypto/keystore/shared_secrets/software_impl.ex +++ b/lib/archethic/crypto/keystore/shared_secrets/software_impl.ex @@ -57,6 +57,18 @@ defmodule Archethic.Crypto.SharedSecretsKeystore.SoftwareImpl do {:ok, %{}} end + # we store functions in the ETS table, so we need to reload them + # every upgrade to avoid: "xxx is invalid, likely because it points to an old version of the code" + @impl true + def code_change(_, state, _extra) do + :node_shared_secrets + |> TransactionChain.list_addresses_by_type() + |> Stream.take(-2) + |> Enum.each(&load_node_shared_secrets_tx/1) + + {:ok, state} + end + defp load_storage_nonce do case DB.get_bootstrap_info("storage_nonce") do nil -> diff --git a/lib/archethic/transaction_chain/transaction_summary.ex b/lib/archethic/transaction_chain/transaction_summary.ex index 02c86fee7..df9fc0c04 100644 --- a/lib/archethic/transaction_chain/transaction_summary.ex +++ b/lib/archethic/transaction_chain/transaction_summary.ex @@ -217,9 +217,9 @@ defmodule Archethic.TransactionChain.TransactionSummary do Apply a tranformation of a transaction summary based on the blockchain version """ @spec transform(binary(), t()) :: t() - def transform("1.0.8", tx_summary = %__MODULE__{version: 1}), do: tx_summary + def transform("1.1.0", tx_summary = %__MODULE__{version: 1}), do: tx_summary - def transform("1.0.8", %__MODULE__{address: address}) do + def transform("1.1.0", %__MODULE__{address: address}) do transaction = case TransactionChain.get_transaction(address) do {:ok, tx} -> @@ -238,8 +238,8 @@ defmodule Archethic.TransactionChain.TransactionSummary do def transform(_, tx_summary), do: tx_summary @doc """ - This function will be used during the summary day of 1.0.8 upgrade. This function can be deleted after the upgrade. - Migrate this function into files 1.0.8-migrate_old_tx_summaries + This function will be used during the summary day of 1.1.0 upgrade. This function can be deleted after the upgrade. + Migrate this function into files 1.1.0-migrate_old_tx_summaries Deserialize an old version of transaction summary """ @spec deserialize_old(bitstring()) :: {t(), bitstring()} diff --git a/mix.exs b/mix.exs index 439d819ec..9a69e9d99 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Archethic.MixProject do def project do [ app: :archethic, - version: "1.1.0-rc5", + version: "1.1.0", build_path: "_build", config_path: "config/config.exs", deps_path: "deps", diff --git a/priv/migration_tasks/prod/1.0.8-rc1@migrate_old_tx_summaries.exs b/priv/migration_tasks/prod/1.1.0@migrate_old_tx_summaries.exs similarity index 98% rename from priv/migration_tasks/prod/1.0.8-rc1@migrate_old_tx_summaries.exs rename to priv/migration_tasks/prod/1.1.0@migrate_old_tx_summaries.exs index e5e1f3ecb..62be359d9 100644 --- a/priv/migration_tasks/prod/1.0.8-rc1@migrate_old_tx_summaries.exs +++ b/priv/migration_tasks/prod/1.1.0@migrate_old_tx_summaries.exs @@ -1,4 +1,4 @@ -defmodule Migration_1_0_8 do +defmodule Migration_1_1_0 do @moduledoc false alias Archethic.TaskSupervisor @@ -46,7 +46,7 @@ defmodule Migration_1_0_8 do replication_attestations = Task.Supervisor.async_stream( TaskSupervisor, - tx_summaries, + tx_summaries, fn tx_summary -> create_attestation(tx_summary) end, @@ -101,7 +101,7 @@ defmodule Migration_1_0_8 do end defp create_attestation(tx_summary) do - new_tx_summary = TransactionSummary.transform("1.0.8", tx_summary) + new_tx_summary = TransactionSummary.transform("1.1.0", tx_summary) %ReplicationAttestation{version: 1, transaction_summary: new_tx_summary} end diff --git a/rel/appups/archethic/1.0.7_to_1.1.0-rc5.appup b/rel/appups/archethic/1.0.7_to_1.1.0.appup similarity index 99% rename from rel/appups/archethic/1.0.7_to_1.1.0-rc5.appup rename to rel/appups/archethic/1.0.7_to_1.1.0.appup index 832e2515b..425140fb0 100644 --- a/rel/appups/archethic/1.0.7_to_1.1.0-rc5.appup +++ b/rel/appups/archethic/1.0.7_to_1.1.0.appup @@ -1,4 +1,4 @@ -{"1.1.0-rc5", +{"1.1.0", [{"1.0.7", [{add_module,'Elixir.Archethic.BeaconChain.NetworkCoordinates'}, {add_module,'Elixir.Archethic.BeaconChain.Subset.StatsCollector'}, @@ -681,8 +681,6 @@ ['Elixir.Archethic.Crypto','Elixir.Archethic.DB', 'Elixir.Archethic.SharedSecrets', 'Elixir.Archethic.TransactionChain']}, - {apply,{supervisor, terminate_child, ['Elixir.Archethic.Crypto.KeystoreSupervisor', 'Elixir.Archethic.Crypto.SharedSecretsKeystore.SoftwareImpl']}}, - {apply,{supervisor, restart_child, ['Elixir.Archethic.Crypto.KeystoreSupervisor', 'Elixir.Archethic.Crypto.SharedSecretsKeystore.SoftwareImpl']}}, {update,'Elixir.Archethic.DB.EmbeddedImpl.ChainIndex', {advanced,[]}, brutal_purge,soft_purge, @@ -1054,7 +1052,7 @@ type => supervisor } ]}}, - {apply,{'Elixir.Mix.Tasks.Archethic.Migrate',run,["1.1.0-rc5",true]}}]}], + {apply,{'Elixir.Mix.Tasks.Archethic.Migrate',run,["1.1.0",true]}}]}], [{"1.0.7", [{delete_module,'Elixir.Archethic.BeaconChain.NetworkCoordinates'}, {delete_module,'Elixir.Archethic.BeaconChain.Subset.StatsCollector'},