diff --git a/doc/RPC.md b/doc/RPC.md index b5edc701af..5713106b93 100644 --- a/doc/RPC.md +++ b/doc/RPC.md @@ -448,9 +448,6 @@ curl -X POST --data '{"jsonrpc":"2.0","method":"taraxa_getConfig","params":[],"i "0x0274cfffea9fa850e54c93a23042f12a87358a82": "0x141e8d17", "0x111f91441efc8c6c0edf6534970cc887e2fabaa8": "0x24048ce3d" }, - "hardforks": { - "fix_genesis_fork_block": "0x102ca0" - } }, "pbft": { "committee_size": "0x3e8", @@ -492,7 +489,7 @@ none #### Returns `OBJECT` - current chain stats object -* `pbft_period`: `QUANTITY` - current PBFT period +* `pbft_period`: `QUANTITY` - current PBFT period * `dag_blocks_executed`: `QUANTITY` - count of executed(finalized) DAG blocks * `transactions_executed`: `QUANTITY` - count of executed transactions diff --git a/libraries/cli/src/config.cpp b/libraries/cli/src/config.cpp index 65f9b02e75..7c19bcbafa 100644 --- a/libraries/cli/src/config.cpp +++ b/libraries/cli/src/config.cpp @@ -214,11 +214,6 @@ Config::Config(int argc, const char* argv[]) { auto default_genesis_json = tools::getGenesis((Config::ChainIdType)chain_id); // override hardforks data with one from default json addNewHardforks(genesis_json, default_genesis_json); - // add vote_eligibility_balance_step field if it is missing in the config - if (genesis_json["dpos"]["vote_eligibility_balance_step"].isNull()) { - genesis_json["dpos"]["vote_eligibility_balance_step"] = - default_genesis_json["dpos"]["vote_eligibility_balance_step"]; - } write_config_and_wallet_files(); } // Override config values with values from CLI diff --git a/libraries/config/CMakeLists.txt b/libraries/config/CMakeLists.txt index 5df88e6af7..75616c110c 100644 --- a/libraries/config/CMakeLists.txt +++ b/libraries/config/CMakeLists.txt @@ -7,7 +7,7 @@ set(HEADERS include/config/dag_config.hpp include/config/pbft_config.hpp include/config/state_config.hpp - include/config/hardfork.hpp + # include/config/hardfork.hpp ) set(SOURCES @@ -18,7 +18,7 @@ set(SOURCES src/dag_config.cpp src/pbft_config.cpp src/state_config.cpp - src/hardfork.cpp + # src/hardfork.cpp ) # Configure file with version diff --git a/libraries/config/include/config/state_config.hpp b/libraries/config/include/config/state_config.hpp index 6cd844094f..1cbda1b401 100644 --- a/libraries/config/include/config/state_config.hpp +++ b/libraries/config/include/config/state_config.hpp @@ -6,7 +6,7 @@ #include "common/encoding_rlp.hpp" #include "common/types.hpp" #include "common/vrf_wrapper.hpp" -#include "config/hardfork.hpp" +// #include "config/hardfork.hpp" namespace taraxa::state_api { diff --git a/libraries/core_libs/network/graphql/src/query.cpp b/libraries/core_libs/network/graphql/src/query.cpp index a71874823b..7606de867b 100644 --- a/libraries/core_libs/network/graphql/src/query.cpp +++ b/libraries/core_libs/network/graphql/src/query.cpp @@ -1,5 +1,7 @@ #include "graphql/query.hpp" +#include + #include "graphql/account.hpp" #include "graphql/block.hpp" #include "graphql/log.hpp" diff --git a/libraries/core_libs/network/graphql/src/types/dag_block.cpp b/libraries/core_libs/network/graphql/src/types/dag_block.cpp index e093a3acc8..7124be5fd2 100644 --- a/libraries/core_libs/network/graphql/src/types/dag_block.cpp +++ b/libraries/core_libs/network/graphql/src/types/dag_block.cpp @@ -1,5 +1,7 @@ #include "graphql/types/dag_block.hpp" +#include + #include "graphql/account.hpp" #include "graphql/transaction.hpp" diff --git a/libraries/core_libs/node/src/node.cpp b/libraries/core_libs/node/src/node.cpp index d3a8a26622..5622c39e30 100644 --- a/libraries/core_libs/node/src/node.cpp +++ b/libraries/core_libs/node/src/node.cpp @@ -302,30 +302,6 @@ void FullNode::start() { }, subscription_pool_); - // Subscription to process hardforks - // final_chain_->block_applying_.subscribe([&](uint64_t block_num) { - // // TODO: should have only common hardfork code calling hardfork executor - // auto &state_conf = conf_.genesis.state; - // if (state_conf.hardforks.fix_genesis_fork_block == block_num) { - // for (auto &e : state_conf.dpos->genesis_state) { - // for (auto &b : e.second) { - // b.second *= kOneTara; - // } - // } - // for (auto &b : state_conf.initial_balances) { - // b.second *= kOneTara; - // } - // // we are multiplying it by TARA precision - // state_conf.dpos->eligibility_balance_threshold *= kOneTara; - // // amount of stake per vote should be 10 times smaller than eligibility threshold - // state_conf.dpos->vote_eligibility_balance_step.assign(state_conf.dpos->eligibility_balance_threshold); - // state_conf.dpos->eligibility_balance_threshold *= 10; - // // if this part of code will be needed we need to overwrite genesis json here - // // conf_.overwrite_chain_config_in_file(); - // final_chain_->update_state_config(state_conf); - // } - // }); - vote_mgr_->setNetwork(network_); pbft_mgr_->setNetwork(network_); dag_mgr_->setNetwork(network_); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 93c965100c..b5b9bc2bf3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,13 +37,6 @@ add_executable(full_node_test full_node_test.cpp) target_link_libraries(full_node_test test_util) add_test(full_node_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/full_node_test) -# add_executable(hardfork_test hardfork_test.cpp) -# target_link_libraries(hardfork_test -# core_libs -# CONAN_PKG::gtest -# ) -# add_test(hardfork_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/hardfork_test) - add_executable(network_test network_test.cpp) target_link_libraries(network_test test_util) add_test(network_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/network_test) diff --git a/tests/final_chain_test.cpp b/tests/final_chain_test.cpp index 9b78ed321b..99d2fdd58f 100644 --- a/tests/final_chain_test.cpp +++ b/tests/final_chain_test.cpp @@ -181,12 +181,6 @@ TEST_F(FinalChainTest, initial_balances) { init(); } -// TEST_F(FinalChainTest, update_state_config) { -// init(); -// cfg.genesis.state.hardforks.fix_genesis_fork_block = 2222222; -// SUT->update_state_config(cfg.genesis.state); -// } - TEST_F(FinalChainTest, contract) { auto sender_keys = dev::KeyPair::create(); const auto& addr = sender_keys.address(); diff --git a/tests/hardfork_test.cpp b/tests/hardfork_test.cpp deleted file mode 100644 index e48784ed19..0000000000 --- a/tests/hardfork_test.cpp +++ /dev/null @@ -1,199 +0,0 @@ -#include - -#include -#include -#include -#include -#include - -#include "cli/config.hpp" -#include "cli/tools.hpp" -#include "dag/dag.hpp" -#include "logger/logger.hpp" -#include "node/node.hpp" -#include "string" -#include "test_util/samples.hpp" -#include "transaction/transaction_manager.hpp" - -namespace taraxa::core_tests { - -// We need separate fixture for this tests because hardfork is overwriting config file. But we can't change config -// stored in global variable because values will change for next test cases -struct HardforkTest : WithDataDir { - FullNodeConfig node_cfg; - - HardforkTest() { - // creating config this way to prevent config files overwriting - auto cfg_filename = std::string("conf_taraxa1.json"); - auto p = DIR_CONF / cfg_filename; - auto w = DIR_CONF / std::string("wallet1.json"); - Json::Value test_node_wallet_json; - std::ifstream(w.string(), std::ifstream::binary) >> test_node_wallet_json; - node_cfg = FullNodeConfig(p.string(), test_node_wallet_json, data_dir / cfg_filename); - - fs::remove_all(node_cfg.data_path); - fs::create_directories(node_cfg.data_path); - - auto data_path_cfg = node_cfg.data_path / fs::path(node_cfg.json_file_name).filename(); - fs::copy_file(node_cfg.json_file_name, data_path_cfg); - node_cfg.json_file_name = data_path_cfg; - - addr_t root_node_addr("de2b1203d72d3549ee2f733b00b2789414c7cea5"); - node_cfg.genesis.state.initial_balances[root_node_addr] = 9007199254740991; - auto &dpos = *node_cfg.genesis.state.dpos; - dpos.genesis_state[root_node_addr][root_node_addr] = dpos.eligibility_balance_threshold; - // speed up block production - { - node_cfg.genesis.sortition.vrf.threshold_upper = 0xffff; - node_cfg.genesis.sortition.vdf.difficulty_min = 0; - node_cfg.genesis.sortition.vdf.difficulty_max = 3; - node_cfg.genesis.sortition.vdf.difficulty_stale = 3; - node_cfg.genesis.sortition.vdf.lambda_bound = 100; - // PBFT config - node_cfg.genesis.pbft.lambda_ms /= 20; - node_cfg.network.transaction_interval_ms /= 20; - } - } - - ~HardforkTest() { fs::remove_all(node_cfg.data_path); } - - HardforkTest(const HardforkTest &) = delete; - HardforkTest(HardforkTest &&) = delete; - HardforkTest &operator=(const HardforkTest &) = delete; - HardforkTest &operator=(HardforkTest &&) = delete; -}; - -TEST_F(HardforkTest, hardfork_override) { - auto default_json = cli::tools::getConfig(cli::Config::DEFAULT_CHAIN_ID); - auto default_hardforks = default_json["genesis"]["hardforks"]; - Json::Value config = default_json; - auto &state_cfg = config["genesis"]; - state_cfg["hardforks"].removeMember("fix_genesis_fork_block"); - - EXPECT_TRUE(state_cfg["hardforks"]["fix_genesis_fork_block"].isNull()); - cli::Config::addNewHardforks(config, default_json); - EXPECT_EQ(state_cfg["hardforks"], default_hardforks); - - state_cfg.removeMember("hardforks"); - EXPECT_TRUE(state_cfg["hardforks"].isNull()); - - cli::Config::addNewHardforks(config, default_json); - EXPECT_EQ(state_cfg["hardforks"], default_hardforks); -} - -TEST_F(HardforkTest, fix_genesis_fork_block_is_zero) { - auto &cfg = node_cfg.genesis; - cfg.state.hardforks.fix_genesis_fork_block = 0; - auto node = launch_nodes({node_cfg}).front(); - - auto dummy_trx = std::make_shared(1, 0, 0, 0, bytes(), node->getSecretKey(), node->getAddress()); - // broadcast dummy transaction - node->getTransactionManager()->insertTransaction(dummy_trx); - wait({100s, 500ms}, [&](auto &ctx) { - if (node->getFinalChain()->last_block_number() <= cfg.state.hardforks.fix_genesis_fork_block) { - ctx.fail(); - } - }); - EXPECT_EQ(cfg.state.initial_balances.begin()->second, - node->getConfig().genesis.state.initial_balances.begin()->second); -} - -TEST_F(HardforkTest, hardfork) { - auto &cfg = node_cfg.genesis; - cfg.state.hardforks.fix_genesis_fork_block = 10; - cfg.state.dpos->eligibility_balance_threshold = 100000; - cfg.state.dpos->vote_eligibility_balance_step.assign(cfg.state.dpos->eligibility_balance_threshold); - cfg.state.dpos->delegation_delay = 5; - cfg.state.dpos->delegation_locking_period = 5; - - auto random_node = addr_t::random(); - auto random_votes = 3; - for (auto &gb : cfg.state.initial_balances) { - gb.second = 110000000; - } - for (auto &gs : cfg.state.dpos->genesis_state) { - for (auto &b : gs.second) { - b.second = 1100000; - std::cout << b.first << ": " << b.second << std::endl; - } - gs.second.emplace(random_node, random_votes * cfg.state.dpos->vote_eligibility_balance_step); - } - - auto node = launch_nodes({node_cfg}).front(); - auto nonce = 0; - auto dummy_trx = [&nonce, node]() { - auto dummy_trx = std::make_shared(nonce++, 0, 0, 0, bytes(), node->getSecretKey(), node->getAddress()); - // broadcast dummy transaction - node->getTransactionManager()->insertTransaction(dummy_trx); - }; - dummy_trx(); - node->getFinalChain()->block_finalized_.subscribe([&](const std::shared_ptr &res) { - const auto block_num = res->final_chain_blk->number; - if (cfg.state.hardforks.fix_genesis_fork_block == block_num) { - return; - } - dummy_trx(); - dummy_trx(); - }); - std::map balances_before; - for (const auto &b : node->getConfig().genesis.state.initial_balances) { - auto balance = node->getFinalChain()->get_account(b.first)->balance; - balances_before.emplace(b.first, balance); - } - auto votes_count = 11; - EXPECT_EQ(votes_count + random_votes, node->getFinalChain()->dpos_eligible_total_vote_count(0)); - EXPECT_EQ(random_votes, node->getFinalChain()->dpos_eligible_vote_count(0, random_node)); - - wait({100s, 500ms}, [&](auto &ctx) { - if (node->getFinalChain()->last_block_number() < cfg.state.hardforks.fix_genesis_fork_block) { - ctx.fail(); - } - }); - - u256 dpos_genesis_sum = 0; - // Verify DPOS initial balances increasing - for (const auto &gs : node->getConfig().genesis.state.dpos->genesis_state) { - for (const auto &b : gs.second) { - EXPECT_EQ(b.second, node->getFinalChain()->get_staking_balance(b.first)); - dpos_genesis_sum += b.second; - } - } - - for (const auto &b : node->getConfig().genesis.state.initial_balances) { - auto balance_after = node->getFinalChain()->get_account(b.first)->balance; - auto res = b.second - dpos_genesis_sum; - EXPECT_EQ(res, balance_after); - } - - auto block = node->getFinalChain()->last_block_number(); - EXPECT_EQ(votes_count, node->getFinalChain()->dpos_eligible_total_vote_count(block)); - EXPECT_EQ(0, node->getFinalChain()->dpos_eligible_vote_count(block, random_node)); - - // check for dpos_query method - { - const auto &genesis_sender = cfg.state.dpos->genesis_state.begin()->first; - - state_api::DPOSQuery::AccountQuery acc_q; - acc_q.with_staking_balance = true; - acc_q.with_outbound_deposits = true; - acc_q.with_inbound_deposits = true; - state_api::DPOSQuery q; - q.with_eligible_count = true; - q.account_queries[genesis_sender] = acc_q; - - // auto q_res = node->getFinalChain()->dpos_query(q); - auto res = q_res.account_results[genesis_sender]; - EXPECT_EQ(res.inbound_deposits.size(), 1); - EXPECT_EQ(res.inbound_deposits.begin()->first, genesis_sender); - EXPECT_EQ(res.inbound_deposits.begin()->second, res.staking_balance); - } - - EXPECT_EQ(cfg.state.dpos->vote_eligibility_balance_step * kOneTara, - node->getConfig().genesis.state.dpos->vote_eligibility_balance_step); - EXPECT_NE(cfg.state.initial_balances.begin()->second, - node->getConfig().genesis.state.initial_balances.begin()->second); - EXPECT_NE(cfg.state.dpos->eligibility_balance_threshold, - node->getConfig().genesis.state.dpos->eligibility_balance_threshold); -} - -} // namespace taraxa::core_tests diff --git a/tests/rpc_test.cpp b/tests/rpc_test.cpp index 3675644792..85f2b98706 100644 --- a/tests/rpc_test.cpp +++ b/tests/rpc_test.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "network/rpc/eth/Eth.h" #include "test_util/gtest.hpp" diff --git a/tests/state_api_test.cpp b/tests/state_api_test.cpp index 6c49267725..49ce8fbe72 100644 --- a/tests/state_api_test.cpp +++ b/tests/state_api_test.cpp @@ -59,7 +59,6 @@ TEST_F(StateAPITest, DISABLED_dpos_integration) { // dpos_cfg.eligibility_balance_threshold = 1000; // dpos_cfg.vote_eligibility_balance_step = 1000; // addr_1_bal_expected -= dpos_cfg.genesis_state[make_addr(1)][make_addr(1)] = dpos_cfg.eligibility_balance_threshold; - // chain_cfg.hardforks.fix_genesis_fork_block = 0; // uint64_t curr_blk = 0; // StateAPI SUT([&](auto /*n*/) -> h256 { assert(false); }, //