Skip to content

Commit

Permalink
Update task timeout for replication and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Neylix committed Dec 12, 2022
1 parent d6b6f17 commit 3a207be
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
10 changes: 5 additions & 5 deletions lib/archethic/mining/transaction_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ defmodule Archethic.Mining.TransactionContext do
alias Archethic.Election

alias Archethic.P2P
alias Archethic.P2P.Message
alias Archethic.P2P.Message.Ok
alias Archethic.P2P.Message.Ping
alias Archethic.P2P.Node
Expand Down Expand Up @@ -61,7 +60,7 @@ defmodule Archethic.Mining.TransactionContext do
prev_tx_task = request_previous_tx(previous_address, prev_tx_nodes_split)
nodes_view_task = request_nodes_view(node_public_keys)

prev_tx = Task.await(prev_tx_task, Message.get_max_timeout())
prev_tx = Task.await(prev_tx_task, 4500)
nodes_view = Task.await(nodes_view_task)

%{
Expand Down Expand Up @@ -102,15 +101,16 @@ defmodule Archethic.Mining.TransactionContext do
Task.Supervisor.async(
TaskSupervisor,
fn ->
case TransactionChain.fetch_transaction_remotely(previous_address, nodes) do
# Timeout of 4 sec because the coordinator node wait 5 sec to get the context
# from the cross validation nodes
case TransactionChain.fetch_transaction_remotely(previous_address, nodes, 4000) do
{:ok, tx} ->
tx

{:error, _} ->
nil
end
end,
timeout: Message.get_max_timeout()
end
)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/archethic/replication.ex
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ defmodule Archethic.Replication do

{previous_transaction, inputs} =
if self_repair? do
{Task.await(t1, Message.get_max_timeout()), []}
{Task.await(t1, Message.get_max_timeout() + 1000), []}
else
t2 = Task.Supervisor.async(TaskSupervisor, fn -> fetch_inputs(tx, download_nodes) end)
{Task.await(t1, Message.get_max_timeout()), Task.await(t2)}
inputs = fetch_inputs(tx, download_nodes)
{Task.await(t1, Message.get_max_timeout() + 1000), inputs}
end

Logger.debug("Previous transaction #{inspect(previous_transaction)}",
Expand Down
16 changes: 12 additions & 4 deletions lib/archethic/transaction_chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -687,14 +687,21 @@ defmodule Archethic.TransactionChain do
If no nodes are available to answer the request, `{:error, :network_issue}` is returned.
"""
@spec fetch_transaction_remotely(address :: Crypto.versioned_hash(), list(Node.t())) ::
@spec fetch_transaction_remotely(
address :: Crypto.versioned_hash(),
list(Node.t()),
non_neg_integer()
) ::
{:ok, Transaction.t()}
| {:error, :transaction_not_exists}
| {:error, :transaction_invalid}
| {:error, :network_issue}
def fetch_transaction_remotely(_, []), do: {:error, :transaction_not_exists}
def fetch_transaction_remotely(address, nodes, timeout \\ Message.get_max_timeout())

def fetch_transaction_remotely(_, [], _), do: {:error, :transaction_not_exists}

def fetch_transaction_remotely(address, nodes) when is_binary(address) and is_list(nodes) do
def fetch_transaction_remotely(address, nodes, timeout)
when is_binary(address) and is_list(nodes) do
conflict_resolver = fn results ->
# Prioritize transactions results over not found
with nil <- Enum.find(results, &match?(%Transaction{}, &1)),
Expand All @@ -709,7 +716,8 @@ defmodule Archethic.TransactionChain do
case P2P.quorum_read(
nodes,
%GetTransaction{address: address},
conflict_resolver
conflict_resolver,
timeout
) do
{:ok, %NotFound{}} ->
{:error, :transaction_not_exists}
Expand Down
6 changes: 3 additions & 3 deletions test/archethic/bootstrap_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ defmodule Archethic.BootstrapTest do

assert :ok =
Bootstrap.do_resync_network_chain(
[:node_shared_secrets],
:node_shared_secrets,
_nodes = P2P.authorized_and_available_nodes()
)
end
Expand Down Expand Up @@ -523,7 +523,7 @@ defmodule Archethic.BootstrapTest do

assert :ok =
Bootstrap.do_resync_network_chain(
[:node_shared_secrets],
:node_shared_secrets,
_nodes = P2P.authorized_and_available_nodes()
)

Expand Down Expand Up @@ -598,7 +598,7 @@ defmodule Archethic.BootstrapTest do

assert :ok =
Bootstrap.do_resync_network_chain(
[:node_shared_secrets],
:node_shared_secrets,
_nodes = P2P.authorized_and_available_nodes()
)

Expand Down

0 comments on commit 3a207be

Please sign in to comment.