diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index a942bfe545..8c7eac849d 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1283,6 +1283,7 @@ asset create_vesting2( database& db, const account_object& to_account, asset liq cprops, a, db.has_hardfork( STEEM_HARDFORK_0_21__3336 ), + db.head_block_num() > STEEM_HF_21_STALL_BLOCK, new_vesting.amount.value ); }); } @@ -4294,6 +4295,7 @@ void database::clear_expired_delegations() while( itr != delegations_by_exp.end() && itr->expiration < now ) { operation vop = return_vesting_delegation_operation( itr->delegator, itr->vesting_shares ); + try{ pre_push_virtual_operation( vop ); modify( get_account( itr->delegator ), [&]( account_object& a ) @@ -4304,6 +4306,7 @@ void database::clear_expired_delegations() gpo, a, has_hardfork( STEEM_HARDFORK_0_21__3336 ), + head_block_num() > STEEM_HF_21_STALL_BLOCK, itr->vesting_shares.amount.value ); } @@ -4314,7 +4317,7 @@ void database::clear_expired_delegations() remove( *itr ); itr = delegations_by_exp.begin(); - } + } FC_CAPTURE_AND_RETHROW( (vop) ) } } #ifdef STEEM_ENABLE_SMT template< typename smt_balance_object_type, class balance_operator_type > diff --git a/libraries/chain/include/steem/chain/util/manabar.hpp b/libraries/chain/include/steem/chain/util/manabar.hpp index 4e94ca6ae3..93d244a180 100644 --- a/libraries/chain/include/steem/chain/util/manabar.hpp +++ b/libraries/chain/include/steem/chain/util/manabar.hpp @@ -20,9 +20,9 @@ struct manabar_params : max_mana(mm), regen_time(rt) {} void validate()const - { + { try{ FC_ASSERT( max_mana >= 0 ); - } + } FC_CAPTURE_AND_RETHROW( (max_mana) ) } }; struct manabar @@ -117,21 +117,41 @@ int64_t get_effective_vesting_shares( const T& account ) } template< typename PropType, typename AccountType > -void update_manabar( const PropType& gpo, AccountType& account, bool downvote_mana = false, int64_t new_mana = 0 ) +void update_manabar( const PropType& gpo, AccountType& account, bool downvote_mana = false, bool check_overflow = true, int64_t new_mana = 0 ) { auto effective_vests = util::get_effective_vesting_shares( account ); + try { manabar_params params( effective_vests, STEEM_VOTING_MANA_REGENERATION_SECONDS ); account.voting_manabar.regenerate_mana( params, gpo.time ); account.voting_manabar.use_mana( -new_mana ); + } FC_CAPTURE_LOG_AND_RETHROW( (account)(effective_vests) ) FC_TODO( "This hardfork check should not be needed. Remove after HF21 if that is the case." ); // This is used as a hardfork check. Can be replaced with if( gpo.downvote_pool_percent ). Leaving as a hard check to be safe until after HF 21 + try{ if( downvote_mana ) { - util::manabar_params params( ( effective_vests * gpo.downvote_pool_percent ) / STEEM_100_PERCENT, STEEM_VOTING_MANA_REGENERATION_SECONDS ); + manabar_params params; + params.regen_time = STEEM_VOTING_MANA_REGENERATION_SECONDS; + + if( check_overflow ) + { + params.max_mana = ( ( uint128_t( effective_vests ) * gpo.downvote_pool_percent ) / STEEM_100_PERCENT ).to_int64(); + } + else + { + FC_TODO( "Cleanup once we have verified the overflow has not permanently made it in to the chain" ); + uint128_t numerator = effective_vests * gpo.downvote_pool_percent; + if( numerator.hi != 0 ) + elog( "NOTIFYALERT! max mana overflow made it in to the chain" ); + + params.max_mana = ( effective_vests * gpo.downvote_pool_percent ) / STEEM_100_PERCENT; + } + account.downvote_manabar.regenerate_mana( params, gpo.time ); account.downvote_manabar.use_mana( ( -new_mana * gpo.downvote_pool_percent ) / STEEM_100_PERCENT ); } + } FC_CAPTURE_LOG_AND_RETHROW( (account)(effective_vests) ) } } } } // steem::chain::util diff --git a/libraries/chain/steem_evaluator.cpp b/libraries/chain/steem_evaluator.cpp index c9ba116a93..6d493c3d43 100644 --- a/libraries/chain/steem_evaluator.cpp +++ b/libraries/chain/steem_evaluator.cpp @@ -1906,7 +1906,7 @@ void hf20_vote_evaluator( const vote_operation& o, database& _db ) _db.modify( voter, [&]( account_object& a ) { - util::update_manabar( _db.get_dynamic_global_properties(), a, _db.has_hardfork( STEEM_HARDFORK_0_21__3336 ) ); + util::update_manabar( _db.get_dynamic_global_properties(), a, _db.has_hardfork( STEEM_HARDFORK_0_21__3336 ), _db.head_block_num() > STEEM_HF_21_STALL_BLOCK ); }); if ( _db.has_hardfork( STEEM_HARDFORK_0_21__3004 ) ) @@ -2975,7 +2975,7 @@ void claim_reward_balance_evaluator::do_apply( const claim_reward_balance_operat { if( _db.has_hardfork( STEEM_HARDFORK_0_20__2539 ) ) { - util::update_manabar( _db.get_dynamic_global_properties(), a, _db.has_hardfork( STEEM_HARDFORK_0_21__3336 ), op.reward_vests.amount.value ); + util::update_manabar( _db.get_dynamic_global_properties(), a, _db.has_hardfork( STEEM_HARDFORK_0_21__3336 ), _db.head_block_num() > STEEM_HF_21_STALL_BLOCK, op.reward_vests.amount.value ); } a.vesting_shares += op.reward_vests; @@ -3084,7 +3084,7 @@ void delegate_vesting_shares_evaluator::do_apply( const delegate_vesting_shares_ _db.modify( delegator, [&]( account_object& a ) { - util::update_manabar( gpo, a, _db.has_hardfork( STEEM_HARDFORK_0_21__3336 ) ); + util::update_manabar( gpo, a, _db.has_hardfork( STEEM_HARDFORK_0_21__3336 ), _db.head_block_num() > STEEM_HF_21_STALL_BLOCK ); }); available_shares = asset( delegator.voting_manabar.current_mana, VESTS_SYMBOL ); @@ -3180,7 +3180,7 @@ void delegate_vesting_shares_evaluator::do_apply( const delegate_vesting_shares_ { if( _db.has_hardfork( STEEM_HARDFORK_0_20__2539 ) ) { - util::update_manabar( gpo, a, _db.has_hardfork( STEEM_HARDFORK_0_21__3336 ), op.vesting_shares.amount.value ); + util::update_manabar( gpo, a, _db.has_hardfork( STEEM_HARDFORK_0_21__3336 ), _db.head_block_num() > STEEM_HF_21_STALL_BLOCK, op.vesting_shares.amount.value ); } a.received_vesting_shares += op.vesting_shares; @@ -3218,7 +3218,7 @@ void delegate_vesting_shares_evaluator::do_apply( const delegate_vesting_shares_ { if( _db.has_hardfork( STEEM_HARDFORK_0_20__2539 ) ) { - util::update_manabar( gpo, a, _db.has_hardfork( STEEM_HARDFORK_0_21__3336 ), delta.amount.value ); + util::update_manabar( gpo, a, _db.has_hardfork( STEEM_HARDFORK_0_21__3336 ), _db.head_block_num() > STEEM_HF_21_STALL_BLOCK, delta.amount.value ); } a.received_vesting_shares += delta; diff --git a/libraries/plugins/rc/rc_plugin.cpp b/libraries/plugins/rc/rc_plugin.cpp index d336c43cf9..2ab1c565a8 100644 --- a/libraries/plugins/rc/rc_plugin.cpp +++ b/libraries/plugins/rc/rc_plugin.cpp @@ -239,6 +239,7 @@ void use_account_rcs( #endif ) { + if( account_name == account_name_type() ) { if( db.is_producing() ) @@ -262,6 +263,8 @@ void use_account_rcs( mbparams.max_mana = get_maximum_rc( account, rc_account ); mbparams.regen_time = STEEM_RC_REGEN_TIME; + try{ + db.modify( rc_account, [&]( rc_account_object& rca ) { rca.rc_manabar.regenerate_mana< true >( mbparams, gpo.time.sec_since_epoch() ); @@ -305,10 +308,11 @@ void use_account_rcs( rca.rc_manabar.use_mana( rc, min_mana ); } ); + }FC_CAPTURE_AND_RETHROW( (account)(rc_account)(mbparams.max_mana) ) } void rc_plugin_impl::on_post_apply_transaction( const transaction_notification& note ) -{ +{ try { const dynamic_global_property_object& gpo = _db.get_dynamic_global_properties(); if( before_first_block() ) return; @@ -357,7 +361,7 @@ void rc_plugin_impl::on_post_apply_transaction( const transaction_notification& } if( export_data ) export_data->tx_info.push_back( tx_info ); -} +} FC_CAPTURE_AND_RETHROW( (note.transaction) ) } struct block_extensions_count_resources_visitor { @@ -383,7 +387,7 @@ struct block_extensions_count_resources_visitor }; void rc_plugin_impl::on_post_apply_block( const block_notification& note ) -{ +{ try{ const dynamic_global_property_object& gpo = _db.get_dynamic_global_properties(); if( before_first_block() ) { @@ -512,7 +516,7 @@ void rc_plugin_impl::on_post_apply_block( const block_notification& note ) steem::plugins::block_data_export::find_export_data< exp_rc_data >( STEEM_RC_PLUGIN_NAME ); if( export_data ) export_data->block_info = block_info; -} +} FC_CAPTURE_AND_RETHROW( (note.block) ) } void rc_plugin_impl::on_first_block() { @@ -617,6 +621,8 @@ struct pre_apply_operation_visitor mbparams.max_mana = get_maximum_rc( account, rc_account ); mbparams.regen_time = STEEM_RC_REGEN_TIME; + try { + if( mbparams.max_mana != rc_account.last_max_rc ) { if( !_skip.skip_reject_unknown_delta_vests ) @@ -636,6 +642,7 @@ struct pre_apply_operation_visitor { rca.rc_manabar.regenerate_mana< true >( mbparams, _current_time ); } ); + } FC_CAPTURE_AND_RETHROW( (account)(rc_account)(mbparams.max_mana) ) } template< bool account_may_not_exist = false > @@ -654,8 +661,9 @@ struct pre_apply_operation_visitor const rc_account_object* rc_account = _db.find< rc_account_object, by_name >( name ); FC_ASSERT( rc_account != nullptr, "Unexpectedly, rc_account ${a} does not exist", ("a", name) ); - + try{ regenerate( *account, *rc_account ); + } FC_CAPTURE_AND_RETHROW( (*account)(*rc_account) ) } void operator()( const account_create_with_delegation_operation& op )const @@ -971,7 +979,7 @@ typedef post_apply_operation_visitor post_apply_optional_action_visitor; void rc_plugin_impl::on_pre_apply_operation( const operation_notification& note ) -{ +{ try { if( before_first_block() ) return; @@ -987,6 +995,7 @@ void rc_plugin_impl::on_pre_apply_operation( const operation_notification& note // ilog( "Calling pre-vtor on ${op}", ("op", note.op) ); note.op.visit( vtor ); + } FC_CAPTURE_AND_RETHROW( (note.op) ) } void update_modified_accounts( database& db, const std::vector< account_regen_info >& modified_accounts ) @@ -1009,7 +1018,7 @@ void update_modified_accounts( database& db, const std::vector< account_regen_in } void rc_plugin_impl::on_post_apply_operation( const operation_notification& note ) -{ +{ try { if( before_first_block() ) return; @@ -1023,7 +1032,7 @@ void rc_plugin_impl::on_post_apply_operation( const operation_notification& note note.op.visit( vtor ); update_modified_accounts( _db, modified_accounts ); -} +} FC_CAPTURE_AND_RETHROW( (note.op) ) } void rc_plugin_impl::on_pre_apply_optional_action( const optional_action_notification& note ) { diff --git a/libraries/protocol/hardfork.d/0_21.hf b/libraries/protocol/hardfork.d/0_21.hf index 5b65b94d81..331599fbc1 100644 --- a/libraries/protocol/hardfork.d/0_21.hf +++ b/libraries/protocol/hardfork.d/0_21.hf @@ -11,6 +11,8 @@ #define STEEM_HARDFORK_0_21__3336 (STEEM_HARDFORK_0_21) #define STEEM_HARDFORK_0_21__3343 (STEEM_HARDFORK_0_21) +#define STEEM_HF_21_STALL_BLOCK 35922615 + #define STEEM_HARDFORK_0_21_VERSION hardfork_version( 0, 21 ) #endif