Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BD-1874 (was MAS-1855) - Add fio_address to producers list of voter #33

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 50 additions & 3 deletions contracts/fio.system/include/fio.system/fio.system.hpp
Expand Up @@ -240,6 +240,11 @@ typedef eosio::multi_index<"producers"_n, producer_info,
producers_table;


struct producername {
name producer;
string fioaddress;
};

struct [[eosio::table, eosio::contract("fio.system")]] voter_info {
uint64_t id; //one up id is primary key.
string fioaddress; //this is the fio address to be used for bundled fee collection
Expand All @@ -249,7 +254,7 @@ struct [[eosio::table, eosio::contract("fio.system")]] voter_info {
uint128_t addresshash; //this is the hash of the fio address for searching
name owner; /// the voter
name proxy; /// the proxy set by the voter, if any
std::vector <name> producers; /// the producers approved by this voter if no proxy set
std::vector <producername> producers; /// the producers approved by this voter if no proxy set
/**
* Every time a vote is cast we must first "undo" the last vote weight, before casting the
* new vote weight. Vote weight is calculated as:
Expand All @@ -276,11 +281,53 @@ struct [[eosio::table, eosio::contract("fio.system")]] voter_info {
)
};

typedef eosio::multi_index<"voters"_n, voter_info,
typedef eosio::multi_index<"voters2"_n, voter_info,
indexed_by<"byaddress"_n, const_mem_fun<voter_info, uint128_t, &voter_info::by_address>>,
indexed_by<"byowner"_n, const_mem_fun<voter_info, uint64_t, &voter_info::by_owner>>
> voters_table;

//***** REMOVE POST MIGRATION *****//
struct [[eosio::table, eosio::contract("fio.system")]] voter_info_old {
uint64_t id; //one up id is primary key.
string fioaddress; //this is the fio address to be used for bundled fee collection
//for tx that are fee type bundled, just use the one fio address
//you want to have pay for the bundled fee transactions associated
//with this voter.
uint128_t addresshash; //this is the hash of the fio address for searching
name owner; /// the voter
name proxy; /// the proxy set by the voter, if any
std::vector <name> producers; /// the producers approved by this voter if no proxy set
/**
* Every time a vote is cast we must first "undo" the last vote weight, before casting the
* new vote weight. Vote weight is calculated as:
*
* stated.amount * 2 ^ ( weeks_since_launch/weeks_per_year)
*/
double last_vote_weight = 0; /// the vote weight cast the last time the vote was updated

/**
* Total vote weight delegated to this voter.
*/
double proxied_vote_weight = 0; /// the total vote weight delegated to this voter as a proxy
bool is_proxy = 0; /// whether the voter is a proxy for others
bool is_auto_proxy = 0;
uint32_t reserved2 = 0;
eosio::asset reserved3;

uint64_t primary_key() const{return id;}
uint128_t by_address() const {return addresshash;}
uint64_t by_owner() const { return owner.value; }

// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE( voter_info_old, (id)(fioaddress)(addresshash)(owner)(proxy)(producers)(last_vote_weight)(proxied_vote_weight)(is_proxy)(is_auto_proxy)(reserved2)(reserved3)
)
};

//***** REMOVE POST MIGRATION *****//
typedef eosio::multi_index<"voters"_n, voter_info_old,
indexed_by<"byaddress"_n, const_mem_fun<voter_info_old, uint128_t, &voter_info_old::by_address>>,
indexed_by<"byowner"_n, const_mem_fun<voter_info_old, uint64_t, &voter_info_old::by_owner>>
> voters_table_old;


//MAS-522 eliminate producers2 table typedef eosio::multi_index<"producers2"_n, producer_info2> producers_table2;
Expand All @@ -297,6 +344,7 @@ class [[eosio::contract("fio.system")]] system_contract : public native {

private:
voters_table _voters;
voters_table_old _voters_old;
producers_table _producers;
top_producers_table _topprods;
locked_tokens_table _lockedtokens;
Expand Down Expand Up @@ -463,7 +511,6 @@ class [[eosio::contract("fio.system")]] system_contract : public native {

void unlock_tokens(const name &actor);


void update_votes(const name &voter, const name &proxy, const std::vector <name> &producers, const bool &voting);

void propagate_weight_change(const voter_info &voter);
Expand Down
6 changes: 5 additions & 1 deletion contracts/fio.system/src/delegate_bandwidth.cpp
Expand Up @@ -77,8 +77,12 @@ namespace eosiosystem {
});
return;
}
vector<name> producers;
for (const auto &p : voter_itr->producers) {
producers.push_back(p.producer);
}
if (voter_itr->producers.size() || voter_itr->proxy) {
update_votes(voter, voter_itr->proxy, voter_itr->producers, false);
update_votes(voter, voter_itr->proxy, producers, false);
}
}

