Skip to content

Commit

Permalink
Merge pull request steemit#1930 from steemit/1765-account-subsidy-limit
Browse files Browse the repository at this point in the history
Account Subsidy Limit
  • Loading branch information
Michael Vandeberg authored Dec 21, 2017
2 parents 9a31d37 + 4986179 commit 95b4175
Showing 8 changed files with 72 additions and 19 deletions.
2 changes: 2 additions & 0 deletions libraries/chain/include/steem/chain/witness_objects.hpp
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ namespace steem { namespace chain {
*/
uint32_t maximum_block_size = STEEM_MIN_BLOCK_SIZE_LIMIT * 2;
uint16_t sbd_interest_rate = STEEM_DEFAULT_SBD_INTEREST_RATE;
uint32_t account_subsidy_limit = 0;
};

/**
@@ -263,6 +264,7 @@ FC_REFLECT( steem::chain::chain_properties,
(account_creation_fee)
(maximum_block_size)
(sbd_interest_rate)
(account_subsidy_limit)
)

FC_REFLECT( steem::chain::witness_object,
11 changes: 11 additions & 0 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
@@ -128,6 +128,7 @@ void witness_set_properties_evaluator::do_apply( const witness_set_properties_op
bool account_creation_changed = false;
bool max_block_changed = false;
bool sbd_interest_changed = false;
bool account_subsidy_changed = false;
bool key_changed = false;
bool sbd_exchange_changed = false;
bool url_changed = false;
@@ -160,6 +161,13 @@ void witness_set_properties_evaluator::do_apply( const witness_set_properties_op
sbd_interest_changed = true;
}

itr = o.props.find( "account_subsidy_limit" );
if( itr != o.props.end() )
{
fc::raw::unpack( itr->second, props.account_subsidy_limit );
account_subsidy_changed = true;
}

itr = o.props.find( "new_signing_key" );
if( itr != o.props.end() )
{
@@ -193,6 +201,9 @@ void witness_set_properties_evaluator::do_apply( const witness_set_properties_op
if( sbd_interest_changed )
w.props.sbd_interest_rate = props.sbd_interest_rate;

if( account_subsidy_changed )
w.props.account_subsidy_limit = props.account_subsidy_limit;

if( key_changed )
w.signing_key = signing_key;

14 changes: 11 additions & 3 deletions libraries/chain/witness_schedule.cpp
Original file line number Diff line number Diff line change
@@ -59,11 +59,19 @@ void update_median_witness_props( database& db )
} );
uint16_t median_sbd_interest_rate = active[active.size()/2]->props.sbd_interest_rate;

/// sort them by account_subsidy_limit
std::sort( active.begin(), active.end(), [&]( const witness_object* a, const witness_object* b )
{
return a->props.account_subsidy_limit < b->props.account_subsidy_limit;
} );
uint32_t median_account_subsidy_limit = active[active.size()/2]->props.account_subsidy_limit;

db.modify( wso, [&]( witness_schedule_object& _wso )
{
_wso.median_props.account_creation_fee = median_account_creation_fee;
_wso.median_props.maximum_block_size = median_maximum_block_size;
_wso.median_props.sbd_interest_rate = median_sbd_interest_rate;
_wso.median_props.account_creation_fee = median_account_creation_fee;
_wso.median_props.maximum_block_size = median_maximum_block_size;
_wso.median_props.sbd_interest_rate = median_sbd_interest_rate;
_wso.median_props.account_subsidy_limit = median_account_subsidy_limit;
} );

db.modify( db.get_dynamic_global_properties(), [&]( dynamic_global_property_object& _dgpo )
1 change: 1 addition & 0 deletions libraries/protocol/hardfork.d/0_20.hf
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

#define STEEM_HARDFORK_0_20__409 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1620 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1765 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1811 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1815 (STEEM_HARDFORK_0_20)

8 changes: 8 additions & 0 deletions libraries/protocol/steem_operations.cpp
Original file line number Diff line number Diff line change
@@ -258,6 +258,14 @@ namespace steem { namespace protocol {
FC_ASSERT( url.size() > 0, "URL size must be greater than 0" );
FC_ASSERT( fc::is_utf8( url ), "URL is not valid UTF8" );
}

itr = props.find( "account_subsidy_limit" );
if( itr != props.end() )
{
uint32_t account_subsidy_limit;
fc::raw::unpack( itr->second, account_subsidy_limit ); // Checks that the value can be deserialized
FC_UNUSED( account_subsidy_limit );
}
}

void account_witness_vote_operation::validate() const
44 changes: 28 additions & 16 deletions tests/db_fixture/database_fixture.cpp
Original file line number Diff line number Diff line change
@@ -532,21 +532,11 @@ void database_fixture::proxy( const string& account, const string& proxy )

void database_fixture::set_price_feed( const price& new_price )
{
try
{
for ( int i = 1; i < 8; i++ )
{
feed_publish_operation op;
op.publisher = STEEM_INIT_MINER_NAME + fc::to_string( i );
op.exchange_rate = new_price;
trx.operations.push_back( op );
trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
db->push_transaction( trx, ~0 );
trx.operations.clear();
}
} FC_CAPTURE_AND_RETHROW( (new_price) )
flat_map< string, vector< char > > props;
props[ "sbd_exchange_rate" ] = fc::raw::pack( new_price );

set_witness_props( props );

generate_blocks( STEEM_BLOCKS_PER_HOUR );
BOOST_REQUIRE(
#ifdef IS_TEST_NET
!db->skip_price_feed_limit_check ||
@@ -555,6 +545,28 @@ void database_fixture::set_price_feed( const price& new_price )
);
}

void database_fixture::set_witness_props( const flat_map< string, vector< char > >& props )
{
for( size_t i = 1; i < 8; i++ )
{
witness_set_properties_operation op;
op.owner = STEEM_INIT_MINER_NAME + fc::to_string( i );
op.props = props;

if( op.props.find( "key" ) == op.props.end() )
{
op.props[ "key" ] = fc::raw::pack( init_account_pub_key );
}

trx.operations.push_back( op );
trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
db->push_transaction( trx, ~0 );
trx.operations.clear();
}

generate_blocks( STEEM_BLOCKS_PER_HOUR );
}

const asset& database_fixture::get_balance( const string& account_name )const
{
return db->get_account( account_name ).balance;
@@ -613,7 +625,7 @@ asset_symbol_type smt_database_fixture::create_smt( signed_transaction& tx, cons

set_price_feed( price( ASSET( "1.000 TBD" ), ASSET( "1.000 TESTS" ) ) );
convert( account_name, ASSET( "5000.000 TESTS" ) );

// The list of available nais is not dependent on SMT desired precision (token_decimal_places).
auto available_nais = db->get_smt_next_identifier();
FC_ASSERT( available_nais.size() > 0, "No available nai returned by get_smt_next_identifier." );
@@ -630,7 +642,7 @@ asset_symbol_type smt_database_fixture::create_smt( signed_transaction& tx, cons

db->push_transaction( tx, 0 );

generate_block();
generate_block();
}
FC_LOG_AND_RETHROW();

1 change: 1 addition & 0 deletions tests/db_fixture/database_fixture.hpp
Original file line number Diff line number Diff line change
@@ -222,6 +222,7 @@ struct database_fixture {
void vest( const string& account, const asset& amount );
void proxy( const string& account, const string& proxy );
void set_price_feed( const price& new_price );
void set_witness_props( const flat_map< string, vector< char > >& new_props );
const asset& get_balance( const string& account_name )const;
void sign( signed_transaction& trx, const fc::ecc::private_key& key );

10 changes: 10 additions & 0 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
@@ -6928,6 +6928,16 @@ BOOST_AUTO_TEST_CASE( witness_set_properties_apply )
tx.sign( old_signing_key, db->get_chain_id() );
STEEM_REQUIRE_THROW( db->push_transaction( tx, 0 ), fc::assert_exception );

BOOST_TEST_MESSAGE( "--- Testing setting account subsidy limit" );
prop_op.props[ "key" ].clear();
prop_op.props[ "key" ] = fc::raw::pack( signing_key.get_public_key() );
prop_op.props[ "account_subsidy_limit" ] = fc::raw::pack( 1000 );
tx.clear();
tx.operations.push_back( prop_op );
tx.sign( signing_key, db->get_chain_id() );
db->push_transaction( tx, 0 );
BOOST_REQUIRE( alice_witness.props.account_subsidy_limit == 1000 );

validate_database();
}
FC_LOG_AND_RETHROW()

0 comments on commit 95b4175

Please sign in to comment.