Skip to content

Commit

Permalink
Track is_voting in account stats, and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
abitmore committed Jun 23, 2018
1 parent 5e42457 commit 8f08ec9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
45 changes: 31 additions & 14 deletions libraries/chain/account_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,15 @@ object_id_type account_create_evaluator::do_apply( const account_create_operatio
referrer_percent = GRAPHENE_100_PERCENT;
}

const auto& new_acnt_object = db().create<account_object>( [&]( account_object& obj ){
const auto& global_properties = d.get_global_properties();

const auto& new_acnt_object = d.create<account_object>( [&o,&d,&global_properties,referrer_percent]( account_object& obj )
{
obj.registrar = o.registrar;
obj.referrer = o.referrer;
obj.lifetime_referrer = o.referrer(db()).lifetime_referrer;
obj.lifetime_referrer = o.referrer(d).lifetime_referrer;

auto& params = db().get_global_properties().parameters;
const auto& params = global_properties.parameters;
obj.network_fee_percentage = params.network_percent_of_fee;
obj.lifetime_referrer_fee_percentage = params.lifetime_referrer_percent_of_fee;
obj.referrer_rewards_percentage = referrer_percent;
Expand All @@ -202,9 +205,10 @@ object_id_type account_create_evaluator::do_apply( const account_create_operatio
obj.owner = o.owner;
obj.active = o.active;
obj.options = o.options;
obj.statistics = db().create<account_statistics_object>([&obj](account_statistics_object& s){
obj.statistics = d.create<account_statistics_object>([&obj](account_statistics_object& s){
s.owner = obj.id;
s.name = obj.name;
s.is_voting = obj.options.is_voting();
}).id;

if( o.extensions.value.owner_special_authority.valid() )
Expand All @@ -229,17 +233,18 @@ object_id_type account_create_evaluator::do_apply( const account_create_operatio
}
*/

const auto& dynamic_properties = db().get_dynamic_global_properties();
db().modify(dynamic_properties, [](dynamic_global_property_object& p) {
const auto& dynamic_properties = d.get_dynamic_global_properties();
d.modify(dynamic_properties, [](dynamic_global_property_object& p) {
++p.accounts_registered_this_interval;
});

const auto& global_properties = db().get_global_properties();
if( dynamic_properties.accounts_registered_this_interval %
global_properties.parameters.accounts_per_fee_scale == 0 )
db().modify(global_properties, [](global_property_object& p) {
if( dynamic_properties.accounts_registered_this_interval % global_properties.parameters.accounts_per_fee_scale == 0
&& global_properties.parameters.account_fee_scale_bitshifts != 0 )
{
d.modify(global_properties, [](global_property_object& p) {
p.parameters.current_fees->get<account_create_operation>().basic_fee <<= p.parameters.account_fee_scale_bitshifts;
});
}

if( o.extensions.value.owner_special_authority.valid()
|| o.extensions.value.active_special_authority.valid() )
Expand Down Expand Up @@ -308,8 +313,20 @@ void_result account_update_evaluator::do_evaluate( const account_update_operatio
void_result account_update_evaluator::do_apply( const account_update_operation& o )
{ try {
database& d = db();
bool sa_before, sa_after;
d.modify( *acnt, [&](account_object& a){

bool sa_before = acnt->has_special_authority();

// update account statistics
if( o.new_options.valid() && o.new_options->is_voting() != acnt->options.is_voting() )
{
d.modify( acnt->statistics( d ), []( account_statistics_object& aso )
{
aso.is_voting = !aso.is_voting;
} );
}

// update account object
d.modify( *acnt, [&o](account_object& a){
if( o.owner )
{
a.owner = *o.owner;
Expand All @@ -321,7 +338,6 @@ void_result account_update_evaluator::do_apply( const account_update_operation&
a.top_n_control_flags = 0;
}
if( o.new_options ) a.options = *o.new_options;
sa_before = a.has_special_authority();
if( o.extensions.value.owner_special_authority.valid() )
{
a.owner_special_authority = *(o.extensions.value.owner_special_authority);
Expand All @@ -332,9 +348,10 @@ void_result account_update_evaluator::do_apply( const account_update_operation&
a.active_special_authority = *(o.extensions.value.active_special_authority);
a.top_n_control_flags = 0;
}
sa_after = a.has_special_authority();
});

bool sa_after = acnt->has_special_authority();

if( sa_before && (!sa_after) )
{
const auto& sa_idx = d.get_index_type< special_authority_index >().indices().get<by_account>();
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void database::perform_account_maintenance(Type tally_helper)
const account_object& acc_obj = acc_stat.owner( *this );
++stats_itr;

if( acc_stat.has_some_core() )
if( acc_stat.has_some_core_voting() )
tally_helper( acc_obj, acc_stat );

if( acc_stat.has_pending_fees() )
Expand Down
12 changes: 9 additions & 3 deletions libraries/chain/include/graphene/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ namespace graphene { namespace chain {

bool has_cashback_vb = false; ///< redundantly store this for better maintenance performance

/// Whether this account owns some CORE asset
inline bool has_some_core() const { return total_core_in_orders > 0 || core_in_balance > 0 || has_cashback_vb; }
bool is_voting = false; ///< redundately store whether this account is voting for better maintenance performance

/// Whether this account owns some CORE asset and is voting
inline bool has_some_core_voting() const
{
return is_voting && ( total_core_in_orders > 0 || core_in_balance > 0 || has_cashback_vb );
}

/**
* Tracks the total fees paid by this account for the purpose of calculating bulk discounts.
Expand All @@ -95,7 +100,7 @@ namespace graphene { namespace chain {
inline bool has_pending_fees() const { return pending_fees > 0 || pending_vested_fees > 0; }

/// Whether need to process this account during the maintenance interval
inline bool need_maintenance() const { return has_some_core() || has_pending_fees(); }
inline bool need_maintenance() const { return has_some_core_voting() || has_pending_fees(); }

/// @brief Split up and pay out @ref pending_fees and @ref pending_vested_fees
void process_fees(const account_object& a, database& d) const;
Expand Down Expand Up @@ -439,6 +444,7 @@ FC_REFLECT_DERIVED( graphene::chain::account_statistics_object,
(total_core_in_orders)
(core_in_balance)
(has_cashback_vb)
(is_voting)
(lifetime_fees_paid)
(pending_fees)(pending_vested_fees)
)
Expand Down
6 changes: 6 additions & 0 deletions libraries/chain/include/graphene/chain/protocol/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ namespace graphene { namespace chain {
flat_set<vote_id_type> votes;
extensions_type extensions;

/// Whether this account is voting
inline bool is_voting() const
{
return ( voting_account != GRAPHENE_PROXY_TO_SELF_ACCOUNT || !votes.empty() );
}

void validate()const;
};

Expand Down

0 comments on commit 8f08ec9

Please sign in to comment.