Skip to content

Commit fc6e067

Browse files
committed
Remove KOLedger
1 parent f65f505 commit fc6e067

File tree

19 files changed

+27
-307
lines changed

19 files changed

+27
-307
lines changed

config/test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ config :archethic, Archethic.SharedSecrets.NodeRenewalScheduler,
170170
application_interval: "0 0 * * * * *"
171171

172172
config :archethic, Archethic.TransactionChain.MemTables.PendingLedger, enabled: false
173-
config :archethic, Archethic.TransactionChain.MemTables.KOLedger, enabled: false
174173
config :archethic, Archethic.TransactionChain.MemTablesLoader, enabled: false
175174

176175
config :archethic, Archethic.TransactionChain.DBLedger, MockTransactionLedger

lib/archethic.ex

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,8 @@ defmodule Archethic do
5555
Search a transaction by its address
5656
Check locally and fallback to a quorum read
5757
"""
58-
@spec search_transaction(address :: binary()) ::
59-
{:ok, Transaction.t()}
60-
| {:error, :transaction_not_exists}
61-
| {:error, :invalid_transaction}
62-
| {:error, :network_issue}
58+
@spec search_transaction(address :: Crypto.prepended_hash()) ::
59+
{:ok, Transaction.t()} | {:error, :transaction_not_exists} | {:error, :network_issue}
6360
def search_transaction(address) when is_binary(address) do
6461
storage_nodes = Election.chain_storage_nodes(address, P2P.authorized_and_available_nodes())
6562

@@ -292,11 +289,8 @@ defmodule Archethic do
292289
@doc """
293290
Retrieve the last transaction for a chain from the closest nodes
294291
"""
295-
@spec get_last_transaction(address :: binary()) ::
296-
{:ok, Transaction.t()}
297-
| {:error, :transaction_not_exists}
298-
| {:error, :invalid_transaction}
299-
| {:error, :network_issue}
292+
@spec get_last_transaction(address :: Crypto.prepended_hash()) ::
293+
{:ok, Transaction.t()} | {:error, :transaction_not_exists} | {:error, :network_issue}
300294
def get_last_transaction(address) when is_binary(address) do
301295
case get_last_transaction_address(address) do
302296
{:ok, last_address} ->

lib/archethic/contracts/interpreter/legacy/library.ex

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,6 @@ defmodule Archethic.Contracts.Interpreter.Legacy.Library do
241241
{:ok, {:error, :transaction_not_exists}} ->
242242
{:error, "Transaction not exists"}
243243

244-
{:ok, {:error, :invalid_transaction}} ->
245-
{:error, "Transaction invalid"}
246-
247244
{:error, :decode_error} ->
248245
{:error, "Error in decoding transaction"}
249246

lib/archethic/mining/pending_transaction_validation.ex

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,9 +909,6 @@ defmodule Archethic.Mining.PendingTransactionValidation do
909909
{:ok, {:error, :transaction_not_exists}} ->
910910
{:error, "Invalid token transaction - token_reference not found"}
911911

912-
{:ok, {:error, :invalid_transaction}} ->
913-
{:error, "Invalid token transaction - token_reference is invalid"}
914-
915912
{:ok, {:error, :network_issue}} ->
916913
{:error, "A network issue was raised, please retry later"}
917914

lib/archethic/p2p/message/get_last_transaction.ex

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@ defmodule Archethic.P2P.Message.GetLastTransaction do
1919
@spec process(__MODULE__.t(), Crypto.key()) :: NotFound.t() | Error.t() | Transaction.t()
2020
def process(%__MODULE__{address: address}, _) do
2121
case TransactionChain.get_last_transaction(address) do
22-
{:ok, tx} ->
23-
tx
24-
25-
{:error, :transaction_not_exists} ->
26-
%NotFound{}
27-
28-
{:error, :invalid_transaction} ->
29-
%Error{reason: :invalid_transaction}
22+
{:ok, tx} -> tx
23+
{:error, :transaction_not_exists} -> %NotFound{}
3024
end
3125
end
3226

lib/archethic/p2p/message/get_transaction.ex

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@ defmodule Archethic.P2P.Message.GetTransaction do
1919
@spec process(__MODULE__.t(), Crypto.key()) :: NotFound.t() | Error.t() | Transaction.t()
2020
def process(%__MODULE__{address: tx_address}, _) do
2121
case TransactionChain.get_transaction(tx_address) do
22-
{:ok, tx} ->
23-
tx
24-
25-
{:error, :transaction_not_exists} ->
26-
%NotFound{}
27-
28-
{:error, :invalid_transaction} ->
29-
%Error{reason: :invalid_transaction}
22+
{:ok, tx} -> tx
23+
{:error, :transaction_not_exists} -> %NotFound{}
3024
end
3125
end
3226

lib/archethic/replication.ex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ defmodule Archethic.Replication do
9696
)
9797

9898
%ValidationContext{mining_error: error} ->
99-
:ok = TransactionChain.write_ko_transaction(tx)
100-
10199
Logger.warning("Invalid transaction for replication - #{inspect(error)}",
102100
transaction_address: Base.encode16(address),
103101
transaction_type: type
@@ -270,8 +268,6 @@ defmodule Archethic.Replication do
270268
else: synchronize_io_transaction(tx, genesis_address, opts)
271269

272270
%ValidationContext{mining_error: error} ->
273-
:ok = TransactionChain.write_ko_transaction(tx)
274-
275271
Logger.warning("Invalid transaction for replication - #{inspect(error)}",
276272
transaction_address: Base.encode16(address),
277273
transaction_type: type

lib/archethic/transaction_chain.ex

Lines changed: 15 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ defmodule Archethic.TransactionChain do
4646
FirstTransactionAddress
4747
}
4848

49-
alias __MODULE__.MemTables.KOLedger
5049
alias __MODULE__.MemTables.PendingLedger
51-
# alias __MODULE__.MemTablesLoader
5250

5351
alias __MODULE__.Transaction
5452
alias __MODULE__.TransactionData
@@ -160,28 +158,17 @@ defmodule Archethic.TransactionChain do
160158

161159
@doc """
162160
Get a transaction
163-
164-
A lookup is performed into the KO ledger to determine if the transaction is invalid
165161
"""
166162
@spec get_transaction(binary(), fields :: list()) ::
167-
{:ok, Transaction.t()}
168-
| {:error, :transaction_not_exists}
169-
| {:error, :invalid_transaction}
170-
def get_transaction(address, fields \\ [], storage_type \\ :chain) when is_list(fields) do
171-
if KOLedger.has_transaction?(address) do
172-
{:error, :invalid_transaction}
173-
else
174-
DB.get_transaction(address, fields, storage_type)
175-
end
176-
end
163+
{:ok, Transaction.t()} | {:error, :transaction_not_exists}
164+
def get_transaction(address, fields \\ [], storage_type \\ :chain) when is_list(fields),
165+
do: DB.get_transaction(address, fields, storage_type)
177166

178167
@doc """
179168
Get the last transaction from a given chain address
180169
"""
181170
@spec get_last_transaction(binary(), list()) ::
182-
{:ok, Transaction.t()}
183-
| {:error, :transaction_not_exists}
184-
| {:error, :invalid_transaction}
171+
{:ok, Transaction.t()} | {:error, :transaction_not_exists}
185172
def get_last_transaction(address, fields \\ []) when is_binary(address) and is_list(fields) do
186173
{address, _} = get_last_address(address)
187174
get_transaction(address, fields)
@@ -258,13 +245,6 @@ defmodule Archethic.TransactionChain do
258245
@spec get_size(binary()) :: non_neg_integer()
259246
defdelegate get_size(address), to: DB, as: :chain_size
260247

261-
@doc """
262-
Get the details from a ko transaction address
263-
"""
264-
@spec get_ko_details(binary()) ::
265-
{ValidationStamp.t(), inconsistencies :: list(), errors :: list()}
266-
defdelegate get_ko_details(address), to: KOLedger, as: :get_details
267-
268248
@doc """
269249
List of all the counter signatures regarding a given transaction
270250
"""
@@ -365,11 +345,7 @@ defmodule Archethic.TransactionChain do
365345
address :: Crypto.prepended_hash(),
366346
storage_nodes :: list(Node.t()),
367347
opts :: search_options()
368-
) ::
369-
{:ok, Transaction.t()}
370-
| {:error, :transaction_not_exists}
371-
| {:error, :invalid_transaction}
372-
| {:error, :network_issue}
348+
) :: {:ok, Transaction.t()} | {:error, :transaction_not_exists} | {:error, :network_issue}
373349
def fetch_transaction(address, nodes, opts \\ []) do
374350
with :hybrid <- Keyword.get(opts, :search_mode, :hybrid),
375351
{:ok, tx} <- get_transaction(address) do
@@ -424,14 +400,8 @@ defmodule Archethic.TransactionChain do
424400
timeout: timeout,
425401
acceptance_resolver: acceptance_resolver
426402
) do
427-
{:ok, %NotFound{}} ->
428-
{:error, :transaction_not_exists}
429-
430-
{:ok, %Error{}} ->
431-
{:error, :invalid_transaction}
432-
433-
res ->
434-
res
403+
{:ok, %NotFound{}} -> {:error, :transaction_not_exists}
404+
res -> res
435405
end
436406
end
437407
end
@@ -1064,30 +1034,18 @@ defmodule Archethic.TransactionChain do
10641034
storage_type \\ :chain
10651035
) do
10661036
DB.write_transaction(tx, storage_type)
1067-
|> tap(fn _ ->
1068-
KOLedger.remove_transaction(address)
1037+
|> tap(fn
1038+
:ok ->
1039+
Logger.info("Transaction stored",
1040+
transaction_address: Base.encode16(address),
1041+
transaction_type: type
1042+
)
10691043

1070-
Logger.info("Transaction stored",
1071-
transaction_address: Base.encode16(address),
1072-
transaction_type: type
1073-
)
1044+
_ ->
1045+
:skip
10741046
end)
10751047
end
10761048

1077-
@doc """
1078-
Write an invalid transaction
1079-
"""
1080-
@spec write_ko_transaction(transaction :: Transaction.t(), errors :: list()) :: :ok
1081-
defdelegate write_ko_transaction(tx, additional_errors \\ []),
1082-
to: KOLedger,
1083-
as: :add_transaction
1084-
1085-
@doc """
1086-
Determine if the transaction already be validated and is invalid
1087-
"""
1088-
@spec transaction_ko?(address :: binary()) :: boolean()
1089-
defdelegate transaction_ko?(address), to: KOLedger, as: :has_transaction?
1090-
10911049
@doc """
10921050
Determine if a transaction address has already sent a counter signature (approval) to another transaction
10931051
"""

lib/archethic/transaction_chain/mem_tables/ko_ledger.ex

Lines changed: 0 additions & 162 deletions
This file was deleted.

0 commit comments

Comments
 (0)