Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorv-2204 committed Sep 5, 2022
1 parent c215943 commit 7e5721f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
3 changes: 0 additions & 3 deletions lib/archethic/account/mem_tables_loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ defmodule Archethic.Account.MemTablesLoader do

{{to, _token_address}, utxo} ->
TokenLedger.add_unspent_output(to, utxo, timestamp)

{{to, _token_address, _token_id}, utxo} ->
TokenLedger.add_unspent_output(to, utxo, timestamp)
end)
end

Expand Down
2 changes: 2 additions & 0 deletions lib/archethic/beacon_chain/slot_timer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ defmodule Archethic.BeaconChain.SlotTimer do

case :persistent_term.get(:archethic_up, nil) do
nil ->
Logger.info("Slot Timer: Waiting for Node to complete Bootstrap.")

Archethic.PubSub.register_to_node_up()
{:ok, %{interval: interval}}

Expand Down
2 changes: 1 addition & 1 deletion lib/archethic/bootstrap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ defmodule Archethic.Bootstrap do
SelfRepair.start_scheduler()

:persistent_term.put(:archethic_up, :up)
Archethic.PubSub.notify_node_up(:up)
Archethic.PubSub.notify_node_up()
Listener.listen()
end

Expand Down
14 changes: 7 additions & 7 deletions lib/archethic/oracle_chain/scheduler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,19 @@ defmodule Archethic.OracleChain.Scheduler do
|> Map.put(:summary_interval, summary_interval)

case :persistent_term.get(:archethic_up, nil) do
:up ->
# when node is already bootstrapped, - handles scheduler crash
{state, new_state_data, events} = start_scheduler(state_data)
{:ok, state, new_state_data, events}

nil ->
# node still bootstrapping , wait for it to finish Bootstrap
Logger.info(" Oracle Scheduler: Waiting for Node to complete Bootstrap. ")

Archethic.PubSub.register_to_node_up()
PubSub.register_to_node_up()

{:ok, :idle, state_data}

# wait for node UP
# wait for node UP
:up ->
# when node is already bootstrapped, - handles scheduler crash
{state, new_state_data, events} = start_scheduler(state_data)
{:ok, state, new_state_data, events}
end
end

Expand Down Expand Up @@ -160,6 +159,7 @@ defmodule Archethic.OracleChain.Scheduler do
end

def handle_event(:info, {:node_up, :up}, :idle, state_data) do
PubSub.unregister_to_node_up()
{:idle, new_state_data, events} = start_scheduler(state_data)
{:keep_state, new_state_data, events}
end
Expand Down
6 changes: 3 additions & 3 deletions lib/archethic/pub_sub.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ defmodule Archethic.PubSub do
@doc """
Notify that Node is Up
"""
@spec notify_node_up(:up | nil) :: :ok
def notify_node_up(status) do
dispatch(:node_up, {:node_up, status})
@spec notify_node_up() :: :ok
def notify_node_up() do
dispatch(:node_up, {:node_up, :up})
end

@spec register_to_node_up :: {:error, {:already_registered, pid}} | {:ok, pid}
Expand Down
3 changes: 2 additions & 1 deletion lib/archethic/reward/scheduler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Archethic.Reward.Scheduler do
nil ->
Logger.info(" Reward Scheduler: Waiting for Node to complete Bootstrap. ")

Archethic.PubSub.register_to_node_up()
PubSub.register_to_node_up()
{:ok, :idle, state_data}

# wait for node up
Expand Down Expand Up @@ -86,6 +86,7 @@ defmodule Archethic.Reward.Scheduler do

def handle_event(:info, {:node_up, :up}, :idle, state_data) do
# Node is up start Scheduler
PubSub.unregister_to_node_up()
{:idle, new_state_data, events} = start_scheduler(state_data)
{:keep_state, new_state_data, events}
end
Expand Down
3 changes: 2 additions & 1 deletion lib/archethic/shared_secrets/node_renewal_scheduler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ defmodule Archethic.SharedSecrets.NodeRenewalScheduler do
nil ->
Logger.info("Node Renewal Scheduler: Waiting for node to complete Bootstrap. ")

Archethic.PubSub.register_to_node_up()
PubSub.register_to_node_up()
{:ok, :idle, state_data}

# wait for node ups
Expand Down Expand Up @@ -108,6 +108,7 @@ defmodule Archethic.SharedSecrets.NodeRenewalScheduler do
end

def handle_event(:info, {:node_up, :up}, :idle, state_data) do
PubSub.unregister_to_node_up()
# Node is Up start Scheduler
{:idle, new_state_data, events} = start_scheduler(state_data)
{:keep_state, new_state_data, events}
Expand Down

0 comments on commit 7e5721f

Please sign in to comment.