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

Fix bootstrap sync restart #1122

Merged
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
2 changes: 1 addition & 1 deletion lib/archethic/bootstrap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ defmodule Archethic.Bootstrap do
Logger.info("Synchronization started")
# Always load the current node list to have the current view for downloading transaction
{:ok, current_nodes} = Sync.connect_current_node(closest_bootstrapping_nodes)
:ok = SelfRepair.bootstrap_sync(last_sync_date, current_nodes)
:ok = SelfRepair.bootstrap_sync(current_nodes)
Logger.info("Synchronization finished")
end

Expand Down
14 changes: 8 additions & 6 deletions lib/archethic/self_repair.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ defmodule Archethic.SelfRepair do
@doc """
Start the bootstrap's synchronization process using the last synchronization date
"""
@spec bootstrap_sync(last_sync_date :: DateTime.t(), download_nodes :: list(Node.t())) ::
@spec bootstrap_sync(download_nodes :: list(Node.t())) ::
:ok | :error
def bootstrap_sync(last_sync_date, download_nodes) do
case sync_with_retry(last_sync_date, download_nodes) do
def bootstrap_sync(download_nodes) do
case sync_with_retry(download_nodes) do
:ok ->
# At the end of self repair, if a new beacon summary as been created
# we run bootstrap_sync again until the last beacon summary is loaded
Expand All @@ -58,7 +58,7 @@ defmodule Archethic.SelfRepair do
|> BeaconChain.previous_summary_time()
|> DateTime.compare(last_sync_date) do
:gt ->
bootstrap_sync(last_sync_date, download_nodes)
bootstrap_sync(download_nodes)

_ ->
:ok
Expand All @@ -68,14 +68,16 @@ defmodule Archethic.SelfRepair do
Logger.error(
"Bootstrap Sync failed to load missed transactions after max retry of #{@max_retry_count} !"
)

:error
end
end

defp sync_with_retry(last_sync_date, download_nodes) do
defp sync_with_retry(download_nodes) do
0..@max_retry_count
|> Enum.reduce_while(:error, fn _, _ ->
try do
:ok = Sync.load_missed_transactions(last_sync_date, download_nodes)
:ok = last_sync_date() |> Sync.load_missed_transactions(download_nodes)
{:halt, :ok}
rescue
error ->
Expand Down