Skip to content

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed May 13, 2016
2 parents 03cea97 + 5012ebe commit 5debb51
Show file tree
Hide file tree
Showing 20 changed files with 857 additions and 349 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ programs/js_operation_serializer/js_operation_serializer
programs/steemd/steemd
programs/steemd/test
programs/delayed_node
programs/build_helpers/cat-parts
programs/size_checker/size_checker
programs/util/get_dev_key
programs/util/inflation_model

tests/app_test
tests/chain_bench
Expand All @@ -39,3 +43,4 @@ witness_node_data_dir

*.pyc
*.pyo
*.egg-info/
1 change: 0 additions & 1 deletion libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ namespace detail {
wild_access.allowed_apis.push_back( "network_broadcast_api" );
wild_access.allowed_apis.push_back( "history_api" );
wild_access.allowed_apis.push_back( "crypto_api" );
wild_access.allowed_apis.push_back( "private_message_api" );
_apiaccess.permission_map["*"] = wild_access;
}

Expand Down
204 changes: 150 additions & 54 deletions libraries/app/database_api.cpp

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion libraries/app/include/steemit/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ class database_api
vector<discussion> get_discussions_by_last_update( string start_author, string start_permlink, uint32_t limit )const;
vector<discussion> get_discussions_in_category_by_last_update( string category, string start_author, string start_permlink, uint32_t limit )const;

vector<discussion> get_discussions_by_last_active( string start_author, string start_permlink, uint32_t limit )const;
vector<discussion> get_discussions_in_category_by_last_active( string category, string start_author, string start_permlink, uint32_t limit )const;

vector<discussion> get_discussions_by_votes( string start_author, string start_permlink, uint32_t limit )const;
vector<discussion> get_discussions_in_category_by_votes( string category, string start_author, string start_permlink, uint32_t limit )const;

vector<discussion> get_discussions_by_created( string start_author, string start_permlink, uint32_t limit )const;
vector<discussion> get_discussions_in_category_by_created( string category, string start_author, string start_permlink, uint32_t limit )const;

Expand All @@ -312,7 +318,7 @@ class database_api
/**
* This method is used to fetch all posts/comments by start_author that occur after before_date and start_permlink with up to limit being returned.
*
* If start_permlink is empty then only before_date will be considered. If both are specified the eariler to the two metrics will be used. This
* If start_permlink is empty then only before_date will be considered. If both are specified the eariler to the two metrics will be used. This
* should allow easy pagination.
*/
vector<discussion> get_discussions_by_author_before_date( string author, string start_permlink, time_point_sec before_date, uint32_t limit )const;
Expand Down Expand Up @@ -400,10 +406,17 @@ FC_API(steemit::app::database_api,
(get_discussions_by_total_pending_payout)
(get_discussions_in_category_by_total_pending_payout)
(get_discussions_by_last_update)
(get_discussions_by_last_active)
(get_discussions_by_votes)
(get_discussions_by_created)
(get_discussions_in_category_by_last_update)
(get_discussions_in_category_by_last_active)
(get_discussions_in_category_by_votes)
(get_discussions_in_category_by_created)
(get_discussions_by_author_before_date)
(get_discussions_by_cashout_time)
(get_discussions_in_category_by_cashout_time)


// Witnesses
(get_witnesses)
Expand Down
7 changes: 5 additions & 2 deletions libraries/app/include/steemit/app/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace steemit { namespace app {
vector<string> trending; /// pending lifetime payout
vector<string> recent; /// creation date
vector<string> active; /// last update or reply
vector<string> votes; /// last update or reply
vector<string> maturing; /// about to be paid out
vector<string> best; /// total lifetime payout
};
Expand Down Expand Up @@ -132,6 +133,7 @@ namespace steemit { namespace app {
vector<string> pow_queue;
map<string, witness_object> witnesses;
witness_schedule_object witness_schedule;
string error;
};

} }
Expand All @@ -145,7 +147,8 @@ FC_REFLECT_DERIVED( steemit::app::extended_account,
FC_REFLECT( steemit::app::vote_state, (voter)(weight) );
FC_REFLECT( steemit::app::account_vote, (authorperm)(weight) );

FC_REFLECT( steemit::app::discussion_index, (category)(trending)(recent)(active)(maturing)(best) )
FC_REFLECT( steemit::app::discussion_index, (category)(trending)(recent)(active)(votes)(maturing)(best) )
FC_REFLECT( steemit::app::category_index, (trending)(active)(recent)(best) )
FC_REFLECT( steemit::app::state, (current_route)(props)(category_idx)(categories)(content)(accounts)(pow_queue)(witnesses)(discussion_idx)(witness_schedule) )
FC_REFLECT_DERIVED( steemit::app::discussion, (steemit::chain::comment_object), (url)(root_title)(pending_payout_value)(total_pending_payout_value)(active_votes)(replies) )

FC_REFLECT( steemit::app::state, (current_route)(props)(category_idx)(categories)(content)(accounts)(pow_queue)(witnesses)(discussion_idx)(witness_schedule)(error) )
69 changes: 38 additions & 31 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,13 +826,12 @@ try {
adjust_balance( to_account, sbd );
adjust_supply( -steem );
adjust_supply( sbd );

return sbd;
} else {
adjust_balance( to_account, steem );
return steem;
}
} FC_CAPTURE_AND_RETHROW( (to_account.name)(steem) ) }
} FC_CAPTURE_LOG_AND_RETHROW( (to_account.name)(steem) ) }

