Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Added votable auction window. Added returning of auction rewards to r…
Browse files Browse the repository at this point in the history
…eward poll. #898

Merge pull request #937 from GolosChain/golos-v0.18.4

Golos v0.18.4
Add chain_properties_19 #295

Merge pull request #938 from GolosChain/295-referral-program

chain_properties_19 #295
Made auction window votable. Fixed rewards calculations. #898

Merge branch 'master' into golos-v0.19.0

Fix naming in chain_properties_19 #295

Merge pull request #939 from GolosChain/295-chain-propertie

Fix naming in chain_properties_19 #295
Updated with current 19.0

Added auction_window_size to wallet update_chain_properties. #898

Fixed some codestyle errors. Changed auction_window_weight to uint128_t. #898

Added HF19 checks. Fixed auction_window_size in update_chain_properties. #898

Added auction_window_max_size constant to config. Added HF19 checks in steem_evaluator. #898

Fixed some comment reward logic in tests. #898

Referral program, ASSERT_REQ_HF improved, HF 19 #295

Merge pull request #942 from GolosChain/295-referral-program-impl2

Referral program implemented #295
Update with current 19.0. #898

Fixed auction window tokens return to reward fund. #898

Renamed modify reward fund function. #898
  • Loading branch information
AKorpusenko committed Sep 18, 2018
1 parent 9524c4d commit b247561
Show file tree
Hide file tree
Showing 35 changed files with 1,022 additions and 163 deletions.
7 changes: 7 additions & 0 deletions libraries/api/account_api_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ account_api_object::account_api_object(const account_object& a, const golos::cha
lifetime_market_bandwidth = market->lifetime_bandwidth;
last_market_bandwidth_update = market->last_bandwidth_update;
}

if (db.head_block_time() < a.referral_end_date) {
referrer_account = a.referrer_account;
referrer_interest_rate = a.referrer_interest_rate;
referral_end_date = a.referral_end_date;
referral_break_fee = a.referral_break_fee;
}
}

account_api_object::account_api_object() = default;
Expand Down
6 changes: 6 additions & 0 deletions libraries/api/chain_api_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ namespace golos { namespace api {
create_account_delegation_time = src.create_account_delegation_time;
min_delegation = src.min_delegation;
}
if (db.has_hardfork(STEEMIT_HARDFORK_0_19)) {
max_referral_interest_rate = src.max_referral_interest_rate;
max_referral_term_sec = src.max_referral_term_sec;
max_referral_break_fee = src.max_referral_break_fee;
auction_window_size = src.auction_window_size;
}
}

} } // golos::api
6 changes: 6 additions & 0 deletions libraries/api/discussion_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ namespace golos { namespace api {
d.allow_replies = o.allow_replies;
d.allow_votes = o.allow_votes;
d.allow_curation_rewards = o.allow_curation_rewards;
d.auction_window_weight = o.auction_window_weight;

for (auto& route : o.beneficiaries) {
d.beneficiaries.push_back(route);
Expand Down Expand Up @@ -191,6 +192,11 @@ namespace golos { namespace api {
break;
}
}

if (db.has_hardfork(STEEMIT_HARDFORK_0_19__898)) {
auto reward_fund_claim = ((max_rewards.value * d.auction_window_weight) / total_weight).to_uint64();
unclaimed_rewards -= reward_fund_claim;
}
}
} else {
unclaimed_rewards = 0;
Expand Down
8 changes: 7 additions & 1 deletion libraries/api/include/golos/api/account_api_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ struct account_api_object {
set<string> witness_votes;

fc::optional<share_type> reputation;

account_name_type referrer_account;
uint16_t referrer_interest_rate = 0;
time_point_sec referral_end_date = time_point_sec::min();
asset referral_break_fee = asset(0, STEEM_SYMBOL);
};

} } // golos::api
Expand All @@ -113,6 +118,7 @@ FC_REFLECT((golos::api::account_api_object),
(average_bandwidth)(average_market_bandwidth)(lifetime_bandwidth)(lifetime_market_bandwidth)
(last_bandwidth_update)(last_market_bandwidth_update)
(last_post)(last_root_post)(post_bandwidth)
(witness_votes)(reputation))
(witness_votes)(reputation)
(referrer_account)(referrer_interest_rate)(referral_end_date)(referral_break_fee))

