From a28b1bc3badf6354e2a38a701c60128e3d83e896 Mon Sep 17 00:00:00 2001 From: Leister Francisco Alvarez Campos Date: Fri, 8 Oct 2021 19:09:08 -0600 Subject: [PATCH 1/2] Fix/minimize migration (#822) * feat(contracts): separte update stats from main migration * feat(contracts): split migration --- .../rateproducer/include/rateproducer.hpp | 19 +-- contracts/rateproducer/rateproducer.abi | 10 ++ contracts/rateproducer/rateproducer.wasm | Bin 42395 -> 42238 bytes .../ricardian/rateproducer-ricardian.cpp | 6 + contracts/rateproducer/src/rateproducer.cpp | 125 +++++++++--------- 5 files changed, 84 insertions(+), 76 deletions(-) diff --git a/contracts/rateproducer/include/rateproducer.hpp b/contracts/rateproducer/include/rateproducer.hpp index b2d4a2bf..2b50f1e3 100644 --- a/contracts/rateproducer/include/rateproducer.hpp +++ b/contracts/rateproducer/include/rateproducer.hpp @@ -594,23 +594,17 @@ namespace eoscostarica { /** * - * NOTE: This function should be removed after migration run - * Erase a rate made for a specific account - * to a specific block producer - * - * @param scope - Table scope, - * @param user - Voter account name, - * @param bp - Block Producer account name + * Update the current logic to newest * - */ - void update_stats_migration(name bp); + */ + void migrate(); /** * - * Update the current logic to newest + * Update stats under rateproducer scope * */ - void migrate(); + void migratestats(); /** * @@ -628,6 +622,7 @@ namespace eoscostarica { action(rminactive, ricardian_contract(rminactive_ricardian)), action(rmrate, user, bp, ricardian_contract(rmrate_ricardian)), action(migrate, ricardian_contract(migrate_ricardian)), - action(freeupram, ricardian_contract(freeupram_ricardian))) + action(freeupram, ricardian_contract(freeupram_ricardian)), + action(migratestats, ricardian_contract(migratestats_ricardian))) } // namespace eoscostarica \ No newline at end of file diff --git a/contracts/rateproducer/rateproducer.abi b/contracts/rateproducer/rateproducer.abi index cafb1af8..56f24f43 100644 --- a/contracts/rateproducer/rateproducer.abi +++ b/contracts/rateproducer/rateproducer.abi @@ -80,6 +80,11 @@ "base": "", "fields": [] }, + { + "name": "migratestats", + "base": "", + "fields": [] + }, { "name": "ratings_v2", "base": "", @@ -192,6 +197,11 @@ "name": "freeupram", "type": "freeupram", "ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Free up RAM\nsummary: The intent of the `{{ freeupram }}` action is to remove all records from old ratings table including the rateproducer and eden scope.\n---" + }, + { + "name": "migratestats", + "type": "migratestats", + "ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Update rateproducer stats\nsummary: The intent of the `{{ migratestats }}` action is to remove from stats table under rateproducer scope the eden ratings averages.\n---" } ], "tables": [ diff --git a/contracts/rateproducer/rateproducer.wasm b/contracts/rateproducer/rateproducer.wasm index f65a49c3679091ff5afce17006b402e54ef5362d..87eceb32d5fe1ef90523c464569937d6d635d534 100755 GIT binary patch delta 1567 zcmY*ZVN4uF6rMM;dkgHYE-gh=(B%&8g4iI%TPm2`(o$$CaEBBQgmM%r#~s!-F_9X= zl4v5o4DA@B5=~PLwJ{;u`DIMhq-mpRf7G-!F)>kp@u$(mAEq%8eKSj&I-8yEo44P* znR)Ncu3n{^-_w;{Wm<@h6~MQet2#A@_M9;QUsKqrPt2^eKy5Mn+Gpi|wZI>?7O zPAN7*P!JD2Rkx(4d^jgG!JHa0#!J6m=^ zh<5ES3P<>E<8_!2>qeH9Ou5vBBpu^{F$dFp-KZ3&%}XUP!w*+{26+KH5(d1?pQyeD zed5pRPh$wHiOVrKE+!i;Q+P$}d^*DrPBj$~cun74;k9gPFei5I+3Ub*zCGOr-Ml}2 z0}k*+CR=&X0@H=yJt$z`T5xq2oP#F+Fw=~J>zU`EN05M?|1kSf>hCYmWC9q9<}03POE3Bc+6$>%*ohb2Bem`)T5r7 z=V)>5e(xH3XEKJkRETS}x-5z*9=09L2(1ycM9>sLV+7JEO6pvK=ZN8;eJc|Xv`E$@ zyGGf0va2gNIA4(@brth42-S);g-ELuZA4a~SPL>ou~uZ3V(rLE(20tU%sIxx$^7q( zDuUr%jnk|L#5Cj7#$E<0A17LhhPZ2jn%kt{Q4*(|70dbRWYWx=wOGk69&C;W^^fns z87pxA6py|G9E#he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I1%hVH-=DGi*uLYRFFJ>n?pVLX`umR v_{dwI@Zjd9zGPF3F-CtkEFNrFse|i~n4qsq-^bM3?*-;Ml0?w`{%80fJP1)9 diff --git a/contracts/rateproducer/ricardian/rateproducer-ricardian.cpp b/contracts/rateproducer/ricardian/rateproducer-ricardian.cpp index 57b94d96..1ca502c6 100644 --- a/contracts/rateproducer/ricardian/rateproducer-ricardian.cpp +++ b/contracts/rateproducer/ricardian/rateproducer-ricardian.cpp @@ -42,6 +42,12 @@ title: Free up RAM summary: The intent of the `{{ freeupram }}` action is to remove all records from old ratings table including the rateproducer and eden scope. ---)"; +const char* migratestats_ricardian = R"(--- +spec_version: 0.1.0 +title: Update rateproducer stats +summary: The intent of the `{{ migratestats }}` action is to remove from stats table under rateproducer scope the eden ratings averages. +---)"; + // CLAUSES const char* datastorage_clause = R"(The rateproducer application values the security of personal data. We may process only minimal user data as much as it is necessary to maintain the rateproducer application running. We only receive and store any information you knowingly provide to us when you create an account, or fill using the app.)"; diff --git a/contracts/rateproducer/src/rateproducer.cpp b/contracts/rateproducer/src/rateproducer.cpp index 5466a683..bcab03a4 100644 --- a/contracts/rateproducer/src/rateproducer.cpp +++ b/contracts/rateproducer/src/rateproducer.cpp @@ -481,68 +481,6 @@ namespace eoscostarica { &bp_average); } - void rateproducer::update_stats_migration(name bp) { - name default_scope = _self; - name ram_payer = _self; - - //update bp stats - float bp_transparency = 0; - float bp_infrastructure = 0; - float bp_trustiness = 0; - float bp_community = 0; - float bp_development = 0; - uint32_t bp_ratings_cntr = 0; - float bp_average = 0; - - //re-calculate stats for the bp - calculate_bp_stats (default_scope, - bp, - &bp_transparency, - &bp_infrastructure, - &bp_trustiness, - &bp_community, - &bp_development, - &bp_ratings_cntr, - &bp_average); - - float totalStats = - bp_transparency + - bp_infrastructure + - bp_trustiness + - bp_community + - bp_development; - - name stats_ram_payer =_self; - stats_table _stats(_self, default_scope.value); - auto itr = _stats.find(bp.value); - if(itr != _stats.end()) { - if(totalStats) { - _stats.modify(itr, stats_ram_payer, [&]( auto& row ) { - row.transparency = bp_transparency; - row.infrastructure = bp_infrastructure; - row.trustiness = bp_trustiness; - row.development = bp_community; - row.community = bp_development; - row.ratings_cntr = bp_ratings_cntr; - row.average = bp_average; - }); - } else _stats.erase(itr); - } else { - if(totalStats) { - _stats.emplace(stats_ram_payer, [&]( auto& row ) { - row.bp = bp; - row.transparency = bp_transparency; - row.infrastructure = bp_infrastructure; - row.trustiness = bp_trustiness; - row.development = bp_community; - row.community = bp_development; - row.ratings_cntr = bp_ratings_cntr; - row.average = bp_average; - }); - } - } - } - void rateproducer::migrate() { config c = cfg.get_or_create(_self, config{.owner = _self, .version = 0}); require_auth(c.owner); @@ -567,7 +505,66 @@ namespace eoscostarica { name temp_scope = is_eden(itr->user) ? eden_scope : _self; if(temp_scope.value == eden_scope.value) _ratings_eden_v2.emplace(_self, emplace_rating); else _ratings_self_v2.emplace(_self, emplace_rating); - update_stats_migration(itr->bp); + } + + c.version++; + cfg.set(c, c.owner); + } + + void rateproducer::migratestats() { + config c = cfg.get_or_create(_self, config{.owner = _self, .version = 0}); + require_auth(c.owner); + // assert we only run once + // the comparison value needs to be hard-coded with each new migration + eosio::check(c.version < 3, "Migration already ran"); + + name default_scope = _self; + name stats_ram_payer = _self; + + stats_table _stats(_self, default_scope.value); + ratings_table_v2 _ratings_self_v2(_self, _self.value); + auto bps_index = _ratings_self_v2.get_index(); + + auto stats_itr = _stats.begin(); + while(stats_itr != _stats.end()) { + name bp = stats_itr->bp; + + auto bps_itr = bps_index.find(bp.value); + + if(bps_itr == bps_index.end()) { + stats_itr = _stats.erase(stats_itr); + continue; + } + + float bp_transparency = 0; + float bp_infrastructure = 0; + float bp_trustiness = 0; + float bp_community = 0; + float bp_development = 0; + uint32_t bp_ratings_cntr = 0; + float bp_average = 0; + + calculate_bp_stats (default_scope, + bp, + &bp_transparency, + &bp_infrastructure, + &bp_trustiness, + &bp_community, + &bp_development, + &bp_ratings_cntr, + &bp_average); + + _stats.modify(stats_itr, stats_ram_payer, [&]( auto& row ) { + row.transparency = bp_transparency; + row.infrastructure = bp_infrastructure; + row.trustiness = bp_trustiness; + row.development = bp_development; + row.community = bp_community; + row.ratings_cntr= bp_ratings_cntr; + row.average = bp_average; + }); + + stats_itr++; } c.version++; @@ -578,7 +575,7 @@ namespace eoscostarica { config c = cfg.get_or_create(_self, config{.owner = _self, .version = 0}); require_auth(_self); - eosio::check(c.version < 3, "Make sure to run `migrate` action before run this action"); + eosio::check(c.version > 2, "Make sure to run `migrate` action before run this action"); ratings_table _ratings_general(_self, _self.value); auto general_itr = _ratings_general.begin(); From b6a415ccc2b825718d0949de9e018df0a136e73f Mon Sep 17 00:00:00 2001 From: Teto Gomez Date: Sun, 10 Oct 2021 14:49:47 -0600 Subject: [PATCH 2/2] fix(webapp): fix login on mainnet (#825) --- webapp/src/context/models/user.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/webapp/src/context/models/user.js b/webapp/src/context/models/user.js index 76115855..4a26c9f9 100644 --- a/webapp/src/context/models/user.js +++ b/webapp/src/context/models/user.js @@ -31,7 +31,9 @@ export const getUserDataModeled = async ual => { const rpc = getRpc(ual) const account = await rpc.get_account(accountName) - const { rows: edenMembers } = await rpc.get_table_rows({ + const { + rows: [edenMembers] + } = await rpc.get_table_rows({ json: true, code: mainConfig.contractEden, scope: 0, @@ -42,10 +44,7 @@ export const getUserDataModeled = async ual => { show_payer: false }) - if ( - edenMembers.length > 0 && - edenMembers[0].value[1].account === accountName - ) { + if (edenMembers?.length > 0 && edenMembers[1].account === accountName) { edenMember = true }