/**
* @param to_account - the account to receive the new vesting shares
Expand Down Expand Up @@ -1262,6 +1261,8 @@ void database::adjust_rshares2( const comment_object& c, fc::uint128_t old_rshar
modify( c, [&](comment_object& comment ){
comment.children_rshares2 -= old_rshares2;
comment.children_rshares2 += new_rshares2;
if( new_rshares2 > old_rshares2 ) /// down't update active index for down votes
comment.active = head_block_time();
});
if( c.depth ) {
adjust_rshares2( get_comment( c.parent_author, c.parent_permlink ), old_rshares2, new_rshares2 );
Expand Down Expand Up @@ -1367,11 +1368,12 @@ void database::cashout_comment_helper( const comment_object& cur, const comment_
sbd_created.amount *= 2; /// 50/50 VESTING SBD means total value is 2x

cashout_comment_helper( parent, origin, parent_vesting_steem_reward, parent_sbd_reward );
} else { /// parent gets the full change, recursion stops

const auto& parent_author = get_account(cur.parent_author);
vest_created = create_vesting( parent_author, vesting_steem_reward );
sbd_created = create_sbd( parent_author, sbd_reward );
}
else /// parent gets the full change, recursion stops
{
const auto& parent_author = get_account( cur.parent_author );
vest_created = create_vesting( parent_author, parent_vesting_steem_reward );
sbd_created = create_sbd( parent_author, parent_sbd_reward );

/// THE FOLLOWING IS NOT REQUIRED FOR VALIDATION
push_applied_operation( comment_reward_operation( cur.parent_author, cur.parent_permlink, origin.author, origin.permlink, sbd_created, vest_created ) );
Expand All @@ -1398,11 +1400,10 @@ share_type database::pay_curators( const comment_object& c, share_type max_rewar
{
u256 total_weight( c.total_vote_weight );
share_type unclaimed_rewards = max_rewards;

const auto& cvidx = get_index_type<comment_vote_index>().indices().get<by_comment_weight_voter>();
auto itr = cvidx.lower_bound( boost::make_tuple( c.id, uint64_t(-1), account_id_type() ) );
auto end = cvidx.lower_bound( boost::make_tuple( c.id, uint64_t(0), account_id_type() ) );
while( itr != end ) {
auto itr = cvidx.lower_bound( c.id );
auto start = itr;
while( itr != cvidx.end() && itr->comment == c.id ) {
// TODO: Add minimum curation pay limit
u256 weight( itr->weight );
auto claim = static_cast<uint64_t>((max_rewards.value * weight) / total_weight);
Expand All @@ -1419,7 +1420,6 @@ share_type database::pay_curators( const comment_object& c, share_type max_rewar
{
p.total_reward_fund_steem += unclaimed_rewards;
});

return unclaimed_rewards;
}

Expand All @@ -1434,8 +1434,8 @@ void database::process_comment_cashout() {

const auto& cidx = get_index_type<comment_index>().indices().get<by_cashout_time>();
auto current = cidx.begin();
//auto end = cidx.lower_bound( head_block_time() );
while( current != cidx.end() && current->cashout_time <= head_block_time() ) {
share_type unclaimed;
const auto& cur = *current; ++current;
asset sbd_created(0,SBD_SYMBOL);
asset vest_created(0,VESTS_SYMBOL);
Expand All @@ -1451,12 +1451,12 @@ void database::process_comment_cashout() {
auto to_sbd = reward_tokens / 2;
auto to_vesting = reward_tokens - to_sbd;

unclaimed = pay_curators( cur, curator_rewards );
cashout_comment_helper( cur, cur, asset( to_vesting, STEEM_SYMBOL ), asset( to_sbd, STEEM_SYMBOL ) );

modify( cat, [&]( category_object& c ) {
c.total_payouts += asset(reward_tokens,STEEM_SYMBOL) * median_price;
c.total_payouts += asset(reward_tokens - unclaimed ,STEEM_SYMBOL) * median_price;
});

pay_curators( cur, curator_rewards );
cashout_comment_helper( cur, cur, asset( to_vesting, STEEM_SYMBOL ), asset( to_sbd, STEEM_SYMBOL ) );
}
fc::uint128_t old_rshares2(cur.net_rshares.value);
old_rshares2 *= old_rshares2;
Expand Down Expand Up @@ -2085,7 +2085,6 @@ void database::_apply_transaction(const signed_transaction& trx)
for( const auto& op : trx.operations )
{ try {
apply_operation(eval_state, op);
// if( head_block_num() > 900000 ) validate_invariants();
++_current_op_in_trx;
} FC_CAPTURE_AND_RETHROW( (op) );
}
Expand Down Expand Up @@ -2512,7 +2511,7 @@ void database::adjust_supply( const asset& delta, bool adjust_vesting ) {
}
case SBD_SYMBOL:
props.current_sbd_supply += delta;
props.virtual_supply += delta * get_feed_history().current_median_history;
props.virtual_supply = props.current_sbd_supply * get_feed_history().current_median_history + props.current_supply;
assert( props.current_sbd_supply.amount.value >= 0 );
break;
default:
Expand Down Expand Up @@ -2588,7 +2587,9 @@ void database::process_hardforks()
switch( hardforks.last_hardfork + 1)
{
case STEEMIT_HARDFORK_0_1_0:
#ifndef IS_TEST_NET
elog( "HARDFORK 1" );
#endif
perform_vesting_share_split( 1000000 );
#ifdef IS_TEST_NET
{
Expand All @@ -2602,19 +2603,27 @@ void database::process_hardforks()
#endif
break;
case STEEMIT_HARDFORK_0_2_0:
#ifndef IS_TEST_NET
elog( "HARDFORK 2" );
#endif
retally_witness_votes();
break;
case STEEMIT_HARDFORK_0_3_0:
#ifndef IS_TEST_NET
elog( "HARDFORK 3" );
#endif
retally_witness_votes();
break;
case STEEMIT_HARDFORK_0_4_0:
#ifndef IS_TEST_NET
elog( "HARDFORK 4" );
#endif
reset_virtual_schedule_time();
break;
case STEEMIT_HARDFORK_0_5_0:
#ifndef IS_TEST_NET
elog( "HARDFORK 5" );
#endif
break;
default:
break;
Expand All @@ -2631,7 +2640,7 @@ void database::process_hardforks()
}
FC_CAPTURE_AND_RETHROW() }

bool database::has_hardfork( uint32_t hardfork )
bool database::has_hardfork( uint32_t hardfork )const
{
return hardfork_property_id_type()( *this ).processed_hardforks.size() > hardfork;
}
Expand All @@ -2656,17 +2665,15 @@ void database::set_hardfork( uint32_t hardfork, bool process_now )
*/
void database::validate_invariants()const
{
const auto& db = *this;
try
{
// const auto& account_idx = get_index_type< account_index >().indices().get< by_id >();
const auto& account_idx = get_index_type<account_index>().indices().get<by_name>();
asset total_supply = asset( 0, STEEM_SYMBOL );
asset total_sbd = asset( 0, SBD_SYMBOL );
asset total_vesting = asset( 0, VESTS_SYMBOL );
share_type total_vsf_votes = share_type( 0 );

auto gpo = db.get_dynamic_global_properties();
auto gpo = get_dynamic_global_properties();

/// verify no witness has too many votes
const auto& witness_idx = get_index_type< witness_index >().indices();
Expand All @@ -2685,7 +2692,7 @@ void database::validate_invariants()const
itr->vesting_shares.amount ) );
}