#endif //GOLOS_ACCOUNT_API_OBJ_HPP
8 changes: 7 additions & 1 deletion libraries/api/include/golos/api/chain_api_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ namespace golos { namespace api {
fc::optional<asset> create_account_min_delegation;
fc::optional<uint32_t> create_account_delegation_time;
fc::optional<asset> min_delegation;

fc::optional<uint16_t> max_referral_interest_rate;
fc::optional<uint32_t> max_referral_term_sec;
fc::optional<asset> max_referral_break_fee;
fc::optional<uint32_t> auction_window_size;
};

} } // golos::api
Expand All @@ -28,4 +33,5 @@ FC_REFLECT(
(golos::api::chain_api_properties),
(account_creation_fee)(maximum_block_size)(sbd_interest_rate)
(create_account_min_golos_fee)(create_account_min_delegation)
(create_account_delegation_time)(min_delegation))
(create_account_delegation_time)(min_delegation)
(max_referral_interest_rate)(max_referral_term_sec)(max_referral_break_fee)(auction_window_size))
2 changes: 2 additions & 0 deletions libraries/api/include/golos/api/comment_api_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace golos { namespace api {
comment_mode mode = not_set;

comment_object::id_type root_comment;

uint128_t auction_window_weight = 0;

string root_title;

Expand Down
24 changes: 17 additions & 7 deletions libraries/chain/chain_properties_evaluators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,24 @@ namespace golos { namespace chain {
}
}

struct chain_properties_convert {
using result_type = chain_properties_18;
struct chain_properties_update {
using result_type = void;

const database& _db;
chain_properties& _wprops;

chain_properties_update(const database& db, chain_properties& wprops)
: _db(db), _wprops(wprops) {
}

result_type operator()(const chain_properties_19& p) const {
ASSERT_REQ_HF(STEEMIT_HARDFORK_0_19__295, "chain_properties_19");
_wprops = p;
}

template<typename Props>
result_type operator()(Props&& p) const {
result_type r;
r = p;
return r;
_wprops = p;
}
};

Expand All @@ -58,13 +68,13 @@ namespace golos { namespace chain {
auto itr = idx.find(o.owner);
if (itr != idx.end()) {
_db.modify(*itr, [&](witness_object& w) {
w.props = o.props.visit(chain_properties_convert());
o.props.visit(chain_properties_update(_db, w.props));
});
} else {
_db.create<witness_object>([&](witness_object& w) {
w.owner = o.owner;
w.created = _db.head_block_time();
w.props = o.props.visit(chain_properties_convert());
o.props.visit(chain_properties_update(_db, w.props));
});
}
}
Expand Down
29 changes: 23 additions & 6 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ namespace golos { namespace chain {

signed_block pending_block;

with_strong_write_lock([&]() {
with_strong_write_lock([&]() { detail::with_generating(*this, [&]() {
//
// The following code throws away existing pending_tx_session and
// rebuilds it by re-applying pending transactions.
Expand Down Expand Up @@ -1198,7 +1198,7 @@ namespace golos { namespace chain {
}

_pending_tx_session.reset();
});
}); });

// We have temporarily broken the invariant that
// _pending_tx_session is the result of applying _pending_tx, as
Expand Down Expand Up @@ -1867,16 +1867,16 @@ namespace golos { namespace chain {
}

void database::update_median_witness_props() {
const witness_schedule_object &wso = get_witness_schedule_object();
const witness_schedule_object& wso = get_witness_schedule_object();

/// fetch all witness objects
vector<const witness_object *> active;
vector<const witness_object*> active;
active.reserve(wso.num_scheduled_witnesses);
for (int i = 0; i < wso.num_scheduled_witnesses; i++) {
active.push_back(&get_witness(wso.current_shuffled_witnesses[i]));
}

chain_properties_18 median_props;
chain_properties_19 median_props;

auto calc_median = [&](auto&& param) {
std::nth_element(
Expand All @@ -1895,12 +1895,16 @@ namespace golos { namespace chain {
calc_median(&chain_properties_18::create_account_min_delegation);
calc_median(&chain_properties_18::create_account_delegation_time);
calc_median(&chain_properties_18::min_delegation);
calc_median(&chain_properties_19::auction_window_size);
calc_median(&chain_properties_19::max_referral_interest_rate);
calc_median(&chain_properties_19::max_referral_term_sec);
calc_median(&chain_properties_19::max_referral_break_fee);

modify(wso, [&](witness_schedule_object &_wso) {
_wso.median_props = median_props;
});

modify(get_dynamic_global_properties(), [&](dynamic_global_property_object &_dgpo) {
modify(get_dynamic_global_properties(), [&](dynamic_global_property_object& _dgpo) {
_dgpo.maximum_block_size = median_props.maximum_block_size;
_dgpo.sbd_interest_rate = median_props.sbd_interest_rate;
});
Expand Down Expand Up @@ -2283,6 +2287,13 @@ namespace golos { namespace chain {

unclaimed_rewards = 0;
}
else if (has_hardfork(STEEMIT_HARDFORK_0_19__898) && c.total_vote_weight > 0) {
auto reward_fund_claim = (max_rewards.value * c.auction_window_weight) / total_weight;
unclaimed_rewards -= reward_fund_claim.to_uint64();
modify(get_dynamic_global_properties(), [&](dynamic_global_property_object &props) {
props.total_reward_fund_steem += asset(reward_fund_claim.to_uint64(), STEEM_SYMBOL);
});
}

return unclaimed_rewards;
} FC_CAPTURE_AND_RETHROW()
Expand Down Expand Up @@ -2927,6 +2938,7 @@ namespace golos { namespace chain {
_my->_evaluator_registry.register_evaluator<proposal_update_evaluator>();
_my->_evaluator_registry.register_evaluator<proposal_delete_evaluator>();
_my->_evaluator_registry.register_evaluator<chain_properties_update_evaluator>();
_my->_evaluator_registry.register_evaluator<break_free_referral_evaluator>();
}

void database::set_custom_operation_interpreter(const std::string &id, std::shared_ptr<custom_operation_interpreter> registry) {
Expand Down Expand Up @@ -4362,6 +4374,9 @@ namespace golos { namespace chain {
FC_ASSERT(STEEMIT_HARDFORK_0_18 == 18, "Invalid hardfork configuration");
_hardfork_times[STEEMIT_HARDFORK_0_18] = fc::time_point_sec(STEEMIT_HARDFORK_0_18_TIME);
_hardfork_versions[STEEMIT_HARDFORK_0_18] = STEEMIT_HARDFORK_0_18_VERSION;
FC_ASSERT(STEEMIT_HARDFORK_0_19 == 19, "Invalid hardfork configuration");
_hardfork_times[STEEMIT_HARDFORK_0_19] = fc::time_point_sec(STEEMIT_HARDFORK_0_19_TIME);
_hardfork_versions[STEEMIT_HARDFORK_0_19] = STEEMIT_HARDFORK_0_19_VERSION;

const auto &hardforks = get_hardfork_property_object();
FC_ASSERT(
Expand Down Expand Up @@ -4615,6 +4630,8 @@ namespace golos { namespace chain {
break;
case STEEMIT_HARDFORK_0_18:
break;
case STEEMIT_HARDFORK_0_19:
break;
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/hardfork.d/0-preamble.hf
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ FC_REFLECT((golos::chain::hardfork_property_object),
(next_hardfork)(next_hardfork_time))
CHAINBASE_SET_INDEX_TYPE( golos::chain::hardfork_property_object, golos::chain::hardfork_property_index)

#define STEEMIT_NUM_HARDFORKS 18
#define STEEMIT_NUM_HARDFORKS 19
14 changes: 14 additions & 0 deletions libraries/chain/hardfork.d/0_19.hf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef STEEMIT_HARDFORK_0_19
#define STEEMIT_HARDFORK_0_19 19
#define STEEMIT_HARDFORK_0_19__898 (STEEMIT_HARDFORK_0_19) // Add votable auction window size
#define STEEMIT_HARDFORK_0_19__295 (STEEMIT_HARDFORK_0_19) // Referral program implemented

#ifdef STEEMIT_BUILD_TESTNET
#define STEEMIT_HARDFORK_0_19_TIME 1534755600 // 20 aug 2018 12:00:00 MSK
#else
#define STEEMIT_HARDFORK_0_19_TIME 1543654800 // 01 dec 2018 12:00:00 MSK - fake date
#endif

#define STEEMIT_HARDFORK_0_19_VERSION hardfork_version( 0, 19 )

#endif
34 changes: 20 additions & 14 deletions libraries/chain/include/golos/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class account_object

time_point_sec last_post;

account_name_type referrer_account;
uint16_t referrer_interest_rate = 0;
time_point_sec referral_end_date = time_point_sec::min();
asset referral_break_fee = asset(0, STEEM_SYMBOL);

/// This function should be used only when the account votes for a witness directly
share_type witness_vote_weight() const {
return std::accumulate(proxied_vsf_votes.begin(),
Expand Down Expand Up @@ -495,20 +500,21 @@ change_recovery_account_request_index;


FC_REFLECT((golos::chain::account_object),
(id)(name)(memo_key)(proxy)(last_account_update)
(created)(mined)
(owner_challenged)(active_challenged)(last_owner_proved)(last_active_proved)(recovery_account)(last_account_recovery)(reset_account)
(comment_count)(lifetime_vote_count)(post_count)(can_vote)(voting_power)(last_vote_time)
(balance)
(savings_balance)
(sbd_balance)(sbd_seconds)(sbd_seconds_last_update)(sbd_last_interest_payment)
(savings_sbd_balance)(savings_sbd_seconds)(savings_sbd_seconds_last_update)(savings_sbd_last_interest_payment)(savings_withdraw_requests)
(vesting_shares)(delegated_vesting_shares)(received_vesting_shares)
(vesting_withdraw_rate)(next_vesting_withdrawal)(withdrawn)(to_withdraw)(withdraw_routes)
(curation_rewards)
(posting_rewards)
(proxied_vsf_votes)(witnesses_voted_for)
(last_post)
(id)(name)(memo_key)(proxy)(last_account_update)
(created)(mined)
(owner_challenged)(active_challenged)(last_owner_proved)(last_active_proved)(recovery_account)(last_account_recovery)(reset_account)
(comment_count)(lifetime_vote_count)(post_count)(can_vote)(voting_power)(last_vote_time)
(balance)
(savings_balance)
(sbd_balance)(sbd_seconds)(sbd_seconds_last_update)(sbd_last_interest_payment)
(savings_sbd_balance)(savings_sbd_seconds)(savings_sbd_seconds_last_update)(savings_sbd_last_interest_payment)(savings_withdraw_requests)
(vesting_shares)(delegated_vesting_shares)(received_vesting_shares)
(vesting_withdraw_rate)(next_vesting_withdrawal)(withdrawn)(to_withdraw)(withdraw_routes)
(curation_rewards)
(posting_rewards)
(proxied_vsf_votes)(witnesses_voted_for)
(last_post)
(referrer_account)(referrer_interest_rate)(referral_end_date)(referral_break_fee)
)
CHAINBASE_SET_INDEX_TYPE(golos::chain::account_object, golos::chain::account_index)

Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/golos/chain/comment_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ namespace golos {

id_type root_comment;

uint128_t auction_window_weight = 0;

comment_mode mode = first_payout;

asset max_accepted_payout = asset(1000000000, SBD_SYMBOL); /// SBD value of the maximum payout this post will receive
Expand Down
9 changes: 9 additions & 0 deletions libraries/chain/include/golos/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ namespace golos { namespace chain {
_is_producing = p;
}

bool is_generating() const {
return _is_generating;
}

void set_generating(bool p) {
_is_generating = p;
}

bool _is_producing = false;
bool _is_generating = false;
bool _is_testing = false; ///< set for tests to avoid low free memory spam
bool _log_hardforks = true;

Expand Down
28 changes: 28 additions & 0 deletions libraries/chain/include/golos/chain/db_with.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ namespace golos {
database &_db;
};

/**
* Class is used to help the with_generating implementation
*/
struct generating_helper final {
generating_helper(database& db): _db(db) {
_db.set_generating(true);
}

~generating_helper() {
_db.set_generating(false);
}

database &_db;
};

/**
* Empty pending_transactions, call callback,
* then reset pending_transactions after callback is done.
Expand Down Expand Up @@ -111,6 +126,19 @@ namespace golos {
producing_helper restorer(db);
callback();
}

/**
* Set generating flag to true, call callback, then set generating flag to false
*/
template <typename Lambda>
void with_generating(
database& db,
Lambda callback
) {
generating_helper restorer(db);
callback();
}

}
}
} // golos::chain::detail
8 changes: 8 additions & 0 deletions libraries/chain/include/golos/chain/evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
#include <golos/protocol/exceptions.hpp>
#include <golos/protocol/operations.hpp>

#define ASSERT_REQ_HF_IN_DB(HF, FEATURE, DATABASE) \
GOLOS_ASSERT(DATABASE.has_hardfork(HF), unsupported_operation, \
"${feature} is not enabled until HF ${hardfork}", \
("feature",FEATURE)("hardfork",BOOST_PP_STRINGIZE(HF)));
#define ASSERT_REQ_HF(HF, FEATURE) \
ASSERT_REQ_HF_IN_DB(HF, FEATURE, _db)
namespace golos {
namespace chain {
Expand Down
Loading

0 comments on commit b247561

Please sign in to comment.