#339 - add function get_son_schedule_id
This commit is contained in:
parent
8bb452858c
commit
aa3da2cf62
4 changed files with 27 additions and 14 deletions
|
|
@ -1105,7 +1105,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
||||||
|
|
||||||
_sso.recent_slots_filled = fc::uint128::max_value();
|
_sso.recent_slots_filled = fc::uint128::max_value();
|
||||||
});
|
});
|
||||||
assert( ssohive.id == son_schedule_id_type(1) );
|
assert( ssohive.id == son_schedule_id_type(get_son_schedule_id(sidechain_type::hive)) );
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
const son_schedule_object& ssobitcoin =
|
const son_schedule_object& ssobitcoin =
|
||||||
|
|
@ -1127,7 +1127,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
||||||
|
|
||||||
_sso.recent_slots_filled = fc::uint128::max_value();
|
_sso.recent_slots_filled = fc::uint128::max_value();
|
||||||
});
|
});
|
||||||
assert( ssobitcoin.id == son_schedule_id_type(2) );
|
assert( ssobitcoin.id == son_schedule_id_type(get_son_schedule_id(sidechain_type::bitcoin)) );
|
||||||
|
|
||||||
// Create FBA counters
|
// Create FBA counters
|
||||||
create<fba_accumulator_object>([&]( fba_accumulator_object& acc )
|
create<fba_accumulator_object>([&]( fba_accumulator_object& acc )
|
||||||
|
|
|
||||||
|
|
@ -874,10 +874,9 @@ void database::update_active_sons()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
unsigned int schedule_id = 1;
|
|
||||||
for(const auto& active_sidechain_type : active_sidechain_types)
|
for(const auto& active_sidechain_type : active_sidechain_types)
|
||||||
{
|
{
|
||||||
const son_schedule_object& sidechain_sso = son_schedule_id_type(schedule_id)(*this);
|
const son_schedule_object& sidechain_sso = son_schedule_id_type(get_son_schedule_id(active_sidechain_type))(*this);
|
||||||
modify(sidechain_sso, [&](son_schedule_object& _sso)
|
modify(sidechain_sso, [&](son_schedule_object& _sso)
|
||||||
{
|
{
|
||||||
flat_set<son_id_type> active_sons;
|
flat_set<son_id_type> active_sons;
|
||||||
|
|
@ -896,8 +895,6 @@ void database::update_active_sons()
|
||||||
_sso.scheduler.produce_schedule(rng);
|
_sso.scheduler.produce_schedule(rng);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
schedule_id += 1;
|
|
||||||
}
|
}
|
||||||
} FC_CAPTURE_AND_RETHROW() }
|
} FC_CAPTURE_AND_RETHROW() }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,16 @@ witness_id_type database::get_scheduled_witness( uint32_t slot_num )const
|
||||||
return wid;
|
return wid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned_int database::get_son_schedule_id( sidechain_type type )const
|
||||||
|
{
|
||||||
|
static const map<sidechain_type, unsigned_int> schedule_map = {
|
||||||
|
{ sidechain_type::bitcoin, 1 },
|
||||||
|
{ sidechain_type::hive, 2 }
|
||||||
|
};
|
||||||
|
|
||||||
|
return schedule_map.at(type);
|
||||||
|
}
|
||||||
|
|
||||||
son_id_type database::get_scheduled_son( sidechain_type type, uint32_t slot_num )const
|
son_id_type database::get_scheduled_son( sidechain_type type, uint32_t slot_num )const
|
||||||
{
|
{
|
||||||
son_id_type sid;
|
son_id_type sid;
|
||||||
|
|
@ -81,14 +91,14 @@ son_id_type database::get_scheduled_son( sidechain_type type, uint32_t slot_num
|
||||||
if (gpo.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SHUFFLED_ALGORITHM)
|
if (gpo.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SHUFFLED_ALGORITHM)
|
||||||
{
|
{
|
||||||
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
|
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
|
||||||
const son_schedule_object& sso = type == sidechain_type::hive ? son_schedule_id_type(1)(*this) : son_schedule_id_type(2)(*this);
|
const son_schedule_object& sso = son_schedule_id_type(get_son_schedule_id(type))(*this);
|
||||||
uint64_t current_aslot = dpo.current_aslot + slot_num;
|
uint64_t current_aslot = dpo.current_aslot + slot_num;
|
||||||
return sso.current_shuffled_sons.at(type)[ current_aslot % sso.current_shuffled_sons.size() ];
|
return sso.current_shuffled_sons.at(type)[ current_aslot % sso.current_shuffled_sons.size() ];
|
||||||
}
|
}
|
||||||
if (gpo.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SCHEDULED_ALGORITHM &&
|
if (gpo.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SCHEDULED_ALGORITHM &&
|
||||||
slot_num != 0 )
|
slot_num != 0 )
|
||||||
{
|
{
|
||||||
const son_schedule_object& sso = type == sidechain_type::hive ? son_schedule_id_type(1)(*this) : son_schedule_id_type(2)(*this);
|
const son_schedule_object& sso = son_schedule_id_type(get_son_schedule_id(type))(*this);
|
||||||
// ask the near scheduler who goes in the given slot
|
// ask the near scheduler who goes in the given slot
|
||||||
bool slot_is_near = sso.scheduler.get_slot(slot_num-1, sid);
|
bool slot_is_near = sso.scheduler.get_slot(slot_num-1, sid);
|
||||||
if(! slot_is_near)
|
if(! slot_is_near)
|
||||||
|
|
@ -192,8 +202,8 @@ void database::update_witness_schedule()
|
||||||
void database::update_son_schedule()
|
void database::update_son_schedule()
|
||||||
{
|
{
|
||||||
const son_schedule_object& sso = son_schedule_id_type()(*this);
|
const son_schedule_object& sso = son_schedule_id_type()(*this);
|
||||||
const son_schedule_object& ssohive = son_schedule_id_type(1)(*this);
|
const son_schedule_object& ssohive = son_schedule_id_type(get_son_schedule_id(sidechain_type::hive))(*this);
|
||||||
const son_schedule_object& ssobitcoin = son_schedule_id_type(2)(*this);
|
const son_schedule_object& ssobitcoin = son_schedule_id_type(get_son_schedule_id(sidechain_type::bitcoin))(*this);
|
||||||
const global_property_object& gpo = get_global_properties();
|
const global_property_object& gpo = get_global_properties();
|
||||||
|
|
||||||
//! Fixme - here we should take active_sons size for sidechain
|
//! Fixme - here we should take active_sons size for sidechain
|
||||||
|
|
@ -462,10 +472,9 @@ void database::update_son_schedule(const signed_block& next_block)
|
||||||
+ 1) << (schedule_slot - 1);
|
+ 1) << (schedule_slot - 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
unsigned int schedule_id = 1;
|
|
||||||
for(const auto& active_sidechain_type : active_sidechain_types)
|
for(const auto& active_sidechain_type : active_sidechain_types)
|
||||||
{
|
{
|
||||||
const son_schedule_object& sidechain_sso = get(son_schedule_id_type(schedule_id));;
|
const son_schedule_object& sidechain_sso = get(son_schedule_id_type(get_son_schedule_id(active_sidechain_type)));
|
||||||
son_id_type first_son_idechain;
|
son_id_type first_son_idechain;
|
||||||
bool slot_is_near_hive = sidechain_sso.scheduler.get_slot( schedule_slot-1, first_son_idechain );
|
bool slot_is_near_hive = sidechain_sso.scheduler.get_slot( schedule_slot-1, first_son_idechain );
|
||||||
son_id_type son_idechain;
|
son_id_type son_idechain;
|
||||||
|
|
@ -502,8 +511,6 @@ void database::update_son_schedule(const signed_block& next_block)
|
||||||
(_sso.recent_slots_filled << 1)
|
(_sso.recent_slots_filled << 1)
|
||||||
+ 1) << (schedule_slot - 1);
|
+ 1) << (schedule_slot - 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
schedule_id += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto end = fc::time_point::now();
|
auto end = fc::time_point::now();
|
||||||
|
|
|
||||||
|
|
@ -242,6 +242,15 @@ namespace graphene { namespace chain {
|
||||||
*/
|
*/
|
||||||
witness_id_type get_scheduled_witness(uint32_t slot_num)const;
|
witness_id_type get_scheduled_witness(uint32_t slot_num)const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get son schedule id for the given sidechain_type.
|
||||||
|
*
|
||||||
|
* type sidechain_type we getting schedule.
|
||||||
|
*
|
||||||
|
* returns Id of the schedule object.
|
||||||
|
*/
|
||||||
|
unsigned_int get_son_schedule_id(sidechain_type type)const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the bitcoin or hive son scheduled for block production in a slot.
|
* @brief Get the bitcoin or hive son scheduled for block production in a slot.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue