Skip to content

Commit

Permalink
Only enforce balance and supply checks after hardfork steemit#1811
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Nov 30, 2017
1 parent 017b653 commit be0109a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
49 changes: 41 additions & 8 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ const reward_fund_object& database::get_reward_fund( const comment_object& c ) c
return get< reward_fund_object, by_name >( STEEM_POST_REWARD_FUND_NAME );
}

#pragma message( "After HF20 passes, re-apply the commit titled 'Remove now-redundant sufficient funds checks #1811'" )
void database::pay_fee( const account_object& account, asset fee )
{
FC_ASSERT( fee.amount >= 0 ); /// NOTE if this fails then validate() on some operation is probably wrong
Expand Down Expand Up @@ -3405,13 +3406,18 @@ void database::clear_expired_delegations()

void database::adjust_balance( const account_object& a, const asset& delta )
{
bool check_balance = has_hardfork( STEEM_HARDFORK_0_20__1811 );

modify( a, [&]( account_object& acnt )
{
switch( delta.symbol.asset_num )
{
case STEEM_ASSET_NUM_STEEM:
acnt.balance += delta;
FC_ASSERT( acnt.balance.amount.value >= 0, "Insufficient STEEM funds" );
if( check_balance )
{
FC_ASSERT( acnt.balance.amount.value >= 0, "Insufficient STEEM funds" );
}
break;
case STEEM_ASSET_NUM_SBD:
if( a.sbd_seconds_last_update != head_block_time() )
Expand Down Expand Up @@ -3441,7 +3447,10 @@ void database::adjust_balance( const account_object& a, const asset& delta )
}
}
acnt.sbd_balance += delta;
FC_ASSERT( acnt.sbd_balance.amount.value >= 0, "Insufficient SBD funds" );
if( check_balance )
{
FC_ASSERT( acnt.sbd_balance.amount.value >= 0, "Insufficient SBD funds" );
}
break;
default:
FC_ASSERT( false, "invalid symbol" );
Expand All @@ -3452,13 +3461,18 @@ void database::adjust_balance( const account_object& a, const asset& delta )

void database::adjust_savings_balance( const account_object& a, const asset& delta )
{
bool check_balance = has_hardfork( STEEM_HARDFORK_0_20__1811 );

modify( a, [&]( account_object& acnt )
{
switch( delta.symbol.asset_num )
{
case STEEM_ASSET_NUM_STEEM:
acnt.savings_balance += delta;
FC_ASSERT( acnt.savings_balance.amount.value >= 0, "Insufficient savings STEEM funds" );
if( check_balance )
{
FC_ASSERT( acnt.savings_balance.amount.value >= 0, "Insufficient savings STEEM funds" );
}
break;
case STEEM_ASSET_NUM_SBD:
if( a.savings_sbd_seconds_last_update != head_block_time() )
Expand Down Expand Up @@ -3488,7 +3502,10 @@ void database::adjust_savings_balance( const account_object& a, const asset& del
}
}
acnt.savings_sbd_balance += delta;
FC_ASSERT( acnt.savings_sbd_balance.amount.value >= 0, "Insufficient savings SBD funds" );
if( check_balance )
{
FC_ASSERT( acnt.savings_sbd_balance.amount.value >= 0, "Insufficient savings SBD funds" );
}
break;
default:
FC_ASSERT( !"invalid symbol" );
Expand All @@ -3499,17 +3516,25 @@ void database::adjust_savings_balance( const account_object& a, const asset& del

void database::adjust_reward_balance( const account_object& a, const asset& delta )
{
bool check_balance = has_hardfork( STEEM_HARDFORK_0_20__1811 );

modify( a, [&]( account_object& acnt )
{
switch( delta.symbol.asset_num )
{
case STEEM_ASSET_NUM_STEEM:
acnt.reward_steem_balance += delta;
FC_ASSERT( acnt.reward_steem_balance.amount.value >= 0, "Insufficient reward STEEM funds" );
if( check_balance )
{
FC_ASSERT( acnt.reward_steem_balance.amount.value >= 0, "Insufficient reward STEEM funds" );
}
break;
case STEEM_ASSET_NUM_SBD:
acnt.reward_sbd_balance += delta;
FC_ASSERT( acnt.reward_sbd_balance.amount.value >= 0, "Insufficient reward SBD funds" );
if( check_balance )
{
FC_ASSERT( acnt.reward_sbd_balance.amount.value >= 0, "Insufficient reward SBD funds" );
}
break;
default:
FC_ASSERT( false, "invalid symbol" );
Expand All @@ -3520,6 +3545,8 @@ void database::adjust_reward_balance( const account_object& a, const asset& delt

void database::adjust_supply( const asset& delta, bool adjust_vesting )
{
bool check_supply = has_hardfork( STEEM_HARDFORK_0_20__1811 );

const auto& props = get_dynamic_global_properties();
if( props.head_block_number < STEEM_BLOCKS_PER_DAY*7 )
adjust_vesting = false;
Expand All @@ -3534,13 +3561,19 @@ void database::adjust_supply( const asset& delta, bool adjust_vesting )
props.current_supply += delta + new_vesting;
props.virtual_supply += delta + new_vesting;
props.total_vesting_fund_steem += new_vesting;
FC_ASSERT( props.current_supply.amount.value >= 0 );
if( check_supply )
{
FC_ASSERT( props.current_supply.amount.value >= 0 );
}
break;
}
case STEEM_ASSET_NUM_SBD:
props.current_sbd_supply += delta;
props.virtual_supply = props.current_sbd_supply * get_feed_history().current_median_history + props.current_supply;
FC_ASSERT( props.current_sbd_supply.amount.value >= 0 );
if( check_supply )
{
FC_ASSERT( props.current_sbd_supply.amount.value >= 0 );
}
break;
default:
FC_ASSERT( false, "invalid symbol" );
Expand Down
2 changes: 2 additions & 0 deletions libraries/protocol/hardfork.d/0_20.hf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#define STEEM_HARDFORK_0_20_TIME 1597970800 // Future 2020...

#define STEEM_HARDFORK_0_20__1811 (STEEM_HARDFORK_0_20)

#define STEEM_HARDFORK_0_20_VERSION hardfork_version( 0, 20 )

#endif

0 comments on commit be0109a

Please sign in to comment.