Skip to content

Commit

Permalink
Add control for mining process before starting mining (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neylix committed Jul 29, 2022
1 parent aaeeebd commit 55bb170
Showing 1 changed file with 16 additions and 6 deletions.
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

0 comments on commit 55bb170

Please sign in to comment.