Skip to content

Commit

Permalink
Remove KOLedger
Browse files Browse the repository at this point in the history
  • Loading branch information
Neylix committed Feb 4, 2025
1 parent f65f505 commit fc6e067
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 307 deletions.
1 change: 0 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ config :archethic, Archethic.SharedSecrets.NodeRenewalScheduler,
application_interval: "0 0 * * * * *"

config :archethic, Archethic.TransactionChain.MemTables.PendingLedger, enabled: false
config :archethic, Archethic.TransactionChain.MemTables.KOLedger, enabled: false
config :archethic, Archethic.TransactionChain.MemTablesLoader, enabled: false

config :archethic, Archethic.TransactionChain.DBLedger, MockTransactionLedger
Expand Down
14 changes: 4 additions & 10 deletions lib/archethic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ defmodule Archethic do
Search a transaction by its address
Check locally and fallback to a quorum read
"""
@spec search_transaction(address :: binary()) ::
{:ok, Transaction.t()}
| {:error, :transaction_not_exists}
| {:error, :invalid_transaction}
| {:error, :network_issue}
@spec search_transaction(address :: Crypto.prepended_hash()) ::
{:ok, Transaction.t()} | {:error, :transaction_not_exists} | {:error, :network_issue}
def search_transaction(address) when is_binary(address) do
storage_nodes = Election.chain_storage_nodes(address, P2P.authorized_and_available_nodes())

Expand Down Expand Up @@ -292,11 +289,8 @@ defmodule Archethic do
@doc """
Retrieve the last transaction for a chain from the closest nodes
"""
@spec get_last_transaction(address :: binary()) ::
{:ok, Transaction.t()}
| {:error, :transaction_not_exists}
| {:error, :invalid_transaction}
| {:error, :network_issue}
@spec get_last_transaction(address :: Crypto.prepended_hash()) ::
{:ok, Transaction.t()} | {:error, :transaction_not_exists} | {:error, :network_issue}
def get_last_transaction(address) when is_binary(address) do
case get_last_transaction_address(address) do
{:ok, last_address} ->
Expand Down
3 changes: 0 additions & 3 deletions lib/archethic/contracts/interpreter/legacy/library.ex
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ defmodule Archethic.Contracts.Interpreter.Legacy.Library do
{:ok, {:error, :transaction_not_exists}} ->
{:error, "Transaction not exists"}

{:ok, {:error, :invalid_transaction}} ->
{:error, "Transaction invalid"}

{:error, :decode_error} ->
{:error, "Error in decoding transaction"}

Expand Down
3 changes: 0 additions & 3 deletions lib/archethic/mining/pending_transaction_validation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -909,9 +909,6 @@ defmodule Archethic.Mining.PendingTransactionValidation do
{:ok, {:error, :transaction_not_exists}} ->
{:error, "Invalid token transaction - token_reference not found"}

{:ok, {:error, :invalid_transaction}} ->
{:error, "Invalid token transaction - token_reference is invalid"}

{:ok, {:error, :network_issue}} ->
{:error, "A network issue was raised, please retry later"}

Expand Down
10 changes: 2 additions & 8 deletions lib/archethic/p2p/message/get_last_transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ defmodule Archethic.P2P.Message.GetLastTransaction do
@spec process(__MODULE__.t(), Crypto.key()) :: NotFound.t() | Error.t() | Transaction.t()
def process(%__MODULE__{address: address}, _) do
case TransactionChain.get_last_transaction(address) do
{:ok, tx} ->
tx

{:error, :transaction_not_exists} ->
%NotFound{}

{:error, :invalid_transaction} ->
%Error{reason: :invalid_transaction}
{:ok, tx} -> tx
{:error, :transaction_not_exists} -> %NotFound{}
end
end

Expand Down
10 changes: 2 additions & 8 deletions lib/archethic/p2p/message/get_transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ defmodule Archethic.P2P.Message.GetTransaction do
@spec process(__MODULE__.t(), Crypto.key()) :: NotFound.t() | Error.t() | Transaction.t()
def process(%__MODULE__{address: tx_address}, _) do
case TransactionChain.get_transaction(tx_address) do
{:ok, tx} ->
tx

{:error, :transaction_not_exists} ->
%NotFound{}

{:error, :invalid_transaction} ->
%Error{reason: :invalid_transaction}
{:ok, tx} -> tx
{:error, :transaction_not_exists} -> %NotFound{}
end
end

Expand Down
4 changes: 0 additions & 4 deletions lib/archethic/replication.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ defmodule Archethic.Replication do
)

%ValidationContext{mining_error: error} ->
:ok = TransactionChain.write_ko_transaction(tx)

Logger.warning("Invalid transaction for replication - #{inspect(error)}",
transaction_address: Base.encode16(address),
transaction_type: type
Expand Down Expand Up @@ -270,8 +268,6 @@ defmodule Archethic.Replication do
else: synchronize_io_transaction(tx, genesis_address, opts)

%ValidationContext{mining_error: error} ->
:ok = TransactionChain.write_ko_transaction(tx)

Logger.warning("Invalid transaction for replication - #{inspect(error)}",
transaction_address: Base.encode16(address),
transaction_type: type
Expand Down
72 changes: 15 additions & 57 deletions lib/archethic/transaction_chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ defmodule Archethic.TransactionChain do
FirstTransactionAddress
}

alias __MODULE__.MemTables.KOLedger
alias __MODULE__.MemTables.PendingLedger
# alias __MODULE__.MemTablesLoader

alias __MODULE__.Transaction
alias __MODULE__.TransactionData
Expand Down Expand Up @@ -160,28 +158,17 @@ defmodule Archethic.TransactionChain do

@doc """
Get a transaction
A lookup is performed into the KO ledger to determine if the transaction is invalid
"""
@spec get_transaction(binary(), fields :: list()) ::
{:ok, Transaction.t()}
| {:error, :transaction_not_exists}
| {:error, :invalid_transaction}
def get_transaction(address, fields \\ [], storage_type \\ :chain) when is_list(fields) do
if KOLedger.has_transaction?(address) do
{:error, :invalid_transaction}
else
DB.get_transaction(address, fields, storage_type)
end
end
{:ok, Transaction.t()} | {:error, :transaction_not_exists}
def get_transaction(address, fields \\ [], storage_type \\ :chain) when is_list(fields),
do: DB.get_transaction(address, fields, storage_type)

@doc """
Get the last transaction from a given chain address
"""
@spec get_last_transaction(binary(), list()) ::
{:ok, Transaction.t()}
| {:error, :transaction_not_exists}
| {:error, :invalid_transaction}
{:ok, Transaction.t()} | {:error, :transaction_not_exists}
def get_last_transaction(address, fields \\ []) when is_binary(address) and is_list(fields) do
{address, _} = get_last_address(address)
get_transaction(address, fields)
Expand Down Expand Up @@ -258,13 +245,6 @@ defmodule Archethic.TransactionChain do
@spec get_size(binary()) :: non_neg_integer()
defdelegate get_size(address), to: DB, as: :chain_size

@doc """
Get the details from a ko transaction address
"""
@spec get_ko_details(binary()) ::
{ValidationStamp.t(), inconsistencies :: list(), errors :: list()}
defdelegate get_ko_details(address), to: KOLedger, as: :get_details

@doc """
List of all the counter signatures regarding a given transaction
"""
Expand Down Expand Up @@ -365,11 +345,7 @@ defmodule Archethic.TransactionChain do
address :: Crypto.prepended_hash(),
storage_nodes :: list(Node.t()),
opts :: search_options()
) ::
{:ok, Transaction.t()}
| {:error, :transaction_not_exists}
| {:error, :invalid_transaction}
| {:error, :network_issue}
) :: {:ok, Transaction.t()} | {:error, :transaction_not_exists} | {:error, :network_issue}
def fetch_transaction(address, nodes, opts \\ []) do
with :hybrid <- Keyword.get(opts, :search_mode, :hybrid),
{:ok, tx} <- get_transaction(address) do
Expand Down Expand Up @@ -424,14 +400,8 @@ defmodule Archethic.TransactionChain do
timeout: timeout,
acceptance_resolver: acceptance_resolver
) do
{:ok, %NotFound{}} ->
{:error, :transaction_not_exists}

{:ok, %Error{}} ->
{:error, :invalid_transaction}

res ->
res
{:ok, %NotFound{}} -> {:error, :transaction_not_exists}
res -> res
end
end
end
Expand Down Expand Up @@ -1064,30 +1034,18 @@ defmodule Archethic.TransactionChain do
storage_type \\ :chain
) do
DB.write_transaction(tx, storage_type)
|> tap(fn _ ->
KOLedger.remove_transaction(address)
|> tap(fn
:ok ->
Logger.info("Transaction stored",
transaction_address: Base.encode16(address),
transaction_type: type
)

Logger.info("Transaction stored",
transaction_address: Base.encode16(address),
transaction_type: type
)
_ ->
:skip
end)
end

@doc """
Write an invalid transaction
"""
@spec write_ko_transaction(transaction :: Transaction.t(), errors :: list()) :: :ok
defdelegate write_ko_transaction(tx, additional_errors \\ []),
to: KOLedger,
as: :add_transaction

@doc """
Determine if the transaction already be validated and is invalid
"""
@spec transaction_ko?(address :: binary()) :: boolean()
defdelegate transaction_ko?(address), to: KOLedger, as: :has_transaction?

@doc """
Determine if a transaction address has already sent a counter signature (approval) to another transaction
"""
Expand Down
162 changes: 0 additions & 162 deletions lib/archethic/transaction_chain/mem_tables/ko_ledger.ex

This file was deleted.

Loading

0 comments on commit fc6e067

Please sign in to comment.