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

Commit

Permalink
Merge pull request #729 from GolosChain/golos-v0.18.0
Browse files Browse the repository at this point in the history
Golos v0.18.0
  • Loading branch information
afalaleev committed Jun 9, 2018
2 parents cbd8613 + e49113b commit 1a5c254
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 76 deletions.
8 changes: 4 additions & 4 deletions libraries/api/chain_api_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace golos { namespace api {
sbd_interest_rate(src.sbd_interest_rate)
{
if (db.has_hardfork(STEEMIT_HARDFORK_0_18__673)) {
create_account_with_golos_modifier = src.create_account_with_golos_modifier;
create_account_delegation_ratio = src.create_account_delegation_ratio;
create_account_min_golos_fee = src.create_account_min_golos_fee;
create_account_min_delegation = src.create_account_min_delegation;
create_account_delegation_time = src.create_account_delegation_time;
min_delegation_multiplier = src.min_delegation_multiplier;
min_delegation = src.min_delegation;
}
}

} } // golos::api
} } // golos::api
14 changes: 7 additions & 7 deletions libraries/api/include/golos/api/chain_api_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ namespace golos { namespace api {
uint32_t maximum_block_size;
uint16_t sbd_interest_rate;

fc::optional<uint32_t> create_account_with_golos_modifier;
fc::optional<uint32_t> create_account_delegation_ratio;
fc::optional<fc::microseconds> create_account_delegation_time;
fc::optional<uint32_t> min_delegation_multiplier;
fc::optional<asset> create_account_min_golos_fee;
fc::optional<asset> create_account_min_delegation;
fc::optional<uint32_t> create_account_delegation_time;
fc::optional<asset> min_delegation;
};

} } // golos::api

