Skip to content

Commit

Permalink
Merge pull request #3484 from steemit/0.21.x
Browse files Browse the repository at this point in the history
0.21.x
  • Loading branch information
Michael Vandeberg authored Aug 28, 2019
2 parents 45473a5 + 51ec865 commit 42a4556
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 23 deletions.
5 changes: 4 additions & 1 deletion libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
});
}
Expand Down Expand Up @@ -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 )
Expand All @@ -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 );
}

Expand All @@ -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 >
Expand Down
28 changes: 24 additions & 4 deletions libraries/chain/include/steem/chain/util/manabar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,24 @@ struct extended_dynamic_global_properties
sbd_interest_rate( o.sbd_interest_rate ),
sbd_print_rate( o.sbd_print_rate ),
maximum_block_size( o.maximum_block_size ),
required_actions_partition_percent( o.required_actions_partition_percent ),
current_aslot( o.current_aslot ),
recent_slots_filled( o.recent_slots_filled ),
participation_count( o.participation_count ),
last_irreversible_block_num( o.last_irreversible_block_num ),
vote_power_reserve_rate( o.vote_power_reserve_rate ),
delegation_return_period( o.delegation_return_period ),
reverse_auction_seconds( o.reverse_auction_seconds ),
available_account_subsidies( o.available_account_subsidies ),
sbd_stop_percent( o.sbd_stop_percent ),
sbd_start_percent( o.sbd_start_percent )
sbd_start_percent( o.sbd_start_percent ),
next_maintenance_time( o.next_maintenance_time ),
last_budget_time( o.last_budget_time ),
content_reward_percent( o.content_reward_percent ),
vesting_reward_percent( o.vesting_reward_percent ),
sps_fund_percent( o.sps_fund_percent ),
sps_interval_ledger( legacy_asset::from_asset( o.sps_interval_ledger ) ),
downvote_pool_percent( o.downvote_pool_percent )
{}

uint32_t head_block_number = 0;
Expand Down Expand Up @@ -408,6 +417,7 @@ struct extended_dynamic_global_properties
uint16_t sbd_print_rate = STEEM_100_PERCENT;

uint32_t maximum_block_size = 0;
uint16_t required_actions_partition_percent = 0;
uint64_t current_aslot = 0;
fc::uint128_t recent_slots_filled;
uint8_t participation_count = 0;
Expand All @@ -419,8 +429,21 @@ struct extended_dynamic_global_properties

uint64_t reverse_auction_seconds = 0;

int64_t available_account_subsidies = 0;

uint16_t sbd_stop_percent = 0;
uint16_t sbd_start_percent = 0;

time_point_sec next_maintenance_time;
time_point_sec last_budget_time;

uint16_t content_reward_percent = STEEM_CONTENT_REWARD_PERCENT_HF16;
uint16_t vesting_reward_percent = STEEM_VESTING_FUND_PERCENT_HF16;
uint16_t sps_fund_percent = STEEM_PROPOSAL_FUND_PERCENT_HF0;

legacy_asset sps_interval_ledger;

uint16_t downvote_pool_percent = 0;
};

struct api_witness_object
Expand Down Expand Up @@ -1213,8 +1236,10 @@ FC_REFLECT( steem::plugins::condenser_api::extended_dynamic_global_properties,
(total_vesting_fund_steem)(total_vesting_shares)
(total_reward_fund_steem)(total_reward_shares2)(pending_rewarded_vesting_shares)(pending_rewarded_vesting_steem)
(sbd_interest_rate)(sbd_print_rate)
(maximum_block_size)(current_aslot)(recent_slots_filled)(participation_count)(last_irreversible_block_num)(vote_power_reserve_rate)
(delegation_return_period)(reverse_auction_seconds)(sbd_stop_percent)(sbd_start_percent) )
(maximum_block_size)(required_actions_partition_percent)(current_aslot)(recent_slots_filled)(participation_count)(last_irreversible_block_num)
(vote_power_reserve_rate)(delegation_return_period)(reverse_auction_seconds)(available_account_subsidies)(sbd_stop_percent)(sbd_start_percent)
(next_maintenance_time)(last_budget_time)(content_reward_percent)(vesting_reward_percent)(sps_fund_percent)(sps_interval_ledger)(downvote_pool_percent)
)

FC_REFLECT( steem::plugins::condenser_api::api_witness_object,
(id)
Expand Down
25 changes: 17 additions & 8 deletions libraries/plugins/rc/rc_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ void use_account_rcs(
#endif
)
{

if( account_name == account_name_type() )
{
if( db.is_producing() )
Expand All @@ -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() );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -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() )
{
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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 )
Expand All @@ -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 >
Expand All @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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 )
Expand All @@ -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;

Expand All @@ -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 )
{
Expand Down
2 changes: 2 additions & 0 deletions libraries/protocol/hardfork.d/0_21.hf
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libraries/protocol/include/steem/protocol/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

#else // IS LIVE STEEM NETWORK

#define STEEM_BLOCKCHAIN_VERSION ( version(0, 21, 0) )
#define STEEM_BLOCKCHAIN_VERSION ( version(0, 21, 1) )

#define STEEM_INIT_PUBLIC_KEY_STR "STM8GC13uCZbP44HzMLV6zPZGwVQ8Nt4Kji8PapsPiNq1BK153XTX"
#define STEEM_CHAIN_ID fc::sha256()
Expand Down
5 changes: 4 additions & 1 deletion tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8187,14 +8187,17 @@ BOOST_AUTO_TEST_CASE( account_update2_apply )

const account_object& acct = db->get_account( "alice" );
const account_authority_object& acct_auth = db->get< account_authority_object, by_account >( "alice" );
const account_metadata_object& acct_metadata = db->get< account_metadata_object, by_account >( acct.id );

BOOST_REQUIRE( acct.name == "alice" );
BOOST_REQUIRE( acct_auth.owner == authority( 1, new_private_key.get_public_key(), 1 ) );
BOOST_REQUIRE( acct_auth.active == authority( 2, new_private_key.get_public_key(), 2 ) );
BOOST_REQUIRE( acct.memo_key == new_private_key.get_public_key() );

#ifdef IS_LOW_MEM
const account_metadata_object& acct_metadata = db->get< account_metadata_object, by_account >( acct.id );
BOOST_REQUIRE( acct_metadata.json_metadata == "{\"bar\":\"foo\"}" );
BOOST_REQUIRE( acct_metadata.posting_json_metadata == "{\"success\":true}" );
#endif

validate_database();

Expand Down

0 comments on commit 42a4556

Please sign in to comment.