#319 - add map for sidechain_vote_ids
This commit is contained in:
parent
072931e4f5
commit
7319127142
5 changed files with 58 additions and 91 deletions
|
|
@ -2192,7 +2192,7 @@ votes_info database_api_impl::get_votes(const string &account_name_or_id) const
|
||||||
votes_for_sons.reserve(son_bitcoin_ids.size());
|
votes_for_sons.reserve(son_bitcoin_ids.size());
|
||||||
for (const auto &son : son_bitcoin_ids) {
|
for (const auto &son : son_bitcoin_ids) {
|
||||||
const auto &son_obj = son.as<son_object>(6);
|
const auto &son_obj = son.as<son_object>(6);
|
||||||
votes_for_sons.emplace_back(votes_info_object{son_obj.vote_id_bitcoin, son_obj.id});
|
votes_for_sons.emplace_back(votes_info_object{son_obj.get_bitcoin_vote_id(), son_obj.id});
|
||||||
}
|
}
|
||||||
result.votes_for_bitcoin_sons = std::move(votes_for_sons);
|
result.votes_for_bitcoin_sons = std::move(votes_for_sons);
|
||||||
}
|
}
|
||||||
|
|
@ -2202,7 +2202,7 @@ votes_info database_api_impl::get_votes(const string &account_name_or_id) const
|
||||||
votes_for_sons.reserve(son_hive_ids.size());
|
votes_for_sons.reserve(son_hive_ids.size());
|
||||||
for (const auto &son : son_hive_ids) {
|
for (const auto &son : son_hive_ids) {
|
||||||
const auto &son_obj = son.as<son_object>(6);
|
const auto &son_obj = son.as<son_object>(6);
|
||||||
votes_for_sons.emplace_back(votes_info_object{son_obj.vote_id_hive, son_obj.id});
|
votes_for_sons.emplace_back(votes_info_object{son_obj.get_hive_vote_id(), son_obj.id});
|
||||||
}
|
}
|
||||||
result.votes_for_hive_sons = std::move(votes_for_sons);
|
result.votes_for_hive_sons = std::move(votes_for_sons);
|
||||||
}
|
}
|
||||||
|
|
@ -2376,16 +2376,16 @@ voters_info database_api_impl::get_voters(const string &account_name_or_id) cons
|
||||||
|
|
||||||
//! Info for son voters
|
//! Info for son voters
|
||||||
if (son_object) {
|
if (son_object) {
|
||||||
const auto &son_bitcoin_voters = get_voters_by_id(son_object->vote_id_bitcoin);
|
const auto &son_bitcoin_voters = get_voters_by_id(son_object->get_bitcoin_vote_id());
|
||||||
voters_info_object voters_for_bitcoin_son;
|
voters_info_object voters_for_bitcoin_son;
|
||||||
voters_for_bitcoin_son.vote_id = son_object->vote_id_bitcoin;
|
voters_for_bitcoin_son.vote_id = son_object->get_bitcoin_vote_id();
|
||||||
voters_for_bitcoin_son.voters.reserve(son_bitcoin_voters.size());
|
voters_for_bitcoin_son.voters.reserve(son_bitcoin_voters.size());
|
||||||
for (const auto &voter : son_bitcoin_voters) {
|
for (const auto &voter : son_bitcoin_voters) {
|
||||||
voters_for_bitcoin_son.voters.emplace_back(voter.get_id());
|
voters_for_bitcoin_son.voters.emplace_back(voter.get_id());
|
||||||
}
|
}
|
||||||
const auto &son_hive_voters = get_voters_by_id(son_object->vote_id_hive);
|
const auto &son_hive_voters = get_voters_by_id(son_object->get_hive_vote_id());
|
||||||
voters_info_object voters_for_hive_son;
|
voters_info_object voters_for_hive_son;
|
||||||
voters_for_hive_son.vote_id = son_object->vote_id_hive;
|
voters_for_hive_son.vote_id = son_object->get_hive_vote_id();
|
||||||
voters_for_hive_son.voters.reserve(son_hive_voters.size());
|
voters_for_hive_son.voters.reserve(son_hive_voters.size());
|
||||||
for (const auto &voter : son_hive_voters) {
|
for (const auto &voter : son_hive_voters) {
|
||||||
voters_for_hive_son.voters.emplace_back(voter.get_id());
|
voters_for_hive_son.voters.emplace_back(voter.get_id());
|
||||||
|
|
|
||||||
|
|
@ -92,33 +92,16 @@ vector<std::reference_wrapper<const son_object>> database::sort_votable_objects<
|
||||||
count = std::min(count, refs.size());
|
count = std::min(count, refs.size());
|
||||||
std::partial_sort(refs.begin(), refs.begin() + count, refs.end(),
|
std::partial_sort(refs.begin(), refs.begin() + count, refs.end(),
|
||||||
[this, sidechain](const son_object& a, const son_object& b)->bool {
|
[this, sidechain](const son_object& a, const son_object& b)->bool {
|
||||||
share_type oa_vote = 0;
|
if(sidechain != sidechain_type::bitcoin && sidechain != sidechain_type::hive)
|
||||||
share_type ob_vote = 0;
|
FC_THROW("Unexpected sidechain type");
|
||||||
switch (sidechain) {
|
|
||||||
case sidechain_type::bitcoin:
|
const share_type oa_vote = _vote_tally_buffer[a.get_sidechain_vote_id(sidechain)];
|
||||||
oa_vote = _vote_tally_buffer[a.vote_id_bitcoin];
|
const share_type ob_vote = _vote_tally_buffer[b.get_sidechain_vote_id(sidechain)];
|
||||||
ob_vote = _vote_tally_buffer[b.vote_id_bitcoin];
|
|
||||||
break;
|
|
||||||
case sidechain_type::hive:
|
|
||||||
oa_vote = _vote_tally_buffer[a.vote_id_hive];
|
|
||||||
ob_vote = _vote_tally_buffer[b.vote_id_hive];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
FC_THROW("Unexpected sidechain type");
|
|
||||||
};
|
|
||||||
|
|
||||||
if( oa_vote != ob_vote )
|
if( oa_vote != ob_vote )
|
||||||
return oa_vote > ob_vote;
|
return oa_vote > ob_vote;
|
||||||
|
|
||||||
switch (sidechain) {
|
return a.get_sidechain_vote_id(sidechain) < b.get_sidechain_vote_id(sidechain);
|
||||||
case sidechain_type::bitcoin:
|
|
||||||
return a.vote_id_bitcoin < b.vote_id_bitcoin;
|
|
||||||
case sidechain_type::hive:
|
|
||||||
return a.vote_id_hive < b.vote_id_hive;
|
|
||||||
default:
|
|
||||||
FC_THROW("Unexpected sidechain type");
|
|
||||||
};
|
|
||||||
return 0;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
refs.resize(count, refs.front());
|
refs.resize(count, refs.front());
|
||||||
|
|
@ -209,8 +192,10 @@ void database::pay_sons()
|
||||||
uint64_t total_votes = 0;
|
uint64_t total_votes = 0;
|
||||||
for( const son_object& son : sons )
|
for( const son_object& son : sons )
|
||||||
{
|
{
|
||||||
total_votes += _vote_tally_buffer[son.vote_id_bitcoin];
|
for(const auto& vote_id : son.sidechain_vote_ids)
|
||||||
total_votes += _vote_tally_buffer[son.vote_id_hive];
|
{
|
||||||
|
total_votes += _vote_tally_buffer[vote_id.second];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0);
|
int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0);
|
||||||
auto get_weight = [&bits_to_drop]( uint64_t son_votes ) {
|
auto get_weight = [&bits_to_drop]( uint64_t son_votes ) {
|
||||||
|
|
@ -229,11 +214,16 @@ void database::pay_sons()
|
||||||
const son_statistics_object& s = static_cast<const son_statistics_object&>(o);
|
const son_statistics_object& s = static_cast<const son_statistics_object&>(o);
|
||||||
const auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
const auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
||||||
auto son_obj = idx.find( s.owner );
|
auto son_obj = idx.find( s.owner );
|
||||||
auto son_weight = get_weight(_vote_tally_buffer[son_obj->vote_id_bitcoin]) +
|
uint16_t son_weight = 0;
|
||||||
get_weight(_vote_tally_buffer[son_obj->vote_id_hive]);
|
if( now >= HARDFORK_SON2_TIME ) {
|
||||||
if( now < HARDFORK_SON2_TIME ) {
|
for (const auto& vote_id : son_obj->sidechain_vote_ids) {
|
||||||
son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_bitcoin]) +
|
son_weight += get_weight(_vote_tally_buffer[vote_id.second]);
|
||||||
get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_hive]);
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (const auto& vote_id : son_obj->sidechain_vote_ids) {
|
||||||
|
son_weight += get_weight_before_son2_hf(_vote_tally_buffer[vote_id.second]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
uint64_t txs_signed = 0;
|
uint64_t txs_signed = 0;
|
||||||
for (const auto &ts : s.txs_signed) {
|
for (const auto &ts : s.txs_signed) {
|
||||||
|
|
@ -253,11 +243,16 @@ void database::pay_sons()
|
||||||
if(txs_signed > 0){
|
if(txs_signed > 0){
|
||||||
const auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
const auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
||||||
auto son_obj = idx.find( s.owner );
|
auto son_obj = idx.find( s.owner );
|
||||||
auto son_weight = get_weight(_vote_tally_buffer[son_obj->vote_id_bitcoin]) +
|
uint16_t son_weight = 0;
|
||||||
get_weight(_vote_tally_buffer[son_obj->vote_id_hive]);
|
if( now >= HARDFORK_SON2_TIME ) {
|
||||||
if( now < HARDFORK_SON2_TIME ) {
|
for (const auto& vote_id : son_obj->sidechain_vote_ids) {
|
||||||
son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_bitcoin]) +
|
son_weight += get_weight(_vote_tally_buffer[vote_id.second]);
|
||||||
get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_hive]);
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (const auto& vote_id : son_obj->sidechain_vote_ids) {
|
||||||
|
son_weight += get_weight_before_son2_hf(_vote_tally_buffer[vote_id.second]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
share_type pay = (txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed;
|
share_type pay = (txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed;
|
||||||
modify( *son_obj, [&]( son_object& _son_obj)
|
modify( *son_obj, [&]( son_object& _son_obj)
|
||||||
|
|
@ -722,7 +717,8 @@ void database::update_active_sons()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
modify( son, [local_vote_buffer_ref]( son_object& obj ){
|
modify( son, [local_vote_buffer_ref]( son_object& obj ){
|
||||||
obj.total_votes = local_vote_buffer_ref[obj.vote_id_bitcoin];
|
//! FIXME - only bitcoin_vote_id ???
|
||||||
|
obj.total_votes = local_vote_buffer_ref[obj.get_bitcoin_vote_id()];
|
||||||
if(obj.status == son_status::request_maintenance)
|
if(obj.status == son_status::request_maintenance)
|
||||||
obj.status = son_status::in_maintenance;
|
obj.status = son_status::in_maintenance;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,7 @@ namespace graphene { namespace chain {
|
||||||
static const uint8_t type_id = son_object_type;
|
static const uint8_t type_id = son_object_type;
|
||||||
|
|
||||||
account_id_type son_account;
|
account_id_type son_account;
|
||||||
vote_id_type vote_id_bitcoin;
|
flat_map<sidechain_type, vote_id_type> sidechain_vote_ids;
|
||||||
vote_id_type vote_id_hive;
|
|
||||||
uint64_t total_votes = 0;
|
uint64_t total_votes = 0;
|
||||||
string url;
|
string url;
|
||||||
vesting_balance_id_type deposit;
|
vesting_balance_id_type deposit;
|
||||||
|
|
@ -79,8 +78,9 @@ namespace graphene { namespace chain {
|
||||||
bool has_valid_config()const;
|
bool has_valid_config()const;
|
||||||
bool has_valid_config(time_point_sec head_block_time)const;
|
bool has_valid_config(time_point_sec head_block_time)const;
|
||||||
|
|
||||||
inline vote_id_type get_vote_id_bitcoin() const { return vote_id_bitcoin; }
|
inline vote_id_type get_sidechain_vote_id(sidechain_type sidechain) const { return sidechain_vote_ids.at(sidechain); }
|
||||||
inline vote_id_type get_vote_id_hive() const { return vote_id_hive; }
|
inline vote_id_type get_bitcoin_vote_id() const { return get_sidechain_vote_id(sidechain_type::bitcoin); }
|
||||||
|
inline vote_id_type get_hive_vote_id() const { return get_sidechain_vote_id(sidechain_type::hive); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct by_account;
|
struct by_account;
|
||||||
|
|
@ -96,10 +96,10 @@ namespace graphene { namespace chain {
|
||||||
member<son_object, account_id_type, &son_object::son_account>
|
member<son_object, account_id_type, &son_object::son_account>
|
||||||
>,
|
>,
|
||||||
ordered_unique< tag<by_vote_id_bitcoin>,
|
ordered_unique< tag<by_vote_id_bitcoin>,
|
||||||
const_mem_fun<son_object, vote_id_type, &son_object::get_vote_id_bitcoin>
|
const_mem_fun<son_object, vote_id_type, &son_object::get_bitcoin_vote_id>
|
||||||
>,
|
>,
|
||||||
ordered_unique< tag<by_vote_id_hive>,
|
ordered_unique< tag<by_vote_id_hive>,
|
||||||
const_mem_fun<son_object, vote_id_type, &son_object::get_vote_id_hive>
|
const_mem_fun<son_object, vote_id_type, &son_object::get_hive_vote_id>
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
|
|
@ -125,8 +125,7 @@ FC_REFLECT_ENUM(graphene::chain::son_status, (inactive)(active)(request_maintena
|
||||||
|
|
||||||
FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object),
|
FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object),
|
||||||
(son_account)
|
(son_account)
|
||||||
(vote_id_bitcoin)
|
(sidechain_vote_ids)
|
||||||
(vote_id_hive)
|
|
||||||
(total_votes)
|
(total_votes)
|
||||||
(url)
|
(url)
|
||||||
(deposit)
|
(deposit)
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,8 @@ object_id_type create_son_evaluator::do_apply(const son_create_operation& op)
|
||||||
|
|
||||||
const auto& new_son_object = db().create<son_object>( [&]( son_object& obj ){
|
const auto& new_son_object = db().create<son_object>( [&]( son_object& obj ){
|
||||||
obj.son_account = op.owner_account;
|
obj.son_account = op.owner_account;
|
||||||
obj.vote_id_bitcoin = vote_id_bitcoin;
|
obj.sidechain_vote_ids[sidechain_type::bitcoin] = vote_id_bitcoin;
|
||||||
obj.vote_id_hive = vote_id_hive;
|
obj.sidechain_vote_ids[sidechain_type::hive] = vote_id_hive;
|
||||||
obj.url = op.url;
|
obj.url = op.url;
|
||||||
obj.deposit = op.deposit;
|
obj.deposit = op.deposit;
|
||||||
obj.signing_key = op.signing_key;
|
obj.signing_key = op.signing_key;
|
||||||
|
|
|
||||||
|
|
@ -2759,28 +2759,18 @@ public:
|
||||||
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_account_id);
|
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_account_id);
|
||||||
if (!son_obj)
|
if (!son_obj)
|
||||||
FC_THROW("Account ${son} is not registered as a son", ("son", son));
|
FC_THROW("Account ${son} is not registered as a son", ("son", son));
|
||||||
|
if(sidechain != sidechain_type::bitcoin && sidechain != sidechain_type::hive)
|
||||||
vote_id_type sidechain_vote_id;
|
FC_THROW("Unexpected sidechain type");
|
||||||
switch (sidechain) {
|
|
||||||
case sidechain_type::bitcoin:
|
|
||||||
sidechain_vote_id = son_obj->vote_id_bitcoin;
|
|
||||||
break;
|
|
||||||
case sidechain_type::hive:
|
|
||||||
sidechain_vote_id = son_obj->vote_id_hive;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
FC_THROW("Invalid sidechain type");
|
|
||||||
};
|
|
||||||
|
|
||||||
if (approve)
|
if (approve)
|
||||||
{
|
{
|
||||||
auto insert_result = voting_account_object.options.votes.insert(sidechain_vote_id);
|
auto insert_result = voting_account_object.options.votes.insert(son_obj->get_sidechain_vote_id(sidechain));
|
||||||
if (!insert_result.second)
|
if (!insert_result.second)
|
||||||
FC_THROW("Account ${account} has already voted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
|
FC_THROW("Account ${account} has already voted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned votes_removed = voting_account_object.options.votes.erase(sidechain_vote_id);
|
unsigned votes_removed = voting_account_object.options.votes.erase(son_obj->get_sidechain_vote_id(sidechain));
|
||||||
if (!votes_removed)
|
if (!votes_removed)
|
||||||
FC_THROW("Account ${account} has already unvoted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
|
FC_THROW("Account ${account} has already unvoted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
|
||||||
}
|
}
|
||||||
|
|
@ -2817,18 +2807,9 @@ public:
|
||||||
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id);
|
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id);
|
||||||
if (!son_obj)
|
if (!son_obj)
|
||||||
FC_THROW("Account ${son} is not registered as a SON", ("son", son));
|
FC_THROW("Account ${son} is not registered as a SON", ("son", son));
|
||||||
vote_id_type sidechain_vote_id;
|
if(sidechain != sidechain_type::bitcoin && sidechain != sidechain_type::hive)
|
||||||
switch (sidechain) {
|
FC_THROW("Unexpected sidechain type");
|
||||||
case sidechain_type::bitcoin:
|
auto insert_result = voting_account_object.options.votes.insert(son_obj->get_sidechain_vote_id(sidechain));
|
||||||
sidechain_vote_id = son_obj->vote_id_bitcoin;
|
|
||||||
break;
|
|
||||||
case sidechain_type::hive:
|
|
||||||
sidechain_vote_id = son_obj->vote_id_hive;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
FC_THROW("Invalid sidechain type");
|
|
||||||
};
|
|
||||||
auto insert_result = voting_account_object.options.votes.insert(sidechain_vote_id);
|
|
||||||
if (!insert_result.second)
|
if (!insert_result.second)
|
||||||
FC_THROW("Account ${account} was already voting for SON ${son}", ("account", voting_account)("son", son));
|
FC_THROW("Account ${account} was already voting for SON ${son}", ("account", voting_account)("son", son));
|
||||||
}
|
}
|
||||||
|
|
@ -2838,18 +2819,9 @@ public:
|
||||||
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id);
|
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id);
|
||||||
if (!son_obj)
|
if (!son_obj)
|
||||||
FC_THROW("Account ${son} is not registered as a SON", ("son", son));
|
FC_THROW("Account ${son} is not registered as a SON", ("son", son));
|
||||||
vote_id_type sidechain_vote_id;
|
if(sidechain != sidechain_type::bitcoin && sidechain != sidechain_type::hive)
|
||||||
switch (sidechain) {
|
FC_THROW("Unexpected sidechain type");
|
||||||
case sidechain_type::bitcoin:
|
unsigned votes_removed = voting_account_object.options.votes.erase(son_obj->get_sidechain_vote_id(sidechain));
|
||||||
sidechain_vote_id = son_obj->vote_id_bitcoin;
|
|
||||||
break;
|
|
||||||
case sidechain_type::hive:
|
|
||||||
sidechain_vote_id = son_obj->vote_id_hive;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
FC_THROW("Invalid sidechain type");
|
|
||||||
};
|
|
||||||
unsigned votes_removed = voting_account_object.options.votes.erase(sidechain_vote_id);
|
|
||||||
if (!votes_removed)
|
if (!votes_removed)
|
||||||
FC_THROW("Account ${account} is already not voting for SON ${son}", ("account", voting_account)("son", son));
|
FC_THROW("Account ${account} is already not voting for SON ${son}", ("account", voting_account)("son", son));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue