Skip to content

Commit 326e2b7

Browse files
asuchvogel76
authored andcommitted
In verify_match_of_blockchain_configuration:
- do not check HIVE_TREASURY_ACCOUNT - in case of mainet, check if chain_id matches specific id depending of hardfork number - in case of mirrornet or testnet, current chain_id should match stored chain_id
1 parent cf89855 commit 326e2b7

File tree

1 file changed

+22
-33
lines changed

1 file changed

+22
-33
lines changed

libraries/chain/util/state_checker_tools.cpp

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,26 @@ void verify_match_of_state_definitions(const chain::util::decoded_types_data_sto
4343
}
4444
}
4545

46-
void verify_match_of_blockchain_configuration(fc::mutable_variant_object current_blockchain_config, const fc::variant& full_current_blockchain_config_as_variant, const std::string& full_stored_blockchain_config_json, const uint32_t hardfork)
46+
void verify_match_of_blockchain_configuration(fc::mutable_variant_object current_blockchain_config, const fc::variant &full_current_blockchain_config_as_variant, const std::string &full_stored_blockchain_config_json, const uint32_t hardfork)
4747
{
4848
constexpr char HIVE_TREASURY_ACCOUNT_KEY[] = "HIVE_TREASURY_ACCOUNT";
4949
constexpr char HIVE_CHAIN_ID_KEY[] = "HIVE_CHAIN_ID";
5050
constexpr char HIVE_BLOCKCHAIN_VERSION_KEY[] = "HIVE_BLOCKCHAIN_VERSION";
5151

5252
fc::mutable_variant_object stored_blockchain_config = fc::json::from_string(full_stored_blockchain_config_json, fc::json::format_validation_mode::full).get_object();
53-
const std::string current_hive_treasury_account = current_blockchain_config[HIVE_TREASURY_ACCOUNT_KEY].as_string();
5453
const std::string current_hive_chain_id = current_blockchain_config[HIVE_CHAIN_ID_KEY].as_string();
54+
const std::string stored_hive_chain_id = stored_blockchain_config[HIVE_CHAIN_ID_KEY].as_string();
55+
56+
#if defined(USE_ALTERNATE_CHAIN_ID) || defined(IS_TEST_NET)
57+
// mirrornet & testnet
58+
if (current_hive_chain_id != stored_hive_chain_id)
59+
FC_THROW_EXCEPTION(blockchain_config_mismatch_exception, "Chain id stored in database: ${stored_hive_chain_id} mismatch chain-id from configuration: ${current_hive_chain_id}", (stored_hive_chain_id)(current_hive_chain_id));
60+
#else
61+
// mainnet
62+
if ((hardfork < HIVE_HARDFORK_1_24 && (current_hive_chain_id != std::string(OLD_CHAIN_ID) || current_hive_chain_id != stored_hive_chain_id)) ||
63+
(hardfork >= HIVE_HARDFORK_1_24 && (current_hive_chain_id != std::string(HIVE_CHAIN_ID) || current_hive_chain_id != stored_hive_chain_id)))
64+
FC_THROW_EXCEPTION(blockchain_config_mismatch_exception, "chain id mismatch. Current config: ${current_hive_chain_id}, stored in db: ${stored_hive_chain_id}, hf: ${hardfork}", (current_hive_chain_id)(stored_hive_chain_id)(hardfork));
65+
#endif
5566

5667
stored_blockchain_config.erase(HIVE_TREASURY_ACCOUNT_KEY);
5768
current_blockchain_config.erase(HIVE_TREASURY_ACCOUNT_KEY);
@@ -60,33 +71,12 @@ void verify_match_of_blockchain_configuration(fc::mutable_variant_object current
6071
stored_blockchain_config.erase(HIVE_BLOCKCHAIN_VERSION_KEY);
6172
current_blockchain_config.erase(HIVE_BLOCKCHAIN_VERSION_KEY);
6273

63-
bool throw_exception = false;
74+
fc::variant modified_current_blockchain_config;
75+
fc::to_variant(current_blockchain_config, modified_current_blockchain_config);
76+
fc::variant modified_stored_blockchain_config;
77+
fc::to_variant(stored_blockchain_config, modified_stored_blockchain_config);
6478

65-
{
66-
fc::variant modified_current_blockchain_config;
67-
fc::to_variant(current_blockchain_config, modified_current_blockchain_config);
68-
fc::variant modified_stored_blockchain_config;
69-
fc::to_variant(stored_blockchain_config, modified_stored_blockchain_config);
70-
71-
if (fc::json::to_string(modified_current_blockchain_config) != fc::json::to_string(modified_stored_blockchain_config))
72-
throw_exception = true;
73-
}
74-
75-
if (!throw_exception)
76-
{
77-
if (hardfork < HIVE_HARDFORK_1_24)
78-
{
79-
if (current_hive_treasury_account != OBSOLETE_TREASURY_ACCOUNT || current_hive_chain_id != std::string(OLD_CHAIN_ID))
80-
throw_exception = true;
81-
}
82-
else
83-
{
84-
if (current_hive_treasury_account != NEW_HIVE_TREASURY_ACCOUNT || current_hive_chain_id != std::string(HIVE_CHAIN_ID))
85-
throw_exception = true;
86-
}
87-
}
88-
89-
if (throw_exception)
79+
if (fc::json::to_string(modified_current_blockchain_config) != fc::json::to_string(modified_stored_blockchain_config))
9080
{
9181
std::fstream loaded_blockchain_config_file, current_blockchain_config_file;
9282
constexpr char current_config_filename[] = "current_blockchain_config.log";
@@ -105,10 +95,9 @@ void verify_match_of_blockchain_configuration(fc::mutable_variant_object current
10595
current_blockchain_config_file.close();
10696

10797
FC_THROW_EXCEPTION(blockchain_config_mismatch_exception,
108-
"Mismatch between blockchain configuration loaded from shared memory file and the current one"
109-
"\nFull data about blockchain configuration are in files: ${current_config_filename}, ${loaded_config_filename}",
110-
(current_config_filename)(loaded_config_filename));
98+
"Mismatch between blockchain configuration loaded from shared memory file and the current one"
99+
"\nFull data about blockchain configuration are in files: ${current_config_filename}, ${loaded_config_filename}",
100+
(current_config_filename)(loaded_config_filename));
111101
}
112102
}
113-
114-
} } } // hive::chain::util
103+
} } } // hive::chain::util

0 commit comments

Comments
 (0)