From 8470e6ac1b28b53451323fc7fa6ce320749e3ad8 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Wed, 14 Jun 2023 15:04:17 -0600 Subject: [PATCH 1/7] BD-3746 fix auto proxy for all actions BD-3746 fix auto proxy for all actions --- contracts/fio.address/fio.address.cpp | 34 +++++++++++++++++++ contracts/fio.request.obt/fio.request.obt.cpp | 17 ++++++++++ 2 files changed, 51 insertions(+) diff --git a/contracts/fio.address/fio.address.cpp b/contracts/fio.address/fio.address.cpp index be05168a..870fd499 100644 --- a/contracts/fio.address/fio.address.cpp +++ b/contracts/fio.address/fio.address.cpp @@ -493,6 +493,11 @@ namespace fioio { const uint64_t bundleeligiblecountdown = fioname_iter->bundleeligiblecountdown; + //handle auto proxy + if (!tpid.empty()) { + set_auto_proxy(tpid, 0, get_self(), actor); + } + if (bundleeligiblecountdown > 0) { namesbyname.modify(fioname_iter, _self, [&](struct fioname &a) { a.bundleeligiblecountdown = (bundleeligiblecountdown - 1); @@ -515,6 +520,8 @@ namespace fioio { ); } } + + return fee_amount; } @@ -617,6 +624,10 @@ namespace fioio { ); } } + //handle auto proxy + if (!tpid.empty()) { + set_auto_proxy(tpid, 0, get_self(), actor); + } return fee_amount; } @@ -749,6 +760,12 @@ namespace fioio { ); } } + + //handle auto proxy + if (!tpid.empty()) { + set_auto_proxy(tpid, 0, get_self(), actor); + } + return fee_amount; } @@ -1793,6 +1810,10 @@ namespace fioio { ); } } + //handle auto proxy + if (!tpid.empty()) { + set_auto_proxy(tpid, 0, get_self(), actor); + } if (ADDNFTRAM > 0) { action( @@ -1955,6 +1976,10 @@ namespace fioio { ); } } + //handle auto proxy + if (!tpid.empty()) { + set_auto_proxy(tpid, 0, get_self(), actor); + } const string response_string = string("{\"status\": \"OK\",\"fee_collected\":") + to_string(fee_amount) + string("}"); @@ -2054,6 +2079,10 @@ namespace fioio { ); } } + //handle auto proxy + if (!tpid.empty()) { + set_auto_proxy(tpid, 0, get_self(), actor); + } const string response_string = string("{\"status\": \"OK\",\"fee_collected\":") + to_string(fee_amount) + string("}"); @@ -2407,6 +2436,7 @@ namespace fioio { "burn_fio_address unexpected fee type for endpoint burn_fio_address, expected 1", ErrorNoEndpoint); + if (bundleeligiblecountdown == 0) { fee_amount = fee_iter->suf_amount; fio_400_assert(max_fee >= (int64_t) fee_amount, "max_fee", to_string(max_fee), @@ -2416,6 +2446,10 @@ namespace fioio { fio_fees(actor, asset(fee_amount, FIOSYMBOL), BURN_FIO_ADDRESS_ENDPOINT); process_rewards(tpid, fee_amount, get_self(), actor); } + //handle auto proxy + if (!tpid.empty()) { + set_auto_proxy(tpid, 0, get_self(), actor); + } const string response_string = string("{\"status\": \"OK\",\"fee_collected\":") + to_string(fee_amount) + string("}"); diff --git a/contracts/fio.request.obt/fio.request.obt.cpp b/contracts/fio.request.obt/fio.request.obt.cpp index 3ea3b991..201b3215 100644 --- a/contracts/fio.request.obt/fio.request.obt.cpp +++ b/contracts/fio.request.obt/fio.request.obt.cpp @@ -263,6 +263,10 @@ namespace fioio { ); } } + //handle auto proxy + if (!tpid.empty()) { + set_auto_proxy(tpid, 0, get_self(), aactor); + } //end fees, bundle eligible fee logic if (fio_request_id.length() > 0) { uint64_t requestId; @@ -449,6 +453,11 @@ namespace fioio { ); } } + + //handle auto proxy + if (!tpid.empty()) { + set_auto_proxy(tpid, 0, get_self(), aActor); + } //end fees, bundle eligible fee logic const uint64_t id = fioTransactionsTable.available_primary_key(); const uint128_t toHash = string_to_uint128_hash(payee_fio_address.c_str()); @@ -603,6 +612,10 @@ namespace fioio { ); } } + //handle auto proxy + if (!tpid.empty()) { + set_auto_proxy(tpid, 0, get_self(), aactor); + } //end fees, bundle eligible fee logic trxtByRequestId.modify(fioreqctx_iter, _self, [&](struct fiotrxt_info &fr) { @@ -741,6 +754,10 @@ namespace fioio { ); } } + //handle auto proxy + if (!tpid.empty()) { + set_auto_proxy(tpid, 0, get_self(), aactor); + } //end fees, bundle eligible fee logic trxtByRequestId.modify(fioreqctx_iter, _self, [&](struct fiotrxt_info &fr) { fr.fio_data_type = static_cast(trxstatus::cancelled); From c36d167a93f87ad8226724a7d3e380dc80ace90c Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Fri, 23 Jun 2023 13:44:29 -0600 Subject: [PATCH 2/7] BD-4577 improved unlocking logic for general locks BD-4577 improved unlocking logic for general locks --- .../fio.token/include/fio.token/fio.token.hpp | 90 +++++++++++-------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/contracts/fio.token/include/fio.token/fio.token.hpp b/contracts/fio.token/include/fio.token/fio.token.hpp index 95c07f8e..ed4abc9e 100755 --- a/contracts/fio.token/include/fio.token/fio.token.hpp +++ b/contracts/fio.token/include/fio.token/fio.token.hpp @@ -389,74 +389,90 @@ namespace eosio { } //begin general locked tokens - //this will compute the present unlocked tokens for this user based on the - //unlocking schedule, it will update the locktokens table if the doupdate + //this will compute the present locked token amount for this user based on the + //unlocking schedule, it will update the locktokensv2 table if the doupdate //is set to true. static uint64_t computegenerallockedtokens(const name &actor, bool doupdate) { uint32_t present_time = now(); - + //set up the query for lock periods this account. eosiosystem::general_locks_table_v2 generalLockTokensTable(SYSTEMACCOUNT, SYSTEMACCOUNT.value); auto locks_by_owner = generalLockTokensTable.get_index<"byowner"_n>(); auto lockiter = locks_by_owner.find(actor.value); + //if we get results from the query if (lockiter != locks_by_owner.end()) { - + //if the lock is not already completely paid out. if (lockiter->payouts_performed < lockiter->periods.size()) { uint32_t secondsSinceGrant = (present_time - lockiter->timestamp); + uint32_t number_unlocks = 0; //this is the number of unlock periods to perform at this time. + uint64_t computed_amount_unlock = 0; // this is the computed amount of fio to unlock at this time. - uint32_t payoutsDue = 0; - + //loop over periods, total number of unlock periods to perform now, and compute present amount unlocked. for (int i=0;iperiods.size(); i++){ if (lockiter->periods[i].duration <= secondsSinceGrant){ - payoutsDue++; + number_unlocks++; + if(i < lockiter->payouts_performed) { + computed_amount_unlock += lockiter->periods[i].amount; + } } } - uint64_t amountpay = 0; - uint64_t newlockedamount = lockiter->remaining_lock_amount; - bool didsomething = false; + //compute the remaining lock amount, for use in incoherency check. + uint64_t computed_remaining_lock_amount = lockiter->lock_amount - computed_amount_unlock; - if (payoutsDue > lockiter->payouts_performed) { - if((lockiter->payouts_performed + payoutsDue) >= lockiter->periods.size()) - { - //payout the remaining lock amount. - amountpay = newlockedamount; - } - else { + 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. - for (int i = lockiter->payouts_performed; i < payoutsDue; i++) { - amountpay += lockiter->periods[i].amount; - } - } + //if there are unlock periods needing processed now, record the number of periods to process. + if (lockiter->payouts_performed < number_unlocks){ + unlock_periods = number_unlocks - lockiter->payouts_performed; + } - if (newlockedamount > amountpay) { - newlockedamount -= amountpay; - } else { - newlockedamount = 0; + //initialize the remaining lock amount to use from state. + uint64_t use_remaining_lock_amount = lockiter->remaining_lock_amount; + + //compare the computed remaining lock amount + // and the state remaining lock amount, if they dont match then the lock + // is incoherent, if its incoherent use the computed remaining lock amount going forward. + if (use_remaining_lock_amount != computed_remaining_lock_amount){ + use_remaining_lock_amount = computed_remaining_lock_amount; + print(" WARNING lock incoherency detected ", actor.to_string(), " using computed value for remaining_lock_amount ", + computed_remaining_lock_amount, " \n "); + } + + //if the number of unlock periods is non zero, compute the amount to unlock at this time. + if (unlock_periods > 0) { + for (int i = lockiter->payouts_performed; i < number_unlocks; i++) { + unlock_amount += lockiter->periods[i].amount; } } - if ((amountpay > 0) && doupdate) { + //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; + + //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; - if (newlockedamount > amount) { - print(" WARNING computed amount ", newlockedamount, " is more than amount in account ", - amount, " \n ", - " Transaction processing order can cause this, this amount is being re-aligned, resetting remaining locked amount to ", - amount, "\n"); - newlockedamount = amount; - } - + //final sanity check. + check(use_remaining_lock_amount <= amount, + "computegenerallockedtokens, remaining lock amount is larger than balance for " + actor.to_string() ); + //update the locked table. locks_by_owner.modify(lockiter, SYSTEMACCOUNT, [&](auto &av) { - av.remaining_lock_amount = newlockedamount; - av.payouts_performed = payoutsDue; + av.remaining_lock_amount = use_remaining_lock_amount; + av.payouts_performed = number_unlocks; }); } - return newlockedamount; + return use_remaining_lock_amount; } else { return lockiter->remaining_lock_amount; From 22526338c3dcdf9722158e5fb5272a559b842f42 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Wed, 5 Jul 2023 10:49:24 -0600 Subject: [PATCH 3/7] BD-4580 add burndomain action BD-4580 add burndomain action --- contracts/fio.address/fio.address.abi | 15 +++++++++++ contracts/fio.address/fio.address.cpp | 39 +++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/contracts/fio.address/fio.address.abi b/contracts/fio.address/fio.address.abi index 86f4bab3..cb63b964 100644 --- a/contracts/fio.address/fio.address.abi +++ b/contracts/fio.address/fio.address.abi @@ -504,6 +504,16 @@ } ] }, + { + "name": "burndomain", + "base": "", + "fields": [ + { + "name": "domainidx", + "type": "uint64" + } + ] + }, { "name": "burnexpired", "base": "", @@ -808,6 +818,11 @@ "type": "renewaddress", "ricardian_contract": "" }, + { + "name": "burndomain", + "type": "burndomain", + "ricardian_contract": "" + }, { "name": "burnexpired", "type": "burnexpired", diff --git a/contracts/fio.address/fio.address.cpp b/contracts/fio.address/fio.address.cpp index 870fd499..46231f96 100644 --- a/contracts/fio.address/fio.address.cpp +++ b/contracts/fio.address/fio.address.cpp @@ -1389,6 +1389,36 @@ namespace fioio { send_response(response_string.c_str()); } + + [[eosio::action]] + void burndomain(const uint64_t &domainidx) { + //only fio.address able to call this. + eosio_assert(has_auth(AddressContract), + "missing required authority of fio.address"); + + auto domainiter = domains.find(domainidx); + + fio_400_assert(domainiter != domains.end(), "domainidx", std::to_string(domainidx), + "Domain index not found", ErrorDomainNotFound); + + const auto domainhash = domainiter->domainhash; + auto nameexpidx = fionames.get_index<"bydomain"_n>(); + auto nameiter = nameexpidx.find(domainhash); + + fio_400_assert(nameiter == nameexpidx.end(), "domainidx", std::to_string(domainidx), + "Cannot burn domain when domain has fio handles", ErrorDomainNotFound); + + domains.erase(domainiter); + + + const string response_string = string("{\"status\": \"OK\" },\""); + + fio_400_assert(transaction_size() <= MAX_TRX_SIZE, "transaction_size", std::to_string(transaction_size()), + "Transaction is too large", ErrorTransactionTooLarge); + + send_response(response_string.c_str()); + } + /* * This action will look for expired domains, then look for expired addresses, it will burn a total * of 25 addresses each time called. please see the code for the logic of identifying expired domains @@ -1474,7 +1504,12 @@ namespace fioio { } if (nameiter == nameexpidx.end()) { - domains.erase(domainiter); + action( + permission_level{get_self(), "active"_n}, + "fio.address"_n, + "burndomain"_n, + std::make_tuple(index) + ).send(); recordProcessed++; // Find any domains listed for sale on the fio.escrow contract table @@ -2695,6 +2730,6 @@ namespace fioio { }; EOSIO_DISPATCH(FioNameLookup,(regaddress)(addaddress)(remaddress)(remalladdr)(regdomain)(renewdomain)(renewaddress) - (setdomainpub)(burnexpired)(decrcounter)(bind2eosio)(burnaddress)(xferdomain)(xferaddress)(addbundles)(xferescrow) + (setdomainpub)(burnexpired)(burndomain)(decrcounter)(bind2eosio)(burnaddress)(xferdomain)(xferaddress)(addbundles)(xferescrow) (addnft)(remnft)(remallnfts)(burnnfts)(regdomadd)(updcryptkey)) } From 187520c06669ddd5240a9b4de15ea638f6db2683 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Wed, 5 Jul 2023 11:33:35 -0600 Subject: [PATCH 4/7] BD-4580 add domain name to action arguments, for easy history access BD-4580 add dojmain name to action arguments for easy history access --- contracts/fio.address/fio.address.abi | 6 +++++- contracts/fio.address/fio.address.cpp | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/contracts/fio.address/fio.address.abi b/contracts/fio.address/fio.address.abi index cb63b964..2f6fe7f0 100644 --- a/contracts/fio.address/fio.address.abi +++ b/contracts/fio.address/fio.address.abi @@ -503,11 +503,15 @@ "type": "string" } ] - }, + } { "name": "burndomain", "base": "", "fields": [ + { + "name": "domainname", + "type": "string" + }, { "name": "domainidx", "type": "uint64" diff --git a/contracts/fio.address/fio.address.cpp b/contracts/fio.address/fio.address.cpp index 46231f96..d030fa5f 100644 --- a/contracts/fio.address/fio.address.cpp +++ b/contracts/fio.address/fio.address.cpp @@ -1389,14 +1389,15 @@ namespace fioio { send_response(response_string.c_str()); } - [[eosio::action]] - void burndomain(const uint64_t &domainidx) { + void burndomain(const string &domainname, const uint64_t &domainidx) { //only fio.address able to call this. eosio_assert(has_auth(AddressContract), "missing required authority of fio.address"); auto domainiter = domains.find(domainidx); + fio_400_assert(domainiter->name.compare(domainname) == 0, "domainname", domainname, + "Domain name does not match name at index", ErrorDomainNotFound); fio_400_assert(domainiter != domains.end(), "domainidx", std::to_string(domainidx), "Domain index not found", ErrorDomainNotFound); @@ -1408,6 +1409,8 @@ namespace fioio { fio_400_assert(nameiter == nameexpidx.end(), "domainidx", std::to_string(domainidx), "Cannot burn domain when domain has fio handles", ErrorDomainNotFound); + print("EDEDEDEEDEDEDEDEDEDEDEDEDEDEDEDEDED burndomain erasing index ",to_string(domainidx),"\n"); + print("EDEDEDEEDEDEDEDEDEDEDEDEDEDEDEDEDED burndomain erasing name ",domainname,"\n"); domains.erase(domainiter); @@ -1508,7 +1511,7 @@ namespace fioio { permission_level{get_self(), "active"_n}, "fio.address"_n, "burndomain"_n, - std::make_tuple(index) + std::make_tuple(domainiter->name,index) ).send(); recordProcessed++; From 11b57ce61f9210c7923b1857cc754e29aa93ebce Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Wed, 5 Jul 2023 11:36:46 -0600 Subject: [PATCH 5/7] BD-4580 proper formatting on abi BD-4580 proper formatting on ABI --- contracts/fio.address/fio.address.abi | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/contracts/fio.address/fio.address.abi b/contracts/fio.address/fio.address.abi index 2f6fe7f0..67d38e65 100644 --- a/contracts/fio.address/fio.address.abi +++ b/contracts/fio.address/fio.address.abi @@ -503,21 +503,21 @@ "type": "string" } ] - } - { - "name": "burndomain", - "base": "", - "fields": [ - { - "name": "domainname", - "type": "string" - }, - { - "name": "domainidx", - "type": "uint64" - } - ] - }, + }, + { + "name": "burndomain", + "base": "", + "fields": [ + { + "name": "domainname", + "type": "string" + }, + { + "name": "domainidx", + "type": "uint64" + } + ] + }, { "name": "burnexpired", "base": "", From e53720c2846449568fd7f3207d7214c149c6f222 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Wed, 5 Jul 2023 11:48:04 -0600 Subject: [PATCH 6/7] remove prints remove prints --- contracts/fio.address/fio.address.abi | 19 +++++++++++++++++++ contracts/fio.address/fio.address.cpp | 2 -- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/contracts/fio.address/fio.address.abi b/contracts/fio.address/fio.address.abi index 67d38e65..ea591349 100644 --- a/contracts/fio.address/fio.address.abi +++ b/contracts/fio.address/fio.address.abi @@ -504,6 +504,20 @@ } ] }, + { + "name": "modexpire", + "base": "", + "fields": [ + { + "name": "fio_address", + "type": "string" + }, + { + "name": "expire", + "type": "int64" + } + ] + }, { "name": "burndomain", "base": "", @@ -822,6 +836,11 @@ "type": "renewaddress", "ricardian_contract": "" }, + { + "name": "modexpire", + "type": "modexpire", + "ricardian_contract": "" + }, { "name": "burndomain", "type": "burndomain", diff --git a/contracts/fio.address/fio.address.cpp b/contracts/fio.address/fio.address.cpp index d030fa5f..861f89cd 100644 --- a/contracts/fio.address/fio.address.cpp +++ b/contracts/fio.address/fio.address.cpp @@ -1409,8 +1409,6 @@ namespace fioio { fio_400_assert(nameiter == nameexpidx.end(), "domainidx", std::to_string(domainidx), "Cannot burn domain when domain has fio handles", ErrorDomainNotFound); - print("EDEDEDEEDEDEDEDEDEDEDEDEDEDEDEDEDED burndomain erasing index ",to_string(domainidx),"\n"); - print("EDEDEDEEDEDEDEDEDEDEDEDEDEDEDEDEDED burndomain erasing name ",domainname,"\n"); domains.erase(domainiter); From c95c72b37ddbfc0ae8c05f8a0d6108e3b76d9298 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Wed, 5 Jul 2023 11:50:48 -0600 Subject: [PATCH 7/7] remove test action remove test action --- contracts/fio.address/fio.address.abi | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/contracts/fio.address/fio.address.abi b/contracts/fio.address/fio.address.abi index ea591349..67d38e65 100644 --- a/contracts/fio.address/fio.address.abi +++ b/contracts/fio.address/fio.address.abi @@ -504,20 +504,6 @@ } ] }, - { - "name": "modexpire", - "base": "", - "fields": [ - { - "name": "fio_address", - "type": "string" - }, - { - "name": "expire", - "type": "int64" - } - ] - }, { "name": "burndomain", "base": "", @@ -836,11 +822,6 @@ "type": "renewaddress", "ricardian_contract": "" }, - { - "name": "modexpire", - "type": "modexpire", - "ricardian_contract": "" - }, { "name": "burndomain", "type": "burndomain",