diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index dcaa6421..56a871e5 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -861,7 +861,7 @@ void database::update_active_sons() } }); - //! Fixme - fix this schedule + //! Fixme - fix this schedule (delete it?) const son_schedule_object& sso = son_schedule_id_type()(*this); modify(sso, [&](son_schedule_object& _sso) { @@ -882,51 +882,31 @@ void database::update_active_sons() } }); - // for now put the all active_sons in hive schedule object - // later we will make here the change which will take only son's from - // active_sons that are hive - const son_schedule_object& ssohive = son_schedule_id_type(1)(*this); - modify(ssohive, [&](son_schedule_object& _sso) + unsigned int schedule_id = 1; + for(const auto& active_sidechain_type : active_sidechain_types) { - flat_set active_sons; - active_sons.reserve(gpo.active_sons.at(sidechain_type::hive).size()); - std::transform(gpo.active_sons.at(sidechain_type::hive).cbegin(), gpo.active_sons.at(sidechain_type::hive).cend(), - std::inserter(active_sons, active_sons.end()), - [](const son_info& swi) { - return swi.son_id; - }); - _sso.scheduler.update(active_sons); - // similar to witness, produce schedule for sons - if(cur_active_sons.at(sidechain_type::hive).size() == 0 && new_active_sons.at(sidechain_type::hive).size() > 0) + const son_schedule_object& sidechain_sso = son_schedule_id_type(schedule_id)(*this); + modify(sidechain_sso, [&](son_schedule_object& _sso) { - witness_scheduler_rng rng(_sso.rng_seed.begin(), GRAPHENE_NEAR_SCHEDULE_CTR_IV); - for( size_t i=0; i active_sons; + active_sons.reserve(gpo.active_sons.at(active_sidechain_type).size()); + std::transform(gpo.active_sons.at(active_sidechain_type).cbegin(), gpo.active_sons.at(active_sidechain_type).cend(), + std::inserter(active_sons, active_sons.end()), + [](const son_info& swi) { + return swi.son_id; + }); + _sso.scheduler.update(active_sons); + // similar to witness, produce schedule for sons + if(cur_active_sons.at(active_sidechain_type).size() == 0 && new_active_sons.at(active_sidechain_type).size() > 0) + { + witness_scheduler_rng rng(_sso.rng_seed.begin(), GRAPHENE_NEAR_SCHEDULE_CTR_IV); + for( size_t i=0; i active_sons; - active_sons.reserve(gpo.active_sons.at(sidechain_type::bitcoin).size()); - std::transform(gpo.active_sons.at(sidechain_type::bitcoin).cbegin(), gpo.active_sons.at(sidechain_type::bitcoin).cend(), - std::inserter(active_sons, active_sons.end()), - [](const son_info& swi) { - return swi.son_id; - }); - _sso.scheduler.update(active_sons); - // similar to witness, produce schedule for sons - if(cur_active_sons.at(sidechain_type::bitcoin).size() == 0 && new_active_sons.at(sidechain_type::bitcoin).size() > 0) - { - witness_scheduler_rng rng(_sso.rng_seed.begin(), GRAPHENE_NEAR_SCHEDULE_CTR_IV); - for( size_t i=0; i schedule_needs_filled = [&gpo]() { flat_map schedule_needs_filled; @@ -425,19 +423,12 @@ void database::update_son_schedule(const signed_block& next_block) bool slot_is_near = sso.scheduler.get_slot( schedule_slot-1, first_son ); son_id_type son; - son_id_type first_son_hive; - bool slot_is_near_hive = ssohive.scheduler.get_slot( schedule_slot-1, first_son_hive ); - son_id_type son_hive; - - son_id_type first_son_bitcoin; - bool slot_is_near_bitcoin = ssobitcoin.scheduler.get_slot( schedule_slot-1, first_son_bitcoin ); - son_id_type son_bitcoin; - const dynamic_global_property_object& dpo = get_dynamic_global_properties(); assert( dpo.random.data_size() == witness_scheduler_rng::seed_length ); assert( witness_scheduler_rng::seed_length == sso.rng_seed.size() ); + //! Fixme - this schedule (delete it?) modify(sso, [&](son_schedule_object& _sso) { _sso.slots_since_genesis += schedule_slot; @@ -471,71 +462,50 @@ void database::update_son_schedule(const signed_block& next_block) + 1) << (schedule_slot - 1); }); - modify(ssohive, [&](son_schedule_object& _sso) + unsigned int schedule_id = 1; + for(const auto& active_sidechain_type : active_sidechain_types) { - _sso.slots_since_genesis += schedule_slot; - witness_scheduler_rng rng(ssohive.rng_seed.data, _sso.slots_since_genesis); + const son_schedule_object& sidechain_sso = get(son_schedule_id_type(schedule_id));; + son_id_type first_son_idechain; + bool slot_is_near_hive = sidechain_sso.scheduler.get_slot( schedule_slot-1, first_son_idechain ); + son_id_type son_idechain; - _sso.scheduler._min_token_count = std::max(int(gpo.active_sons.at(sidechain_type::hive).size()) / 2, 1); + modify(sidechain_sso, [&](son_schedule_object& _sso) + { + _sso.slots_since_genesis += schedule_slot; + witness_scheduler_rng rng(sidechain_sso.rng_seed.data, _sso.slots_since_genesis); - if( slot_is_near_hive ) - { - uint32_t drain = schedule_slot; - while( drain > 0 ) - { - if( _sso.scheduler.size() == 0 ) - break; - _sso.scheduler.consume_schedule(); - --drain; - } - } - else - { - _sso.scheduler.reset_schedule( first_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()); - } - _sso.last_scheduling_block = next_block.block_num(); - _sso.recent_slots_filled = ( - (_sso.recent_slots_filled << 1) - + 1) << (schedule_slot - 1); - }); + _sso.scheduler._min_token_count = std::max(int(gpo.active_sons.at(active_sidechain_type).size()) / 2, 1); - modify(ssobitcoin, [&](son_schedule_object& _sso) - { - _sso.slots_since_genesis += schedule_slot; - witness_scheduler_rng rng(ssohive.rng_seed.data, _sso.slots_since_genesis); + if( slot_is_near_hive ) + { + uint32_t drain = schedule_slot; + while( drain > 0 ) + { + if( _sso.scheduler.size() == 0 ) + break; + _sso.scheduler.consume_schedule(); + --drain; + } + } + else + { + _sso.scheduler.reset_schedule( first_son_idechain ); + } + while( !_sso.scheduler.get_slot(schedule_needs_filled.at(active_sidechain_type), son_idechain) ) + { + if( _sso.scheduler.produce_schedule(rng) & emit_turn ) + memcpy(_sso.rng_seed.begin(), dpo.random.data(), dpo.random.data_size()); + } + _sso.last_scheduling_block = next_block.block_num(); + _sso.recent_slots_filled = ( + (_sso.recent_slots_filled << 1) + + 1) << (schedule_slot - 1); + }); - _sso.scheduler._min_token_count = std::max(int(gpo.active_sons.at(sidechain_type::bitcoin).size()) / 2, 1); + schedule_id += 1; + } - if( slot_is_near_bitcoin ) - { - uint32_t drain = schedule_slot; - while( drain > 0 ) - { - if( _sso.scheduler.size() == 0 ) - break; - _sso.scheduler.consume_schedule(); - --drain; - } - } - else - { - _sso.scheduler.reset_schedule( first_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()); - } - _sso.last_scheduling_block = next_block.block_num(); - _sso.recent_slots_filled = ( - (_sso.recent_slots_filled << 1) - + 1) << (schedule_slot - 1); - }); auto end = fc::time_point::now(); static uint64_t total_time = 0; static uint64_t calls = 0;