FC_REFLECT(
(golos::api::chain_api_properties),
(account_creation_fee)(maximum_block_size)(maximum_block_size)
(create_account_with_golos_modifier)(create_account_delegation_ratio)
(create_account_delegation_time)(min_delegation_multiplier))
(account_creation_fee)(maximum_block_size)(sbd_interest_rate)
(create_account_min_golos_fee)(create_account_min_delegation)
(create_account_delegation_time)(min_delegation))
6 changes: 3 additions & 3 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1671,10 +1671,10 @@ namespace golos { namespace chain {
calc_median(&chain_properties_17::account_creation_fee);
calc_median(&chain_properties_17::maximum_block_size);
calc_median(&chain_properties_17::sbd_interest_rate);
calc_median(&chain_properties_18::create_account_with_golos_modifier);
calc_median(&chain_properties_18::create_account_delegation_ratio);
calc_median(&chain_properties_18::create_account_min_golos_fee);
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_multiplier);
calc_median(&chain_properties_18::min_delegation);

modify(wso, [&](witness_schedule_object &_wso) {
_wso.median_props = median_props;
Expand Down
41 changes: 19 additions & 22 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,14 @@ namespace golos { namespace chain {
}

void account_create_evaluator::do_apply(const account_create_operation &o) {
database &_db = db();
const auto &creator = _db.get_account(o.creator);

const auto &props = _db.get_dynamic_global_properties();
const auto& median_props = _db.get_witness_schedule_object().median_props;
const auto& creator = _db.get_account(o.creator);

FC_ASSERT(creator.balance >=
o.fee, "Insufficient balance to create account.", ("creator.balance", creator.balance)("required", o.fee));
FC_ASSERT(creator.balance >= o.fee,
"Insufficient balance to create account.", ("creator.balance", creator.balance)("required", o.fee));

if (_db.has_hardfork(STEEMIT_HARDFORK_0_1)) {
auto min_fee = _db.get_witness_schedule_object().median_props.account_creation_fee;
if (_db.has_hardfork(STEEMIT_HARDFORK_0_18__535)) {
min_fee *= median_props.create_account_with_golos_modifier;
}
const auto& median_props = _db.get_witness_schedule_object().median_props;
auto min_fee = median_props.account_creation_fee;
FC_ASSERT(o.fee >= min_fee,
"Insufficient Fee: ${f} required, ${p} provided.", ("f", min_fee)("p", o.fee));
}
Expand All @@ -145,6 +139,7 @@ namespace golos { namespace chain {
c.balance -= o.fee;
});

const auto& props = _db.get_dynamic_global_properties();
const auto& new_account = _db.create<account_object>([&](account_object& acc) {
acc.name = o.new_account_name;
acc.memo_key = o.memo_key;
Expand Down Expand Up @@ -187,18 +182,20 @@ namespace golos { namespace chain {

const auto& v_share_price = _db.get_dynamic_global_properties().get_vesting_share_price();
const auto& median_props = _db.get_witness_schedule_object().median_props;
auto target_delegation =
median_props.create_account_delegation_ratio *
median_props.create_account_with_golos_modifier *
median_props.account_creation_fee * v_share_price;
auto current_delegation =
median_props.create_account_delegation_ratio * o.fee * v_share_price + o.delegation;
const auto target = median_props.create_account_min_golos_fee + median_props.create_account_min_delegation;
auto target_delegation = target * v_share_price;
auto min_fee = median_props.account_creation_fee.amount.value;
#ifdef STEEMIT_BUILD_TESTNET
if (!min_fee)
min_fee = 1;
#endif
auto current_delegation = o.fee * target.amount.value / min_fee * v_share_price + o.delegation;

FC_ASSERT(current_delegation >= target_delegation,
"Inssufficient Delegation ${f} required, ${p} provided.",
("f", target_delegation)("p", current_delegation)("o.fee", o.fee) ("o.delegation", o.delegation));
FC_ASSERT(o.fee >= median_props.account_creation_fee,
"Insufficient Fee: ${f} required, ${p} provided.", ("f", median_props.account_creation_fee)("p", o.fee));
FC_ASSERT(o.fee >= median_props.create_account_min_golos_fee,
"Insufficient Fee: ${f} required, ${p} provided.", ("f", median_props.create_account_min_golos_fee)("p", o.fee));

for (auto& a : o.owner.account_auths) {
_db.get_account(a.first);
Expand Down Expand Up @@ -239,7 +236,7 @@ namespace golos { namespace chain {
d.delegator = o.creator;
d.delegatee = o.new_account_name;
d.vesting_shares = o.delegation;
d.min_delegation_time = now + median_props.create_account_delegation_time;
d.min_delegation_time = now + fc::seconds(median_props.create_account_delegation_time);
});
}
if (o.fee.amount > 0) {
Expand Down Expand Up @@ -2200,8 +2197,8 @@ namespace golos { namespace chain {

const auto& median_props = _db.get_witness_schedule_object().median_props;
const auto v_share_price = _db.get_dynamic_global_properties().get_vesting_share_price();
auto min_delegation = median_props.account_creation_fee * median_props.min_delegation_multiplier * v_share_price;
auto min_update = median_props.account_creation_fee * v_share_price;
auto min_delegation = median_props.min_delegation * v_share_price;
auto min_update = median_props.create_account_min_golos_fee * v_share_price;

auto now = _db.head_block_time();
auto delta = delegation ?
Expand Down
46 changes: 25 additions & 21 deletions libraries/protocol/include/golos/protocol/steem_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ namespace golos { namespace protocol {
uint16_t sbd_interest_rate = STEEMIT_DEFAULT_SBD_INTEREST_RATE;

void validate() const {
FC_ASSERT(account_creation_fee.symbol == STEEM_SYMBOL);
FC_ASSERT(account_creation_fee.amount >= STEEMIT_MIN_ACCOUNT_CREATION_FEE);
FC_ASSERT(maximum_block_size >= STEEMIT_MIN_BLOCK_SIZE_LIMIT);
FC_ASSERT(sbd_interest_rate >= 0);
Expand All @@ -462,39 +463,42 @@ namespace golos { namespace protocol {
struct chain_properties_18: public chain_properties_17 {

/**
* Modifier for delegated GP on account creation
*
* target_delegation =
* create_account_delegation_ratio * create_account_with_golos_modifier * account_creation_fee
* Minimum fee (in GOLOS) payed when create account with delegation
*/
uint32_t create_account_with_golos_modifier = GOLOS_CREATE_ACCOUNT_WITH_GOLOS_MODIFIER;
asset create_account_min_golos_fee =
asset(STEEMIT_MIN_ACCOUNT_CREATION_FEE * GOLOS_CREATE_ACCOUNT_WITH_GOLOS_MODIFIER, STEEM_SYMBOL);

/**
* Ratio for delegated GP on account creation
* Minimum GP delegation amount when create account with delegation
*
* target_delegation =
* create_account_delegation_ratio * create_account_with_golos_modifier * account_creation_fee
* Note: this minimum is applied only when fee is minimal. If fee is greater,
* then actual delegation can be less (up to 0 if fee part is greater or equal than account_creation_fee)
*/
uint32_t create_account_delegation_ratio = GOLOS_CREATE_ACCOUNT_DELEGATION_RATIO;
asset create_account_min_delegation =
asset(STEEMIT_MIN_ACCOUNT_CREATION_FEE *
GOLOS_CREATE_ACCOUNT_WITH_GOLOS_MODIFIER * GOLOS_CREATE_ACCOUNT_DELEGATION_RATIO, STEEM_SYMBOL);

/**
* Minimum time of delegated GP on create account
* Minimum time of delegated GP on create account (in seconds)
*/
fc::microseconds create_account_delegation_time = GOLOS_CREATE_ACCOUNT_DELEGATION_TIME;
uint32_t create_account_delegation_time = (GOLOS_CREATE_ACCOUNT_DELEGATION_TIME).to_seconds();

/**
* Multiplier of minimum delegated GP
*
* minimum delegated GP = delegation_multiplier * account_creation_fee
* Minimum delegated GP
*/
uint32_t min_delegation_multiplier = GOLOS_MIN_DELEGATION_MULTIPLIER;
asset min_delegation =
asset(STEEMIT_MIN_ACCOUNT_CREATION_FEE * GOLOS_MIN_DELEGATION_MULTIPLIER, STEEM_SYMBOL);


void validate() const {
chain_properties_17::validate();
FC_ASSERT(min_delegation_multiplier > 0);
FC_ASSERT(create_account_delegation_time.count() > GOLOS_CREATE_ACCOUNT_DELEGATION_TIME.count() / 2);
FC_ASSERT(create_account_delegation_ratio > 0);
FC_ASSERT(create_account_with_golos_modifier > 0);
FC_ASSERT(create_account_min_golos_fee.amount > 0);
FC_ASSERT(create_account_min_golos_fee.symbol == STEEM_SYMBOL);
FC_ASSERT(create_account_min_delegation.amount > 0);
FC_ASSERT(create_account_min_delegation.symbol == STEEM_SYMBOL);
FC_ASSERT(min_delegation.amount > 0);
FC_ASSERT(min_delegation.symbol == STEEM_SYMBOL);
FC_ASSERT(create_account_delegation_time > (GOLOS_CREATE_ACCOUNT_DELEGATION_TIME).to_seconds() / 2);
}

chain_properties_18& operator=(const chain_properties_17& src) {
Expand Down Expand Up @@ -1153,8 +1157,8 @@ FC_REFLECT(
(account_creation_fee)(maximum_block_size)(sbd_interest_rate))
FC_REFLECT_DERIVED(
(golos::protocol::chain_properties_18),((golos::protocol::chain_properties_17)),
(create_account_with_golos_modifier)(create_account_delegation_ratio)
(create_account_delegation_time)(min_delegation_multiplier))
(create_account_min_golos_fee)(create_account_min_delegation)
(create_account_delegation_time)(min_delegation))

FC_REFLECT_TYPENAME((golos::protocol::versioned_chain_properties))

Expand Down
22 changes: 19 additions & 3 deletions libraries/wallet/include/golos/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ namespace golos { namespace wallet {
vector<string> key_approvals_to_remove;
};

struct optional_chain_props {
fc::optional<asset> account_creation_fee;
fc::optional<uint32_t> maximum_block_size;
fc::optional<uint16_t> sbd_interest_rate;

fc::optional<asset> create_account_min_golos_fee;
fc::optional<asset> create_account_min_delegation;
fc::optional<uint32_t> create_account_delegation_time;
fc::optional<asset> min_delegation;
};

struct memo_data {

static optional<memo_data> from_string( string str ) {
Expand Down Expand Up @@ -678,7 +689,7 @@ namespace golos { namespace wallet {
*/
annotated_signed_transaction update_chain_properties(
string witness_name,
const chain_properties& props,
const optional_chain_props& props,
bool broadcast = false
);

Expand Down Expand Up @@ -1203,10 +1214,15 @@ FC_API( golos::wallet::wallet_api,
(get_outbox)
)

FC_REFLECT( (golos::wallet::memo_data), (from)(to)(nonce)(check)(encrypted) )
FC_REFLECT((golos::wallet::memo_data), (from)(to)(nonce)(check)(encrypted))
FC_REFLECT(
(golos::wallet::approval_delta),
(active_approvals_to_add)(active_approvals_to_remove)
(owner_approvals_to_add)(owner_approvals_to_remove)
(posting_approvals_to_add)(posting_approvals_to_remove)
(key_approvals_to_add)(key_approvals_to_remove) )
(key_approvals_to_add)(key_approvals_to_remove))

FC_REFLECT((golos::wallet::optional_chain_props),
(account_creation_fee)(maximum_block_size)(sbd_interest_rate)
(create_account_min_golos_fee)(create_account_min_delegation)
(create_account_delegation_time)(min_delegation))
37 changes: 29 additions & 8 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ namespace golos { namespace wallet {

auto hf = _remote_database_api->get_hardfork_version();
if (hf >= hardfork_version(0, STEEMIT_HARDFORK_0_18)) {
result["create_account_with_golos_modifier"] = median_props.create_account_with_golos_modifier;
result["create_account_delegation_ratio"] = median_props.create_account_delegation_ratio;
result["create_account_min_golos_fee"] = median_props.create_account_min_golos_fee;
result["create_account_min_delegation"] = median_props.create_account_min_delegation;
result["create_account_delegation_time"] = median_props.create_account_delegation_time;
result["min_delegation_multiplier"] = median_props.min_delegation_multiplier;
result["min_delegation"] = median_props.min_delegation;
}

return result;
Expand Down Expand Up @@ -1834,9 +1834,6 @@ fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_st
auto prop = my->_remote_database_api->get_chain_properties();
auto hf = my->_remote_database_api->get_hardfork_version();
fee = prop.account_creation_fee;
if (hf >= hardfork_version(0, STEEMIT_HARDFORK_0_18)) {
fee *= prop.create_account_with_golos_modifier;
}
}
return create_account_with_keys(
creator, new_account_name, json_meta, fee,
Expand Down Expand Up @@ -1895,16 +1892,40 @@ fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_st

annotated_signed_transaction wallet_api::update_chain_properties(
string witness_account_name,
const chain_properties& props,
const optional_chain_props& props,
bool broadcast
) {
FC_ASSERT(!is_locked());

signed_transaction tx;
chain_properties_update_operation op;
chain_api_properties ap;
chain_properties p;

// copy defaults in case of missing witness object
ap.account_creation_fee = p.account_creation_fee;
ap.maximum_block_size = p.maximum_block_size;
ap.sbd_interest_rate = p.sbd_interest_rate;

auto wit = my->_remote_witness_api->get_witness_by_account(witness_account_name);
if (wit.valid()) {
FC_ASSERT(wit->owner == witness_account_name);
ap = wit->props;
}
#define SET_PROP(X) {p.X = !!props.X ? *(props.X) : ap.X;}
SET_PROP(account_creation_fee);
SET_PROP(maximum_block_size);
SET_PROP(sbd_interest_rate);
#undef SET_PROP
#define SET_PROP(X) {if (!!props.X) p.X = *(props.X); else if (!!ap.X) p.X = *(ap.X);}
SET_PROP(create_account_min_golos_fee);
SET_PROP(create_account_min_delegation);
SET_PROP(create_account_delegation_time);
SET_PROP(min_delegation);
#undef SET_PROP

op.owner = witness_account_name;
op.props = props;
op.props = p;
tx.operations.push_back(op);

tx.validate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ namespace mongo_db {

bool format_comment(const std::string& auth, const std::string& perm);

void format_account(const std::string& name);

named_document create_document(const std::string& name,
const std::string& key, const std::string& keyval);

Expand Down
Loading

0 comments on commit 1a5c254

Please sign in to comment.