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

check if at least one of the transactions satisfy existential deposit #4460

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Jpserrat
Copy link
Contributor

Closes #4242

Hey @acatangiu, created this PR as a draft. I still have to figure things out.
Is this what you had in mind?
Which error should I return in case all transactions fail?

Copy link
Contributor

@acatangiu acatangiu left a comment

Choose a reason for hiding this comment

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

yes, the approach looks good, only have implementation details comments

also, you should move this to a helper function because it needs to happen for DepositReserveAsset instruction as well as DepositAsset (it too uses does Config::AssetTransactor::deposit_asset)

@@ -825,7 +826,29 @@ impl<Config: config::Config> XcmExecutor<Config> {
let old_holding = self.holding.clone();
let result = Config::TransactionalProcessor::process(|| {
let deposited = self.holding.saturating_take(assets);
let mut all_failed = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

I would use a "mirrored" boolean for clarity, smth like:

Suggested change
let mut all_failed = true;
let mut deposit_succeeded = false;

or even better, just don't mark anything and always retry failed_deposits / failed_ed_deposits - they either work or throw some error which we will simply bubble up with ?.

@@ -825,7 +826,29 @@ impl<Config: config::Config> XcmExecutor<Config> {
let old_holding = self.holding.clone();
let result = Config::TransactionalProcessor::process(|| {
let deposited = self.holding.saturating_take(assets);
let mut all_failed = true;
let mut failed_deposits = Vec::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let mut failed_deposits = Vec::new();
let mut failed_ed_deposits = Vec::with_capacity(deposited.len());

Ok(_) => {
all_failed = false;
}
Err(_err) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to explicitly match against the error happening because of ED not satisfied. We only want to retry on that specific error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately the underlying error is lost along the way, we only get a string description.

We could either do the retry regardless of error, or match on the string description:

Suggested change
Err(_err) => {
Err(e) if matches!(e, FailedToTransactAsset("Account cannot exist with the funds that would be given")) => {

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've decided to go with retry for any error.

Comment on lines 847 to 849
if all_failed {
return Err(XcmError::FailedToTransactAsset(""))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We can simply fall through to always retry any failed ones. On second try, they either all work or not.

Suggested change
if all_failed {
return Err(XcmError::FailedToTransactAsset(""))
}

all_failed = false;
}
Err(_err) => {
// check if is not enough ED
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// check if is not enough ED
failed_ed_deposits.push(asset);

@Jpserrat Jpserrat marked this pull request as ready for review June 9, 2024 18:54
@Jpserrat Jpserrat requested a review from a team as a code owner June 9, 2024 18:54
@Jpserrat
Copy link
Contributor Author

Jpserrat commented Jun 9, 2024

@acatangiu Sorry for the long delay with this one. One last thing, I'm not sure how to do the tests for this one. What do you guys usually do with the xcm executor test?

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-clippy
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6428939

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.

[xcm] depositing multiple assets to inexistent account should work if at least one of them satisfies ED
3 participants