From c915fa7ee361bf4581abd2d2d19eb2d59c41fbe8 Mon Sep 17 00:00:00 2001 From: Samuel Manzanera Date: Mon, 27 Feb 2023 09:14:19 +0100 Subject: [PATCH] Take previous reward address in node bootstrap --- lib/archethic/bootstrap.ex | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/archethic/bootstrap.ex b/lib/archethic/bootstrap.ex index e3250c393..ddf8c5800 100644 --- a/lib/archethic/bootstrap.ex +++ b/lib/archethic/bootstrap.ex @@ -16,6 +16,8 @@ defmodule Archethic.Bootstrap do P2P.Node, SelfRepair, TransactionChain, + TransactionChain.Transaction, + TransactionChain.TransactionData, Replication } @@ -146,7 +148,7 @@ defmodule Archethic.Bootstrap do transport, bootstrapping_seeds, network_patch, - reward_address + configured_reward_address ) do Logger.info("Bootstrapping starting") @@ -161,7 +163,7 @@ defmodule Archethic.Bootstrap do port, http_port, transport, - reward_address + configured_reward_address ) Sync.initialize_network(tx) @@ -179,7 +181,7 @@ defmodule Archethic.Bootstrap do transport, network_patch, bootstrapping_seeds, - reward_address + configured_reward_address ) post_bootstrap(sync?: true) @@ -187,6 +189,14 @@ defmodule Archethic.Bootstrap do 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, @@ -194,7 +204,7 @@ defmodule Archethic.Bootstrap do transport, network_patch, bootstrapping_seeds, - reward_address + last_reward_address ) post_bootstrap(sync?: true) @@ -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) @@ -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)