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: add connectors v2 extrinsics & inbound msg handlers #1364

Merged
merged 56 commits into from Jul 3, 2023

Conversation

wischli
Copy link
Contributor

@wischli wischli commented May 25, 2023

Description

Please note that the spec is not finalized. I marked the corresponding sections in the code with TODO(@review) and added a couple of other ones which were not crystal clear to me. Of course, this does not mean, that you reviewers should solve this issue here. It should merely raise awareness as this PR is quite large such that there's a lot of noise. In order to simplify the reviewing process, I have left a couple of notes.

As discussed, we want to solve issues such as handling Executed* messages in subsequent PRs. Thus, I have divided open tasks related to this PR into three sections: Now, either now or later and later.

Changes and Descriptions

  • Adds InvestmentCollector trait required for {Collect | Redeem}For inbound messages
    • Could also be part of Investment
  • Adds ForeignInvestment trait required to verify a given currency...
    • Is the matching currency of the given pool
    • Has pool_currency metadata enabled
  • Adds CurrencyInspect trait to enable checking whether a currency is a tranche token
  • Adds thorough integration (rather unit) tests for outgoing and incoming connectors messages
  • Fixes bug in do_collect_redeem, see commit 6158fca and this DAO Slack message for details
  • Temporarily: Disables CI for draft PRs

Open tasks connected to this PR and Connectors V2

TODOs in this PR

  • Write tests (preferably integration, otherwise using the mock-builder)
  • Rebase to main after Polkadot v0.9.38 #1332 is merged
  • Solve open questions marked by TODO(@review)

TODOs in this PR or later

TODO in other PRs

  • Changing PoolInspect trait based on this proposal
  • valid_until rework
  • Handling and tests for Executed*: Write pallet-foreign-investments which should handle the storage and dispatch of Executed* connectors messages and pallet-connectors relays the storage relevant data to pallet-foreign-investments when it executes inbound messages Decrease{Invest, Redeem}Order and Collect{Invest, Redeem}
  • Remove hard-coupling with pallet-xcm-transactor and remove/rework handle
  • E2E Tests

Checklist:

  • I have added Rust doc comments to structs, enums, traits and functions
  • I have made corresponding changes to the documentation
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works

@wischli wischli self-assigned this May 25, 2023
@wischli wischli added the I8-enhancement An additional feature. label May 25, 2023
@wischli
Copy link
Contributor Author

wischli commented Jun 29, 2023

@NunoAlexandre @mustermeiszer I have applied all requested changes and linked the corresponding commits. I would love to get a re-review soonish so we can finally get this PR merged.

@mustermeiszer
Copy link
Collaborator

Will do tonight or tomorrow!

Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Two changes we need to do IMO. Otherwise, good to go.

libs/traits/src/connectors.rs Outdated Show resolved Hide resolved
pallets/connectors/src/inbound.rs Outdated Show resolved Hide resolved
pallets/connectors/src/inbound.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
libs/traits/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@NunoAlexandre NunoAlexandre left a comment

Choose a reason for hiding this comment

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

GH tells me I left 16 comments but I think this is pretty much ready apart from Frederik's last review which are important points.

Amazing work, @wischli 💯

libs/traits/src/connectors.rs Outdated Show resolved Hide resolved
libs/traits/src/connectors.rs Outdated Show resolved Hide resolved
libs/traits/src/connectors.rs Outdated Show resolved Hide resolved
libs/traits/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

