Skip to content

Commit

Permalink
Some fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Neylix committed Nov 23, 2022
1 parent 3e2facb commit a0aca17
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 60 deletions.
6 changes: 0 additions & 6 deletions lib/archethic/p2p.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ defmodule Archethic.P2P do
@spec list_nodes() :: list(Node.t())
defdelegate list_nodes, to: MemTable

@doc """
Stream the registered nodes.
"""
@spec stream_nodes() :: Enumerable.t()
defdelegate stream_nodes(), to: MemTable

@doc """
Return the list of available nodes
"""
Expand Down
45 changes: 0 additions & 45 deletions lib/archethic/p2p/mem_table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -433,51 +433,6 @@ defmodule Archethic.P2P.MemTable do
)
end

@doc """
Stream List of nodes from heap to stack
"""
@spec stream_nodes :: Enumerable.t()
def stream_nodes do
Stream.resource(
fn ->
nil
end,
fn
nil ->
# first iteration
node_from_key(:ets.first(@discovery_table))

prev_ele ->
# next and last iteration
next_key = :ets.next(@discovery_table, prev_ele)
node_from_key(next_key)
end,
fn _ ->
:ok
end
)
end

def node_from_key(:"$end_of_table"), do: {:halt, nil}

def node_from_key(key) when is_binary(key) do
case :ets.lookup(@discovery_table, key) do
[] ->
{:halt, nil}

[object] ->
node =
object
|> Node.cast()
|> toggle_node_authorization
|> toggle_node_availability

{[node], key}
end
end

def node_from_key(_), do: {:halt, nil}

@doc """
List the authorized nodes
Expand Down
3 changes: 1 addition & 2 deletions lib/archethic/p2p/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ defmodule Archethic.P2P.Message do
ListNodes,
NewBeaconSlot,
NewTransaction,
NodeAvailability,
NodeList,
NotFound,
NotifyEndOfNodeSync,
Expand Down Expand Up @@ -1840,6 +1839,7 @@ defmodule Archethic.P2P.Message do
def process(%NotifyPreviousChain{address: address}, _) do
Replication.acknowledge_previous_storage_nodes(address)
%Ok{}
end

def process(
msg = %ShardRepair{
Expand Down Expand Up @@ -1885,7 +1885,6 @@ defmodule Archethic.P2P.Message do
%Ok{}
end


defp process_replication_chain(tx, replying_node_public_key) do
Task.Supervisor.start_child(TaskSupervisor, fn ->
response =
Expand Down
3 changes: 2 additions & 1 deletion test/archethic/self_repair/notifier/repair_worker_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Archethic.SelfRepair.Notifier.RepairWorkerTest do
@moduledoc false
use ArchethicCase

alias Plug.Crypto
alias Archethic.SelfRepair.Notifier.Impl, as: NotifierImpl
alias Archethic.SelfRepair.Notifier.RepairWorker

Expand Down Expand Up @@ -117,7 +118,7 @@ defmodule Archethic.SelfRepair.Notifier.RepairWorkerTest do

assert Enum.map(chain_list, fn _x ->
%Message.Ok{}
end) == Enum.map(msg_list, fn msg -> Message.process(msg) end)
end) == Enum.map(msg_list, fn msg -> Message.process(msg, nil) end)

assert [{pid, _}] = Registry.lookup(NotifierImpl.registry_name(), first_address)

Expand Down
10 changes: 4 additions & 6 deletions test/support/transaction_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ defmodule Archethic.TransactionFactory do

alias Archethic.TransactionChain.TransactionData

# @deprecated "use_create_valid_chain/2 instead"
def create_valid_transaction(
inputs \\ [],
opts \\ []
Expand Down Expand Up @@ -227,8 +226,7 @@ defmodule Archethic.TransactionFactory do
end

@doc """
Creates a valid Node Shared Secrets Tx with parameters index, timestamp, prev_txn.any()
requires valid_p2p_Context
Creates a valid Node Shared Secrets Tx with parameters index, timestamp, prev_txn
"""
@spec create_network_tx(:node_shared_secrets, keyword) ::
Archethic.TransactionChain.Transaction.t()
Expand Down Expand Up @@ -275,12 +273,12 @@ defmodule Archethic.TransactionFactory do
}
end

@spec create_valid_chain(input :: list(), opts :: list()) ::
Archethic.TransactionChain.Transaction.t()
@doc """
Creates a valid Txn Chain with parameters index, timestamp, prev_txn.
required valid_p2p_Context
"""
@spec create_valid_chain(input :: list(), opts :: list()) ::
Archethic.TransactionChain.Transaction.t()
def create_valid_chain(
inputs \\ [],
opts \\ []
Expand All @@ -296,7 +294,7 @@ defmodule Archethic.TransactionFactory do

ledger_operations =
%LedgerOperations{
fee: Fee.calculate(txn, 0.07),
fee: Fee.calculate(txn, 0.07, timestamp),
transaction_movements: Transaction.get_movements(txn)
}
|> LedgerOperations.consume_inputs(txn.address, inputs, timestamp)
Expand Down

0 comments on commit a0aca17

Please sign in to comment.