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

Add control for mining process before starting mining #480

Merged
merged 1 commit into from
Jul 29, 2022
Merged
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: 16 additions & 6 deletions lib/archethic/p2p/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1170,16 +1170,26 @@ defmodule Archethic.P2P.Message do
validation_node_public_keys: validation_nodes
})
when length(validation_nodes) > 0 do
if Mining.valid_election?(tx, validation_nodes) do
with {:election, true} <- {:election, Mining.valid_election?(tx, validation_nodes)},
{:mining, false} <- {:mining, Mining.processing?(tx.address)} do
{:ok, _} = Mining.start(tx, welcome_node_public_key, validation_nodes)
%Ok{}
else
Logger.error("Invalid validation node election",
transaction_address: Base.encode16(tx.address),
transaction_type: tx.type
)
{:election, _} ->
Logger.error("Invalid validation node election",
transaction_address: Base.encode16(tx.address),
transaction_type: tx.type
)

raise "Invalid validate node election"

raise "Invalid validate node election"
{:mining, _} ->
Logger.warning("Transaction already in mining process",
transaction_address: Base.encode16(tx.address),
transaction_type: tx.type
)

%Ok{}
end
end

Expand Down