Upgrading node and wallet config to new account numbers and adding version number.
This commit is contained in:
parent
7e0e2ec443
commit
43550586c7
4 changed files with 118 additions and 15 deletions
|
@ -449,6 +449,42 @@ TEST (node_config, v1_v2_upgrade)
|
|||
ASSERT_TRUE (!!tree.get_child_optional ("work_peers"));
|
||||
}
|
||||
|
||||
TEST (node_config, unversioned_v2_upgrade)
|
||||
{
|
||||
rai::logging logging1;
|
||||
boost::property_tree::ptree tree;
|
||||
tree.put ("peering_port", std::to_string (0));
|
||||
tree.put ("packet_delay_microseconds", std::to_string (0));
|
||||
tree.put ("bootstrap_fraction_numerator", std::to_string (0));
|
||||
tree.put ("creation_rebroadcast", std::to_string (0));
|
||||
tree.put ("rebroadcast_delay", std::to_string (0));
|
||||
tree.put ("receive_minimum", rai::amount (0).to_string_dec ());
|
||||
boost::property_tree::ptree logging_l;
|
||||
logging1.serialize_json (logging_l);
|
||||
tree.add_child ("logging", logging_l);
|
||||
boost::property_tree::ptree preconfigured_peers_l;
|
||||
tree.add_child ("preconfigured_peers", preconfigured_peers_l);
|
||||
boost::property_tree::ptree preconfigured_representatives_l;
|
||||
boost::property_tree::ptree entry;
|
||||
entry.put ("", "TR6ZJ4pdp6HC76xMRpVDny5x2s8AEbrhFue3NKVxYYdmKuTEib");
|
||||
preconfigured_representatives_l.push_back (std::make_pair ("", entry));
|
||||
tree.add_child ("preconfigured_representatives", preconfigured_representatives_l);
|
||||
boost::property_tree::ptree work_peers_l;
|
||||
tree.add_child ("work_peers", work_peers_l);
|
||||
bool upgraded (false);
|
||||
rai::node_config config1;
|
||||
ASSERT_FALSE (tree.get_optional <std::string> ("version"));
|
||||
config1.deserialize_json (upgraded, tree);
|
||||
ASSERT_TRUE (upgraded);
|
||||
ASSERT_EQ (1, config1.preconfigured_representatives.size ());
|
||||
ASSERT_EQ ("xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", config1.preconfigured_representatives [0].to_account ());
|
||||
auto reps (tree.get_child ("preconfigured_representatives"));
|
||||
ASSERT_EQ (1, reps.size ());
|
||||
ASSERT_EQ ("xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", reps.begin ()->second.get <std::string> (""));
|
||||
auto version (tree.get <std::string> ("version"));
|
||||
ASSERT_GT (std::stoull (version), 1);
|
||||
}
|
||||
|
||||
TEST (node, confirm_locked)
|
||||
{
|
||||
rai::system system (24000, 1);
|
||||
|
|
|
@ -726,11 +726,55 @@ void rai::node_config::serialize_json (boost::property_tree::ptree & tree_a) con
|
|||
tree_a.add_child ("preconfigured_representatives", preconfigured_representatives_l);
|
||||
}
|
||||
|
||||
bool rai::node_config::upgrade_json (unsigned version, boost::property_tree::ptree & tree_a)
|
||||
{
|
||||
auto result (false);
|
||||
switch (version)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
auto reps_l (tree_a.get_child ("preconfigured_representatives"));
|
||||
boost::property_tree::ptree reps;
|
||||
for (auto i (reps_l.begin ()), n (reps_l.end ()); i != n; ++i)
|
||||
{
|
||||
rai::uint256_union account;
|
||||
account.decode_account (i->second.get <std::string> (""));
|
||||
boost::property_tree::ptree entry;
|
||||
entry.put ("", account.to_account ());
|
||||
reps.push_back (std::make_pair ("", entry));
|
||||
}
|
||||
tree_a.erase ("preconfigured_representatives");
|
||||
tree_a.add_child ("preconfigured_representatives", reps);
|
||||
tree_a.erase ("version");
|
||||
tree_a.put ("version", "2");
|
||||
result = true;
|
||||
}
|
||||
case 2:
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error ("Unknown node_config version");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool rai::node_config::deserialize_json (bool & upgraded_a, boost::property_tree::ptree & tree_a)
|
||||
{
|
||||
auto result (false);
|
||||
try
|
||||
{
|
||||
auto version_l (tree_a.get_optional <std::string> ("version"));
|
||||
if (!version_l)
|
||||
{
|
||||
tree_a.put ("version", "1");
|
||||
version_l = "1";
|
||||
auto work_peers_l (tree_a.get_child_optional ("work_peers"));
|
||||
if (!work_peers_l)
|
||||
{
|
||||
tree_a.add_child ("work_peers", boost::property_tree::ptree ());
|
||||
}
|
||||
upgraded_a = true;
|
||||
}
|
||||
upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a);
|
||||
auto peering_port_l (tree_a.get <std::string> ("peering_port"));
|
||||
auto packet_delay_microseconds_l (tree_a.get <std::string> ("packet_delay_microseconds"));
|
||||
auto bootstrap_fraction_numerator_l (tree_a.get <std::string> ("bootstrap_fraction_numerator"));
|
||||
|
@ -738,23 +782,15 @@ bool rai::node_config::deserialize_json (bool & upgraded_a, boost::property_tree
|
|||
auto rebroadcast_delay_l (tree_a.get <std::string> ("rebroadcast_delay"));
|
||||
auto receive_minimum_l (tree_a.get <std::string> ("receive_minimum"));
|
||||
auto logging_l (tree_a.get_child ("logging"));
|
||||
auto work_peers_l (tree_a.get_child_optional ("work_peers"));
|
||||
work_peers.clear ();
|
||||
if (work_peers_l)
|
||||
auto work_peers_l (tree_a.get_child ("work_peers"));
|
||||
for (auto i (work_peers_l.begin ()), n (work_peers_l.end ()); i != n; ++i)
|
||||
{
|
||||
for (auto i (work_peers_l.get ().begin ()), n (work_peers_l.get ().end ()); i != n; ++i)
|
||||
{
|
||||
auto work_peer (i->second.get <std::string> (""));
|
||||
boost::asio::ip::address address;
|
||||
uint16_t port;
|
||||
result |= rai::parse_address_port (work_peer, address, port);
|
||||
work_peers.push_back (std::make_pair (address, port));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tree_a.add_child ("work_peers", boost::property_tree::ptree ());
|
||||
upgraded_a = true;
|
||||
auto work_peer (i->second.get <std::string> (""));
|
||||
boost::asio::ip::address address;
|
||||
uint16_t port;
|
||||
result |= rai::parse_address_port (work_peer, address, port);
|
||||
work_peers.push_back (std::make_pair (address, port));
|
||||
}
|
||||
auto preconfigured_peers_l (tree_a.get_child ("preconfigured_peers"));
|
||||
preconfigured_peers.clear ();
|
||||
|
|
|
@ -282,6 +282,7 @@ public:
|
|||
node_config (uint16_t, rai::logging const &);
|
||||
void serialize_json (boost::property_tree::ptree &) const;
|
||||
bool deserialize_json (bool &, boost::property_tree::ptree &);
|
||||
bool upgrade_json (unsigned, boost::property_tree::ptree &);
|
||||
rai::account random_representative ();
|
||||
uint16_t peering_port;
|
||||
rai::logging logging;
|
||||
|
|
|
@ -18,11 +18,41 @@ public:
|
|||
rai::random_pool.GenerateBlock (wallet.bytes.data (), wallet.bytes.size ());
|
||||
assert (!wallet.is_zero ());
|
||||
}
|
||||
bool upgrade_json (unsigned version_a, boost::property_tree::ptree & tree_a)
|
||||
{
|
||||
auto result (false);
|
||||
switch (version_a)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
rai::account account;
|
||||
account.decode_account (tree_a.get <std::string> ("account"));
|
||||
tree_a.erase ("account");
|
||||
tree_a.put ("account", account.to_account ());
|
||||
tree_a.erase ("version");
|
||||
tree_a.put ("version", "2");
|
||||
result = true;
|
||||
}
|
||||
case 2:
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error ("Unknown qt_wallet_config version");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool deserialize_json (bool & upgraded_a, boost::property_tree::ptree & tree_a)
|
||||
{
|
||||
auto error (false);
|
||||
if (!tree_a.empty ())
|
||||
{
|
||||
auto version_l (tree_a.get_optional <std::string> ("version"));
|
||||
if (!version_l)
|
||||
{
|
||||
tree_a.put ("version", "1");
|
||||
version_l = "1";
|
||||
upgraded_a = true;
|
||||
}
|
||||
upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a);
|
||||
auto wallet_l (tree_a.get <std::string> ("wallet"));
|
||||
auto account_l (tree_a.get <std::string> ("account"));
|
||||
auto & node_l (tree_a.get_child ("node"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue