Skip to content

Commit

Permalink
Add burning address to I/O storage nodes only if it's intentional (#749)
Browse files Browse the repository at this point in the history
* Removing unneeded potential addition of burning address
* Remove fetching the last address of burning addresses
* Add burning address only if part of recipients originally
  • Loading branch information
netboz committed Dec 22, 2022
1 parent 7cfcee2 commit 57132b7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 33 deletions.
28 changes: 0 additions & 28 deletions lib/archethic/account/mem_tables_loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ defmodule Archethic.Account.MemTablesLoader do

alias Archethic.Crypto

alias Archethic.Election

alias Archethic.P2P

alias Archethic.TransactionChain
alias Archethic.TransactionChain.Transaction
alias Archethic.TransactionChain.Transaction.ValidationStamp
Expand All @@ -24,8 +20,6 @@ defmodule Archethic.Account.MemTablesLoader do

alias Archethic.TransactionChain.Transaction.ValidationStamp.LedgerOperations.VersionedUnspentOutput

alias Archethic.Utils

require Logger

alias Archethic.Reward
Expand Down Expand Up @@ -81,7 +75,6 @@ defmodule Archethic.Account.MemTablesLoader do
timestamp: timestamp,
protocol_version: protocol_version,
ledger_operations: %LedgerOperations{
fee: fee,
unspent_outputs: unspent_outputs,
transaction_movements: transaction_movements
}
Expand All @@ -96,27 +89,6 @@ defmodule Archethic.Account.MemTablesLoader do
TokenLedger.spend_all_unspent_outputs(previous_address)
end

burn_storage_nodes =
Election.storage_nodes(
LedgerOperations.burning_address(),
P2P.authorized_and_available_nodes(timestamp)
)

transaction_movements =
if Utils.key_in_node_list?(burn_storage_nodes, Crypto.first_node_public_key()) and
fee > 0 do
[
%TransactionMovement{
to: LedgerOperations.burning_address(),
amount: fee,
type: :UCO
}
| transaction_movements
]
else
transaction_movements
end

:ok =
set_transaction_movements(
address,
Expand Down
2 changes: 0 additions & 2 deletions lib/archethic/mining/distributed_workflow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ defmodule Archethic.Mining.DistributedWorkflow do

alias Archethic.TransactionChain
alias Archethic.TransactionChain.Transaction
alias Archethic.TransactionChain.Transaction.ValidationStamp.LedgerOperations
alias Archethic.TransactionChain.Transaction.CrossValidationStamp
alias Archethic.TransactionChain.Transaction.ValidationStamp
alias Archethic.TransactionChain.TransactionSummary
Expand Down Expand Up @@ -189,7 +188,6 @@ defmodule Archethic.Mining.DistributedWorkflow do
else
resolved_addresses
|> Enum.map(fn {_origin, resolved} -> resolved end)
|> Enum.concat([LedgerOperations.burning_address()])
|> Election.io_storage_nodes(authorized_nodes)
end

Expand Down
2 changes: 0 additions & 2 deletions lib/archethic/mining/standalone_workflow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ defmodule Archethic.Mining.StandaloneWorkflow do

alias Archethic.TransactionChain
alias Archethic.TransactionChain.Transaction
alias Archethic.TransactionChain.Transaction.ValidationStamp.LedgerOperations
alias Archethic.TransactionChain.TransactionSummary

require Logger
Expand Down Expand Up @@ -83,7 +82,6 @@ defmodule Archethic.Mining.StandaloneWorkflow do
else
resolved_addresses
|> Enum.map(fn {_origin, resolved} -> resolved end)
|> Enum.concat([LedgerOperations.burning_address()])
|> Election.io_storage_nodes(authorized_nodes)
end

Expand Down
10 changes: 10 additions & 0 deletions lib/archethic/transaction_chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ defmodule Archethic.TransactionChain do
alias __MODULE__.TransactionData
alias __MODULE__.Transaction.ValidationStamp

alias __MODULE__.Transaction.ValidationStamp.LedgerOperations

alias __MODULE__.Transaction.ValidationStamp.LedgerOperations.TransactionMovement.Type,
as: TransactionMovementType

Expand Down Expand Up @@ -539,6 +541,8 @@ defmodule Archethic.TransactionChain do
tx = %Transaction{data: %TransactionData{recipients: recipients}},
time = %DateTime{}
) do
burning_address = LedgerOperations.burning_address()

addresses =
tx
|> Transaction.get_movements()
Expand All @@ -549,6 +553,9 @@ defmodule Archethic.TransactionChain do
TaskSupervisor,
addresses,
fn
{^burning_address, type} ->
{{burning_address, type}, burning_address}

{to, type} ->
case resolve_last_address(to, time) do
{:ok, resolved} ->
Expand All @@ -558,6 +565,9 @@ defmodule Archethic.TransactionChain do
{{to, type}, to}
end

^burning_address ->
{burning_address, burning_address}

to ->
case resolve_last_address(to, time) do
{:ok, resolved} ->
Expand Down
9 changes: 8 additions & 1 deletion test/archethic/account/mem_tables_loader_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ defmodule Archethic.Account.MemTablesLoaderTest do
timestamp: ^timestamp
}
}
] = UCOLedger.get_unspent_outputs(LedgerOperations.burning_address())
] = TokenLedger.get_unspent_outputs(LedgerOperations.burning_address())

assert [] = UCOLedger.get_unspent_outputs(LedgerOperations.burning_address())

assert [
%VersionedUnspentOutput{
Expand Down Expand Up @@ -255,6 +257,11 @@ defmodule Archethic.Account.MemTablesLoaderTest do
to: "@Bob3",
amount: 1_000_000_000,
type: {:token, "@CharlieToken", 0}
},
%TransactionMovement{
to: LedgerOperations.burning_address(),
amount: 100_000_000,
type: {:token, "@Charlie2", 0}
}
],
unspent_outputs: [
Expand Down

0 comments on commit 57132b7

Please sign in to comment.