Skip to content

Next

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
Minds Backend - Engine
Minds Backend - Engine
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Dependency List
    • Cycle Analytics
    • Insights
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
    • Locked Files
  • Issues 197
    • Issues 197
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 27
    • Merge Requests 27
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Packages
    • Packages
    • List
    • Container Registry
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Minds
  • Minds Backend - EngineMinds Backend - Engine
  • Merge Requests
  • !251

Open
Opened 4 weeks ago by Ben Hayward@benhayward.ben
  • Report abuse
Report abuse

[Sprint/InterestingIguana](feat): Offchain boost rate limiting #475

Closes #475

May need to distribute off-chain tokens for staging, using the php-cli. php cli.php rewards issue --username=nemofin --amount=10000

image

Edited 4 weeks ago by Ben Hayward

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch origin
git checkout -b feat/rate-limit-boost-475 origin/feat/rate-limit-boost-475

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git fetch origin
git checkout origin/master
git merge --no-ff feat/rate-limit-boost-475

Step 4. Push the result of the merge to GitLab

git push origin master

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

Request to merge feat/rate-limit-boost-475 into master
The source branch is 128 commits behind the target branch
Open in Web IDE
  • Email patches
  • Plain diff
Pipeline #74421257 passed for 5358b5e3 on feat/rate-limit-boost-475
          Requires 2 more approvals from Devs and Deployers.
          Brian Hatchet
          Brian Hatchet
          Mark Harding
          Mark Harding
          Emiliano Balbuena
          Emiliano Balbuena
          Marcelo Rivera
          Marcelo Rivera
          Martin Santangelo
          Martin Santangelo
          Ready to be merged automatically. Ask someone with write access to this repository to merge this request

          Closes #475

          Deletes source branch

          • Discussion 26
          • Commits 11
          • Pipelines 11
          • Changes 5
          14/18 threads resolved
          • Loading...
          • Ben Hayward
            Ben Hayward @benhayward.ben · 4 weeks ago
            Developer

            Need to do some testing, and run this by somebody. Not 100% sure I've properly filtered down the transactions as the number coming out is not quite what I'd expect (though is close). Could be related to ES running under low disk constraints.

          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 4 weeks ago
            Resolved by Ben Hayward 4 weeks ago
          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 4 weeks ago
            Resolved by Ben Hayward 4 weeks ago
          • Mark Harding @markeharding added MR::Requires Changes scoped label 4 weeks ago

            added MR::Requires Changes scoped label

          • Ben Hayward @benhayward.ben added 2 commits 4 weeks ago

            added 2 commits

            • 6015b386 - Added in rate limits for offchain boosts.
            • ad1bd20f - Updates, refactor and added tests

            Compare with previous version

          • Ben Hayward @benhayward.ben added 1 commit 4 weeks ago

            added 1 commit

            • 21f43ead - Updated, added in reduce for counting impressions and extra test

            Compare with previous version

          • Ben Hayward @benhayward.ben added 2 commits 4 weeks ago

            added 2 commits

            • 1e8d36d4 - spacing
            • 3817cb1f - syntax

            Compare with previous version

          • Ben Hayward @benhayward.ben unmarked as a Work In Progress 4 weeks ago

            unmarked as a Work In Progress

          • Ben Hayward @benhayward.ben changed the description 4 weeks ago

            changed the description

          • Ben Hayward @benhayward.ben resolved all discussions 4 weeks ago

            resolved all discussions

          • Ben Hayward @benhayward.ben resolved all discussions 4 weeks ago

            resolved all discussions

          • Ben Hayward @benhayward.ben added MR::Awaiting Review scoped label and automatically removed MR::Requires Changes label 4 weeks ago

            added MR::Awaiting Review scoped label and automatically removed MR::Requires Changes label

          • Ben Hayward @benhayward.ben mentioned in issue #591 4 weeks ago

            mentioned in issue #591

          • Ben Hayward @benhayward.ben mentioned in issue #592 4 weeks ago

            mentioned in issue #592

          • Brian Hatchet :speech_balloon: @brianhatchet approved this merge request 3 weeks ago

            approved this merge request

          • Marcelo Rivera @eiennohi approved this merge request 3 weeks ago

            approved this merge request

          • Ben Hayward
            Ben Hayward @benhayward.ben · 3 weeks ago
            Developer

            @eiennohi @brianhatchet did you test with tokens? I was trying to get into this with kubectl to issue some to people. (this may have to wait till monday but if you haven't already got some, send me your usernames on staging)

          • Mark Harding @markeharding added Squad::Green scoped label 2 weeks ago

            added Squad::Green scoped label

          • Ben Hayward
            Ben Hayward @benhayward.ben · 2 weeks ago
            Developer
            1. boosted for 5000
            2. boosted dif post for 4000
            3. boosted dif post for 2000 - error
            4. boosted for 1000 - success (max of 10k now reached)
            5. boosted for 1000 - error

            image

          • Emiliano Balbuena
            Emiliano Balbuena @edgebal started a thread on an old version of the diff 2 weeks ago
            Resolved by Ben Hayward 1 week ago
          • Ben Hayward @benhayward.ben added 1 commit 1 week ago

            added 1 commit

            • 2f37b154 - added in config for max

            Compare with previous version

          • Ben Hayward @benhayward.ben added 1 commit 1 week ago

            added 1 commit

            • 6c616c16 - added in config for max

            Compare with previous version

          • Ben Hayward @benhayward.ben resolved all threads 1 week ago

            resolved all threads

          • Ben Hayward @benhayward.ben added 1 commit 1 week ago

            added 1 commit

            • 9f3bcb40 - fixed failing tests

            Compare with previous version

          • Brian Hatchet :speech_balloon: @brianhatchet approved this merge request 3 days ago

            approved this merge request

          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 1 day ago
            Resolved by Ben Hayward 23 hours ago
          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 1 day ago
            Resolved by Ben Hayward 23 hours ago
          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 1 day ago
            Resolved by Ben Hayward 23 hours ago
          • Mark Harding
            Mark Harding @markeharding started a thread on the diff 1 day ago
            Controllers/api/v2/boost.php
            292 292
            293 if ($manager->checkExisting($boost)) {
            294 return Factory::response([
            295 'status' => 'error',
            296 'message' => "There's already an ongoing boost for this entity"
            297 ]);
            298 }
            299
            293 if ($manager->checkExisting($boost)) {
            294 return Factory::response([
            295 'status' => 'error',
            296 'message' => "There's already an ongoing boost for this entity"
            297 ]);
            298 }
            299
            300 if ($manager->boostLimitReached($boost)) {
            • Mark Harding
              Mark Harding @markeharding · 1 day ago
              Owner

              ideally this function would be called isBoost... so we know it will be a boolean

            • Please register or sign in to reply
          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 1 day ago
            Resolved by Ben Hayward 23 hours ago
          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 1 day ago
            Resolved by Ben Hayward 23 hours ago
          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 1 day ago
            Resolved by Ben Hayward 23 hours ago
          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 1 day ago
            Resolved by Ben Hayward 23 hours ago
          • Mark Harding
            Mark Harding @markeharding started a thread on the diff 1 day ago
            Resolved by Ben Hayward 23 hours ago
          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 1 day ago
            Last updated by Mark Harding 1 hour ago
            Core/Boost/Network/Manager.php
            162 *
            163 * @param Boost $type the Boost object.
            164 * @return boolean true if the boost limit has been reached.
            165 */
            166 public function boostLimitReached($boost) {
            167 //get offchain boosts
            168 $offchain = $this->getOffchainBoosts($boost);
            169
            170 //filter to get todays offchain transactions
            171 $offlineToday = array_filter($offchain->toArray(), function($result) {
            172 return $result->getCreatedTimestamp() > time() - (60 * 60 * 24);
            173 });
            174
            175 //reduce the impressions to count the days boosts.
            176 $acc = array_reduce($offlineToday, function($acc, $_boost) {
            177 $acc += $_boost->getImpressions();
            • Mark Harding
              Mark Harding @markeharding · 1 day ago
              Owner

              if using += on the $carry ($acc) parameter, should you not also set the initial parameter to 0? Looks to be null at present.

              https://www.php.net/manual/en/function.array-reduce.php

            • Ben Hayward @benhayward.ben changed this line in version 8 of the diff 23 hours ago

              changed this line in version 8 of the diff

            • Mark Harding
              Mark Harding @markeharding · 1 hour ago
              Owner

              not resolved

            • Please register or sign in to reply
          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 1 day ago
            Resolved by Ben Hayward 23 hours ago
          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 1 day ago
            Resolved by Ben Hayward 23 hours ago
          • Mark Harding
            Mark Harding @markeharding started a thread on an old version of the diff 1 day ago
            Resolved by Ben Hayward 23 hours ago
          • Mark Harding @markeharding added MR::Requires Changes scoped label and automatically removed MR::Awaiting Review label 1 day ago

            added MR::Requires Changes scoped label and automatically removed MR::Awaiting Review label

          • Ben Hayward @benhayward.ben added 1 commit 23 hours ago

            added 1 commit

            • 0cdeb613 - updated to meet feedback

            Compare with previous version

          • Ben Hayward @benhayward.ben added 1 commit 23 hours ago

            added 1 commit

            • 38602fa9 - more feedback

            Compare with previous version

          • Ben Hayward @benhayward.ben resolved all threads 23 hours ago

            resolved all threads

          • Ben Hayward @benhayward.ben added MR::Awaiting Review scoped label and automatically removed MR::Requires Changes label 23 hours ago

            added MR::Awaiting Review scoped label and automatically removed MR::Requires Changes label

          • Mark Harding @markeharding added MR::Requires Changes scoped label and automatically removed MR::Awaiting Review label 3 hours ago

            added MR::Requires Changes scoped label and automatically removed MR::Awaiting Review label

          • Mark Harding
            Mark Harding @markeharding · 3 hours ago
            Owner

            failing tests

          • Ben Hayward @benhayward.ben added 1 commit 3 hours ago

            added 1 commit

            • 5358b5e3 - fixed test

            Compare with previous version

          • Mark Harding
            Mark Harding @markeharding started a thread on the diff 2 hours ago
            Controllers/api/v2/boost.php
            292 292
            293 if ($manager->checkExisting($boost)) {
            294 return Factory::response([
            295 'status' => 'error',
            296 'message' => "There's already an ongoing boost for this entity"
            297 ]);
            298 }
            299
            293 if ($manager->isDuplicateBoost($boost)) {
            294 return Factory::response([
            295 'status' => 'error',
            296 'message' => "There's already an ongoing boost for this entity"
            297 ]);
            298 }
            299
            300 if ($manager->boostLimitReached($boost)) {
            • Mark Harding
              Mark Harding @markeharding · 2 hours ago
              Owner

              Why was this resolved?

            • Please register or sign in to reply
          • Mark Harding
            Mark Harding @markeharding started a thread on the diff 2 hours ago
            Core/Boost/Network/Manager.php
            168 * True if the boost is invalid due to the offchain boost limit being reached
            169 *
            170 * @param Boost $type the Boost object.
            171 * @return boolean true if the boost limit has been reached.
            172 */
            173 public function boostLimitReached($boost) {
            174 //get offchain boosts
            175 $offchain = $this->getOffchainBoosts($boost);
            176
            177 //filter to get todays offchain transactions
            178 $offlineToday = array_filter($offchain->toArray(), function($result) {
            179 return $result->getCreatedTimestamp() > time() - (60 * 60 * 24);
            180 });
            181
            182 //reduce the impressions to count the days boosts.
            183 $acc = array_reduce($offlineToday, function($carry = 0, $_boost) {
            • Mark Harding
              Mark Harding @markeharding · 2 hours ago
              Owner

              This doesn't appear to be resolved. Please read the PHP docs, an initial value must be set in array_reduce or else it will be null.

            • Please register or sign in to reply
          • You're only seeing other activity in the feed. To add a comment, switch to one of the following options.
          Please register or sign in to reply
          0 Assignees
          None
          Assign to
          None
          Milestone
          None
          Assign milestone
          None
          Time tracking
          No estimate or time spent
          2
          Labels
          MR::Requires Changes Squad::Green
          Assign labels
          • View project labels
          Lock merge request
          Unlocked
          7
          7 participants
          user avatar
          Brian Hatchet
          user avatar
          Mark Harding
          user avatar
          Emiliano Balbuena
          user avatar
          Marcelo Rivera
          user avatar
          Martin Santangelo
          user avatar
          Rami Albatal
          user avatar
          Ben Hayward
          Reference: minds/engine!251