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

Take previous reward address in node bootstrap #916

Merged
merged 1 commit into from
Feb 28, 2023
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
35 changes: 30 additions & 5 deletions lib/archethic/bootstrap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ defmodule Archethic.Bootstrap do
P2P.Node,
SelfRepair,
TransactionChain,
TransactionChain.Transaction,
TransactionChain.TransactionData,
Replication
}

Expand Down Expand Up @@ -146,7 +148,7 @@ defmodule Archethic.Bootstrap do
transport,
bootstrapping_seeds,
network_patch,
reward_address
configured_reward_address
) do
Logger.info("Bootstrapping starting")

Expand All @@ -161,7 +163,7 @@ defmodule Archethic.Bootstrap do
port,
http_port,
transport,
reward_address
configured_reward_address
)

Sync.initialize_network(tx)
Expand All @@ -179,22 +181,30 @@ defmodule Archethic.Bootstrap do
transport,
network_patch,
bootstrapping_seeds,
reward_address
configured_reward_address
)

post_bootstrap(sync?: true)

true ->
Logger.info("Update node chain...")

{:ok, %Transaction{data: %TransactionData{content: content}}} =
TransactionChain.get_last_transaction(
Crypto.derive_address(Crypto.first_node_public_key())
)

{:ok, _ip, _p2p_port, _http_port, _transport, last_reward_address, _origin_public_key,
_key_certificate} = Node.decode_transaction_content(content)

update_node(
ip,
port,
http_port,
transport,
network_patch,
bootstrapping_seeds,
reward_address
last_reward_address
)

post_bootstrap(sync?: true)
Expand Down Expand Up @@ -284,7 +294,7 @@ defmodule Archethic.Bootstrap do
transport,
patch,
bootstrapping_seeds,
reward_address
configured_reward_address
) do
Enum.each(bootstrapping_seeds, &P2P.add_and_connect_node/1)

Expand All @@ -302,6 +312,21 @@ defmodule Archethic.Bootstrap do

Crypto.set_node_key_index(length)

reward_address =
if length > 0 do
{:ok, %Transaction{data: %TransactionData{content: content}}} =
TransactionChain.get_last_transaction(
Crypto.derive_address(Crypto.first_node_public_key())
)

{:ok, _ip, _p2p_port, _http_port, _transport, last_reward_address, _origin_public_key,
_key_certificate} = Node.decode_transaction_content(content)

last_reward_address
else
configured_reward_address
end

tx =
TransactionHandler.create_node_transaction(ip, port, http_port, transport, reward_address)

Expand Down