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

Asset from polkadot #1155

Merged
merged 64 commits into from
Sep 2, 2024
Merged

Asset from polkadot #1155

merged 64 commits into from
Sep 2, 2024

Conversation

yrong
Copy link
Contributor

@yrong yrong commented Mar 13, 2024

Copy link

codecov bot commented Mar 13, 2024

Codecov Report

Attention: Patch coverage is 44.58599% with 87 lines in your changes missing coverage. Please review.

Project coverage is 70.93%. Comparing base (24b9d31) to head (6efc7a1).
Report is 98 commits behind head on main.

Files with missing lines Patch % Lines
contracts/src/TokenLib.sol 23.07% 40 Missing ⚠️
contracts/src/Assets.sol 63.26% 15 Missing and 3 partials ⚠️
contracts/src/Gateway.sol 48.57% 18 Missing ⚠️
contracts/src/Token.sol 42.10% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1155      +/-   ##
==========================================
- Coverage   77.83%   70.93%   -6.90%     
==========================================
  Files          14       18       +4     
  Lines         415      609     +194     
  Branches       76      112      +36     
==========================================
+ Hits          323      432     +109     
- Misses         75      165      +90     
+ Partials       17       12       -5     
Flag Coverage Δ
solidity 70.93% <44.58%> (-6.90%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@yrong
Copy link
Contributor Author

yrong commented Mar 26, 2024

@vgeddes In 0b3344c I made the change to reuse IGateway.sendToken for polkadot native asset.

But I'd still prefer to separate as different message types internally(rename as SendForeignToken). The two branches differ in several aspects(e.g. AssetHub is not involved in SendForeignToken and the xcm constructed is different) and the separating will make the code cleaner/maintainable IMO.

@yrong
Copy link
Contributor Author

yrong commented Mar 26, 2024

Add 3 smoke tests to cover the basic flow

cargo test --test register_polkadot_token // register relay token(i.e. ROC|KSM|DOT) on Ethereum
cargo test --test transfer_polkadot_token // transfer relay token from AssetHub to Ethereum
cargo test --test send_polkadot_token // send relay token from Ethereum back to AssetHub

@yrong yrong marked this pull request as ready for review March 26, 2024 17:04
Copy link
Collaborator

@vgeddes vgeddes left a comment

Choose a reason for hiding this comment

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

Looks good! Though in retrospect, some of my previous recommendations to you were not good ideas in the end, and so I'd like you to revert those.

@@ -107,5 +109,8 @@ struct Ticket {

struct TokenInfo {
bool isRegistered;
bytes31 __padding;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to make sure that the storage layout of the old and new versions of the struct are compatible - ie. that isForeign and isRegistered are all packed into a single 32 byte slot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, could be a problem. I'd prefer a specific migration e5d9dd8

contracts/src/interfaces/IGateway.sol Outdated Show resolved Hide resolved
contracts/src/AgentExecutor.sol Outdated Show resolved Hide resolved
contracts/src/Assets.sol Outdated Show resolved Hide resolved
contracts/src/Assets.sol Outdated Show resolved Hide resolved
contracts/src/Assets.sol Outdated Show resolved Hide resolved
contracts/src/Gateway.sol Outdated Show resolved Hide resolved
contracts/src/Assets.sol Outdated Show resolved Hide resolved
contracts/src/Assets.sol Outdated Show resolved Hide resolved
contracts/src/Gateway.sol Outdated Show resolved Hide resolved
@yrong yrong changed the base branch from bridge-next-gen to main August 22, 2024 15:08
* Improve PNA implementation

* More improvents to ERC20 token

* Fix implementation of Assets._sendForeignToken

* Fix build payload for foreign token

---------

Co-authored-by: ron <[email protected]>
Copy link
Collaborator

@vgeddes vgeddes Aug 28, 2024

Choose a reason for hiding this comment

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

i think we should preserve the existing storage layout in AssetStorage.sol rather than doing a full storage migration. The gas cost of migrating storage is unbounded (many tokens registered) so that could cost a lot and introduce a lot of errors.

We can however add new fields to the end of the Layout struct in AssetStorage.sol.

Copy link
Contributor Author

@yrong yrong Aug 29, 2024

Choose a reason for hiding this comment

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

Removed the storage migration in 64b9ef4

The initial concern in #1155 (comment) is about the TokenInfo structure we changed. I'd assume it's safe to add the new foreignID without overwritten the exist storage, but not 100% sure.

From Vincent: we may need a fork testing, add a test testUpgradeGatewayForPNA that upgrades the mainnet contract, and then runs some other nested tests as a sanity check(e.g. making sure the storage layout is not corrupted after the upgrade).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yrong yrong force-pushed the ron/polkadot-assets-on-ethereum branch from 13e8c32 to cf596f3 Compare August 31, 2024 15:01
@yrong yrong merged commit 07bea54 into main Sep 2, 2024
2 checks passed
@yrong yrong deleted the ron/polkadot-assets-on-ethereum branch September 2, 2024 09:00
github-merge-queue bot pushed a commit to paritytech/polkadot-sdk that referenced this pull request Sep 13, 2024
# Description

Adding support for send polkadot native assets(PNA) to Ethereum network
through snowbridge. Asset with location in view of AH Including:

- Relay token `(1,Here)`
- Native asset `(0,[PalletInstance(instance),GenereIndex(index)])`
managed by Assets Pallet
- Native asset of Parachain `(1,[Parachain(paraId)])` managed by Foreign
Assets Pallet

The original PR in Snowfork#128
which has been internally reviewed by Snowbridge team.

# Notes

- This feature depends on the companion solidity change in
Snowfork/snowbridge#1155. Currently register PNA
is only allowed from
[sudo](https://github.com/Snowfork/polkadot-sdk/blob/46cb3528cd8cd1394af2335a6907d7ab8647717a/bridges/snowbridge/pallets/system/src/lib.rs#L621),
so it's actually not enabled. Will require another runtime upgrade to
make the call permissionless together with upgrading the Gateway
contract.

- To make things easy multi-hop transfer(i.e. sending PNA from Ethereum
through AH to Destination chain) is not support ed in this PR. For this
case user can switch to 2-phases transfer instead.

---------

Co-authored-by: Clara van Staden <[email protected]>
Co-authored-by: Alistair Singh <[email protected]>
Co-authored-by: Vincent Geddes <[email protected]>
Co-authored-by: Francisco Aguirre <[email protected]>
Co-authored-by: Adrian Catangiu <[email protected]>
vgeddes added a commit to Snowfork/polkadot-sdk that referenced this pull request Sep 13, 2024
# Description

Adding support for send polkadot native assets(PNA) to Ethereum network
through snowbridge. Asset with location in view of AH Including:

- Relay token `(1,Here)`
- Native asset `(0,[PalletInstance(instance),GenereIndex(index)])`
managed by Assets Pallet
- Native asset of Parachain `(1,[Parachain(paraId)])` managed by Foreign
Assets Pallet

The original PR in #128
which has been internally reviewed by Snowbridge team.

# Notes

- This feature depends on the companion solidity change in
Snowfork/snowbridge#1155. Currently register PNA
is only allowed from
[sudo](https://github.com/Snowfork/polkadot-sdk/blob/46cb3528cd8cd1394af2335a6907d7ab8647717a/bridges/snowbridge/pallets/system/src/lib.rs#L621),
so it's actually not enabled. Will require another runtime upgrade to
make the call permissionless together with upgrading the Gateway
contract.

- To make things easy multi-hop transfer(i.e. sending PNA from Ethereum
through AH to Destination chain) is not support ed in this PR. For this
case user can switch to 2-phases transfer instead.

---------

Co-authored-by: Clara van Staden <[email protected]>
Co-authored-by: Alistair Singh <[email protected]>
Co-authored-by: Vincent Geddes <[email protected]>
Co-authored-by: Francisco Aguirre <[email protected]>
Co-authored-by: Adrian Catangiu <[email protected]>
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