From 446d89764cf6ca6fce74737c453c8c48d2b5e7a4 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Tue, 5 Apr 2022 08:05:42 +0300 Subject: [PATCH] #308 - fix global_props.active_sons.size --- libraries/chain/db_block.cpp | 2 ++ libraries/chain/db_witness_schedule.cpp | 17 ++++++++--- .../chain/son_wallet_deposit_evaluator.cpp | 2 +- .../chain/son_wallet_withdraw_evaluator.cpp | 2 +- .../peerplays_sidechain_plugin.cpp | 1 + .../sidechain_net_handler.cpp | 3 ++ .../sidechain_net_handler_hive.cpp | 4 +-- tests/cli/son.cpp | 30 ++++++++++++------- 8 files changed, 43 insertions(+), 18 deletions(-) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 9ce436a7..62fee47f 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -742,6 +742,8 @@ void database::_apply_block( const signed_block& next_block ) update_maintenance_flag( maint_needed ); if (global_props.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SHUFFLED_ALGORITHM) { update_witness_schedule(); + + //! Fixme - here we should take active_sons size for sidechain if(global_props.active_sons.size() > 0) { update_son_schedule(); } diff --git a/libraries/chain/db_witness_schedule.cpp b/libraries/chain/db_witness_schedule.cpp index 5d940a17..54a798cb 100644 --- a/libraries/chain/db_witness_schedule.cpp +++ b/libraries/chain/db_witness_schedule.cpp @@ -196,6 +196,7 @@ void database::update_son_schedule() const son_schedule_object& ssobitcoin = son_schedule_id_type(2)(*this); const global_property_object& gpo = get_global_properties(); + //! Fixme - here we should take active_sons size for sidechain if( head_block_num() % gpo.active_sons.size() == 0 ) { modify( sso, [&]( son_schedule_object& _sso ) @@ -402,7 +403,15 @@ void database::update_son_schedule(const signed_block& next_block) const son_schedule_object& sso = get(son_schedule_id_type()); const son_schedule_object& ssohive = get(son_schedule_id_type(1)); const son_schedule_object& ssobitcoin = get(son_schedule_id_type(2)); - uint32_t schedule_needs_filled = gpo.active_sons.size(); + const flat_map schedule_needs_filled = [&gpo]() + { + flat_map schedule_needs_filled; + for(const auto& sidechain_active_sons : gpo.active_sons) + { + schedule_needs_filled[sidechain_active_sons.first] = sidechain_active_sons.second.size(); + } + return schedule_needs_filled; + }(); uint32_t schedule_slot = get_slot_at_time(next_block.timestamp); // We shouldn't be able to generate _pending_block with timestamp @@ -451,7 +460,7 @@ void database::update_son_schedule(const signed_block& next_block) { _sso.scheduler.reset_schedule( first_son ); } - while( !_sso.scheduler.get_slot(schedule_needs_filled, son) ) + while( !_sso.scheduler.get_slot(schedule_needs_filled.at(sidechain_type::bitcoin), son) ) { if( _sso.scheduler.produce_schedule(rng) & emit_turn ) memcpy(_sso.rng_seed.begin(), dpo.random.data(), dpo.random.data_size()); @@ -484,7 +493,7 @@ void database::update_son_schedule(const signed_block& next_block) { _sso.scheduler.reset_schedule( first_son_hive ); } - while( !_sso.scheduler.get_slot(schedule_needs_filled, son_hive) ) + while( !_sso.scheduler.get_slot(schedule_needs_filled.at(sidechain_type::hive), son_hive) ) { if( _sso.scheduler.produce_schedule(rng) & emit_turn ) memcpy(_sso.rng_seed.begin(), dpo.random.data(), dpo.random.data_size()); @@ -517,7 +526,7 @@ void database::update_son_schedule(const signed_block& next_block) { _sso.scheduler.reset_schedule( first_son_bitcoin ); } - while( !_sso.scheduler.get_slot(schedule_needs_filled, son_bitcoin) ) + while( !_sso.scheduler.get_slot(schedule_needs_filled.at(sidechain_type::bitcoin), son_bitcoin) ) { if( _sso.scheduler.produce_schedule(rng) & emit_turn ) memcpy(_sso.rng_seed.begin(), dpo.random.data(), dpo.random.data_size()); diff --git a/libraries/chain/son_wallet_deposit_evaluator.cpp b/libraries/chain/son_wallet_deposit_evaluator.cpp index e109c2f8..8d0199d4 100644 --- a/libraries/chain/son_wallet_deposit_evaluator.cpp +++ b/libraries/chain/son_wallet_deposit_evaluator.cpp @@ -142,11 +142,11 @@ void_result process_son_wallet_deposit_evaluator::do_evaluate(const son_wallet_d { try{ FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." ); - FC_ASSERT(db().get_global_properties().active_sons.size() >= db().get_chain_properties().immutable_parameters.min_son_count, "Min required voted SONs not present"); const auto& idx = db().get_index_type().indices().get(); const auto& itr = idx.find(op.son_wallet_deposit_id); FC_ASSERT(itr != idx.end(), "Son wallet deposit not found"); + FC_ASSERT(db().get_global_properties().active_sons.at(itr->sidechain).size() >= db().get_chain_properties().immutable_parameters.min_son_count, "Min required voted SONs not present"); FC_ASSERT(!itr->processed, "Son wallet deposit is already processed"); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } diff --git a/libraries/chain/son_wallet_withdraw_evaluator.cpp b/libraries/chain/son_wallet_withdraw_evaluator.cpp index 3fb04ae2..d3f24f19 100644 --- a/libraries/chain/son_wallet_withdraw_evaluator.cpp +++ b/libraries/chain/son_wallet_withdraw_evaluator.cpp @@ -140,11 +140,11 @@ void_result process_son_wallet_withdraw_evaluator::do_evaluate(const son_wallet_ { try{ FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." ); - FC_ASSERT(db().get_global_properties().active_sons.size() >= db().get_chain_properties().immutable_parameters.min_son_count, "Min required voted SONs not present"); const auto& idx = db().get_index_type().indices().get(); const auto& itr = idx.find(op.son_wallet_withdraw_id); FC_ASSERT(itr != idx.end(), "Son wallet withdraw not found"); + FC_ASSERT(db().get_global_properties().active_sons.at(itr->sidechain).size() >= db().get_chain_properties().immutable_parameters.min_son_count, "Min required voted SONs not present"); FC_ASSERT(!itr->processed, "Son wallet withdraw is already processed"); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index 80bebc59..3b4faeff 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -456,6 +456,7 @@ void peerplays_sidechain_plugin_impl::schedule_son_processing() { } void peerplays_sidechain_plugin_impl::son_processing() { + //! Fixme - here we must check size for every sidechain if (plugin.database().get_global_properties().active_sons.size() <= 0) { return; } diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp index 86876782..b4b2ba01 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp @@ -399,6 +399,7 @@ void sidechain_net_handler::process_active_sons_change() { } void sidechain_net_handler::create_deposit_addresses() { + //! Fixme - here we must consider sidechain size if (database.get_global_properties().active_sons.size() < database.get_chain_properties().immutable_parameters.min_son_count) { return; } @@ -406,6 +407,7 @@ void sidechain_net_handler::create_deposit_addresses() { } void sidechain_net_handler::process_deposits() { + //! Fixme - here we must consider sidechain size if (database.get_global_properties().active_sons.size() < database.get_chain_properties().immutable_parameters.min_son_count) { return; } @@ -441,6 +443,7 @@ void sidechain_net_handler::process_deposits() { } void sidechain_net_handler::process_withdrawals() { + //! Fixme - here we must consider sidechain size if (database.get_global_properties().active_sons.size() < database.get_chain_properties().immutable_parameters.min_son_count) { return; } diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp index c03d2eb3..6e840be9 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp @@ -214,14 +214,14 @@ bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) { const auto swo = idx.find(swo_id); if (swo != idx.end()) { - auto active_sons = gpo.active_sons; + auto active_sons = gpo.active_sons.at(sidechain); vector wallet_sons = swo->sons.at(sidechain); bool son_sets_equal = (active_sons.size() == wallet_sons.size()); if (son_sets_equal) { for (size_t i = 0; i < active_sons.size(); i++) { - son_sets_equal = son_sets_equal && active_sons.at(sidechain).at(i) == wallet_sons.at(i); + son_sets_equal = son_sets_equal && active_sons.at(i) == wallet_sons.at(i); } } diff --git a/tests/cli/son.cpp b/tests/cli/son.cpp index 3fd9909a..25d96aee 100644 --- a/tests/cli/son.cpp +++ b/tests/cli/son.cpp @@ -408,10 +408,12 @@ BOOST_FIXTURE_TEST_CASE( select_top_fifteen_sons, cli_fixture ) vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, sidechain_type::hive, true, true); } gpo = con.wallet_api_ptr->get_global_properties(); - BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size()); + BOOST_TEST_MESSAGE("gpo active_sons[bitcoin]: " << gpo.active_sons.at(sidechain_type::bitcoin).size()); + BOOST_TEST_MESSAGE("gpo active_sons[hive]: " << gpo.active_sons.at(sidechain_type::hive).size()); BOOST_CHECK(generate_maintenance_block()); gpo = con.wallet_api_ptr->get_global_properties(); - BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size()); + BOOST_TEST_MESSAGE("gpo active_sons[bitcoin]: " << gpo.active_sons.at(sidechain_type::bitcoin).size()); + BOOST_TEST_MESSAGE("gpo active_sons[hive]: " << gpo.active_sons.at(sidechain_type::hive).size()); for(unsigned int i = 0; i < son_number - 1; i++) { @@ -421,10 +423,12 @@ BOOST_FIXTURE_TEST_CASE( select_top_fifteen_sons, cli_fixture ) vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, sidechain_type::hive, true, true); } gpo = con.wallet_api_ptr->get_global_properties(); - BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size()); + BOOST_TEST_MESSAGE("gpo active_sons[bitcoin]: " << gpo.active_sons.at(sidechain_type::bitcoin).size()); + BOOST_TEST_MESSAGE("gpo active_sons[hive]: " << gpo.active_sons.at(sidechain_type::hive).size()); BOOST_CHECK(generate_maintenance_block()); gpo = con.wallet_api_ptr->get_global_properties(); - BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size()); + BOOST_TEST_MESSAGE("gpo active_sons[bitcoin]: " << gpo.active_sons.at(sidechain_type::bitcoin).size()); + BOOST_TEST_MESSAGE("gpo active_sons[hive]: " << gpo.active_sons.at(sidechain_type::hive).size()); for(unsigned int i = 0; i < son_number - 2; i++) { @@ -434,10 +438,12 @@ BOOST_FIXTURE_TEST_CASE( select_top_fifteen_sons, cli_fixture ) vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, sidechain_type::hive, true, true); } gpo = con.wallet_api_ptr->get_global_properties(); - BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size()); + BOOST_TEST_MESSAGE("gpo active_sons[bitcoin]: " << gpo.active_sons.at(sidechain_type::bitcoin).size()); + BOOST_TEST_MESSAGE("gpo active_sons[hive]: " << gpo.active_sons.at(sidechain_type::hive).size()); BOOST_CHECK(generate_maintenance_block()); - BOOST_CHECK(gpo.active_sons.size() == gpo.parameters.maximum_son_count()); + BOOST_CHECK(gpo.active_sons.at(sidechain_type::bitcoin).size() == gpo.parameters.maximum_son_count()); + BOOST_CHECK(gpo.active_sons.at(sidechain_type::hive).size() == gpo.parameters.maximum_son_count()); } catch( fc::exception& e ) { BOOST_TEST_MESSAGE("SON cli wallet tests exception"); @@ -721,7 +727,8 @@ BOOST_AUTO_TEST_CASE( related_functions ) try { global_property_object gpo = con.wallet_api_ptr->get_global_properties(); - BOOST_CHECK(gpo.active_sons.size() == 0); + BOOST_CHECK(gpo.active_sons.at(sidechain_type::bitcoin).size() == 0); + BOOST_CHECK(gpo.active_sons.at(sidechain_type::hive).size() == 0); flat_map sidechain_public_keys; @@ -738,7 +745,8 @@ BOOST_AUTO_TEST_CASE( related_functions ) sth.create_son("son2account", "http://son2", sidechain_public_keys); gpo = con.wallet_api_ptr->get_global_properties(); - BOOST_CHECK(gpo.active_sons.size() == 2); + BOOST_CHECK(gpo.active_sons.at(sidechain_type::bitcoin).size() == 2); + BOOST_CHECK(gpo.active_sons.at(sidechain_type::hive).size() == 2); } catch( fc::exception& e ) { BOOST_TEST_MESSAGE("SON cli wallet tests exception"); @@ -797,9 +805,11 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture ) } BOOST_CHECK(generate_maintenance_block()); gpo = con.wallet_api_ptr->get_global_properties(); - BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size()); + BOOST_TEST_MESSAGE("gpo active_sons[bitcoin]: " << gpo.active_sons.at(sidechain_type::bitcoin).size()); + BOOST_TEST_MESSAGE("gpo active_sons[hive]: " << gpo.active_sons.at(sidechain_type::hive).size()); - BOOST_CHECK(gpo.active_sons.size() == son_number); + BOOST_CHECK(gpo.active_sons.at(sidechain_type::bitcoin).size() == son_number); + BOOST_CHECK(gpo.active_sons.at(sidechain_type::hive).size() == son_number); map active_sons = con.wallet_api_ptr->list_active_sons(); BOOST_CHECK(active_sons.size() == son_number);