Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.4.8 upgrade #1433

Merged
merged 10 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/archethic/account/mem_tables/state_ledger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Archethic.Account.MemTables.StateLedger do
alias Archethic.TransactionChain.Transaction.ValidationStamp.LedgerOperations.VersionedUnspentOutput

use GenServer
@vsn 1
@vsn 2

require Logger

Expand Down Expand Up @@ -88,4 +88,20 @@ defmodule Archethic.Account.MemTables.StateLedger do
:ets.new(@ledger_table, [:set, :named_table, :public, read_concurrency: true])
{:ok, :no_state}
end

# add timestamp in the ETS table
def code_change(1, state, _extra) do
elements =
:ets.tab2list(@ledger_table)
|> Enum.map(fn {address, encoded_payload, protocol_version} ->
{address, encoded_payload, nil, protocol_version}
end)

# since it's a set it will override them
:ets.insert(@ledger_table, elements)

{:ok, state}
end

def code_change(_version, state, _extra), do: {:ok, state}
end
24 changes: 23 additions & 1 deletion lib/archethic/beacon_chain/subset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule Archethic.BeaconChain.Subset do
alias Archethic.Utils

use GenServer
@vsn 1
@vsn 2

require Logger

Expand Down Expand Up @@ -99,6 +99,28 @@ defmodule Archethic.BeaconChain.Subset do
}}
end

# update the TransactionSummary in memory
def code_change(1, state, _extra) do
state =
update_in(
state,
[Access.key!(:current_slot), Access.key!(:transaction_attestations)],
fn attestations ->
Enum.map(
attestations,
fn attestation = %ReplicationAttestation{transaction_summary: summary} ->
%ReplicationAttestation{
attestation
| transaction_summary: Map.put(summary, :genesis_address, nil)
}
end
)
end
)

{:ok, state}
end

def code_change(_, state, _extra), do: {:ok, state}

def handle_call(:get_current_slot, _from, state = %{current_slot: current_slot}) do
Expand Down
35 changes: 34 additions & 1 deletion lib/archethic/beacon_chain/subset/summary_cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Archethic.BeaconChain.Subset.SummaryCache do
alias Archethic.BeaconChain
alias Archethic.BeaconChain.Slot
alias Archethic.BeaconChain.SummaryTimer
alias Archethic.BeaconChain.ReplicationAttestation
alias Archethic.Crypto

alias Archethic.PubSub
Expand All @@ -14,7 +15,7 @@ defmodule Archethic.BeaconChain.Subset.SummaryCache do
alias Archethic.Utils.VarInt

use GenServer
@vsn 1
@vsn 2

@table_name :archethic_summary_cache

Expand All @@ -39,6 +40,38 @@ defmodule Archethic.BeaconChain.Subset.SummaryCache do
{:ok, %{}}
end

# update the TransactionSummary in memory
def code_change(1, state, _extra) do
# credo:disable-for-lines:26
elements =
:ets.tab2list(@table_name)
|> Enum.map(fn {subset, {slot, node_public_key}} ->
slot =
Map.update!(
slot,
:transaction_attestations,
fn attestations ->
Enum.map(
attestations,
fn attestation = %ReplicationAttestation{transaction_summary: summary} ->
%ReplicationAttestation{
attestation
| transaction_summary: Map.put(summary, :genesis_address, nil)
}
end
)
end
)

{subset, {slot, node_public_key}}
end)

:ets.delete_all_objects(@table_name)
:ets.insert(@table_name, elements)

{:ok, state}
end

def code_change(_version, state, _extra), do: {:ok, state}

def handle_info(:self_repair_sync, state) do
Expand Down
11 changes: 10 additions & 1 deletion lib/archethic/self_repair/repair_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Archethic.SelfRepair.RepairWorker do
alias Archethic.SelfRepair.NotifierSupervisor

use GenServer, restart: :transient
@vsn 1
@vsn 2

require Logger

Expand Down Expand Up @@ -102,6 +102,15 @@ defmodule Archethic.SelfRepair.RepairWorker do

def handle_info(_, data), do: {:noreply, data}

# add the genesis_address to the state
def code_change(1, state, _extra) do
[genesis_address] = Registry.keys(RepairRegistry, self())
state = Map.put(state, :genesis_address, genesis_address)
{:ok, state}
end

def code_change(_version, state, _extra), do: {:ok, state}

defp start_repair(
data = %{
storage_addresses: [],
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Archethic.MixProject do
def project do
[
app: :archethic,
version: "1.4.7",
version: "1.4.8-rc1",
build_path: "_build",
config_path: "config/config.exs",
deps_path: "deps",
Expand Down
11 changes: 6 additions & 5 deletions priv/migration_tasks/prod/1.4.8@aeip_21-1.exs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ defmodule Migration_1_4_8 do
do: fetch_transaction(last_chain_address, authorized_nodes),
else: nil

unless TransactionChain.transaction_exists?(last_chain_address) do
Replication.sync_transaction_chain(last_transaction, genesis_address, authorized_nodes,
self_repair: true
)
end
if not is_nil(last_transaction) && not TransactionChain.transaction_exists?(last_chain_address) do
Replication.sync_transaction_chain(last_transaction, genesis_address, authorized_nodes,
self_repair: true
)
end


inputs = fetch_transaction_inputs(last_chain_address, authorized_nodes)

Expand Down
4 changes: 1 addition & 3 deletions rel/appups/archethic/1.0.7_to_1.1.0.appup
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@
'Elixir.Archethic.SelfRepair',
'Elixir.Archethic.SharedSecrets',
'Elixir.Archethic.TransactionChain']},

{load_module,'Elixir.Archethic.DB.EmbeddedImpl',brutal_purge,soft_purge,
['Elixir.Archethic.DB.EmbeddedImpl.BootstrapInfo',
'Elixir.Archethic.DB.EmbeddedImpl.ChainIndex',
Expand Down Expand Up @@ -2075,5 +2075,3 @@
{add_module,'Elixir.Archethic.Contracts.Interpreter.TransactionStatements'},
{add_module,'Elixir.Archethic.Contracts.Interpreter.Utils'},
{add_module,'Elixir.Archethic.P2P.Message.ReplicateTransactionChain'}]}]}.


Loading