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

Feat: Core DCA #5106

Merged
merged 31 commits into from
Aug 16, 2024
Merged

Feat: Core DCA #5106

merged 31 commits into from
Aug 16, 2024

Conversation

msgmaxim
Copy link
Contributor

@msgmaxim msgmaxim commented Aug 2, 2024

Pull Request

Closes: PRO-1531, PRO-1539

Checklist

Please conduct a thorough self-review before opening the PR.

  • I am confident that the code works.
  • I have updated documentation where appropriate.

Summary

I'm hoping to merge this core functionality early so that @j4m1ef0rd could start working on this in parallel (we can/might also work on this branch ofc, but that's not ideal). This means some important features might come in separate PRs (see below).

  • The commits are mostly self contained and can be reviewed one-by-one.
  • Added dca_parameters to the request_swap_deposit_address_with_affiliates extrinsic and the the broker rpc method; the parameters are saved on the channel's actions (similarly to refund params). New migration adds None to any existing channels.
  • DCA state is stored in RequestState. Now when a swap completes, we check DCA state to see what should happen next: if the swap/chunk is successful, we either schedule the next chunk (recording output) or egress if this was the final chunk; on failure, we refund any unexecuted amount, but still egress output from any previous chunks. No migration is needed since RequestStates don't exist in 1.5.

Out of scope:

  • Configurable DCA Limits and parameter validation (PRO-1538)
  • Bouncer tests (PRO-1532)
  • Broker fee charged per chunk (PRO-1540)

Update: since this is early in review, I pushed another commit that now handles CCM too.

@msgmaxim msgmaxim requested a review from kylezs August 2, 2024 07:01
@msgmaxim msgmaxim marked this pull request as ready for review August 2, 2024 07:02
Copy link

codecov bot commented Aug 2, 2024

Codecov Report

Attention: Patch coverage is 88.27586% with 85 lines in your changes missing coverage. Please review.

Project coverage is 71%. Comparing base (be0ab82) to head (5e4bd9c).
Report is 1 commits behind head on main.

Files Patch % Lines
state-chain/pallets/cf-swapping/src/lib.rs 84% 52 Missing and 9 partials ⚠️
...cf-ingress-egress/src/migrations/add_dca_params.rs 91% 16 Missing ⚠️
state-chain/pallets/cf-ingress-egress/src/lib.rs 78% 4 Missing ⚠️
api/lib/src/lib.rs 0% 3 Missing ⚠️
state-chain/primitives/src/lib.rs 0% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #5106    +/-   ##
======================================
- Coverage     72%     71%    -0%     
======================================
  Files        453     454     +1     
  Lines      81473   81768   +295     
  Branches   81473   81768   +295     
======================================
+ Hits       58268   58451   +183     
- Misses     20111   20205    +94     
- Partials    3094    3112    +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/tests/dca.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/tests/dca.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/tests/dca.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/tests/dca.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
@msgmaxim msgmaxim changed the title Feat: Core DCA for non-ccm swaps Feat: Core DCA Aug 6, 2024
Comment on lines 73 to +74
None,
None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator

@dandanlen dandanlen left a comment

Choose a reason for hiding this comment

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

As mentioned in the previous PR, I think it's worth distinguishing more strongly between id types just for peace of mind. I've created a Linear issue PRO-1548.

state-chain/primitives/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
@dandanlen
Copy link
Collaborator

(Will continue reviewing tomorrow)

Copy link
Collaborator

@dandanlen dandanlen left a comment

Choose a reason for hiding this comment

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

Actually a few more comments here. More to follow tomorrow.

state-chain/pallets/cf-swapping/src/lib.rs Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@dandanlen dandanlen left a comment

Choose a reason for hiding this comment

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

Some more comments...

state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Show resolved Hide resolved
Copy link
Collaborator

@dandanlen dandanlen left a comment

Choose a reason for hiding this comment

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

Thanks, looking good 🚀 . I'll take a closer look at tests on Monday.

state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
@kylezs
Copy link
Contributor

kylezs commented Aug 12, 2024

Migrations / storage versions might be impacted, this PR was required because otherwise CI on main doesn't pass: #5142

Copy link
Collaborator

@dandanlen dandanlen left a comment

Choose a reason for hiding this comment

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

Test cases look fine to me. Although I feel we can do better to reduce duplication in the tests and make them more readable - they are quite verbose and repetitive (this applies to pre-existing tests too, not just the newly added ones). For example, the use of 'global' constants for test amounts etc makes things a little hard to follow.

I think it's time we added some simple extension traits with common setup/update/check methods that are used across all the swapping tests. I'll raise an issue.

Apart from that I believe the only things that needs changing is what was discussed this morning re. expiry being implicit from the FoK retry delay and number of dca chunks - I think this implies simply updating the refund params for every chunk.

state-chain/pallets/cf-swapping/src/tests/dca.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
@msgmaxim msgmaxim added this pull request to the merge queue Aug 16, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 16, 2024
@dandanlen dandanlen added this pull request to the merge queue Aug 16, 2024
Merged via the queue into main with commit f11e5cd Aug 16, 2024
48 checks passed
@dandanlen dandanlen deleted the feat/dca branch August 16, 2024 10:57
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.

5 participants