From 100ed75e843a4d175c06e32ef8a12cfc4b077555 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 14 Jul 2018 13:37:19 -0400 Subject: [PATCH] Add compile-time option TRACK_STANDBY_VOTES #987 --- CMakeLists.txt | 8 ++++ libraries/chain/db_maint.cpp | 74 ++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index afde6407d9..3a9c096099 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,13 @@ if( ASSET_BALANCE_SORTING ) SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DASSET_BALANCE_SORTED" ) endif() +OPTION( STANDBY_VOTES_TRACKING "Keep votes on standby witnesses and committee members updated (ON OR OFF)" ON ) +if( STANDBY_VOTES_TRACKING ) + MESSAGE( STATUS "Configurating STANDBY_VOTES_TRACKING" ) + SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTRACK_STANDBY_VOTES" ) + SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTRACK_STANDBY_VOTES" ) +endif() + if( WIN32 ) message( STATUS "Configuring BitShares on WIN32") @@ -213,4 +220,5 @@ endif(ENABLE_INSTALLER) MESSAGE( STATUS "" ) MESSAGE( STATUS "ASSET_BALANCE_SORTING: ${ASSET_BALANCE_SORTING}" ) +MESSAGE( STATUS "STANDBY_VOTES_TRACKING: ${STANDBY_VOTES_TRACKING}" ) MESSAGE( STATUS "" ) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index fada61075d..290f8ff492 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -215,14 +215,17 @@ struct worker_pay_visitor worker.pay_worker(pay, db); } }; + void database::update_worker_votes() { - auto& idx = get_index_type(); - auto itr = idx.indices().get().begin(); + const auto& idx = get_index_type().indices().get(); + auto itr = idx.begin(); + auto itr_end = idx.end(); bool allow_negative_votes = (head_block_time() < HARDFORK_607_TIME); - while( itr != idx.indices().get().end() ) + while( itr != itr_end ) { - modify( *itr, [&]( worker_object& obj ){ + modify( *itr, [this,allow_negative_votes]( worker_object& obj ) + { obj.total_votes_for = _vote_tally_buffer[obj.vote_for]; obj.total_votes_against = allow_negative_votes ? _vote_tally_buffer[obj.vote_against] : 0; }); @@ -294,21 +297,27 @@ void database::update_active_witnesses() } const chain_property_object& cpo = get_chain_properties(); - auto wits = sort_votable_objects(std::max(witness_count*2+1, (size_t)cpo.immutable_parameters.min_witness_count)); + + witness_count = std::max( witness_count*2+1, (size_t)cpo.immutable_parameters.min_witness_count ); + auto wits = sort_votable_objects( witness_count ); const global_property_object& gpo = get_global_properties(); +#ifdef TRACK_STANDBY_VOTES const auto& all_witnesses = get_index_type().indices(); - for( const witness_object& wit : all_witnesses ) +#else + for( const witness_object& wit : wits ) +#endif { - modify( wit, [&]( witness_object& obj ){ - obj.total_votes = _vote_tally_buffer[wit.vote_id]; - }); + modify( wit, [this]( witness_object& obj ) + { + obj.total_votes = _vote_tally_buffer[obj.vote_id]; + }); } // Update witness authority - modify( get(GRAPHENE_WITNESS_ACCOUNT), [&]( account_object& a ) + modify( get(GRAPHENE_WITNESS_ACCOUNT), [this,&wits]( account_object& a ) { if( head_block_time() < HARDFORK_533_TIME ) { @@ -346,7 +355,8 @@ void database::update_active_witnesses() } } ); - modify(gpo, [&]( global_property_object& gp ){ + modify( gpo, [&wits]( global_property_object& gp ) + { gp.active_witnesses.clear(); gp.active_witnesses.reserve(wits.size()); std::transform(wits.begin(), wits.end(), @@ -368,24 +378,37 @@ void database::update_active_committee_members() uint64_t stake_tally = 0; // _committee_count_histogram_buffer[0]; size_t committee_member_count = 0; if( stake_target > 0 ) + { while( (committee_member_count < _committee_count_histogram_buffer.size() - 1) && (stake_tally <= stake_target) ) + { stake_tally += _committee_count_histogram_buffer[++committee_member_count]; + } + } const chain_property_object& cpo = get_chain_properties(); - auto committee_members = sort_votable_objects(std::max(committee_member_count*2+1, (size_t)cpo.immutable_parameters.min_committee_member_count)); - for( const committee_member_object& del : committee_members ) + committee_member_count = std::max( committee_member_count*2+1, (size_t)cpo.immutable_parameters.min_committee_member_count ); + auto committee_members = sort_votable_objects( committee_member_count ); + +#ifdef TRACK_STANDBY_VOTES + const auto& all_committee_members = get_index_type().indices(); + for( const committee_member_object& cm : all_committee_members ) +#else + for( const committee_member_object& cm : committee_members ) +#endif { - modify( del, [&]( committee_member_object& obj ){ - obj.total_votes = _vote_tally_buffer[del.vote_id]; - }); + modify( cm, [this]( committee_member_object& obj ) + { + obj.total_votes = _vote_tally_buffer[obj.vote_id]; + }); } // Update committee authorities if( !committee_members.empty() ) { - modify(get(GRAPHENE_COMMITTEE_ACCOUNT), [&](account_object& a) + const account_object& committee_account = get(GRAPHENE_COMMITTEE_ACCOUNT); + modify( committee_account, [this,&committee_members](account_object& a) { if( head_block_time() < HARDFORK_533_TIME ) { @@ -394,10 +417,10 @@ void database::update_active_committee_members() a.active.weight_threshold = 0; a.active.clear(); - for( const committee_member_object& del : committee_members ) + for( const committee_member_object& cm : committee_members ) { - weights.emplace(del.committee_member_account, _vote_tally_buffer[del.vote_id]); - total_votes += _vote_tally_buffer[del.vote_id]; + weights.emplace( cm.committee_member_account, _vote_tally_buffer[cm.vote_id] ); + total_votes += _vote_tally_buffer[cm.vote_id]; } // total_votes is 64 bits. Subtract the number of leading low bits from 64 to get the number of useful bits, @@ -421,12 +444,14 @@ void database::update_active_committee_members() vc.add( cm.committee_member_account, _vote_tally_buffer[cm.vote_id] ); vc.finish( a.active ); } - } ); - modify(get(GRAPHENE_RELAXED_COMMITTEE_ACCOUNT), [&](account_object& a) { - a.active = get(GRAPHENE_COMMITTEE_ACCOUNT).active; + }); + modify( get(GRAPHENE_RELAXED_COMMITTEE_ACCOUNT), [&committee_account](account_object& a) + { + a.active = committee_account.active; }); } - modify(get_global_properties(), [&](global_property_object& gp) { + modify( get_global_properties(), [&committee_members](global_property_object& gp) + { gp.active_committee_members.clear(); std::transform(committee_members.begin(), committee_members.end(), std::inserter(gp.active_committee_members, gp.active_committee_members.begin()), @@ -473,7 +498,6 @@ void database::initialize_budget_record( fc::time_point_sec now, budget_record& // be able to use the entire reserve budget_u128 += ((uint64_t(1) << GRAPHENE_CORE_ASSET_CYCLE_RATE_BITS) - 1); budget_u128 >>= GRAPHENE_CORE_ASSET_CYCLE_RATE_BITS; - share_type budget; if( budget_u128 < reserve.value ) rec.total_budget = share_type(budget_u128.to_uint64()); else