Expand Down
34 changes: 18 additions & 16 deletions contracts/fio.system/src/fio.system.cpp
Expand Up @@ -4,7 +4,7 @@
* @file fio.system.cpp
* @license FIO Foundation ( https://github.com/fioprotocol/fio/blob/master/LICENSE ) Dapix
*
* Changes:
* Changes: Adam Androulidakis - 8/10/2020 MAS-1855
*/
#include <fio.system/fio.system.hpp>
#include <eosiolib/dispatcher.hpp>
Expand All @@ -20,6 +20,7 @@ namespace eosiosystem {
system_contract::system_contract(name s, name code, datastream<const char *> ds)
: native(s, code, ds),
_voters(_self, _self.value),
_voters_old(_self, _self.value), //***** REMOVE POST MIGRATION *****//
_producers(_self, _self.value),
_topprods(_self, _self.value),
_global(_self, _self.value),
Expand Down Expand Up @@ -156,6 +157,7 @@ namespace eosiosystem {
void eosiosystem::native::addaction(const name &action, const string &contract, const name &actor) {

}

void eosiosystem::native::remaction(const name &action, const name &actor) {

}
Expand Down Expand Up @@ -245,19 +247,19 @@ namespace eosiosystem {


EOSIO_DISPATCH( eosiosystem::system_contract,
// native.hpp (newaccount definition is actually in fio.system.cpp)
(newaccount)(addaction)(remaction)(updateauth)(deleteauth)(linkauth)(unlinkauth)(canceldelay)(onerror)(setabi)
// fio.system.cpp
(init)(addlocked)(addgenlocked)(setparams)(setpriv)
(rmvproducer)(updtrevision)
// delegate_bandwidth.cpp
(updatepower)
// voting.cpp
(regproducer)(regiproducer)(unregprod)(voteproducer)(voteproxy)(inhibitunlck)
(updlocked)(unlocktokens)(setautoproxy)(crautoproxy)(burnaction)(incram)
(unregproxy)(regiproxy)(regproxy)
// producer_pay.cpp
(onblock)
(resetclaim)
(updlbpclaim)
// native.hpp (newaccount definition is actually in fio.system.cpp)
(newaccount)(addaction)(remaction)(updateauth)(deleteauth)(linkauth)(unlinkauth)(canceldelay)(onerror)(setabi)
// fio.system.cpp
(init)(addlocked)(addgenlocked)(setparams)(setpriv)
(rmvproducer)(updtrevision)
// delegate_bandwidth.cpp
(updatepower)
// voting.cpp
(regproducer)(regiproducer)(unregprod)(voteproducer)(voteproxy)(inhibitunlck)
(updlocked)(unlocktokens)(setautoproxy)(crautoproxy)(burnaction)(incram)
(unregproxy)(regiproxy)(regproxy)
// producer_pay.cpp
(onblock)
(resetclaim)
(updlbpclaim)
)
53 changes: 50 additions & 3 deletions contracts/fio.system/src/voting.cpp
Expand Up @@ -493,6 +493,40 @@ namespace eosiosystem {
void system_contract::voteproducer(const std::vector<string> &producers, const string &fio_address, const name &actor, const int64_t &max_fee) {
require_auth(actor);

//***** REMOVE POST MIGRATION *****//
auto old_table_iter = _voters_old.begin();
const uint32_t MOVELIMIT = 3;
uint32_t c = 0;
if (old_table_iter != _voters_old.end()) {
auto new_table_iter = _voters.begin();
//copy records
while(old_table_iter !=_voters_old.end()) {
_voters.emplace(get_self(), [&](voter_info &new_table) {
new_table.id = _voters.available_primary_key();
new_table.fioaddress = old_table_iter->fioaddress;
new_table.addresshash = old_table_iter->addresshash;
new_table.owner = old_table_iter->owner;
new_table.proxy = old_table_iter->proxy;

for(uint32_t i = 0; i < old_table_iter->producers.size(); i++) {
new_table.producers.push_back(producername{old_table_iter->producers[i]});
}

new_table.last_vote_weight = old_table_iter->last_vote_weight;
new_table.proxied_vote_weight = old_table_iter->proxied_vote_weight;
new_table.is_proxy = old_table_iter->is_proxy;
new_table.is_auto_proxy = old_table_iter->is_auto_proxy;
new_table.reserved2 = old_table_iter->reserved2;
new_table.reserved3 = old_table_iter->reserved3;
});
old_table_iter = _voters_old.erase(old_table_iter);
c++;
if (c > MOVELIMIT) break;
}

} else {
//***** REMOVE POST MIGRATION *****//

fio_400_assert(max_fee >= 0, "max_fee", to_string(max_fee), "Invalid fee value",
ErrorMaxFeeInvalid);
name proxy;
Expand Down Expand Up @@ -619,6 +653,10 @@ namespace eosiosystem {
"Transaction is too large", ErrorTransactionTooLarge);

send_response(response_string.c_str());


} //***** REMOVE POST MIGRATION *****//

}

void system_contract::voteproxy(const string &proxy, const string &fio_address, const name &actor, const int64_t &max_fee) {
Expand Down Expand Up @@ -955,7 +993,7 @@ namespace eosiosystem {
propagate_weight_change(*old_proxy);
} else {
for (const auto &p : voter->producers) {
auto &d = producer_deltas[p];
auto &d = producer_deltas[p.producer];
d.first -= voter->last_vote_weight;
d.second = false;
}
Expand Down Expand Up @@ -1009,9 +1047,18 @@ namespace eosiosystem {

update_total_votepay_share(ct, -total_inactive_vpay_share, delta_change_rate);


vector<producername> producers_addresses;

auto namesbyname = _fionames.get_index<"byowner"_n>();
for (const auto &p : producers) {
auto res = namesbyname.find(p.value);
producers_addresses.push_back(producername{p, res->name});
}

votersbyowner.modify(voter, same_payer, [&](auto &av) {
av.last_vote_weight = new_vote_weight;
av.producers = producers;
av.producers = producers_addresses;
av.proxy = proxy;
});
}
Expand Down Expand Up @@ -1366,7 +1413,7 @@ namespace eosiosystem {
double total_inactive_vpay_share = 0;
for (auto acnt : voter.producers) {
auto prodbyowner = _producers.get_index<"byowner"_n>();
auto prod = prodbyowner.find(acnt.value);
auto prod = prodbyowner.find(acnt.producer.value);
check(prod != prodbyowner.end(), "producer not found"); //data corruption
const double init_total_votes = prod->total_votes;
prodbyowner.modify(prod, same_payer, [&](auto &p) {
Expand Down