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

Evaluator Rewards #47

Merged
merged 27 commits into from
Jul 21, 2023
Merged

Evaluator Rewards #47

merged 27 commits into from
Jul 21, 2023

Conversation

JuaniRios
Copy link
Contributor

@JuaniRios JuaniRios commented Jul 13, 2023

Objective

Implement automatic rewards for evaluations based on the knowledge hub logic.

Changes Overview

  • We now have a state machine that handles the "cleaning" of a finished project. We call it a "finalizer"

    • The finalizer is triggered in on_idle on a per-operation basis
    • each operation has to return the used weight
    • The finalizer has a funding success and failure version
    • For now, only the evaluation rewards are implemented.
    • Other cleaning operations are mentioned but not implemented
  • Bids over the final weighted average price are counted down to the average price

    • The difference is returned to the bidder
  • Unbonding an evaluation is done in a single extrinsic, irrespective of if the funding was a success or not.

  • We can now represent a failed or successful funding for the project, and handle it with the new state machine.

Issues

  • PLMC unbonding tests are broken
  • Failed projects are panicking the runtime once on_initialize tries to initialize the finalizer.
    • This is because a new logic was added to check if the project needs to be manually accepted for funding or not. and only the automatic acceptance when the funding is >90% is implemented.
  • Current cleaning operations of the finalizer return weight 0. This means all of the finalizations will occur inside one block, which might lead to longer than expected block times.
    • We should benchmark each cleaning operation and return those weights instead

@linear
Copy link

linear bot commented Jul 13, 2023

PLMC-214 Finalize Evaluations

Implement slashing and rewards

@JuaniRios JuaniRios changed the title Draft: Feature/plmc 214 finalize evaluations Feature/plmc 214 finalize evaluations Jul 13, 2023
@JuaniRios JuaniRios self-assigned this Jul 13, 2023
@JuaniRios JuaniRios requested a review from lrazovic July 13, 2023 16:17
Copy link
Member

@lrazovic lrazovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an offline review:

  • Calculating the total bonded in evaluations every time you evaluate is inefficient. We should store the total bonded somewhere and add to this on every evaluation.
  • Use StorageNMap instead of having a BoundedVec for all the evaluations/bids/contributions for a single project/user pair.
  • Use PerQuintill instead of Perbill. Perbill only has 9 zeroes, and our Balance type uses 10, so we have precision problems right now, which we circumvent in tests with the new macro assert_close_enough
  • We are not explicitly testing failed bid currency refunds
  • Test bids with original price higher than weighed average are returned the difference on the community funding new_with method.
  • Failed bid return is implemented on BadMath rejection, and it needs to be implemented as well in after candle end
  • Write down test for CT sold out on remainder round. Right now it will fail because of the ensure in do_funding_end
  • Write test for PLMC unbonding on success and fail evaluation rounds
  • Extract success or fail funding logic in do_end_funding into a function to call by the issuer in case of needing a manual acceptance (certain funding thresholds)

@JuaniRios JuaniRios marked this pull request as ready for review July 19, 2023 14:39
@JuaniRios
Copy link
Contributor Author

JuaniRios commented Jul 19, 2023

  • Total bonded calculation now stored in ProjectDetails
  • StorageNmap change is reserved for another PR
  • Perbill is now PerQuintill. assert_close_enough macro is now used with 0.01 parts per billion instead of 1 part. Calculation of reward still leads to an error though
  • Failed bids due to after block end, and ct sold out are now tested for funding return
  • The possibility of checking that a final price for a bid is lower is actually there, inside BidInfoFilter.
  • CT sold out on remainder round now tested
  • Tests for PLMC evaluation unbond in success and fail funding are written, but only success passes since the failure path is unimplemented yet.
  • Extraction feedback is not clear enough, and would make sense to extract once we actually need it, so leaving it off for now.

@JuaniRios JuaniRios removed the ci-run label Jul 19, 2023
let mut consumed_weight = T::WeightInfo::insert_cleaned_project();
while !consumed_weight.any_gt(max_weight_per_project) {
if let Ok(weight) = project_finalizer.do_one_operation::<T>(project_id) {
consumed_weight += weight
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
consumed_weight += weight
consumed_weight.saturating_accrue(weight);

@JuaniRios JuaniRios removed the ci-run label Jul 21, 2023
@lrazovic lrazovic self-requested a review July 21, 2023 09:04
@lrazovic lrazovic merged commit 964b53a into main Jul 21, 2023
1 check failed
@JuaniRios JuaniRios changed the title Feature/plmc 214 finalize evaluations Evaluator Rewards Jul 21, 2023
@linear
Copy link

linear bot commented Jul 21, 2023

PLMC-214 Finalize Evaluations

Implement slashing and rewards

@lrazovic lrazovic deleted the feature/plmc-214-finalize-evaluations branch October 11, 2023 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants