Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change asset symbol internal implementation #1549 #1577

Merged
merged 7 commits into from
Oct 4, 2017
Merged
36 changes: 18 additions & 18 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3340,12 +3340,12 @@ void database::adjust_balance( const account_object& a, const asset& delta )
{
modify( a, [&]( account_object& acnt )
{
switch( delta.symbol )
switch( delta.symbol.asset_num )
{
case STEEM_SYMBOL:
case STEEM_ASSET_NUM_STEEM:
acnt.balance += delta;
break;
case SBD_SYMBOL:
case STEEM_ASSET_NUM_SBD:
if( a.sbd_seconds_last_update != head_block_time() )
{
acnt.sbd_seconds += fc::uint128_t(a.sbd_balance.amount.value) * (head_block_time() - a.sbd_seconds_last_update).to_seconds();
Expand Down Expand Up @@ -3385,12 +3385,12 @@ void database::adjust_savings_balance( const account_object& a, const asset& del
{
modify( a, [&]( account_object& acnt )
{
switch( delta.symbol )
switch( delta.symbol.asset_num )
{
case STEEM_SYMBOL:
case STEEM_ASSET_NUM_STEEM:
acnt.savings_balance += delta;
break;
case SBD_SYMBOL:
case STEEM_ASSET_NUM_SBD:
if( a.savings_sbd_seconds_last_update != head_block_time() )
{
acnt.savings_sbd_seconds += fc::uint128_t(a.savings_sbd_balance.amount.value) * (head_block_time() - a.savings_sbd_seconds_last_update).to_seconds();
Expand Down Expand Up @@ -3430,12 +3430,12 @@ void database::adjust_reward_balance( const account_object& a, const asset& delt
{
modify( a, [&]( account_object& acnt )
{
switch( delta.symbol )
switch( delta.symbol.asset_num )
{
case STEEM_SYMBOL:
case STEEM_ASSET_NUM_STEEM:
acnt.reward_steem_balance += delta;
break;
case SBD_SYMBOL:
case STEEM_ASSET_NUM_SBD:
acnt.reward_sbd_balance += delta;
break;
default:
Expand All @@ -3454,9 +3454,9 @@ void database::adjust_supply( const asset& delta, bool adjust_vesting )

modify( props, [&]( dynamic_global_property_object& props )
{
switch( delta.symbol )
switch( delta.symbol.asset_num )
{
case STEEM_SYMBOL:
case STEEM_ASSET_NUM_STEEM:
{
asset new_vesting( (adjust_vesting && delta.amount > 0) ? delta.amount * 9 : 0, STEEM_SYMBOL );
props.current_supply += delta + new_vesting;
Expand All @@ -3465,7 +3465,7 @@ void database::adjust_supply( const asset& delta, bool adjust_vesting )
assert( props.current_supply.amount.value >= 0 );
break;
}
case SBD_SYMBOL:
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;
assert( props.current_sbd_supply.amount.value >= 0 );
Expand All @@ -3479,11 +3479,11 @@ void database::adjust_supply( const asset& delta, bool adjust_vesting )

asset database::get_balance( const account_object& a, asset_symbol_type symbol )const
{
switch( symbol )
switch( symbol.asset_num )
{
case STEEM_SYMBOL:
case STEEM_ASSET_NUM_STEEM:
return a.balance;
case SBD_SYMBOL:
case STEEM_ASSET_NUM_SBD:
return a.sbd_balance;
default:
FC_ASSERT( false, "invalid symbol" );
Expand All @@ -3492,11 +3492,11 @@ asset database::get_balance( const account_object& a, asset_symbol_type symbol )

asset database::get_savings_balance( const account_object& a, asset_symbol_type symbol )const
{
switch( symbol )
switch( symbol.asset_num )
{
case STEEM_SYMBOL:
case STEEM_ASSET_NUM_STEEM:
return a.savings_balance;
case SBD_SYMBOL:
case STEEM_ASSET_NUM_SBD:
return a.savings_sbd_balance;
default:
FC_ASSERT( !"invalid symbol" );
Expand Down
31 changes: 30 additions & 1 deletion libraries/chain/include/steem/chain/witness_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace steem { namespace chain {

using steem::protocol::chain_properties;
using steem::protocol::digest_type;
using steem::protocol::public_key_type;
using steem::protocol::version;
Expand All @@ -18,6 +17,30 @@ namespace steem { namespace chain {
using steem::protocol::asset;
using steem::protocol::asset_symbol_type;

/**
* Witnesses must vote on how to set certain chain properties to ensure a smooth
* and well functioning network. Any time @owner is in the active set of witnesses these
* properties will be used to control the blockchain configuration.
*/
struct chain_properties
{
/**
* This fee, paid in STEEM, is converted into VESTING SHARES for the new account. Accounts
* without vesting shares cannot earn usage rations and therefore are powerless. This minimum
* fee requires all accounts to have some kind of commitment to the network that includes the
* ability to vote and make transactions.
*/
asset account_creation_fee =
asset( STEEM_MIN_ACCOUNT_CREATION_FEE, STEEM_SYMBOL );

/**
* This witnesses vote for the maximum_block_size which is used by the network
* to tune rate limiting and capacity
*/
uint32_t maximum_block_size = STEEM_MIN_BLOCK_SIZE_LIMIT * 2;
uint16_t sbd_interest_rate = STEEM_DEFAULT_SBD_INTEREST_RATE;
};

/**
* All witnesses with at least 1% net positive approval and
* at least 2 weeks old are able to participate in block
Expand Down Expand Up @@ -236,6 +259,12 @@ namespace steem { namespace chain {

FC_REFLECT_ENUM( steem::chain::witness_object::witness_schedule_type, (top19)(timeshare)(miner)(none) )

FC_REFLECT( steem::chain::chain_properties,
(account_creation_fee)
(maximum_block_size)
(sbd_interest_rate)
)

FC_REFLECT( steem::chain::witness_object,
(id)
(owner)
Expand Down
24 changes: 16 additions & 8 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,23 @@ struct strcmp_equal
}
};

template< bool force_canon >
void copy_legacy_chain_properties( chain_properties& dest, const legacy_chain_properties& src )
{
dest.account_creation_fee = src.account_creation_fee.to_asset< force_canon >();
dest.maximum_block_size = src.maximum_block_size;
dest.sbd_interest_rate = src.sbd_interest_rate;
}

void witness_update_evaluator::do_apply( const witness_update_operation& o )
{
_db.get_account( o.owner ); // verify owner exists

if ( _db.has_hardfork( STEEM_HARDFORK_0_14__410 ) )
{
FC_ASSERT( o.props.account_creation_fee.symbol == STEEM_SYMBOL );
FC_ASSERT( o.props.account_creation_fee.symbol.is_canon() );
}
else if( o.props.account_creation_fee.symbol != STEEM_SYMBOL )
else if( !o.props.account_creation_fee.symbol.is_canon() )
{
// after HF, above check can be moved to validate() if reindex doesn't show this warning
wlog( "Wrong fee symbol in block ${b}", ("b", _db.head_block_num()+1) );
Expand All @@ -82,7 +90,7 @@ void witness_update_evaluator::do_apply( const witness_update_operation& o )
_db.modify( *wit_itr, [&]( witness_object& w ) {
from_string( w.url, o.url );
w.signing_key = o.block_signing_key;
w.props = o.props;
copy_legacy_chain_properties< false >( w.props, o.props );
});
}
else
Expand All @@ -92,7 +100,7 @@ void witness_update_evaluator::do_apply( const witness_update_operation& o )
from_string( w.url, o.url );
w.signing_key = o.block_signing_key;
w.created = _db.head_block_time();
w.props = o.props;
copy_legacy_chain_properties< false >( w.props, o.props );
});
}
}
Expand Down Expand Up @@ -1609,15 +1617,15 @@ void pow_apply( database& db, Operation o )
if( cur_witness ) {
FC_ASSERT( cur_witness->pow_worker == 0, "This account is already scheduled for pow block production." );
db.modify(*cur_witness, [&]( witness_object& w ){
w.props = o.props;
copy_legacy_chain_properties< true >( w.props, o.props );
w.pow_worker = dgp.total_pow;
w.last_work = o.work.work;
});
} else {
db.create<witness_object>( [&]( witness_object& w )
{
w.owner = o.get_worker_account();
w.props = o.props;
copy_legacy_chain_properties< true >( w.props, o.props );
w.signing_key = o.work.worker;
w.pow_worker = dgp.total_pow;
w.last_work = o.work.work;
Expand Down Expand Up @@ -1703,7 +1711,7 @@ void pow2_evaluator::do_apply( const pow2_operation& o )
db.create<witness_object>( [&]( witness_object& w )
{
w.owner = worker_account;
w.props = o.props;
copy_legacy_chain_properties< true >( w.props, o.props );
w.signing_key = *o.new_owner_key;
w.pow_worker = dgp.total_pow;
});
Expand All @@ -1716,7 +1724,7 @@ void pow2_evaluator::do_apply( const pow2_operation& o )
FC_ASSERT( cur_witness->pow_worker == 0, "This account is already scheduled for pow block production." );
db.modify(*cur_witness, [&]( witness_object& w )
{
w.props = o.props;
copy_legacy_chain_properties< true >( w.props, o.props );
w.pow_worker = dgp.total_pow;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define STEEM_DEBUG_NODE_PLUGIN_NAME "debug_node"

namespace steem { namespace protocol {
struct chain_properties;
struct pow2;
struct signed_block;
} }
Expand Down