#308 - fix global_props.active_sons.size
This commit is contained in:
parent
550727757f
commit
446d89764c
8 changed files with 43 additions and 18 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<sidechain_type, uint32_t> schedule_needs_filled = [&gpo]()
|
||||
{
|
||||
flat_map<sidechain_type, uint32_t> 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());
|
||||
|
|
|
|||
|
|
@ -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<son_wallet_deposit_index>().indices().get<by_id>();
|
||||
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) ) }
|
||||
|
|
|
|||
|
|
@ -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<son_wallet_withdraw_index>().indices().get<by_id>();
|
||||
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) ) }
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<son_info> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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_type, string> 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<string, son_id_type> active_sons = con.wallet_api_ptr->list_active_sons();
|
||||
BOOST_CHECK(active_sons.size() == son_number);
|
||||
|
|
|
|||
Loading…
Reference in a new issue