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

Feature/settlement rewrite #202

Merged
merged 24 commits into from Apr 2, 2024
Merged

Feature/settlement rewrite #202

merged 24 commits into from Apr 2, 2024

Conversation

vstam1
Copy link
Collaborator

@vstam1 vstam1 commented Mar 21, 2024

What?

This Pr removes the old settlement code and replaces it with new functions. This Pr makes the following big changes to the code:
Settlement:

  • All previous settlement functions are deleted and replaces with 6 new settlement functions, 3 for successful projects and 3 for failed projects, to settle an evaluation, bid or contribution.
  • For each successful project, for each eval, bid, cont -> CT tokens are minted + we calculate the correct Migration data and store this in a new storage item UserMigrations
  • All evals, bids and contributions are removed from storage once the settlement is successful.

Migrations:

  • Migrations are done per User (1 user can have a total of 48 migrations (16 Evals, 16 Bids, 16 Contributions).
  • The functions do_migrate_one_participant takes all the users Migrations and sends them over to the destination chain. The QueryId associated with the Xcm is stored in the ActiveMigrationQueue that stored QueryId -> (project_id, participant) and is used to get the correct information associated with the Query id from the UserMigrations storage.
  • UserMigrations stores for each (project, user) pair a tuple of (MigrationStatus, BoundedVec)
  • Based on the return status of the QueryId we either set the MigrationStatus to Failed or Confirmed.
  • If the migration Failed, a user can restart the Migration again.

Rest:

  • Updated the Average Price calculation logic. We do the following things:
    • Split the bids into accepted, rejected.
    • Remove Rejected bids after they have been refunded.
    • After price calculations adjust bids for either:
      • PartiallyAccepted
      • Bids with current price > weighted price
  • Remove the "in between" settlement variables from BidInfo and ContributionInfo:
    • For bids and Contributions:
      • funds_released
      • ct_minted
      • ct_migration_status
    • For evaluations:
      • rewarded_or_slashed
      • ct_migration_status
  • Removed all "Cleaner" functionalities.

Why?

To improve code maintainability and quality

How?

Testing?

  • Most tests in mod funding_end are updated
  • All the tests in CT_migrations integration test are updated

Screenshots (optional)

Anything Else?

Copy link
Contributor

@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 a preliminary review the code looks good! It is difficult to tell if the logic is 100% correct simply from the code, so I await the e2e test to do a more thorough review.

Besides tests and benchmarks, what features are missing compared to main?

pallets/funding/src/settlement.rs Outdated Show resolved Hide resolved
pallets/funding/src/settlement.rs Outdated Show resolved Hide resolved
pallets/funding/src/settlement.rs Outdated Show resolved Hide resolved
pallets/funding/src/settlement.rs Outdated Show resolved Hide resolved
pallets/funding/src/settlement.rs Outdated Show resolved Hide resolved
pallets/funding/src/functions.rs Show resolved Hide resolved
Copy link
Contributor

@JuaniRios JuaniRios left a comment

Choose a reason for hiding this comment

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

General direction seems very good.
A lot of changes were done, so I focused more on the structure than the internal logic.
A last review should be done after the PR is marked as ready.

When it's marked as ready I would like to see an in-detail description about the most important changes so we are all on the same page. Specially about the migrations. What was happening before, and how it's happening now.

pallets/funding/src/instantiator.rs Outdated Show resolved Hide resolved
pallets/funding/src/functions.rs Show resolved Hide resolved
pallets/funding/src/settlement.rs Outdated Show resolved Hide resolved
@vstam1 vstam1 marked this pull request as ready for review March 25, 2024 19:34
Copy link
Contributor

@JuaniRios JuaniRios left a comment

Choose a reason for hiding this comment

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

Really really good changes Just, well done!
It feels like we are finally transitioning from a spaghetti to a production-ready codebase.

My main request is to fix the benchmarks cause they aren't working. Try the command just dry-run-benchmarks to see what I mean.

The rest you'll see on the specific comments :)

pallets/funding/src/functions.rs Outdated Show resolved Hide resolved
pallets/funding/src/functions.rs Show resolved Hide resolved
pallets/funding/src/functions.rs Show resolved Hide resolved
pallets/funding/src/instantiator.rs Outdated Show resolved Hide resolved
pallets/funding/src/instantiator.rs Outdated Show resolved Hide resolved
pallets/funding/src/settlement.rs Outdated Show resolved Hide resolved
pallets/funding/src/settlement.rs Outdated Show resolved Hide resolved
pallets/funding/src/settlement.rs Outdated Show resolved Hide resolved
integration-tests/src/tests/ct_migration.rs Show resolved Hide resolved
integration-tests/src/tests/ct_migration.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@JuaniRios JuaniRios left a comment

Choose a reason for hiding this comment

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

Missing fixes and tests that will be addressed in future PRs, but lets merge

@vstam1 vstam1 merged commit 187ca4b into main Apr 2, 2024
@JuaniRios JuaniRios deleted the feature/settlement-rewrite branch April 4, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants