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

DepositAsset need failure recover of holding #912

Closed
zqhxuyuan opened this issue Nov 9, 2021 · 7 comments
Closed

DepositAsset need failure recover of holding #912

zqhxuyuan opened this issue Nov 9, 2021 · 7 comments
Labels
T6-XCM This PR/Issue is related to XCM.

Comments

@zqhxuyuan
Copy link

zqhxuyuan commented Nov 9, 2021

Current the logic of DepositAsset is first take assets from holding, then do AssetTransactor::deposit_asset(). If deposit_asset() throw Error, for example receiver not recognize token from sender, and for now it has no mechanism of recover holding, thus Config::AssetTrap would't be executed, in this case it'll cause token lossing.

I've test this case in orml: paraA transfer tokenA to paraB, and we let paraB not recognize tokenA temporary which will throw an Error. and in my test result, when execute xcm on paraB side,it will loss tokenA, this's not we wanted.

So maybe we need recover holding data when deposit_asset cause an Error. and this ability may extend to other instructions? cc @gavofyork @KiChjang

@zqhxuyuan
Copy link
Author

Ah, I found my testcase missing the Appendix which have RefundSurplus instruction inside. and RefundSurplus will refund asset in total_surplus to holding, then Config::AssetTrap can continue executed.

@KiChjang
Copy link
Contributor

KiChjang commented Nov 9, 2021

Yeah, using SetErrorHandler and combining it with RefundSurplus or DepositAsset was my instinct as well, and as you have correctly observed, RefundSurplus would also need to have a proper AssetTrap configured in order to deal with excess assets found in the holding register after XCM execution has ended.

Closing this for now, feel free to reopen if you think there's anything more that we need to address here.

@KiChjang KiChjang closed this as completed Nov 9, 2021
@zqhxuyuan
Copy link
Author

zqhxuyuan commented Nov 9, 2021

@KiChjang I've add SetAppendix(RefundSurplus) before DepositAsset, and the receiver xcm message:

Xcm([
    ReserveAssetDeposited(MultiAssets([MultiAsset { 
        id: Concrete(MultiLocation { parents: 1, interior: X2(Parachain(1), GeneralKey([65])) }), fun: Fungible(500) }])
    ), 
    ClearOrigin, 
    BuyExecution { 
        fees: MultiAsset { id: Concrete(MultiLocation { parents: 1, interior: X2(Parachain(1), GeneralKey([65])) }), fun: Fungible(500) },
        weight_limit: Limited(100) 
    }, 
    SetAppendix(Xcm([
        RefundSurplus
    ])), 
    DepositAsset { 
        assets: Wild(All), 
        max_assets: 1, 
        beneficiary: MultiLocation { parents: 0, interior: X1(AccountId32 { network: Any, id: [1111111] }) } 
	}
])

and the log shows total_surplus/refunded: 0/0 which means refund_surplus() executed without any effect on holding?
image

how can I recover the holding before execute deposit_asset() into holding again?

@KiChjang
Copy link
Contributor

KiChjang commented Nov 9, 2021

Okay, it looks like that all the error messages that deposit_asset can emit needs to accept an additional parameter to indicate the amount and the kind of asset that had errored. Without reporting the assets, there is currently no way of recovering those funds as they are neither brought back into the holding register, nor are they put into the surplus register.

@KiChjang KiChjang reopened this Nov 9, 2021
@KiChjang
Copy link
Contributor

KiChjang commented Nov 9, 2021

My instinct is telling me that the best way to handle this is to add a new "recovery register" for cases where XCM execution failed and some assets were taken from holding. Additionally, it may also be a good idea to allow the appendix or the error handler to somehow gain access to these funds and operate upon them.

@KiChjang
Copy link
Contributor

KiChjang commented Dec 24, 2021

Actually, now that I think about it, the AssetTransactor is configurable, so the recovery process is 100% controllable by the implementer. I don't think we should change the XcmError type to include the assets that errored, nor should we create a recovery register, since the XCM executor has no way of guaranteeing that the total issuance of a particular asset has unchanged -- there's nothing stopping from an AssetTransactor to keep a local record of the errored out assets and then proceeding to send the errored out assets again to the XCM executor. Such a scenario could then be exploited to increase the total issuance unwittingly, as both the AssetTransactor and the XCM executor now have and act upon the same assets that have errored.

@KiChjang
Copy link
Contributor

Closing, as this is the responsibility of the sender to ensure that the recipient handles the asset kind that's being sent over -- the recipient has no way of representing the asset otherwise.

claravanstaden pushed a commit to Snowfork/polkadot-sdk that referenced this issue Dec 8, 2023
* wait for foreign asset to be created

* rustfmt

* safety commit

* updated cumulus

* upgrade code hash

* increase block time

* completed test

* fixe usings

* remove test
helin6 pushed a commit to boolnetwork/polkadot-sdk that referenced this issue Feb 5, 2024
Bumps [ripemd](https://github.com/RustCrypto/hashes) from 0.1.1 to 0.1.3.
- [Release notes](https://github.com/RustCrypto/hashes/releases)
- [Commits](RustCrypto/hashes@ripemd-v0.1.1...ripemd-v0.1.3)

---
updated-dependencies:
- dependency-name: ripemd
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T6-XCM This PR/Issue is related to XCM.
Projects
None yet
Development

No branches or pull requests

2 participants