Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete burn of the transaction fee #259

Merged
3 commits merged into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions lib/archethic/account/mem_tables_loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ defmodule ArchEthic.Account.MemTablesLoader do

alias ArchEthic.Crypto

alias ArchEthic.P2P
alias ArchEthic.P2P.Node

alias ArchEthic.TransactionChain
alias ArchEthic.TransactionChain.Transaction
alias ArchEthic.TransactionChain.Transaction.ValidationStamp
alias ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperations
alias ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperations.NodeMovement

alias ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperations.TransactionMovement

Expand All @@ -29,7 +25,7 @@ defmodule ArchEthic.Account.MemTablesLoader do
:previous_public_key,
validation_stamp: [
:timestamp,
ledger_operations: [:node_movements, :unspent_outputs, :transaction_movements]
ledger_operations: [:unspent_outputs, :transaction_movements]
]
]

Expand Down Expand Up @@ -69,7 +65,6 @@ defmodule ArchEthic.Account.MemTablesLoader do
timestamp: timestamp,
ledger_operations: %LedgerOperations{
unspent_outputs: unspent_outputs,
node_movements: node_movements,
transaction_movements: transaction_movements
}
}
Expand All @@ -81,7 +76,6 @@ defmodule ArchEthic.Account.MemTablesLoader do

:ok = set_transaction_movements(address, transaction_movements, timestamp)
:ok = set_unspent_outputs(address, unspent_outputs, timestamp)
:ok = set_node_rewards(address, node_movements, timestamp)

Logger.info("Loaded into in memory account tables",
transaction_address: Base.encode16(address),
Expand Down Expand Up @@ -125,18 +119,4 @@ defmodule ArchEthic.Account.MemTablesLoader do
NFTLedger.add_unspent_output(address, unspent_output, timestamp)
end)
end