const auto& convert_request_idx = db.get_index_type< convert_index >().indices();
const auto& convert_request_idx = get_index_type< convert_index >().indices();

for( auto itr = convert_request_idx.begin(); itr != convert_request_idx.end(); itr++ )
{
Expand All @@ -2697,7 +2704,7 @@ void database::validate_invariants()const
FC_ASSERT( !"Encountered illegal symbol in convert_request_object" );
}

const auto& limit_order_idx = db.get_index_type< limit_order_index >().indices();
const auto& limit_order_idx = get_index_type< limit_order_index >().indices();

for( auto itr = limit_order_idx.begin(); itr != limit_order_idx.end(); itr++ )
{
Expand All @@ -2714,7 +2721,7 @@ void database::validate_invariants()const
fc::uint128_t total_rshares2;
fc::uint128_t total_children_rshares2;

const auto& comment_idx = db.get_index_type< comment_index >().indices();
const auto& comment_idx = get_index_type< comment_index >().indices();

for( auto itr = comment_idx.begin(); itr != comment_idx.end(); itr++ )
{
Expand All @@ -2736,11 +2743,11 @@ void database::validate_invariants()const
FC_ASSERT( total_rshares2 == total_children_rshares2, "", ("total_rshares2", total_rshares2)("total_children_rshares2",total_children_rshares2));

FC_ASSERT( gpo.virtual_supply >= gpo.current_supply );
if ( !db.get_feed_history().current_median_history.is_null() )
FC_ASSERT( gpo.current_sbd_supply * db.get_feed_history().current_median_history + gpo.current_supply
== gpo.virtual_supply );
if ( !get_feed_history().current_median_history.is_null() )
FC_ASSERT( gpo.current_sbd_supply * get_feed_history().current_median_history + gpo.current_supply
== gpo.virtual_supply, "", ("gpo.current_sbd_supply",gpo.current_sbd_supply)("get_feed_history().current_median_history",get_feed_history().current_median_history)("gpo.current_supply",gpo.current_supply)("gpo.virtual_supply",gpo.virtual_supply) );
}
FC_CAPTURE_LOG_AND_RETHROW( (db.head_block_num()) );
FC_CAPTURE_LOG_AND_RETHROW( (head_block_num()) );
}

void database::perform_vesting_share_split( uint32_t magnitude )
Expand Down Expand Up @@ -2785,7 +2792,7 @@ void database::perform_vesting_share_split( uint32_t magnitude )
for( const auto& vote : vote_idx ) {
modify( vote, [&]( comment_vote_object& cv )
{
cv.weight = ( cv.weight * magnitude ) * magnitude;
cv.weight = cv.weight * magnitude ;
});
}

Expand Down
Loading

0 comments on commit 5debb51

Please sign in to comment.