Skip to content

Commit

Permalink
Merge pull request #345 from fioprotocol/BD-4643-fiocontracts-develop…
Browse files Browse the repository at this point in the history
…-06132024

BD-4643 fixes for main net for whole enchilada token transfer edge cases
  • Loading branch information
misterleet authored Jun 26, 2024
2 parents e48ae09 + fb004b9 commit 2c95bd5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
1 change: 0 additions & 1 deletion contracts/fio.system/src/fio.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,6 @@ namespace eosiosystem {
}
//end audit machine


} /// fio.system


Expand Down
16 changes: 13 additions & 3 deletions contracts/fio.system/src/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,18 +834,28 @@ namespace eosiosystem {
const name &proxy,
const std::vector <name> &producers,
const bool &voting) {

auto votersbyowner = _voters.get_index<"byowner"_n>();
auto voter = votersbyowner.find(voter_name.value);
//validate input
if (proxy) {
check(producers.size() == 0, "cannot vote for producers and proxy at same time");
// check(producers.size() == 0, "cannot vote for producers and proxy at same time");
//if producers are set and a proxy is set. then clear the proxy and the is_auto_proxy
if(producers.size() > 0){
name noproxy;
votersbyowner.modify(voter, same_payer, [&](auto &av) {
av.proxy = noproxy;
av.is_auto_proxy = false;
});
}
check(voter_name != proxy, "Invalid or duplicated producers0");
} else {
check(producers.size() <= 30, "attempt to vote for too many producers");
for (size_t i = 1; i < producers.size(); ++i) {
check(producers[i - 1] < producers[i], "producer votes must be unique and sorted");
}
}
auto votersbyowner = _voters.get_index<"byowner"_n>();
auto voter = votersbyowner.find(voter_name.value);

check(voter != votersbyowner.end(), "user must vote before votes can be updated");
check(!proxy || !voter->is_proxy, "account registered as a proxy is not allowed to use a proxy");

Expand Down
42 changes: 25 additions & 17 deletions contracts/fio.token/include/fio.token/fio.token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,12 @@ namespace eosio {
}

}
//compute the remaining lock amount, for use in incoherency check.
uint64_t computed_remaining_lock_amount = lockiter->lock_amount - computed_amount_unlock;

uint64_t computed_remaining_lock_amount = 0;
if(computed_amount_unlock <= lockiter->lock_amount) {
//compute the remaining lock amount, for use in incoherency check.
computed_remaining_lock_amount = lockiter->lock_amount - computed_amount_unlock;
}

uint64_t unlock_amount = 0; //the amount to unlock at this time
int unlock_periods = 0; //the number of periods to unlock at this time.
Expand Down Expand Up @@ -450,23 +454,27 @@ namespace eosio {

//sanity check the amount to unlock and remaining lock amount, if they dont pass the sanity check
//do not proceed. prevent un-expected side effects of bad data.
check(use_remaining_lock_amount >= unlock_amount,
"computegenerallockedtokens, amount to unlock cannot be greater than remaining lock amount " + actor.to_string() );

//compute the present remaining lock amount, subtract the amount to unlock at this time.
use_remaining_lock_amount -= unlock_amount;
//BD4643 remove checks and remove locks if they are incoherent instead.
// check(use_remaining_lock_amount >= unlock_amount,
// "computegenerallockedtokens, amount to unlock cannot be greater than remaining lock amount " + actor.to_string() );

if(use_remaining_lock_amount < unlock_amount){
use_remaining_lock_amount = 0;
}else {
//compute the present remaining lock amount, subtract the amount to unlock at this time.
use_remaining_lock_amount -= unlock_amount;
}

//if there is an amount to unlock, update state with the present lock info.
if (((unlock_amount > 0) && doupdate)) {
//get fio balance for this account,
uint32_t present_time = now();
const auto my_balance = eosio::token::get_balance("fio.token"_n, actor, FIOSYMBOL.code());
uint64_t amount = my_balance.amount;
const auto my_balance = eosio::token::get_balance("fio.token"_n, actor, FIOSYMBOL.code());
uint64_t amount = my_balance.amount;

//final sanity check.
check(use_remaining_lock_amount <= amount,
"computegenerallockedtokens, remaining lock amount is larger than balance for " + actor.to_string() );

//if remaining is larger than balance then we need to remove these locks from the system.
//they are incoherent for some reason and we dont want to keep them around any longer.
if(use_remaining_lock_amount > amount){
//delete these locks from the locks by owner!!
locks_by_owner.erase(lockiter);
use_remaining_lock_amount = 0;
}else if (((unlock_amount > 0) && doupdate)) {
//update the locked table.
locks_by_owner.modify(lockiter, SYSTEMACCOUNT, [&](auto &av) {
av.remaining_lock_amount = use_remaining_lock_amount;
Expand Down

0 comments on commit 2c95bd5

Please sign in to comment.