defp set_node_rewards(address, node_movements, timestamp) do
node_movements
|> Enum.filter(&(&1.amount > 0))
|> Enum.each(fn %NodeMovement{to: to, amount: amount} ->
%Node{reward_address: reward_address} = P2P.get_node_info!(to)

UCOLedger.add_unspent_output(
reward_address,
%UnspentOutput{amount: amount, from: address, type: :UCO, reward?: true},
timestamp
)
end)
end
end
10 changes: 7 additions & 3 deletions lib/archethic/beacon_chain/replication_attestation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ defmodule ArchEthic.BeaconChain.ReplicationAttestation do
...> address: <<0, 0, 232, 183, 247, 15, 195, 209, 138, 58, 226, 218, 221, 135, 181, 43, 216, 164, 4, 187, 38,
...> 200, 170, 241, 23, 249, 75, 17, 23, 241, 185, 36, 15, 66>>,
...> type: :transfer,
...> timestamp: ~U[2022-01-27 09:14:22Z]
...> timestamp: ~U[2022-01-27 09:14:22Z],
...> fee: 10_000_000
...> },
...> confirmations: [
...> {
Expand All @@ -52,6 +53,8 @@ defmodule ArchEthic.BeaconChain.ReplicationAttestation do
0, 0, 1, 126, 154, 208, 125, 176,
# Transaction type
253,
# Fee
0, 0, 0, 0, 0, 152, 150, 128,
# Nb movements
0, 0,
# Nb confirmations
Expand Down Expand Up @@ -92,7 +95,7 @@ defmodule ArchEthic.BeaconChain.ReplicationAttestation do
iex> <<1, 0, 0, 232, 183, 247, 15, 195, 209, 138, 58, 226, 218, 221, 135, 181, 43, 216,
...> 164, 4, 187, 38, 200, 170, 241, 23, 249, 75, 17, 23, 241, 185, 36, 15, 66,
...> 0, 0, 1, 126, 154, 208, 125, 176,
...> 253,0, 0,
...> 253, 0, 0, 0, 0, 0, 152, 150, 128, 0, 0,
...> 1, 0,64,
...> 129, 204, 107, 81, 235, 88, 234, 207, 125, 1, 208, 227, 239, 175, 78, 217,
...> 100, 172, 67, 228, 131, 42, 177, 200, 54, 225, 34, 241, 35, 226, 108, 138,
Expand All @@ -106,7 +109,8 @@ defmodule ArchEthic.BeaconChain.ReplicationAttestation do
address: <<0, 0, 232, 183, 247, 15, 195, 209, 138, 58, 226, 218, 221, 135, 181, 43, 216, 164, 4, 187, 38,
200, 170, 241, 23, 249, 75, 17, 23, 241, 185, 36, 15, 66>>,
type: :transfer,
timestamp: ~U[2022-01-27 09:14:22.000Z]
timestamp: ~U[2022-01-27 09:14:22.000Z],
fee: 10_000_000
},
confirmations: [
{
Expand Down
21 changes: 15 additions & 6 deletions lib/archethic/beacon_chain/slot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ defmodule ArchEthic.BeaconChain.Slot do
...> <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166,
...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>
...> ],
...> fee: 10_000_000
...> },
...> confirmations: [{0, <<185, 37, 172, 79, 189, 197, 94, 202, 41, 160, 222, 127, 227, 180, 133, 62, 76,
...> 29, 230, 10, 100, 79, 47, 49, 139, 117, 0, 64, 89, 229, 228, 214, 6, 49, 119,
Expand All @@ -86,7 +87,8 @@ defmodule ArchEthic.BeaconChain.Slot do
movements_addresses: [
<<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166,
99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>
]
],
fee: 10_000_000
},
confirmations: [
{
Expand All @@ -113,7 +115,8 @@ defmodule ArchEthic.BeaconChain.Slot do
...> movements_addresses: [
...> <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166,
...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>
...> ]
...> ],
...> fee: 10_000_000
...> },
...> confirmations: [{0, <<185, 37, 172, 79, 189, 197, 94, 202, 41, 160, 222, 127, 227, 180, 133, 62, 76,
...> 29, 230, 10, 100, 79, 47, 49, 139, 117, 0, 64, 89, 229, 228, 214, 6, 49, 119,
Expand All @@ -132,6 +135,7 @@ defmodule ArchEthic.BeaconChain.Slot do
...> <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166,
...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>
...> ],
...> fee: 10_000_000
...> },
...> confirmations: [{1, <<89, 98, 246, 6, 202, 116, 247, 88, 69, 148, 188, 173, 34, 0, 194, 108, 169,
...> 155, 63, 197, 200, 6, 31, 148, 57, 152, 195, 154, 181, 14, 77, 9, 161, 38,
Expand All @@ -149,7 +153,8 @@ defmodule ArchEthic.BeaconChain.Slot do
movements_addresses: [
<<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166,
99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>
]
],
fee: 10_000_000
},
confirmations: [
{
Expand Down Expand Up @@ -292,7 +297,8 @@ defmodule ArchEthic.BeaconChain.Slot do
...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>,
...> timestamp: ~U[2020-06-25 15:11:53Z],
...> type: :transfer,
...> movements_addresses: []
...> movements_addresses: [],
...> fee: 10_000_000
...> },
...> confirmations: [{0, <<129, 204, 107, 81, 235, 88, 234, 207, 125, 1, 208, 227, 239, 175, 78, 217,
...> 100, 172, 67, 228, 131, 42, 177, 200, 54, 225, 34, 241, 35, 226, 108, 138,
Expand Down Expand Up @@ -332,6 +338,8 @@ defmodule ArchEthic.BeaconChain.Slot do
0, 0, 1, 114, 236, 9, 2, 168,
# Type (transfer)
253,
# Fee
0, 0, 0, 0, 0, 152, 150, 128,
# Nb movements addresses
0, 0,
# Nb confirmations
Expand Down Expand Up @@ -409,7 +417,7 @@ defmodule ArchEthic.BeaconChain.Slot do
iex> <<1, 0, 96, 8, 1, 120, 0, 0, 0, 1,
...> 1, 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166,
...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12,
...> 0, 0, 1, 114, 236, 9, 2, 168, 253, 0, 0,
...> 0, 0, 1, 114, 236, 9, 2, 168, 253, 0, 0, 0, 0, 0, 152, 150, 128, 0, 0,
...> 1, 0, 64, 129, 204, 107, 81, 235, 88, 234, 207, 125, 1, 208, 227, 239, 175, 78, 217,
...> 100, 172, 67, 228, 131, 42, 177, 200, 54, 225, 34, 241, 35, 226, 108, 138,
...> 201, 2, 32, 75, 92, 49, 194, 42, 113, 154, 20, 43, 216, 176, 11, 159, 188,
Expand All @@ -431,7 +439,8 @@ defmodule ArchEthic.BeaconChain.Slot do
99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>,
timestamp: ~U[2020-06-25 15:11:53.000Z],
type: :transfer,
movements_addresses: []
movements_addresses: [],
fee: 10_000_000
},
confirmations: [{0, <<129, 204, 107, 81, 235, 88, 234, 207, 125, 1, 208, 227, 239, 175, 78, 217,
100, 172, 67, 228, 131, 42, 177, 200, 54, 225, 34, 241, 35, 226, 108, 138,
Expand Down
22 changes: 15 additions & 7 deletions lib/archethic/beacon_chain/summary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ defmodule ArchEthic.BeaconChain.Summary do
...> address: <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166,
...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>,
...> type: :transfer,
...> timestamp: ~U[2020-06-25 15:11:53Z]
...> timestamp: ~U[2020-06-25 15:11:53Z],
...> fee: 10_000_000
...> }
...> }
...> ],
Expand All @@ -82,7 +83,8 @@ defmodule ArchEthic.BeaconChain.Summary do
address: <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166,
99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>,
type: :transfer,
timestamp: ~U[2020-06-25 15:11:53Z]
timestamp: ~U[2020-06-25 15:11:53Z],
fee: 10_000_000
}
}
],
Expand All @@ -101,7 +103,8 @@ defmodule ArchEthic.BeaconChain.Summary do
...> address: <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166,
...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>,
...> type: :transfer,
...> timestamp: ~U[2020-06-25 15:11:53Z]
...> timestamp: ~U[2020-06-25 15:11:53Z],
...> fee: 10_000_000
...> }
...> }
...> ],
Expand All @@ -123,7 +126,8 @@ defmodule ArchEthic.BeaconChain.Summary do
address: <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166,
99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>,
type: :transfer,
timestamp: ~U[2020-06-25 15:11:53Z]
timestamp: ~U[2020-06-25 15:11:53Z],
fee: 10_000_000
}
}
],
Expand Down Expand Up @@ -266,7 +270,8 @@ defmodule ArchEthic.BeaconChain.Summary do
...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>,
...> timestamp: ~U[2020-06-25 15:11:53Z],
...> type: :transfer,
...> movements_addresses: []
...> movements_addresses: [],
...> fee: 10_000_000
...> },
...> confirmations: [{0, <<255, 120, 232, 52, 141, 15, 97, 213, 231, 93, 242, 160, 123, 25, 192, 3, 133,
...> 170, 197, 102, 148, 208, 119, 130, 225, 102, 130, 96, 223, 61, 36, 76, 229,
Expand Down Expand Up @@ -296,6 +301,8 @@ defmodule ArchEthic.BeaconChain.Summary do
0, 0, 1, 114, 236, 9, 2, 168,
# Type (transfer)
253,
# Fee
0, 0, 0, 0, 0, 152, 150, 128,
# Nb movement addresses
0, 0,
# Nb confirmations
Expand Down Expand Up @@ -352,7 +359,7 @@ defmodule ArchEthic.BeaconChain.Summary do

iex> <<1, 0, 96, 7, 114, 128, 0, 0, 0, 1, 1, 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166,
...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12,
...> 0, 0, 1, 114, 236, 9, 2, 168, 253, 0, 0,
...> 0, 0, 1, 114, 236, 9, 2, 168, 253, 0, 0, 0, 0, 0, 152, 150, 128, 0, 0,
...> 1, 0, 64, 255, 120, 232, 52, 141, 15, 97, 213, 231, 93, 242, 160, 123, 25, 192, 3, 133,
...> 170, 197, 102, 148, 208, 119, 130, 225, 102, 130, 96, 223, 61, 36, 76, 229,
...> 210, 5, 142, 79, 249, 177, 51, 15, 45, 45, 141, 217, 85, 77, 146, 199, 126,
Expand All @@ -370,7 +377,8 @@ defmodule ArchEthic.BeaconChain.Summary do
99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>,
timestamp: ~U[2020-06-25 15:11:53.000Z],
type: :transfer,
movements_addresses: []
movements_addresses: [],
fee: 10_000_000
},
confirmations: [{0, <<255, 120, 232, 52, 141, 15, 97, 213, 231, 93, 242, 160, 123, 25, 192, 3, 133,
170, 197, 102, 148, 208, 119, 130, 225, 102, 130, 96, 223, 61, 36, 76, 229,
Expand Down
6 changes: 0 additions & 6 deletions lib/archethic/bootstrap/network_init.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ defmodule ArchEthic.Bootstrap.NetworkInit do
alias ArchEthic.Mining

alias ArchEthic.PubSub
alias ArchEthic.P2P.Node

alias ArchEthic.Replication

Expand Down Expand Up @@ -133,11 +132,6 @@ defmodule ArchEthic.Bootstrap.NetworkInit do
transaction_movements: Transaction.get_movements(tx)
}
|> LedgerOperations.from_transaction(tx)
|> LedgerOperations.distribute_rewards(
%Node{last_public_key: Crypto.last_node_public_key()},
[%Node{last_public_key: Crypto.last_node_public_key()}],
[]
)
|> LedgerOperations.consume_inputs(tx.address, unspent_outputs)

validation_stamp =
Expand Down
40 changes: 0 additions & 40 deletions lib/archethic/mining.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ defmodule ArchEthic.Mining do
alias ArchEthic.P2P.Node

alias ArchEthic.SelfRepair
alias ArchEthic.SharedSecrets

alias ArchEthic.TransactionChain.Transaction
alias ArchEthic.TransactionChain.Transaction.CrossValidationStamp
Expand Down Expand Up @@ -102,45 +101,6 @@ defmodule ArchEthic.Mining do
validation_node_public_keys == Enum.map(validation_nodes, & &1.last_public_key)
end

def valid_election?(
tx = %Transaction{
address: tx_address,
type: tx_type,
validation_stamp: %ValidationStamp{timestamp: timestamp, proof_of_election: poe}
},
validation_node_public_keys
)
when is_list(validation_node_public_keys) do
daily_nonce_public_key = SharedSecrets.get_daily_nonce_public_key(timestamp)

if daily_nonce_public_key == SharedSecrets.genesis_daily_nonce_public_key() do
# Should happens only during the network bootstrapping
true
else
node_list = transaction_validation_node_list(tx_type, timestamp)
storage_nodes = Election.chain_storage_nodes_with_type(tx_address, tx_type, node_list)

constraints = Election.get_validation_constraints()

with true <-
Election.valid_proof_of_election?(tx, poe, daily_nonce_public_key),
nodes = [_ | _] <-
Election.validation_nodes(
tx,
poe,
node_list,
storage_nodes,
constraints
),
set_of_validation_node_public_keys <- Enum.map(nodes, & &1.last_public_key) do
Enum.all?(validation_node_public_keys, &(&1 in set_of_validation_node_public_keys))
else
_ ->
false
end
end
end

@doc """
Add transaction mining context which built by another cross validation node
"""
Expand Down
Loading