@mustermeiszer should we emit an event in such a case so that we can more easily monitor and debug those scenarios?

) -> Result<Self::Result, Self::Error> {
Pallet::<T>::do_collect_invest(who, investment_id)
.map_err(|e| e.error)
.map(|_| ())
Copy link
Contributor

Choose a reason for hiding this comment

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

@mustermeiszer shouldn't this return how much was actually collected? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, do_collect_invest would return the post dispatch weight. We might need to add the collected amount in a subsequent PR which handles the Executed* messages.

pallets/investments/src/lib.rs Show resolved Hide resolved
pallets/pool-system/src/tests/mod.rs Show resolved Hide resolved
runtime/common/src/lib.rs Show resolved Hide resolved
@mustermeiszer
Copy link
Collaborator

@mustermeiszer should we emit an event in such a case so that we can more easily monitor and debug those scenarios?

GH not showing what this is related to. Could you list it here again @NunoAlexandre ^^

@wischli
Copy link
Contributor Author

wischli commented Jun 30, 2023

GH not showing what this is related to. Could you list it here again @NunoAlexandre ^^

I also had to dig: #1364 (comment)

NunoAlexandre
NunoAlexandre previously approved these changes Jun 30, 2023
Copy link
Contributor

@NunoAlexandre NunoAlexandre left a comment

Choose a reason for hiding this comment

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

Ready to 🚢

Kudus for your work, perseverance, and patience, @wischli 🎖️

mustermeiszer
mustermeiszer previously approved these changes Jun 30, 2023
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Approve for now. Although, we got inconsistent now in naming and handling actions after hitting pallet investments...

But we will handle this in the subsequent PR so I am fine. Just noteing here for visibility.

/// decreased amount on the source domain. The dispatch of this message is
/// delayed until the execution of the investment, e.g. at least until the
/// next epoch transition.
pub fn do_decrease_invest_order(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We got really inconsistent here now. Haha.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh boy, I fully relied on search and replace without double checking 🥶 Will fix. This should not be merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I normalized all inbound handlers with the handle prefix as some prefix was required for the transfer functions.

T::ForeignInvestment::update_investment(&investor, invest_id, post_amount)?;

// Burn decreased amount
T::Tokens::burn_from(currency, &investor, amount)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we keep the burn, below we removed the transfer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, this slipped through. Will handle this.

Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

❤️

@wischli wischli enabled auto-merge (squash) June 30, 2023 14:49
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Re-approve

Copy link
Contributor

@NunoAlexandre NunoAlexandre left a comment

Choose a reason for hiding this comment

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

🤟🏻

@wischli wischli merged commit 86e6544 into main Jul 3, 2023
11 checks passed
wischli added a commit that referenced this pull request Jul 3, 2023
* refactor: move connectors codec to traits

* refactor: move TypeId for DomainAddress

* Revert "fix: remove new extrinsics"

This reverts commit 2f22dae.

* refactor: move TypeId impl for DomainLocator

* chore: add sanity checks to transfer_tranche_tokens

* wip: invest & redeem handlers

* feat: add foreign investment traits

* feat: add u128 conv for GeneralCurrencyPrefix

* refactor: normalize message codec vars

* feat: add v2 extrinsics + inbound handlers

* docs: minor inv improvements

* tests: apply add_member changes

* ci: disable on draft PRs

* feat: add CurrencyInspect trait

* feat: apply CurrencyInspect

* tests: add transfer_non_tranche_tokens

* tests: add add_currency, allow_pool_currency

* chore: finish tests, fix inbound handlers

* fix: order id storage in do_collect_redeem

* chore: various fixes and cleanups

* tests: add inbound tranche token transfer

* tests: add non tranche transfers to local

* chore: apply clippy

* Revert "ci: disable on draft PRs"

This reverts commit 9c3947d.

* fix: revert creep changes

* refactor: apply suggestions from review

* fix: apply evm meta derivation from asset

* refactor: normalize token, currency

* docs: apply suggestion from code review

* fix: cleanup

* tests: extend allow_pool_currency fails

* clippy: fix

* docs: add pallets config types

* refactor: apply suggestions from review

* refactor: rename to ConnectorsWrappedToken

* docs: improve update_asset in con tests

* fix: derive tranche decimals from registry

* refactor: investments trait

* fix: use DomainLocator

* refactor: apply suggestions from code review

* refactor: extend try_get_wrapped_token

* refactor: remove wrapped token conversions

* docs: add subsequent pr todos

* feat: add connectors queue traits

* refactor: cleanup

* refactor: rm local transfer checks

* chore: apply clippy to connectors tests

* fix: issues after rebasing

* refactor: apply suggestions from code review

* tests: fix after rebase

* fix: remove burn, normalize inbound handlers
@NunoAlexandre NunoAlexandre deleted the feat/connectors-v2-extrinsics branch July 3, 2023 09:30
wischli added a commit that referenced this pull request Jul 3, 2023
* feat: trait PoolMetadata

* fmt

* refactor: change get return type to result

* tests: add PoolMetadata

* fmt: taplo

* feat: add connectors v2 extrinsics & inbound msg handlers (#1364)

* refactor: move connectors codec to traits

* refactor: move TypeId for DomainAddress

* Revert "fix: remove new extrinsics"

This reverts commit 2f22dae.

* refactor: move TypeId impl for DomainLocator

* chore: add sanity checks to transfer_tranche_tokens

* wip: invest & redeem handlers

* feat: add foreign investment traits

* feat: add u128 conv for GeneralCurrencyPrefix

* refactor: normalize message codec vars

* feat: add v2 extrinsics + inbound handlers

* docs: minor inv improvements

* tests: apply add_member changes

* ci: disable on draft PRs

* feat: add CurrencyInspect trait

* feat: apply CurrencyInspect

* tests: add transfer_non_tranche_tokens

* tests: add add_currency, allow_pool_currency

* chore: finish tests, fix inbound handlers

* fix: order id storage in do_collect_redeem

* chore: various fixes and cleanups

* tests: add inbound tranche token transfer

* tests: add non tranche transfers to local

* chore: apply clippy

* Revert "ci: disable on draft PRs"

This reverts commit 9c3947d.

* fix: revert creep changes

* refactor: apply suggestions from review

* fix: apply evm meta derivation from asset

* refactor: normalize token, currency

* docs: apply suggestion from code review

* fix: cleanup

* tests: extend allow_pool_currency fails

* clippy: fix

* docs: add pallets config types

* refactor: apply suggestions from review

* refactor: rename to ConnectorsWrappedToken

* docs: improve update_asset in con tests

* fix: derive tranche decimals from registry

* refactor: investments trait

* fix: use DomainLocator

* refactor: apply suggestions from code review

* refactor: extend try_get_wrapped_token

* refactor: remove wrapped token conversions

* docs: add subsequent pr todos

* feat: add connectors queue traits

* refactor: cleanup

* refactor: rm local transfer checks

* chore: apply clippy to connectors tests

* fix: issues after rebasing

* refactor: apply suggestions from code review

* tests: fix after rebase

* fix: remove burn, normalize inbound handlers

* refactor: simplify trait imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I8-enhancement An additional feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants