Skip to content

Commit

Permalink
fix governance validation workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tenmoves committed May 3, 2023
1 parent fb88d67 commit f17285f
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 79 deletions.
24 changes: 0 additions & 24 deletions .iex.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,3 @@ alias Archethic.TransactionChain
alias Archethic.TransactionChain.Transaction
alias Archethic.TransactionChain.TransactionData
alias Archethic.BeaconChain


alias Archethic.Governance.Code.CICD.Docker
prop = %Archethic.Governance.Code.Proposal{
address: <<0, 0, 135, 189, 175, 8, 43, 160, 49, 21, 23, 241, 61, 189, 221,
177, 45, 120, 59, 243, 80, 75, 193, 250, 119, 188, 219, 73, 209, 197, 118,
170, 122, 142>>,
previous_public_key: <<0, 1, 62, 205, 23, 142, 29, 217, 94, 202, 136, 109,
165, 135, 153, 205, 202, 132, 122, 116, 97, 18, 90, 34, 141, 225, 172, 138,
16, 138, 85, 15, 41, 149>>,
timestamp: nil,
description: "\Testing code proposal\"",
changes: "diff --git a/mix.exs b/mix.exs\nindex a82c0b3c..b94d4323 100644\n--- a/mix.exs\n+++ b/mix.exs\n@@ -4,7 +4,7 @@ defmodule Archethic.MixProject do\n def project do\n [\n app: :archethic,\n- version: \"1.0.7\",\n+ version: \"1.0.8\",\n build_path: \"_build\",\n config_path: \"config/config.exs\",\n deps_path: \"deps\",\ndiff --git a/rel/appups/archethic/1.0.7_to_1.0.8.appup b/rel/appups/archethic/1.0.7_to_1.0.8.appup\nnew file mode 100644\nindex 00000000..18b6d541\n--- /dev/null\n+++ b/rel/appups/archethic/1.0.7_to_1.0.8.appup\n@@ -0,0 +1,4 @@\n+{\"1.0.8\",\n+ [{\"1.0.7\",\n+ [{load_module,'Elixir.Archethic', []}]}],\n+ [{\"1.0.7\",\n+ [{load_module,'Elixir.Archethic', []}]}]\n+}.\n",
version: "1.0.8",
files: ["mix.exs", "rel/appups/archethic/1.0.7_to_1.0.8.appup"],
approvals: [
<<0, 0, 135, 189, 175, 8, 43, 160, 49, 21, 23, 241, 61, 189, 221, 177, 45,
120, 59, 243, 80, 75, 193, 250, 119, 188, 219, 73, 209, 197, 118, 170,
122, 142>>,
<<0, 0, 168, 220, 209, 92, 167, 255, 187, 168, 176, 63, 128, 210, 199, 35,
63, 0, 252, 36, 147, 196, 130, 249, 233, 17, 132, 0, 6, 88, 232, 198, 98,
44>>
]
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ RUN git config user.name aebot \

# build release
RUN mix assets.deploy
RUN MIX_ENV=prod mix distillery.release
RUN MIX_ENV=${MIX_ENV} mix distillery.release
# Install
RUN mkdir -p /opt/app \
&& tar zxf /opt/code/_build/${MIX_ENV}/rel/archethic_node/releases/*/archethic_node.tar.gz -C /opt/app
Expand Down
36 changes: 16 additions & 20 deletions lib/archethic/crypto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1141,26 +1141,22 @@ defmodule Archethic.Crypto do
"""
@spec get_root_ca_public_key(key()) :: binary()
def get_root_ca_public_key(<<curve::8, origin_id::8, _::binary>>) do
if System.get_env("ARCHETHIC_NETWORK_TYPE") == "testnet" do
""
else
case Keyword.get(@certification_public_keys, ID.to_origin(origin_id)) do
nil ->
"no_key"

# Only for dev
[] ->
""

curves when is_list(curves) ->
case Keyword.get(curves, ID.to_curve(curve)) do
nil ->
"no_key"

public_key ->
public_key
end
end
case Keyword.get(@certification_public_keys, ID.to_origin(origin_id)) do
nil ->
"no_key"

# Only for dev
[] ->
""

curves when is_list(curves) ->
case Keyword.get(curves, ID.to_curve(curve)) do
nil ->
"no_key"

public_key ->
public_key
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/archethic/db/embedded_impl/chain_index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Archethic.DB.EmbeddedImpl.ChainIndex do
{:ok, %{db_path: db_path}}
end

def code_change("1.0.6", state, _extra) do
def code_change("1.0.7", state, _extra) do
## We start the unstarted LRU cache
cache_max_size = Application.get_env(:archethic, Archethic.DB.ChainIndex.MaxCacheSize)
LRU.start_link(@archetic_db_tx_index_cache, cache_max_size)
Expand Down
30 changes: 25 additions & 5 deletions lib/archethic/governance/code/cicd/docker/cicd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ defmodule Archethic.Governance.Code.CICD.Docker do
|> Path.basename()
|> String.downcase()

validator_container = "#{compose_prefix}-validator-1"
validator_1_container = "#{compose_prefix}-validator_1-1"
validator_2_container = "#{compose_prefix}-validator_2-1"

nodes = 1..nb_nodes |> Enum.map(&"#{compose_prefix}-node#{&1}-1")

Expand All @@ -226,25 +227,27 @@ defmodule Archethic.Governance.Code.CICD.Docker do
%{cmd: {_, 0}, testnet: _testnet} <- testnet_start(dir, nb_nodes),
# wait until the validator is ready for upgrade
:ok <- Logger.info("#{dir} Part I", address: address_encoded),
{:ok, _} <- wait_for_marker(validator_container, @marker),
{:ok, _} <- wait_for_marker(validator_1_container, @marker),
:ok <- Logger.info("#{dir} Upgrade", address: address_encoded),
true <- testnet_upgrade(dir, nodes, version),
:ok <- Logger.info("#{dir} Part II", address: address_encoded),
# {_, 0} <- validator_continue(validator_container, testnet),
{_, 0} <- validator_continue(dir),
0 <-
docker_wait(validator_container, System.monotonic_time(:second)) do
docker_wait(validator_2_container, System.monotonic_time(:second)) do
testnet_cleanup(dir, 0, address_encoded)
else
_ ->
testnet_cleanup(dir, 1, address_encoded)
end
end

@logfile_name "ci_logfile.txt"
defp testnet_prepare(dir, address, version) do
ci = container_name(address)

with :ok <- File.mkdir_p!(dir),
{_, 0} <- docker(["cp", "#{ci}:#{@releases}/#{version}/#{@release}", dir]) do
{_, 0} <- docker(["cp", "#{ci}:#{@releases}/#{version}/#{@release}", dir]),
{_, 0} <- docker(["cp", "#{ci}:/opt/code/#{@logfile_name}", dir <> "/#{@logfile_name}"]) do
:ok
else
_ -> :error
Expand Down Expand Up @@ -340,6 +343,23 @@ defmodule Archethic.Governance.Code.CICD.Docker do
end
end

defp validator_continue(dir) do
compose = compose_file(dir)

System.cmd(
"docker-compose",
[
"--profile",
"validate_2",
"-f",
compose,
"up",
"-d"
],
@cmd_options
)
end

defp testnet_cleanup(dir, code, address_encoded) do
Logger.info("#{dir} Cleanup", address: address_encoded)

Expand Down
18 changes: 11 additions & 7 deletions lib/archethic/governance/code/proposal/validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ defmodule Archethic.Governance.Code.Proposal.Validator do
require Logger

alias Archethic.Utils.Regression
alias Archethic.Utils

@marker Application.compile_env(:archethic, :marker)

def run(nodes, _) do
def run(nodes, 1) do
with true <- Regression.nodes_up?(nodes),
:ok <- Regression.run_benchmarks(nodes, phase: :before) do
put_marker(nodes)
end
end

def run(nodes, 2) do
start = System.monotonic_time(:second)

with true <- Regression.nodes_up?(nodes),
:ok <- Regression.run_benchmarks(nodes, phase: :before),
:ok <- put_marker(nodes),
_ <- Process.sleep(3 * 60 * 1000),
:ok <- Regression.run_benchmarks(nodes, phase: :after),
with :ok <- Regression.run_benchmarks(nodes, phase: :after),
:ok <- Regression.run_playbooks(nodes),
{:ok, _metrics} <-
{:ok, metrics} <-
Regression.get_metrics("collector", 9090, 5 + System.monotonic_time(:second) - start) do
write_metrics(metrics)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Archethic.Networking.IPLookup.NATDiscovery.MiniUPNP do

require Logger

def upnpc() do
defp upnpc() do
Application.app_dir(:archethic, "priv/c_dist/upnpc")
end

Expand Down
37 changes: 30 additions & 7 deletions lib/archethic/utils/testnet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ defmodule Archethic.Utils.Testnet do
defp p2p_port, do: 30_002
defp web_port, do: 40_000

@validator_ip 220
@validator_1_ip 220
@validator_2_ip 230
@bench_ip 221
@collector_ip 200

Expand Down Expand Up @@ -280,7 +281,7 @@ defmodule Archethic.Utils.Testnet do
networks: %{:net => %{ipv4_address: "1.2.3.#{@collector_ip}"}},
volumes: [".prometheus.yml:/etc/prometheus/prometheus.yml:ro"]
},
"validator" => %{
"validator_1" => %{
image: "i",
environment: %{
"ARCHETHIC_MUT_DIR" => "/opt/data"
Expand All @@ -289,7 +290,19 @@ defmodule Archethic.Utils.Testnet do
volumes: [
"./validator_data/:/opt/data"
],
networks: %{:net => %{ipv4_address: "1.2.3.#{@validator_ip}"}},
networks: %{:net => %{ipv4_address: "1.2.3.#{@validator_1_ip}"}},
},
"validator_2" => %{
image: "i",
environment: %{
"ARCHETHIC_MUT_DIR" => "/opt/data"
},
command: ["./bin/archethic_node", "validate", "1.2.3.2", "1.2.3.3", "1.2.3.4", "--phase=2"],
volumes: [
"./validator_data/:/opt/data"
],
networks: %{:net => %{ipv4_address: "1.2.3.#{@validator_2_ip}"}},
profiles: ["validate_2"]
},
"bench" => %{
image: "i",
Expand Down Expand Up @@ -330,7 +343,7 @@ defmodule Archethic.Utils.Testnet do
networks: %{:net => %{ipv4_address: ip.(@collector_ip)}},
volumes: [".prometheus.yml:/etc/prometheus/prometheus.yml:ro"]
})
|> Map.put("validator", %{
|> Map.put("validator_1", %{
image: image,
environment: %{
"ARCHETHIC_MUT_DIR" => "/opt/data"
Expand All @@ -339,8 +352,19 @@ defmodule Archethic.Utils.Testnet do
volumes: [
"./validator_data/:/opt/data"
],
# profiles: ["validate"],
networks: %{:net => %{ipv4_address: ip.(@validator_ip)}}
networks: %{:net => %{ipv4_address: ip.(@validator_1_ip)}}
})
|> Map.put("validator_2", %{
image: image,
environment: %{
"ARCHETHIC_MUT_DIR" => "/opt/data"
},
command: ["./bin/archethic_node", "validate" | uninodes] ++ ["--phase=2"],
volumes: [
"./validator_data/:/opt/data"
],
profiles: ["validate_2"],
networks: %{:net => %{ipv4_address: ip.(@validator_2_ip)}}
})
|> Map.put("bench", %{
image: image,
Expand All @@ -351,7 +375,6 @@ defmodule Archethic.Utils.Testnet do
volumes: [
"./bench_data/:/opt/data"
],
# profiles: ["validate"],
networks: %{:net => %{ipv4_address: ip.(@bench_ip)}}
})

Expand Down
15 changes: 6 additions & 9 deletions lib/mix/tasks/validate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule Mix.Tasks.Archethic.Proposal.Validator do
use Mix.Task

alias Archethic.Governance.Code.Proposal.Validator
alias Mix.Tasks.Utils

@impl Mix.Task
@spec run([binary]) :: any
Expand All @@ -37,16 +38,12 @@ defmodule Mix.Tasks.Archethic.Proposal.Validator do
if parsed[:help] do
Mix.shell().cmd("mix help #{Mix.Task.task_name(__MODULE__)}")
else
:ok = maybe(parsed, :phase, &Validator.run/2, [nodes, parsed[:phase]])
:ok =
Utils.apply_function_if_key_exists(parsed, :phase, &Validator.run/2, [
nodes,
parsed[:phase]
])
end
end
end

defp maybe(opts, key, func, args) do
if opts[key] do
apply(func, args)
else
:ok
end
end
end
3 changes: 0 additions & 3 deletions scripts/governance/proposal_ci_job.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ PROPOSAL_ADDRESS=$1
PROPOSAL_DESCRIPTION=$2
PROPOSAL_FILENAME=./proposal.diff

echo "=== Test proposal ${PROPOSAL_ADDRESS}"
tee ${PROPOSAL_FILENAME}

echo "=== Create branch ${PROPOSAL_ADDRESS}"
git checkout -b "prop_${PROPOSAL_ADDRESS}"

Expand Down
2 changes: 1 addition & 1 deletion src/c/nat/miniupnp

0 comments on commit f17285f

Please sign in to comment.